diff --git a/software/software/deploy_host_state.py b/software/software/deploy_host_state.py index cc934a39..fb381654 100644 --- a/software/software/deploy_host_state.py +++ b/software/software/deploy_host_state.py @@ -71,19 +71,22 @@ class DeployHostState(object): def transform(self, target_state: DEPLOY_HOST_STATES): db_api = get_instance() + cur_state = self.get_deploy_host_state() db_api.begin_update() try: if self.check_transition(target_state): db_api.update_deploy_host(self._hostname, target_state) - LOG.info("Deploy host state for host %s updated to: %s" % (self._hostname, target_state.value)) - for callback in DeployHostState._callbacks: - callback(self._hostname, target_state) + msg = f"[deploy state] {self._hostname} from {cur_state.value} to {target_state.value}." + LOG.info(msg) else: - msg = "Host can not transform to %s from current state" % target_state.value + msg = f"{self._hostname} can not transform from {cur_state.value} to {target_state.value}." raise InvalidOperation(msg) finally: db_api.end_update() + for callback in DeployHostState._callbacks: + callback(self._hostname, target_state) + def deploy_started(self): state = self.get_deploy_host_state() if state in [DEPLOY_HOST_STATES.PENDING, DEPLOY_HOST_STATES.FAILED]: diff --git a/software/software/deploy_state.py b/software/software/deploy_state.py index 27946bcb..ac93f26b 100644 --- a/software/software/deploy_state.py +++ b/software/software/deploy_state.py @@ -142,12 +142,10 @@ class DeployState(object): if target_state == cur_state and cur_state in deploy_reentrant_states: return True - # TODO(bqian) reverse lookup the operation that is not permitted, as feedback - msg = f"Deploy state transform not permitted from {str(cur_state)} to {str(target_state)}" - LOG.info(msg) return False def transform(self, target_state: DEPLOY_STATES): + cur_state = DeployState.get_deploy_state() db_api = get_instance() db_api.begin_update() try: @@ -155,14 +153,17 @@ class DeployState(object): # None means not existing or deleting if target_state is not None: db_api.update_deploy(state=target_state) - LOG.info("Deploy state updated to: %s" % target_state.value) + msg = f"[deploy state] from {cur_state.value} to {target_state.value}" + LOG.info(msg) + else: + LOG.info("[deploy state] Deploy is deleted") else: # TODO(bqian) check the current state, and provide guidence on what is # the possible next operation if target_state is None: - msg = "Deployment can not deleted in current state." + msg = f"Can not delete deploy as it is {cur_state.value}." else: - msg = "Host can not transform to %s from current state" % target_state.value + msg = f"Can not transform deploy to {target_state.value} from {cur_state.value}" raise InvalidOperation(msg) finally: db_api.end_update() @@ -179,7 +180,7 @@ class DeployState(object): if isinstance(to_release, SWRelease): to_release = to_release.sw_release - msg = f"Start deploy {to_release}, current sw {from_release}" + msg = f"[deploy state] deploy ({from_release} to {to_release}) started" LOG.info(msg) db_api_instance = get_instance() db_api_instance.create_deploy(from_release, to_release, feed_repo, commit_id, reboot_required) diff --git a/software/software/software_controller.py b/software/software/software_controller.py index b1e01f14..8b608c1a 100644 --- a/software/software/software_controller.py +++ b/software/software/software_controller.py @@ -3468,6 +3468,7 @@ class PatchController(PatchService): msg_info += "Deploy deleted with success" self.db_api_instance.delete_deploy_host_all() self.db_api_instance.delete_deploy() + LOG.info("Deploy is deleted") return dict(info=msg_info, warning=msg_warning, error=msg_error) def _deploy_complete(self): @@ -3880,13 +3881,13 @@ class PatchController(PatchService): return dict(info=msg_info, warning=msg_warning, error=msg_error) @require_deploy_state([DEPLOY_STATES.START_DONE, DEPLOY_STATES.HOST, DEPLOY_STATES.HOST_FAILED], - "Current deployment ({state}) is not ready to deploy host") + "Current deployment ({state.value}) is not ready to deploy host") def software_deploy_host_api(self, hostname, force, async_req=False): return self._deploy_host(hostname, force, async_req) @require_deploy_state([DEPLOY_STATES.ACTIVATE_ROLLBACK_DONE, DEPLOY_STATES.HOST_ROLLBACK, DEPLOY_STATES.HOST_ROLLBACK_FAILED], - "Current deployment ({state}) is not ready to rollback host") + "Current deployment ({state.value}) is not ready to rollback host") def software_deploy_host_rollback_api(self, hostname, force, async_req=False): return self._deploy_host(hostname, force, async_req, rollback=True) diff --git a/software/software/software_functions.py b/software/software/software_functions.py index df614e22..6a561e09 100644 --- a/software/software/software_functions.py +++ b/software/software/software_functions.py @@ -939,8 +939,7 @@ class PatchFile(object): try: patch_sw_version = utils.get_major_release_version( - thispatch.metadata[patch_id]["sw_version"] - ) + thispatch.metadata[patch_id]["sw_version"]) abs_ostree_tar_dir = package_dir[patch_sw_version] os.remove("%s/%s-software.tar" % (abs_ostree_tar_dir, patch_id)) except Exception: