示例#1
0
 def test_wait_with_timeout(self):
     # assume there are always to be running processes on host
     process = sh.list_processes(pid=1, **self.parameters).unique
     ex = self.assertRaises(sh.PsWaitTimeout, process.wait, timeout=3.)
     self.assertEqual(3., ex.timeout)
     self.assertEqual(sh.get_hostname(ssh_client=self.ssh_client),
                      ex.hostname)
示例#2
0
    def is_destroyed(self, pid, command_filter, hostname):
        '''Check if process has been terminated

        :param pid: Process ID to check if exist and handles specific command
        :type pid: int
        :param command_filter: Patter to be found in process command details
        :type command_filter: string
        :param hostname: Hostname of the node to look for PID on
        :type hostname: string
        '''
        host = topology.get_openstack_node(hostname=hostname)
        processes = sh.list_processes(ssh_client=host.ssh_client)
        process = processes.with_attributes(pid=pid)
        process_destroyed = False
        if not process:
            LOG.debug(f'No PID {pid} has been found in process list')
            process_destroyed = True
        else:
            try:
                command = sh.execute(f'cat /proc/{pid}/cmdline',
                                     ssh_client=host.ssh_client)
                if command_filter not in command.stdout:
                    LOG.debug(f'Different process with same PID {pid} exist')
                    process_destroyed = True
            except sh.ShellCommandFailed:
                LOG.debug(f'Process {pid} has been terminated right after the'
                          f' process list has been collected')
                process_destroyed = True
        return process_destroyed
示例#3
0
 def test_wait_for_processes(self):
     # assume the PID of the first execution of PS process is not more there
     # at the second execution
     process = sh.list_processes(command='ps', **self.parameters).first
     sh.wait_for_processes(pid=process.pid,
                           command='ps',
                           timeout=30.,
                           **self.parameters)
示例#4
0
 def test_list_processes_with_command_line(self):
     cat_process = sh.process('cat -', ssh_client=self.ssh_client).execute()
     self.addCleanup(cat_process.kill)
     processes = sh.list_processes(command_line='cat -', **self.parameters)
     for process in processes:
         self.assertEqual('cat', process.command)
         self.assertEqual(('cat', '-'), process.command_line)
     cat_process.kill()
     sh.wait_for_processes(command_line='cat -',
                           timeout=30.,
                           **self.parameters)
示例#5
0
def list_nodes_processes(command: str = None,
                         command_line: sh.ShellCommandType = None,
                         hostnames: typing.Iterable[str] = None,
                         topology: _topology.OpenStackTopology = None,
                         **list_processes_params) \
        -> tobiko.Selection[sh.PsProcess]:
    processes = tobiko.Selection[sh.PsProcess]()
    nodes = _topology.list_openstack_nodes(topology=topology,
                                           hostnames=hostnames)
    for node in nodes:
        processes += sh.list_processes(command=command,
                                       command_line=command_line,
                                       ssh_client=node.ssh_client,
                                       **list_processes_params)
    return processes
示例#6
0
def list_docker_urls(
        ssh_client: ssh.SSHClientType,
        sudo=False) \
        -> typing.List[str]:
    urls = []
    try:
        processes = sh.list_processes(command='^dockerd',
                                      ssh_client=ssh_client,
                                      sudo=sudo)
    except sh.PsError as ex:
        raise _exception.DockerUrlNotFoundError(
            "Docker demon is not running") from ex

    for process in processes:
        if process.command_line:
            urls += urls_from_command_line(process.command_line)
    urls = list(collections.OrderedDict.fromkeys(urls))
    return urls
示例#7
0
    def list_pids(self, host, command_filter, process_name):
        '''Search for PIDs matched with filter and process name

        :param host: Hostname of the node to search processes on
        :type host: string
        :param command_filter: Regex to be found in process command details
        :type command_filter: string
        :param process_name: Name of the executable in process list
        :type process_name: string
        '''
        ssh_client = topology.get_openstack_node(hostname=host).ssh_client
        processes = sh.list_processes(command=process_name,
                                      ssh_client=ssh_client)
        pids = []
        for process in processes:
            try:
                command = sh.execute(f'cat /proc/{process.pid}/cmdline',
                                     ssh_client=ssh_client)
                if re.search(command_filter, command.stdout):
                    pids.append(process.pid)
            except sh.ShellCommandFailed:
                LOG.debug(f'Process {process.pid} has been terminated right '
                          f'after the process list has been collected')
        return pids
示例#8
0
 def test_list_processes_with_exact_command(self):
     processes = sh.list_processes(command='^systemd$', **self.parameters)
     self.assertEqual(processes.with_attributes(command='systemd'),
                      processes)
示例#9
0
 def test_list_processes_with_command(self):
     processes = sh.list_processes(command='systemd', **self.parameters)
     for process in processes:
         self.assertTrue(process.command.startswith('systemd'), process)
示例#10
0
 def test_list_processes_with_pid(self):
     processes = sh.list_processes(**self.parameters)
     processes_with_pid = sh.list_processes(pid=processes[0].pid,
                                            **self.parameters)
     self.assertEqual(processes[:1], processes_with_pid)
示例#11
0
 def test_list_processes(self):
     processes = sh.list_processes(**self.parameters)
     self._check_processes(processes, is_kernel=False)
示例#12
0
 def test_wait(self):
     process = sh.list_processes(command='ps', **self.parameters).first
     process.wait()