Beispiel #1
0
 def test_assert_file_size(self):
     file_name = os.path.join(sh.make_temp_dir(),
                              self.id())
     sh.execute(f'echo "{self.id()}" > "{file_name}"')
     sh.assert_file_size(len(self.id()) + 1, file_name)
Beispiel #2
0
 def test_assert_file_size_when_empty(self):
     file_name = os.path.join(sh.make_temp_dir(),
                              self.id())
     sh.execute(f'touch "{file_name}"')
     sh.assert_file_size(0, file_name)
Beispiel #3
0
 def test_get_file_size(self):
     file_name = os.path.join(sh.make_temp_dir(),
                              self.id())
     sh.execute(f'echo "{self.id()}" > "{file_name}"')
     file_size = sh.get_file_size(file_name)
     self.assertEqual(len(self.id()) + 1, file_size)
Beispiel #4
0
 def test_get_file_size_when_empty(self):
     file_name = os.path.join(sh.make_temp_dir(),
                              self.id())
     sh.execute(f'touch "{file_name}"')
     file_size = sh.get_file_size(file_name)
     self.assertEqual(0, file_size)
Beispiel #5
0
 def test_python(self):
     python_version = sh.execute(['python', '--version'],
                                 ssh_client=self.stack.ssh_client).stderr
     self.assertTrue(python_version.startswith('Python 2.7'),
                     python_version)
Beispiel #6
0
 def execute(self, **kwargs):
     return sh.execute(**kwargs)
Beispiel #7
0
 def _create_bridge(self, hostname, bridges):
     for br_name in bridges:
         agent_host = topology.get_openstack_node(hostname=hostname)
         sh.execute("sudo ovs-vsctl --may-exist add-br %s" % br_name,
                    ssh_client=agent_host.ssh_client)
Beispiel #8
0
def get_rhosp_version():
    ssh_client = list_openstack_nodes(group='controller')[0].ssh_client
    rhosp_release = sh.execute('cat /etc/rhosp-release',
                               ssh_client=ssh_client).stdout
    rhosp_version = re.search(r"[0-9]*\.[0-9]*\.[0-9]*", rhosp_release)[0]
    return rhosp_version
Beispiel #9
0
    def kill_ovn_controller(self,
                            hosts: typing.Optional[typing.List[str]] = None,
                            timeout=60, interval=5):
        '''Stop OVN controller container by killing ovn-controller process
        running into it

        Docker/Podman service should restart it automatically

        :parm hosts: List of hostnames to stop agent on
        :type hosts: list of strings
        :param timeout: Time to wait OVN controller is recovered
        :type timeout: int
        :param interval: Time to wait between attempts
        :type interval: int
        '''
        hosts = hosts or self.hosts
        self.assertNotEqual([], hosts, "Host list is empty")

        if self.container_name == '':
            self.container_name = self.get_agent_container_name(
                self.agent_name)

        if not self.container_name:
            self.skipTest(f"Missing container(s): '{self.container_name}'")

        for host in hosts:
            ssh_client = topology.get_openstack_node(hostname=host).ssh_client
            pid = None
            for directory in ('ovn', 'openvswitch'):
                try:
                    pid = sh.execute(f'{self.container_runtime_name} exec '
                                     f'-uroot {self.container_name} cat '
                                     f'/run/{directory}/ovn-controller.pid',
                                     ssh_client=ssh_client,
                                     sudo=True).stdout.splitlines()[0]
                except sh.ShellCommandFailed:
                    LOG.debug(f'/run/{directory}/ovn-controller.pid cannot '
                              f'be accessed')
                else:
                    LOG.debug(f'/run/{directory}/ovn-controller.pid returned '
                              f'pid {pid}')
                    break

            self.assertIsNotNone(pid)
            LOG.debug(f'Killing process {pid} from container '
                      f'{self.container_name} on host {host}')
            sh.execute(f'{self.container_runtime_name} exec -uroot '
                       f'{self.container_name} kill {pid}',
                       ssh_client=ssh_client,
                       sudo=True)
            LOG.debug(f'Container {self.container_name} has been killed '
                      f"on host '{host}'...")
            # Schedule auto-restart of service at the end of this test case
            self.addCleanup(self.start_agent, hosts=[host, ])

            # Verify the container is restarted automatically
            for attempt in tobiko.retry(timeout=timeout, interval=interval):
                search_running_ovn_cont = (f"{self.container_runtime_name} ps "
                                           "--format '{{.Names}}'"
                                           f" -f name={self.container_name}")
                output = sh.execute(search_running_ovn_cont,
                                    ssh_client=ssh_client,
                                    sudo=True).stdout.splitlines()

                if self.container_name in output:
                    LOG.debug(f'{self.container_name} successfully restarted')
                    break
                attempt.check_limits()
