Example #1
0
 def create_process(self):
     tobiko.setup_fixture(self.path_execute)
     parameters = self.parameters
     args = self.command
     stdin = parameters.stdin and subprocess.PIPE or None
     stdout = parameters.stdout and subprocess.PIPE or None
     stderr = parameters.stderr and subprocess.PIPE or None
     env = merge_dictionaries(os.environ, parameters.environment)
     try:
         return subprocess.Popen(args=args,
                                 bufsize=parameters.buffer_size,
                                 shell=False,
                                 universal_newlines=False,
                                 env=env,
                                 cwd=parameters.current_dir,
                                 stdin=stdin,
                                 stdout=stdout,
                                 stderr=stderr)
     except FileNotFoundError as ex:
         LOG.debug(f"Error executing local command: args={args}")
         raise _exception.ShellCommandFailed(command=self.command,
                                             exit_status=-1,
                                             stdin=parameters.stdin,
                                             stdout=None,
                                             stderr=str(ex)) from ex
Example #2
0
def get_nova_client(session=None, shared=True, init_client=None,
                    manager=None) -> NovaClient:
    manager = manager or CLIENTS
    client = manager.get_client(session=session, shared=shared,
                                init_client=init_client)
    tobiko.setup_fixture(client)
    return client.client
Example #3
0
 def setup_ssh_client(self):
     ssh_client = self.ssh_client
     if ssh_client is None:
         self.ssh_client = ssh_client = ssh.ssh_proxy_client() or False
         if ssh_client:
             tobiko.setup_fixture(ssh_client)
     return ssh_client
Example #4
0
 def ensure_server(self, status='ACTIVE'):
     try:
         server_id: str = self.stack.server_id
         nova.get_server(server_id=server_id)
     except heat.HeatStackNotFound:
         tobiko.setup_fixture(self.stack)
     except nova.ServerNotFoundError:
         tobiko.reset_fixture(self.stack)
     return self.stack.ensure_server_status(status=status)
Example #5
0
 def found_lines(self) \
         -> typing.List[typing.Tuple[str, str]]:
     # ensure diggers are ready before looking for lines
     tobiko.setup_fixture(self)
     lines: typing.List[typing.Tuple[str, str]] = []
     if self.diggers is not None:
         for hostname, digger in self.diggers.items():
             for line in digger.found_lines:
                 lines.append((hostname, line))
     return lines
Example #6
0
 def test_get_fixture_with_fixture_id_1(self):
     fixture_0 = tobiko.get_fixture(MyStack)
     fixture_1 = tobiko.get_fixture(MyStack, fixture_id=1)
     self.assertIsNot(fixture_0, fixture_1)
     stack_0 = tobiko.setup_fixture(fixture_0).get_stack()
     stack_1 = tobiko.setup_fixture(fixture_1).get_stack()
     self.assertNotEqual(stack_0.id, stack_1.id)
     self.assertEqual(tobiko.get_fixture_name(MyStack), stack_0.stack_name)
     self.assertEqual(
         tobiko.get_fixture_name(MyStack) + '-1', stack_1.stack_name)
Example #7
0
    def test_setup_with_empty_cloud_name(self):
        file_fixture = self.useFixture(V2CloudsFileFixture())
        credentials_fixture = keystone.CloudsFileKeystoneCredentialsFixture(
            clouds_file=file_fixture.clouds_file, cloud_name='')

        self.assertIsNone(credentials_fixture.credentials)
        self.assertEqual('', credentials_fixture.cloud_name)
        tobiko.setup_fixture(credentials_fixture)
        self.assertIsNone(credentials_fixture.credentials)
        self.assertEqual('', credentials_fixture.cloud_name)
Example #8
0
def reboot_host(ssh_client: ssh.SSHClientFixture,
                wait: bool = True,
                timeout: tobiko.Seconds = None,
                method: RebootHostMethod = RebootHostMethod.SOFT):
    reboot = RebootHostOperation(ssh_client=ssh_client,
                                 timeout=timeout,
                                 method=method)
    tobiko.setup_fixture(reboot)
    if wait:
        reboot.wait_for_operation()
    return reboot
Example #9
0
def get_designate_client(session=None,
                         shared=True,
                         init_client=None,
                         manager: DesignateClientManager = None) \
        -> client.Client:
    manager = manager or CLIENTS
    fixture = manager.get_client(session=session,
                                 shared=shared,
                                 init_client=init_client)
    tobiko.setup_fixture(fixture)
    return fixture.client
Example #10
0
    def test_setup_with_no_cloud_name(self):
        self.patch(self.config, 'cloud_name', None)

        file_fixture = self.useFixture(V2CloudsFileFixture())
        credentials_fixture = keystone.CloudsFileKeystoneCredentialsFixture(
            clouds_file=file_fixture.clouds_file)

        self.assertIsNone(credentials_fixture.credentials)
        self.assertIsNone(credentials_fixture.cloud_name)
        tobiko.setup_fixture(credentials_fixture)
        self.assertIsNone(credentials_fixture.credentials)
        self.assertIsNone(credentials_fixture.cloud_name)
