Martin Sivák has uploaded a new change for review. Change subject: Add metadata cleanup functionality ......................................................................
Add metadata cleanup functionality This patch adds a new command line arguments to the agent service. --clean and --force-clean The agent connects to vdsm, broker and storage as usual, cleans its metadata block using 0x0 bytes and quits. If the metadata block contains dirty status (crc does not match or stopped is not True) the agent reports an error and quits. The force-clean option overrides this. Change-Id: I4e0979bdfc45e7e07c9970994d98dfa1c9c94be0 Signed-off-by: Martin Sivak <[email protected]> --- M ovirt_hosted_engine_ha/agent/agent.py M ovirt_hosted_engine_ha/agent/hosted_engine.py 2 files changed, 51 insertions(+), 8 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-ha refs/changes/89/38289/1 diff --git a/ovirt_hosted_engine_ha/agent/agent.py b/ovirt_hosted_engine_ha/agent/agent.py index 1c4aec4..9ccef93 100644 --- a/ovirt_hosted_engine_ha/agent/agent.py +++ b/ovirt_hosted_engine_ha/agent/agent.py @@ -47,8 +47,19 @@ dest="daemon", help="don't start as a daemon") parser.add_option("--pdb", action="store_true", dest="pdb", help="start pdb in case of crash") + parser.add_option("--cleanup", action="store_true", + dest="cleanup", help="purge the metadata block") + parser.add_option("--force-cleanup", action="store_true", + dest="force_cleanup", help="purge the metadata block" + "even when not clean") parser.set_defaults(daemon=True) (options, args) = parser.parse_args() + + action = lambda he: he.start_monitoring() + + if options.cleanup: + options.daemon = False + action = lambda he: he.clean(options.force_cleanup) self._initialize_logging(options.daemon) self._log.info("%s started", constants.FULL_PROG_NAME) @@ -96,10 +107,10 @@ with daemon.DaemonContext(signal_map=self._get_signal_map(), files_preserve=logs): - self._run_agent() + self._run_agent(action) else: self._log.debug("Running agent in foreground") - self._run_agent() + self._run_agent(action) except Exception as e: self._log.critical("Could not start ha-agent", exc_info=True) @@ -151,13 +162,12 @@ def shutdown_requested(self): return self._shutdown - def _run_agent(self): + def _run_agent(self, action): # Only one service type for now, run it in the main thread for attempt in range(constants.AGENT_START_RETRIES): try: - hosted_engine.HostedEngine(self.shutdown_requested)\ - .start_monitoring() + action(hosted_engine.HostedEngine(self.shutdown_requested)) # if we're here, the agent stopped gracefully, # so we don't want to restart it break diff --git a/ovirt_hosted_engine_ha/agent/hosted_engine.py b/ovirt_hosted_engine_ha/agent/hosted_engine.py index a96ceb0..42b4496 100644 --- a/ovirt_hosted_engine_ha/agent/hosted_engine.py +++ b/ovirt_hosted_engine_ha/agent/hosted_engine.py @@ -297,6 +297,37 @@ self._push_to_storage(blocks) self.update_hosts_state(state) + def clean(self, force = False): + """ + Make sure the metadata storage is connected and publish + an empty record to purge the old data. + """ + self._log.debug("Connecting to ha-broker") + self._initialize_vdsm() + self._initialize_domain_monitor() + self._initialize_broker(monitors=[]) + self._initialize_sanlock() + + data = {} + + try: + data = self.collect_stats(get_local=True) + except MetadataTooNewError as ex: + self._log.exception(ex) + + try: + if data["hosts"][self.host_id].get("stopped", False) or force: + self._push_to_storage("") + else: + self._log.error("Cannot clean unclean metadata block." + " Consider --force-clean.") + except (ValueError, KeyError) as ex: + self._log.error("Metadata for current host missing.") + + self._log.debug("Disconnecting from ha-broker") + if self._broker and self._broker.is_connected(): + self._broker.disconnect() + def start_monitoring(self): error_count = 0 @@ -371,7 +402,7 @@ if self._broker and self._broker.is_connected(): self._broker.disconnect() - def _initialize_broker(self): + def _initialize_broker(self, monitors = None): if self._broker and self._broker.is_connected(): return self._log.info("Initializing ha-broker connection") @@ -383,6 +414,8 @@ except Exception as e: self._log.error("Failed to connect to ha-broker: %s", str(e)) raise + + required_monitors = monitors or self._required_monitors for m in self._required_monitors: try: @@ -755,7 +788,7 @@ self._config.get(config.ENGINE, config.HOST_ID), engine_state.data.alive_hosts) - def collect_stats(self): + def collect_stats(self, get_local = False): data = { # Flag is set if the local agent discovers metadata too new for it @@ -790,7 +823,7 @@ try: # we are not interested in stale data about local # machine - if host_id == self.host_id: + if host_id == self.host_id and not get_local: continue stats = self.process_remote_metadata(host_id, remote_data) data["hosts"][host_id] = stats -- To view, visit https://gerrit.ovirt.org/38289 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4e0979bdfc45e7e07c9970994d98dfa1c9c94be0 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-hosted-engine-ha Gerrit-Branch: master Gerrit-Owner: Martin Sivák <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
