diff --git a/server/src/uds/core/managers/UserServiceManager.py b/server/src/uds/core/managers/UserServiceManager.py index d2a77e3e3..36b5cdad1 100644 --- a/server/src/uds/core/managers/UserServiceManager.py +++ b/server/src/uds/core/managers/UserServiceManager.py @@ -51,7 +51,7 @@ import requests import json import logging -__updated__ = '2017-01-26' +__updated__ = '2017-03-22' logger = logging.getLogger(__name__) traceLogger = logging.getLogger('traceLog') @@ -472,17 +472,22 @@ class UserServiceManager(object): uService.remove() def notifyReadyFromOsManager(self, uService, data): - ui = uService.getInstance() - logger.debug('Notifying user service ready state') - state = ui.notifyReadyFromOsManager(data) - logger.debug('State: {0}'.format(state)) - uService.updateData(ui) - if state == State.FINISHED: - logger.debug('Service is now ready') - uService.save() - elif uService.state in (State.USABLE, State.PREPARING): # We don't want to get active deleting or deleted machines... - uService.setState(State.PREPARING) - UserServiceOpChecker.makeUnique(uService, ui, state) + try: + ui = uService.getInstance() + logger.debug('Notifying user service ready state') + state = ui.notifyReadyFromOsManager(data) + logger.debug('State: {0}'.format(state)) + uService.updateData(ui) + if state == State.FINISHED: + logger.debug('Service is now ready') + uService.save() + elif uService.state in (State.USABLE, State.PREPARING): # We don't want to get active deleting or deleted machines... + uService.setState(State.PREPARING) + UserServiceOpChecker.makeUnique(uService, ui, state) + except Exception as e: + logger.exception('Unhandled exception on notyfyReady: {}'.format(e)) + UserService.setState(State.ERROR) + return def getService(self, user, srcIp, idService, idTransport, doTest=True): ''' diff --git a/server/src/uds/services/OVirt/OVirtLinkedDeployment.py b/server/src/uds/services/OVirt/OVirtLinkedDeployment.py index 2a6674779..15283e904 100644 --- a/server/src/uds/services/OVirt/OVirtLinkedDeployment.py +++ b/server/src/uds/services/OVirt/OVirtLinkedDeployment.py @@ -46,6 +46,7 @@ logger = logging.getLogger(__name__) opCreate, opStart, opStop, opSuspend, opRemove, opWait, opError, opFinish, opRetry, opChangeMac = range(10) NO_MORE_NAMES = 'NO-NAME-ERROR' +UP_STATES = ('up', 'reboot_in_progress', 'powering_up', 'restoring_state') class OVirtLinkedDeployment(UserDeployment): @@ -177,7 +178,7 @@ class OVirtLinkedDeployment(UserDeployment): if state == 'unknown': return self.__error('Machine is not available anymore') - if state not in ('up', 'powering_up', 'restoring_state'): + if state not in UP_STATES: self._queue = [opStart, opFinish] return self.__executeQueue() @@ -231,7 +232,7 @@ class OVirtLinkedDeployment(UserDeployment): return self.__error('Machine not found') ret = State.RUNNING - if type(chkState) is list: + if isinstance(chkState, (list, tuple)): for cks in chkState: if state == cks: ret = State.FINISHED @@ -368,7 +369,7 @@ class OVirtLinkedDeployment(UserDeployment): if state == 'unknown': raise Exception('Machine not found') - if state in ('up',): # Already started, return + if state in UP_STATES: # Already started, return return if state != 'down' and state != 'suspended': @@ -429,7 +430,7 @@ class OVirtLinkedDeployment(UserDeployment): ''' Checks if machine has started ''' - return self.__checkMachineState('up') + return self.__checkMachineState(UP_STATES) def __checkStop(self): ''' diff --git a/server/src/uds/services/OVirt/OVirtPublication.py b/server/src/uds/services/OVirt/OVirtPublication.py index 0c98933a7..d29a66a13 100644 --- a/server/src/uds/services/OVirt/OVirtPublication.py +++ b/server/src/uds/services/OVirt/OVirtPublication.py @@ -38,7 +38,7 @@ from datetime import datetime import logging -__updated__ = '2015-05-14' +__updated__ = '2017-03-22' logger = logging.getLogger(__name__) @@ -111,7 +111,18 @@ class OVirtPublication(Publication): if self._state == 'error': return State.ERROR - self._state = self.service().getTemplateState(self._templateId) + try: + self._state = self.service().getTemplateState(self._templateId) + except Exception as e: + self._state = 'error' + self._reason = str(e) + return State.ERROR + + + if self._state == 'removed': + self._state = 'error' + self._reason = 'Template has been removed!' + return State.ERROR # If publication os done (template is ready), and cancel was requested, do it just after template becomes ready if self._state == 'ok':