Example #11
0
def keystone_client(obj: KeystoneClientType) -> KeystoneClient:
    if obj is None:
        return get_keystone_client()

    if isinstance(obj, CLIENT_CLASSES):
        return obj

    fixture = tobiko.setup_fixture(obj)
    if isinstance(fixture, KeystoneClientFixture):
        return tobiko.setup_fixture(obj).client

    raise TypeError(f"Object {obj} is not a KeystoneClientFixture")
Example #12
0
    def test_setup_with_empty_cloud_name_from_env(self):
        self.patch(self.config, 'cloud_name', None)

        file_fixture = self.useFixture(V2CloudsFileFixture())
        self.patch(os, 'environ', {'OS_CLOUD': ''})
        credentials_fixture = keystone.CloudsFileKeystoneCredentialsFixture(
            clouds_file=file_fixture.clouds_file)

        self.assertIsNone(credentials_fixture.credentials)
        self.assertIsNone(credentials_fixture.cloud_name)
        tobiko.setup_fixture(credentials_fixture)
        self.assertIsNone(credentials_fixture.credentials)
        self.assertIsNone(credentials_fixture.cloud_name)
Example #13
0
 def run(cls, after: bool, **params):
     fixture = tobiko.get_fixture(cls)
     params.setdefault('passive_checks_only', False)
     params.setdefault('skip_mac_table_size_test', True)
     skips = frozenset(k for k, v in params.items() if v)
     if after or skips < fixture.skips:
         # Force re-check
         tobiko.cleanup_fixture(fixture)
     else:
         LOG.info("Will skip Overcloud health checks if already "
                  f"executed: {params}")
     fixture.skips = skips
     tobiko.setup_fixture(fixture)
Example #14
0
 def find_lines(self,
                pattern: str = None,
                new_lines: bool = False) \
         -> typing.List[typing.Tuple[str, str]]:
     # ensure diggers are ready before looking for lines
     tobiko.setup_fixture(self)
     lines: typing.List[typing.Tuple[str, str]] = []
     if self.diggers is not None:
         for hostname, digger in self.diggers.items():
             for line in digger.find_lines(pattern=pattern,
                                           new_lines=new_lines):
                 lines.append((hostname, line))
     return lines
Example #15
0
 def run_playbook(self,
                  command: sh.ShellCommand = None,
                  playbook: str = None,
                  playbook_dirname: str = None,
                  playbook_filename: str = None,
                  inventory_filename: str = None,
                  vars_files: typing.Iterable[str] = None):
     tobiko.setup_fixture(self)
     command = self._get_command(command=command,
                                 playbook=playbook,
                                 playbook_dirname=playbook_dirname,
                                 playbook_filename=playbook_filename,
                                 inventory_filename=inventory_filename,
                                 vars_files=vars_files)
     return self.sh_connection.execute(command, current_dir=self.work_dir)
Example #16
0
 def setup_fixtures(self, stream=None):
     stream = stream or sys.stdout
     test_cases = self.discover_testcases()
     success = True
     for fixture_name in tobiko.list_required_fixtures(test_cases):
         output = fixture_name + '\n'
         if six.PY2:
             output = output.decode()
         stream.write(output)
         try:
             tobiko.setup_fixture(fixture_name)
         except Exception:
             LOG.exception('Fixture %r setup failed', fixture_name)
             success = False
     if not success:
         sys.exit(1)
Example #17
0
    def get_forwarder(self, address, ssh_client):
        try:
            return self.forwarders[address, ssh_client]
        except KeyError:
            pass

        if ssh_client:
            tobiko.check_valid_type(ssh_client, _client.SSHClientFixture)
            forwarder = SSHTunnelForwarderFixture(ssh_client=ssh_client)
            forwarder.put_forwarding(address)
            tobiko.setup_fixture(forwarder)
        else:
            forwarder = None

        self.forwarders[address, ssh_client] = forwarder
        return forwarder
Example #18
0
def default_nameservers(
        ip_version: typing.Optional[int] = None) -> \
        tobiko.Selection[netaddr.IPAddress]:
    nameservers = tobiko.setup_fixture(DEFAULT_NAMESERVERS_FIXTURE).nameservers
    if ip_version is not None:
        nameservers = nameservers.with_attributes(version=ip_version)
    return nameservers
Example #19
0
def ansible_playbook_manager(manager: 'AnsiblePlaybookManager' = None) -> \
        'AnsiblePlaybookManager':
    if manager is None:
        return tobiko.setup_fixture(AnsiblePlaybookManager)
    else:
        tobiko.check_valid_type(manager, AnsiblePlaybookManager)
        return manager