Beispiel #10
0
 def test_stdout(self):
     fixture = self.fixture
     sh.execute(f"echo some text > '{fixture.temp_filename}'",
                ssh_client=fixture.ssh_client)
     line = self.fixture.process.stdout.readline()
     self.assertEqual(b'some text\n', line)
Beispiel #11
0
def stop_process(pid_list):
    """Stop (kill) a process from a list"""
    for pid in pid_list:

        LOG.info(f'stopping process with pid: {pid}')
        sh.execute(f'sudo kill -9 {pid}')
Beispiel #12
0
 def test_make_temp_dir(self):
     temp_dir = sh.make_temp_dir()
     files = sh.execute(f'ls "{temp_dir}"').stdout.splitlines()
     self.assertEqual([], files)
Beispiel #13
0
 def test_ncat_command(self):
     output = sh.execute('ncat --version',
                         ssh_client=self.stack.ssh_client).stderr.strip()
     self.assertIn('Ncat: Version', output)
     self.assertIn('https://nmap.org/ncat', output)
Beispiel #14
0
 def execute(self, **kwargs):
     kwargs.setdefault('shell', self.shell)
     kwargs.setdefault('ssh_client', self.ssh_client)
     return sh.execute(**kwargs)
Beispiel #15
0
 def _delete_bridges(self, hostname, bridges):
     for br_name in bridges:
         agent_host = topology.get_openstack_node(hostname=hostname)
         sh.execute("sudo ovs-vsctl del-br %s" % br_name,
                    ssh_client=agent_host.ssh_client)
         self.deleted_bridges[hostname].add(br_name)
Beispiel #16
0
 def test_execute_command(self):
     result = sh.execute('hostname', ssh_client=self.ssh_client)
     self.assertTrue(result.stdout.startswith('undercloud-0'))
