From ddc2699774d98a90f0e3cf16b8cb5374f55cb347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Thu, 26 Dec 2019 11:54:55 +0100 Subject: [PATCH] Fixed oVirt jobs & aasigned an unused worker --- server/src/uds/core/workers/assigned_unused.py | 4 ++-- server/src/uds/services/OVirt/jobs.py | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/server/src/uds/core/workers/assigned_unused.py b/server/src/uds/core/workers/assigned_unused.py index 86b0d6eb..88543bed 100644 --- a/server/src/uds/core/workers/assigned_unused.py +++ b/server/src/uds/core/workers/assigned_unused.py @@ -45,8 +45,8 @@ class AssignedAndUnused(Job): # frecuency_cfg = GlobalConfig.CHECK_UNUSED_TIME friendly_name = 'Unused services checker' - def run(self): - since_state = getSqlDatetime() - timedelta(seconds=GlobalConfig.CHECK_UNUSED_TIME) + def run(self) -> None: + since_state = getSqlDatetime() - timedelta(seconds=GlobalConfig.CHECK_UNUSED_TIME.getInt()) for ds in ServicePool.objects.all(): # Skips checking deployed services in maintenance mode or ignores assigned and unused if ds.isInMaintenance() is True or ds.ignores_unused: diff --git a/server/src/uds/services/OVirt/jobs.py b/server/src/uds/services/OVirt/jobs.py index 6cd60254..55365911 100644 --- a/server/src/uds/services/OVirt/jobs.py +++ b/server/src/uds/services/OVirt/jobs.py @@ -34,6 +34,8 @@ import typing from uds.core import jobs +from uds.models import Provider + # Not imported at runtime, just for type checking if typing.TYPE_CHECKING: from .provider import OVirtProvider @@ -75,21 +77,21 @@ class OVirtDeferredRemoval(jobs.Job): except Exception as e: logger.warning('Exception got queuing for Removal: %s', e) - def run(self): + def run(self) -> None: from .provider import OVirtProvider logger.debug('Looking for deferred vm removals') - provider: OVirtProvider + provider: Provider # Look for Providers of type VCServiceProvider - for provider in OVirtProvider.objects.filter(maintenance_mode=False, data_type=OVirtProvider.typeType): + for provider in Provider.objects.filter(maintenance_mode=False, data_type=OVirtProvider.typeType): logger.debug('Provider %s if os type ovirt', provider) storage = provider.getEnvironment().storage - instance = provider.getInstance() + instance: OVirtProvider = typing.cast(OVirtProvider, provider.getInstance()) for i in storage.filter('tRm'): - vmId = i[1] + vmId = i[1].decode() try: logger.debug('Found %s for removal %s', vmId, i) # If machine is powered on, tries to stop it @@ -105,7 +107,7 @@ class OVirtDeferredRemoval(jobs.Job): # It this is reached, remove check storage.remove('tr' + vmId) except Exception as e: # Any other exception wil be threated again - instance.doLog('Delayed removal of %s has failed: %s. Will retry later', vmId, e) + # instance.doLog('Delayed removal of %s has failed: %s. Will retry later', vmId, e) logger.error('Delayed removal of %s failed: %s', i, e) logger.debug('Deferred removal finished')