Example #20
0
 def _setup_shell_connection(ssh_client: ssh.SSHClientFixture = None) \
         -> 'ShellConnection':
     if ssh_client is None:
         return local_shell_connection()
     else:
         return tobiko.setup_fixture(SSHShellConnection(
             ssh_client=ssh_client))
Example #21
0
 def create_process(self):
     tobiko.setup_fixture(self.path_execute)
     parameters = self.parameters
     args = self.command
     stdin = parameters.stdin and subprocess.PIPE or None
     stdout = parameters.stdout and subprocess.PIPE or None
     stderr = parameters.stderr and subprocess.PIPE or None
     env = merge_dictionaries(os.environ, parameters.environment)
     return subprocess.Popen(args=args,
                             bufsize=parameters.buffer_size,
                             shell=False,
                             universal_newlines=False,
                             env=env,
                             cwd=parameters.current_dir,
                             stdin=stdin,
                             stdout=stdout,
                             stderr=stderr)
Example #22
0
def docker_client(obj=None):
    if obj is None:
        obj = get_docker_client()
    if tobiko.is_fixture(obj):
        obj = tobiko.setup_fixture(obj).client
    if isinstance(obj, docker.DockerClient):
        return obj
    raise TypeError('Cannot obtain a DockerClient from {!r}'.format(obj))
Example #23
0
def get_keystone_session(credentials=None,
                         shared=True,
                         init_session=None,
                         manager=None):
    manager = manager or SESSIONS
    session = manager.get_session(credentials=credentials,
                                  shared=shared,
                                  init_session=init_session)
    return tobiko.setup_fixture(session).session
Example #24
0
def setup_tobiko_config(conf):
    # Redirect all warnings to logging library
    logging.captureWarnings(True)
    warnings_logger = log.getLogger('py.warnings')
    if conf.debug:
        if not warnings_logger.isEnabledFor(log.WARNING):
            # Print Python warnings
            warnings_logger.logger.setLevel(log.WARNING)
    elif warnings_logger.isEnabledFor(log.WARNING):
        # Silence Python warnings
        warnings_logger.logger.setLevel(log.ERROR)

    tobiko.setup_fixture(HttpProxyFixture)

    for module_name in CONFIG_MODULES:
        module = importlib.import_module(module_name)
        if hasattr(module, 'setup_tobiko_config'):
            module.setup_tobiko_config(conf=conf)
Example #25
0
def get_heat_client(session=None,
                    shared=True,
                    init_client=None,
                    manager=None) -> HeatClient:
    manager = manager or CLIENTS
    fixture = manager.get_client(session=session,
                                 shared=shared,
                                 init_client=init_client)
    return tobiko.setup_fixture(fixture).client
Example #26
0
 def basic_overcloud_services_running(self):
     """
     Checks that the oc_services dataframe has all of the list services
     running
     :return: Bool
     """
     tobiko.setup_fixture(self)
     for service_name in self.services_to_check:
         if not self.oc_services_df.query('UNIT=="{}"'.format(
                 service_name)).empty:
             LOG.info("overcloud processes status checks: process {} is  "
                      "in running state".format(service_name))
             continue
         else:
             LOG.info("Failure : overcloud processes status checks: "
                      "process {} is not running ".format(service_name))
             raise OvercloudServiceException()
     return True
Example #27
0
def get_openstack_topology(topology_class: typing.Type = None) -> \
        OpenStackTopology:
    if topology_class:
        if not issubclass(topology_class, OpenStackTopology):
            raise TypeError(f"'{topology_class}' is not subclass of "
                            f"'{OpenStackTopology}'")
    else:
        topology_class = get_default_openstack_topology_class()
    return tobiko.setup_fixture(topology_class)
Example #28
0
def overcloud_host_config(hostname=None,
                          ip_version=None,
                          network_name=None,
                          server=None):
    host_config = OvercloudHostConfig(host=hostname,
                                      ip_version=ip_version,
                                      network_name=network_name,
                                      server=server)
    return tobiko.setup_fixture(host_config)
Example #29
0
async def setup_actor(obj: ActorType,
                      fixture_id: typing.Optional[str] = None,
                      manager=None,
                      timeout: tobiko.Seconds = None) -> _actor.ActorRef[A]:
    actor = tobiko.setup_fixture(obj,
                                 fixture_id=fixture_id,
                                 manager=manager)
    await asyncio.wait_for(actor.setup_actor_future,
                           timeout=timeout)
    return actor.ref
Example #30
0
def create_floating_ip(floating_network_id=None, client=None, **params):
    if floating_network_id is None:
        from tobiko.openstack import stacks
        floating_network_id = tobiko.setup_fixture(
            stacks.FloatingNetworkStackFixture).external_id
    if floating_network_id is not None:
        params['floating_network_id'] = floating_network_id
    floating_ip = neutron_client(client).create_floatingip(
        body={'floatingip': params})
    return floating_ip['floatingip']