Example #1
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 #2
0
 def test_setup(self, credentials=None):
     session = keystone.KeystoneSessionFixture(credentials=credentials)
     session.setUp()
     if tobiko.is_fixture(credentials):
         credentials = tobiko.get_fixture(credentials)
         self.assertIs(credentials.credentials, session.credentials)
     else:
         self.assertIs(credentials or DEFAULT_CREDENTIALS,
                       session.credentials)
Example #3
0
 def check_stack_template(self, stack, template):
     expected_template = template or type(stack).template
     if tobiko.is_fixture(expected_template):
         self.assertIs(expected_template, stack.template)
     elif isinstance(expected_template, collections.Mapping):
         self.assertEqual(expected_template, stack.template.template)
     else:
         message = "Unsupported template type: {!r}".format(
             expected_template)
         self.fail(message)
Example #4
0
def podman_client(obj=None):
    if obj is None:
        obj = get_podman_client()

    if tobiko.is_fixture(obj):
        obj = tobiko.setup_fixture(obj).client

    if isinstance(obj, PODMAN_CLIENT_CLASSES):
        return obj

    raise TypeError('Cannot obtain a Podman client from {!r}'.format(obj))
Example #5
0
def keystone_session(obj):
    if not obj:
        return default_keystone_session()
    if tobiko.is_fixture(obj):
        obj = tobiko.get_fixture(obj)
        if isinstance(obj, KeystoneSessionFixture):
            obj = tobiko.setup_fixture(obj).session
    if isinstance(obj, _session.Session):
        return obj
    raise TypeError("Can't get {!r} object from {!r}".format(
        _session.Session, obj))
Example #6
0
 def test_setup(self, session=None):
     client = self.create_client(session=session)
     client.setUp()
     if session:
         if tobiko.is_fixture(session):
             if inspect.isclass(session):
                 session = tobiko.get_fixture(session)
             self.assertIs(session.session, client.session)
         else:
             self.assertIs(session, client.session)
     else:
         self.assertIs(keystone.get_keystone_session(), client.session)
Example #7
0
def get_keystone_credentials(obj: KeystoneCredentialsType = None) -> \
        typing.Optional[KeystoneCredentials]:
    if obj is None:
        return default_keystone_credentials()
    if isinstance(obj, KeystoneCredentials):
        return obj
    if tobiko.is_fixture(obj):
        obj = tobiko.get_fixture(obj)
        if isinstance(obj, KeystoneCredentialsFixture):
            obj = tobiko.setup_fixture(obj).credentials
            return get_keystone_credentials(obj)
    raise TypeError(f"Can't get {KeystoneCredentials} object from {obj}")
Example #8
0
def get_keystone_credentials(obj=None):
    if not obj:
        return default_keystone_credentials()
    if tobiko.is_fixture(obj):
        obj = tobiko.get_fixture(obj)
        if isinstance(obj, KeystoneCredentialsFixture):
            obj = tobiko.setup_fixture(obj).credentials
    if isinstance(obj, KeystoneCredentials):
        return obj

    message = "Can't get {!r} object from {!r}".format(KeystoneCredentials,
                                                       obj)
    raise TypeError(message)
Example #9
0
    def get_client(self, session=None, shared=True, init_client=None):
        if shared:
            if session and tobiko.is_fixture(session):
                key = tobiko.get_fixture_name(session)
            else:
                key = session

            client = self.clients.get(key)
            if client:
                return client

        init_client = init_client or self.create_client
        assert callable(init_client)
        LOG.debug('Initialize OpenStack client: %r(session=%r)', init_client,
                  session)
        client = init_client(session=session)

        if shared:
            self.clients[key] = client
        return client
Example #10
0
def glance_client(obj=None):
    obj = obj or default_glance_client()
    if tobiko.is_fixture(obj):
        obj = tobiko.setup_fixture(obj).client
    return tobiko.check_valid_type(obj, glanceclient.Client)
Example #11
0
 def get_shared_session(self, credentials):
     if tobiko.is_fixture(credentials):
         key = tobiko.get_fixture_name(credentials)
     else:
         key = credentials
     return key, self.sessions.get(key)