Beispiel #17
0
def ovn_dbs_are_synchronized(test_case):
    from tobiko.tripleo import containers
    # declare commands
    runtime_name = containers.get_container_runtime_name()
    search_container_cmd = (
        "%s ps --format '{{.Names}}' -f name=ovn-dbs-bundle" % runtime_name)
    container_cmd_prefix = ('%s exec -uroot {container}' % runtime_name)
    ovndb_sync_cmd = ('ovs-appctl -t /var/run/openvswitch/{ovndb_ctl_file} '
                      'ovsdb-server/sync-status')
    ovndb_show_cmd = '{ovndb} show'
    ovndb_ctl_file_dict = {'nb': 'ovnnb_db.ctl', 'sb': 'ovnsb_db.ctl'}
    ovndb_dict = {'nb': 'ovn-nbctl', 'sb': 'ovn-sbctl'}
    expected_state_active_str = 'state: active'
    expected_state_backup_str = 'state: backup'

    # use ovn master db as a reference
    ovn_master_node_name = pacemaker.get_ovn_db_master_node()
    test_case.assertEqual(1, len(ovn_master_node_name))
    ovn_master_node = topology.get_openstack_node(ovn_master_node_name[0])
    ovn_master_dbs_show_dict = {}
    # obtained the container name
    container_name = sh.execute(search_container_cmd,
                                ssh_client=ovn_master_node.ssh_client,
                                sudo=True).stdout.splitlines()[0]
    for db in ('nb', 'sb'):
        # check its synchronization is active
        sync_cmd = (' '.join(
            (container_cmd_prefix,
             ovndb_sync_cmd)).format(container=container_name,
                                     ovndb_ctl_file=ovndb_ctl_file_dict[db]))
        sync_status = sh.execute(sync_cmd,
                                 ssh_client=ovn_master_node.ssh_client,
                                 sudo=True).stdout
        test_case.assertIn(expected_state_active_str, sync_status)
        # obtain nb and sb show output
        show_cmd = (' '.join((container_cmd_prefix,
                              ovndb_show_cmd)).format(container=container_name,
                                                      ovndb=ovndb_dict[db]))
        ovn_db_show = sh.execute(show_cmd,
                                 ssh_client=ovn_master_node.ssh_client,
                                 sudo=True).stdout
        ovn_master_dbs_show_dict[db] = build_ovn_db_show_dict(ovn_db_show)

    # ovn dbs are located on the controller nodes
    for node in topology.list_openstack_nodes(group='controller'):
        if node.name == ovn_master_node.name:
            # master node is the reference and do not need to be checked again
            continue
        container_name = sh.execute(search_container_cmd,
                                    ssh_client=node.ssh_client,
                                    sudo=True).stdout.splitlines()[0]
        # verify ovn nb and sb dbs are synchronized
        ovn_dbs_show_dict = {}
        for db in ('nb', 'sb'):
            # check its synchronization is active
            sync_cmd = (' '.join(
                (container_cmd_prefix, ovndb_sync_cmd)).format(
                    container=container_name,
                    ovndb_ctl_file=ovndb_ctl_file_dict[db]))
            sync_status = sh.execute(sync_cmd,
                                     ssh_client=node.ssh_client,
                                     sudo=True).stdout
            test_case.assertIn(expected_state_backup_str, sync_status)
            # obtain nb and sb show output
            show_cmd = (' '.join(
                (container_cmd_prefix,
                 ovndb_show_cmd)).format(container=container_name,
                                         ovndb=ovndb_dict[db]))
            ovn_db_show = sh.execute(show_cmd,
                                     ssh_client=node.ssh_client,
                                     sudo=True).stdout
            ovn_dbs_show_dict[db] = build_ovn_db_show_dict(ovn_db_show)
            test_case.assertEqual(len(ovn_dbs_show_dict[db]),
                                  len(ovn_master_dbs_show_dict[db]))
            for key in ovn_dbs_show_dict[db]:
                test_case.assertEqual(
                    sorted(ovn_dbs_show_dict[db][key]),
                    sorted(ovn_master_dbs_show_dict[db][key]))

    LOG.info("All OVN DBs are synchronized")
Beispiel #18
0
 def setUp(self):
     super().setUp()
     try:
         sh.execute('pgrep systemd')
     except sh.ShellCommandFailed:
         self.skipTest("systemd is not running")
Beispiel #19
0
 def test_python3(self):
     python_version = sh.execute(['/usr/bin/python3',
                                  '--version'],
                                 ssh_client=self.stack.ssh_client).stdout
     self.assertTrue(python_version.startswith('Python 3.'),
                     python_version)
Beispiel #20
0
def _get_undercloud_file(ssh_client, source, destination, mode):
    content = sh.execute(['cat', source], ssh_client=ssh_client).stdout
    with io.open(destination, 'wb') as fd:
        fd.write(content.encode())
    os.chmod(destination, mode)
Beispiel #21
0
def get_fqdn_from_topology_node(topology_node):
    return sh.execute("hostname -f", ssh_client=topology_node.ssh_client,
                      expect_exit_status=None).stdout.strip()