def action_four(): """An action which raises an CallbackAfterResponse""" def action_four_callback(): return 'action_four_called_back' raise CallbackAfterResponse('result', action_four_callback)
def restart_agent(): def _shutdown(): daemon_log.info("Restarting iml-storage-server.target") # Use subprocess.Popen instead of try_run because we don't want to # wait for completion. subprocess.Popen(["systemctl", "restart", "iml-storage-server.target"]) raise CallbackAfterResponse(None, _shutdown)
def restart_agent(): def _shutdown(): daemon_log.info("Restarting agent") # Use subprocess.Popen instead of try_run because we don't want to # wait for completion. subprocess.Popen(['service', 'chroma-agent', 'restart']) raise CallbackAfterResponse(None, _shutdown)
def reboot_server(at_time="now"): def _reboot(): console_log.info("Initiating server reboot per manager request") # reboot(8) just calls shutdown anyhow. AgentShell.try_run(["shutdown", "-r", at_time]) console_log.info("Terminating") os._exit(0) raise CallbackAfterResponse(None, _reboot)
def shutdown_server(halt=True, at_time="now"): def _shutdown(): console_log.info("Initiating server shutdown per manager request") # This will initiate a "nice" shutdown with a wall from root, etc. AgentShell.try_run(["shutdown", "-H" if halt else "-h", at_time]) console_log.info("Terminating") os._exit(0) raise CallbackAfterResponse(None, _shutdown)
def deregister_server(): config.delete('settings', 'server') def disable_and_kill(): console_log.info("Disabling chroma-agent service") _disable_service() console_log.info("Terminating") os._exit(0) raise CallbackAfterResponse(None, disable_and_kill)
def deregister_server(): conf.remove_server_url() def disable_and_kill(): console_log.info("Terminating") storage_server_target = ServiceControl.create('iml-storage-server.target') storage_server_target.disable() storage_server_target.stop() raise CallbackAfterResponse(None, disable_and_kill)
def run(self, cmd, agent_daemon_context, kwargs): # This is a little hackish: we don't actually separate the thread_state for # each simulated agent (they mostly don't even shell out when simulated) but # do this to avoid the subprocess log building up indefinitely. AgentShell.thread_state = ResultStore() log.debug("FakeActionPlugins: %s %s" % (cmd, kwargs)) with self._lock: if cmd == 'device_plugin': device_plugins = FakeDevicePlugins(self._server) if kwargs['plugin']: return { kwargs['plugin']: device_plugins.get( kwargs['plugin'])(None).start_session() } else: data = {} for plugin, klass in device_plugins.get_plugins().items(): data[plugin] = klass(None).start_session() return data elif cmd in [ 'configure_ntp', 'unconfigure_ntp', 'unconfigure_corosync', 'unconfigure_corosync2', 'initialise_block_device_drivers' ]: return agent_result_ok elif cmd == 'deregister_server': sim = self._simulator server = self._server class StopServer(threading.Thread): def run(self): sim.stop_server(server.fqdn) def kill(): server.crypto.delete() # Got to go and run stop_server in another thread, because it will try # to join all the agent threads (including the one that is running this # callback) StopServer().start() raise CallbackAfterResponse(None, kill) elif cmd == 'shutdown_server': server = self._server def _shutdown(): server.shutdown(simulate_shutdown=True) raise CallbackAfterResponse(None, _shutdown) elif cmd == 'reboot_server': server = self._server def _reboot(): server.shutdown(simulate_shutdown=True, reboot=True) raise CallbackAfterResponse(None, _reboot) elif cmd == 'failover_target': self._server._cluster.failover(kwargs['ha_label']) return agent_result_ok elif cmd == 'failback_target': self._server._cluster.failback(kwargs['ha_label']) return agent_result_ok elif cmd == 'set_conf_param': self._server.set_conf_param(kwargs['key'], kwargs.get('value', None)) elif cmd in [ 'configure_pacemaker', 'unconfigure_pacemaker', 'enable_pacemaker', 'configure_target_store', 'unconfigure_target_store', 'configure_repo' ]: return elif cmd == 'kernel_status': return { 'running': 'fake_kernel-0.1', 'required': 'fake_kernel-0.1', 'available': ['fake_kernel-0.1'] } elif cmd in ['configure_fencing', 'unconfigure_fencing']: # This shouldn't happen if the fence reconfiguration logic # is working. Good to simulate a failure here in case of # regressions, though. if self._server.is_worker: raise PacemakerConfigurationError() return elif cmd == "host_corosync_config": return {} elif cmd == 'mount_lustre_filesystems': for mountspec, mountpoint in kwargs['filesystems']: self._server.add_client_mount(mountspec, mountpoint) elif cmd == 'unmount_lustre_filesystems': for mountspec, _ in kwargs['filesystems']: self._server.del_client_mount(mountspec) elif cmd == 'configure_copytool': self._simulator.configure_hsm_copytool(self._server, **kwargs) elif cmd == 'unconfigure_copytool': self._simulator.unconfigure_hsm_copytool(kwargs['id']) elif cmd == 'start_monitored_copytool': self._simulator.start_monitored_copytool( self._server, kwargs['id']) elif cmd == 'stop_monitored_copytool': self._simulator.stop_monitored_copytool(kwargs['id']) else: try: fn = getattr(self._server, cmd) except AttributeError: raise RuntimeError("Unknown command %s" % cmd) else: return fn(**kwargs)
def action_four(): """An action which raises an CallbackAfterResponse""" def action_four_callback(): return "action_four_called_back" raise CallbackAfterResponse("result", action_four_callback)
def restart_agent(self): def _restart(): # FIXME: don't actually want to simulate_shutdown but otherwise it tries to join from the current thread self.shutdown(simulate_shutdown=True, reboot=True) raise CallbackAfterResponse(None, _restart)