mirror of
https://github.com/dkmstr/openuds.git
synced 2025-03-11 00:58:39 +03:00
Some minor fixes
This commit is contained in:
parent
9defc46083
commit
77e7df76bf
@ -131,7 +131,14 @@ class UserService(Environmentable, Serializable):
|
||||
|
||||
_db_obj: typing.Optional['models.UserService'] = None
|
||||
|
||||
def __init__(self, environment: 'Environment', **kwargs):
|
||||
def __init__(
|
||||
self,
|
||||
environment: 'Environment',
|
||||
service: 'services.Service',
|
||||
publication: typing.Optional['services.Publication'] = None,
|
||||
osmanager: typing.Optional['osmanagers.OSManager'] = None,
|
||||
uuid: str = '',
|
||||
):
|
||||
"""
|
||||
Do not forget to invoke this in your derived class using "super(self.__class__, self).__init__(environment, **kwargs)"
|
||||
We want to use the env, service and storage methods outside class. If not called, you must implement your own methods
|
||||
@ -151,10 +158,10 @@ class UserService(Environmentable, Serializable):
|
||||
"""
|
||||
Environmentable.__init__(self, environment)
|
||||
Serializable.__init__(self)
|
||||
self._service = kwargs['service'] # Raises an exception if service is not included. Parent
|
||||
self._publication = kwargs.get('publication', None)
|
||||
self._osmanager = kwargs.get('osmanager', None)
|
||||
self._uuid = kwargs.get('uuid', '')
|
||||
self._service = service
|
||||
self._publication = publication
|
||||
self._osmanager = osmanager
|
||||
self._uuid = uuid
|
||||
|
||||
self.initialize()
|
||||
|
||||
|
@ -250,5 +250,5 @@ class ProxmoxFixedService(FixedService): # pylint: disable=too-many-public-meth
|
||||
self._save_assigned_machines(self._get_assigned_machines() - {str(vmid)}) # Remove from assigned
|
||||
return types.states.State.FINISHED
|
||||
except Exception as e:
|
||||
logger.warn('Cound not save assigned machines on fixed pool: %s', e)
|
||||
logger.warning('Cound not save assigned machines on fixed pool: %s', e)
|
||||
raise
|
||||
|
@ -64,6 +64,7 @@ class XenFixedUserService(FixedUserService, autoserializable.AutoSerializable):
|
||||
|
||||
# : Recheck every ten seconds by default (for task methods)
|
||||
suggested_delay = 4
|
||||
|
||||
# Utility overrides for type checking...
|
||||
def service(self) -> 'service_fixed.XenFixedService':
|
||||
return typing.cast('service_fixed.XenFixedService', super().service())
|
||||
@ -97,7 +98,7 @@ class XenFixedUserService(FixedUserService, autoserializable.AutoSerializable):
|
||||
def error(self, reason: str) -> str:
|
||||
return self._error(reason)
|
||||
|
||||
def _start_machine(self) -> str:
|
||||
def _start_machine(self) -> None:
|
||||
try:
|
||||
state = self.service().get_machine_power_state(self._vmid)
|
||||
except Exception as e:
|
||||
@ -106,9 +107,7 @@ class XenFixedUserService(FixedUserService, autoserializable.AutoSerializable):
|
||||
if state != xen_client.XenPowerState.running:
|
||||
self._task = self.service().start_machine(self._vmid) or ''
|
||||
|
||||
return State.RUNNING
|
||||
|
||||
def _stop_machine(self) -> str:
|
||||
def _stop_machine(self) -> None:
|
||||
try:
|
||||
state = self.service().get_machine_power_state(self._vmid)
|
||||
except Exception as e:
|
||||
@ -118,8 +117,6 @@ class XenFixedUserService(FixedUserService, autoserializable.AutoSerializable):
|
||||
logger.debug('Stopping machine %s', self._vmid)
|
||||
self._task = self.service().stop_machine(self._vmid) or ''
|
||||
|
||||
return State.RUNNING
|
||||
|
||||
# Check methods
|
||||
def _check_task_finished(self) -> str:
|
||||
if self._task == '':
|
||||
|
@ -271,8 +271,10 @@ class XenFixedService(FixedService): # pylint: disable=too-many-public-methods
|
||||
def get_machine_name(self, vmid: str) -> str:
|
||||
return self.parent().get_machine_name(vmid)
|
||||
|
||||
def remove_and_free_machine(self, vmid: str) -> None:
|
||||
def remove_and_free_machine(self, vmid: str) -> str:
|
||||
try:
|
||||
self._save_assigned_machines(self._get_assigned_machines() - {str(vmid)}) # Remove from assigned
|
||||
return types.states.State.FINISHED
|
||||
except Exception as e:
|
||||
logger.warn('Cound not save assigned machines on fixed pool: %s', e)
|
||||
logger.warning('Cound not save assigned machines on fixed pool: %s', e)
|
||||
raise
|
||||
|
@ -33,7 +33,7 @@ try:
|
||||
wreg.SetValueEx(key, sp['ip'], 0, wreg.REG_DWORD, 255) # type: ignore
|
||||
wreg.CloseKey(key) # type: ignore
|
||||
except Exception as e: # nosec: Not really interested in the exception
|
||||
# logger.warn('Exception fixing redirection dialog: %s', e)
|
||||
# logger.warning('Exception fixing redirection dialog: %s', e)
|
||||
pass # Key does not exists, ok...
|
||||
|
||||
# The password must be encoded, to be included in a .rdp file, as 'UTF-16LE' before protecting (CtrpyProtectData) it in order to work with mstsc
|
||||
|
@ -37,7 +37,7 @@ try:
|
||||
wreg.SetValueEx(key, '127.0.0.1', 0, wreg.REG_DWORD, 255) # type: ignore
|
||||
wreg.CloseKey(key) # type: ignore
|
||||
except Exception as e: # nosec: Not really interested in the exception
|
||||
# logger.warn('Exception fixing redirection dialog: %s', e)
|
||||
# logger.warning('Exception fixing redirection dialog: %s', e)
|
||||
pass # Key does not exists, but it's ok
|
||||
|
||||
# The password must be encoded, to be included in a .rdp file, as 'UTF-16LE' before protecting (CtrpyProtectData) it in order to work with mstsc
|
||||
|
@ -38,7 +38,13 @@ from uds.core.services.specializations.fixed_machine import fixed_service, fixed
|
||||
|
||||
|
||||
class FixedServiceTest(UDSTestCase):
|
||||
pass
|
||||
def create_elements(self) -> tuple['FixedProvider', 'FixedService', 'FixedUserService']:
|
||||
environment = self.create_environment()
|
||||
prov = FixedProvider(environment=environment)
|
||||
service = FixedService(environment=environment, parent=prov)
|
||||
user_service = FixedUserService(environment=environment, service=service)
|
||||
|
||||
return prov, service, user_service
|
||||
|
||||
|
||||
class FixedUserService(fixed_userservice.FixedUserService):
|
||||
@ -67,6 +73,10 @@ class FixedUserService(fixed_userservice.FixedUserService):
|
||||
|
||||
|
||||
class FixedService(fixed_service.FixedService):
|
||||
type_name = 'Fixed Service'
|
||||
type_type = 'FixedService'
|
||||
type_description = 'Fixed Service description'
|
||||
|
||||
token = fixed_service.FixedService.token
|
||||
snapshot_type = fixed_service.FixedService.snapshot_type
|
||||
machines = fixed_service.FixedService.machines
|
||||
@ -119,4 +129,8 @@ class FixedService(fixed_service.FixedService):
|
||||
|
||||
|
||||
class FixedProvider(services.provider.ServiceProvider):
|
||||
type_name = 'Fixed Provider'
|
||||
type_type = 'FixedProvider'
|
||||
type_description = 'Fixed Provider description'
|
||||
|
||||
offers = [FixedService]
|
||||
|
@ -36,6 +36,7 @@ from django.test import TestCase, TransactionTestCase
|
||||
from django.test.client import Client, AsyncClient # type: ignore # Pylance does not know about AsyncClient, but it is there
|
||||
from django.http.response import HttpResponse
|
||||
from django.conf import settings
|
||||
from uds.core.environment import Environment
|
||||
|
||||
from uds.core.managers.crypto import CryptoManager
|
||||
|
||||
@ -250,6 +251,8 @@ class UDSTestCase(UDSTestCaseMixin, TestCase):
|
||||
super().setUpClass()
|
||||
setupClass(cls) # The one local to this module
|
||||
|
||||
def create_environment(self) -> Environment:
|
||||
return Environment.testing_environment()
|
||||
|
||||
class UDSTransactionTestCase(UDSTestCaseMixin, TransactionTestCase):
|
||||
@classmethod
|
||||
|
Loading…
x
Reference in New Issue
Block a user