def _import_callback(self, deployment_id, bundle_id, future): """Callback called when a deployment process is completed. This callback, scheduled in self.import_bundle(), receives the deployment_id identifying one specific deployment job, and the fired future returned by the executor. """ if future.cancelled(): # Notify a deployment has been cancelled. self._observer.notify_cancelled(deployment_id) success = False else: error = None success = True exception = future.exception() if exception is not None: error = utils.message_from_error(exception) success = False # Notify a deployment completed. self._observer.notify_completed(deployment_id, error=error) # Remove the completed deployment job from the queue. self._queue.remove(deployment_id) del self._futures[deployment_id] # Notify the new position of all remaining deployments in the queue. for position, deploy_id in enumerate(self._queue): self._observer.notify_position(deploy_id, position) # Increment the Charmworld deployment count upon successful # deployment. if success and bundle_id is not None: utils.increment_deployment_counter( bundle_id, self._charmworldurl)
def _import_callback(self, deployment_id, bundle_id, future): """Callback called when a deployment process is completed. This callback, scheduled in self.import_bundle(), receives the deployment_id identifying one specific deployment job, and the fired future returned by the executor. """ if future.cancelled(): # Notify a deployment has been cancelled. self._observer.notify_cancelled(deployment_id) success = False else: error = None success = True exception = future.exception() if exception is not None: error = utils.message_from_error(exception) success = False # Notify a deployment completed. self._observer.notify_completed(deployment_id, error=error) # Remove the completed deployment job from the queue. self._queue.remove(deployment_id) del self._futures[deployment_id] # Notify the new position of all remaining deployments in the queue. for position, deploy_id in enumerate(self._queue): self._observer.notify_position(deploy_id, position) # Increment the Charmworld deployment count upon successful # deployment. if success and bundle_id is not None: utils.increment_deployment_counter(bundle_id, self._charmworldurl)
def test_with_message(self): # The error message is logged and returned. expected_type = "error type: <type 'exceptions.ValueError'>" expected_message = 'error message: bad wolf' with ExpectLog('', expected_type, required=True): with ExpectLog('', expected_message, required=True): error = utils.message_from_error(ValueError('bad wolf')) self.assertEqual('bad wolf', error)
def test_without_message(self): # A placeholder message is returned. expected_type = "error type: <type 'exceptions.SystemExit'>" expected_message = 'empty error message' with ExpectLog('', expected_type, required=True): with ExpectLog('', expected_message, required=True): error = utils.message_from_error(SystemExit()) self.assertEqual('no further details can be provided', error)
def test_env_error_extracted(self): # An EnvError as returned from the Go environment is not suitable for # display to the user. The Error field is extracted and returned. expected_type = "error type: <class 'jujuclient.EnvError'>" expected_message = 'error message: cannot parse json' with ExpectLog('', expected_type, required=True): with ExpectLog('', expected_message, required=True): exception = EnvError({'Error': 'cannot parse json'}) error = utils.message_from_error(exception) self.assertEqual('cannot parse json', error)