def run_once(self): sig = getattr(signal, self.config['listen_signal']) dkrcmd = AsyncDockerCmd(self, 'run', self.sub_stuff['subargs'], timeout=self.config['docker_timeout']) self.logdebug("Starting background docker command, " "timeout %s seconds: " "%s", self.config['docker_timeout'], dkrcmd.command) dkrcmd.verbose = True # Runs in background self.sub_stuff['dkrcmd'] = dkrcmd dkrcmd.execute() pid = dkrcmd.process_id ss = self.config['secret_sauce'] while True: stdout = dkrcmd.stdout if stdout.count(ss) >= 1: break time.sleep(0.1) wait_start = self.config['wait_start'] self.loginfo("Container running, waiting %d seconds to send signal" % wait_start) # Allow noticable time difference for date command, # and eat into dkrcmd timeout after receiving signal. time.sleep(wait_start) self.failif(not utils.pid_is_alive(pid), "Pid %s not running after wait: %s" % (pid, dkrcmd.exit_status)) self.loginfo("Signaling pid %d with signal %s", pid, self.config['listen_signal']) utils.signal_pid(pid, sig) self.loginfo("Waiting up to %d seconds for exit", dkrcmd.timeout) # Throw exception if takes > docker_timeout to exit dkrcmd.wait()
def signal_program(program_name, sig=signal.SIGTERM, pid_files_dir=None): """ Sends a signal to the process listed in <program_name>.pid @param program_name the name of the program @param sig signal to send """ pid = get_pid_from_file(program_name, pid_files_dir) if pid: utils.signal_pid(pid, sig)
def cleanup(self): super(stop_base, self).cleanup() # In case of internal failure the running container might not finish. container_cmd = self.sub_stuff.get('container_cmd') if container_cmd and not container_cmd.done: utils.signal_pid(container_cmd.process_id, 15) if not container_cmd.done: utils.signal_pid(container_cmd.process_id, 9) if (self.config.get('remove_after_test') and self.sub_stuff.get('container_name')): args = ['--force', '--volumes', self.sub_stuff['container_name']] OutputGood(DockerCmd(self, 'rm', args).execute())
def run_once(self): super(psa, self).run_once() self.wait_start() self.loginfo("Container running, waiting %d seconds to examine" % self.config['wait_start']) time.sleep(self.config['wait_start']) self.logdebug("Post-wait status: %s", self.stuff['dkrcmd']) dc = self.stuff['dc'] self.stuff['cl1'] = dc.list_containers() sig = getattr(signal, 'SIGUSR1') self.loginfo("Signaling container with signal %s", sig) json = dc.json_by_name(self.stuff['container_name']) self.failif( not json[0]["State"]["Running"], "Can't signal non-running container, see debug " "log for more detail") pid = int(json[0]["State"]["Pid"]) self.failif( not utils.signal_pid(pid, sig), "Failed to cause container exit with signal: " "still running, see debug log for more detail.") self.loginfo("Waiting up to %d seconds for exit", self.config['wait_stop']) self.stuff['cmdresult'] = self.stuff['dkrcmd'].wait( self.config['wait_stop']) self.stuff['cl2'] = dc.list_containers()
def cleanup(self): super(stop_base, self).cleanup() # In case of internal failure the running container might not finish. container_cmd = self.sub_stuff.get('container_cmd') if container_cmd and not container_cmd.done: utils.signal_pid(container_cmd.process_id, 15) if not container_cmd.done: utils.signal_pid(container_cmd.process_id, 9) if (self.config.get('remove_after_test') and self.sub_stuff.get('container_name')): args = ['--force', '--volumes', self.sub_stuff['container_name']] cmdrslt = DockerCmd(self, 'rm', args).execute() if cmdrslt.exit_status != 0: if 'No such container' not in cmdrslt.stderr: self.logwarning("Unable to remove docker container: %s ", cmdrslt.stderr)
def cleanup(self): super(sigproxy_base, self).cleanup() # In case of internal failure the running container might not finish. failures = [] container_cmd = self.sub_stuff.get('container_cmd') # container_cmd might be temporarily NoFailDockerCmd if (container_cmd and hasattr(container_cmd, 'done') and not container_cmd.done): utils.signal_pid(container_cmd.process_id, 15) if not container_cmd.done: utils.signal_pid(container_cmd.process_id, 9) if self.sub_stuff.get('container_name'): args = ['--force', '--volumes', self.sub_stuff['container_name']] try: NoFailDockerCmd(self, 'rm', args).execute() except DockerExecError, details: failures.append("Remove after test failed: %s" % details)
def signal_container(self, name): dc = self.sub_stuff["dc"] sig = getattr(signal, self.config["listen_signal"]) self.loginfo("Signaling container %s with %s(%d)", name, self.config["listen_signal"], sig) json = dc.json_by_name(name) self.failif( not json[0]["State"]["Running"], "Can't signal non-running container, see debug " "log for more detail" ) pid = int(json[0]["State"]["Pid"]) self.failif( not utils.signal_pid(pid, sig), "Failed to cause container exit with signal: " "still running, see debug log for more detail.", )
def run_once(self): super(run_base, self).run_once() # Prints out basic info sig = getattr(signal, self.config['listen_signal']) dkrcmd = AsyncDockerCmd(self.parent_subtest, 'run', self.sub_stuff['subargs'], timeout=self.config['docker_timeout']) # Runs in background self.sub_stuff['cmdresult'] = dkrcmd.execute() pid = dkrcmd.process_id self.loginfo("Container running, waiting %d seconds to send signal" % self.config['wait_start']) # Allow noticable time difference for date command, # and eat into dkrcmd timeout after receiving signal. time.sleep(self.config['wait_start']) self.loginfo("Signaling pid %d with signal %s", pid, self.config['listen_signal']) utils.signal_pid(pid, sig) self.loginfo("Waiting up to %d seconds for exit", dkrcmd.timeout) # Throw exception if takes > docker_timeout to exit dkrcmd.wait()
def signal_container(self, name): dc = self.sub_stuff['dc'] sig = getattr(signal, self.config['listen_signal']) self.loginfo("Signaling container %s with %s(%d)", name, self.config['listen_signal'], sig) json = dc.json_by_name(name) self.failif( not json[0]["State"]["Running"], "Can't signal non-running container, see debug " "log for more detail") pid = int(json[0]["State"]["Pid"]) self.failif( not utils.signal_pid(pid, sig), "Failed to cause container exit with signal: " "still running, see debug log for more detail.")
def run_once(self): super(psa, self).run_once() self.wait_start() self.loginfo("Container running, waiting %d seconds to examine" % self.config['wait_start']) time.sleep(self.config['wait_start']) self.logdebug("Post-wait status: %s", self.stuff['dkrcmd']) dc = self.stuff['dc'] self.stuff['cl1'] = dc.list_containers() sig = getattr(signal, 'SIGUSR1') self.loginfo("Signaling container with signal %s", sig) json = dc.json_by_name(self.stuff['container_name']) self.failif(not json[0]["State"]["Running"], "Can't signal non-running container, see debug " "log for more detail") pid = int(json[0]["State"]["Pid"]) self.failif(not utils.signal_pid(pid, sig), "Failed to cause container exit with signal: " "still running, see debug log for more detail.") self.loginfo("Waiting up to %d seconds for exit", self.config['wait_stop']) self.stuff['cmdresult'] = self.stuff['dkrcmd'].wait( self.config['wait_stop']) self.stuff['cl2'] = dc.list_containers()