Exemplo n.º 1
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)
Exemplo n.º 2
0
    def test_init(self,
                  fixture_class=MyStack,
                  stack_name=None,
                  template=None,
                  parameters=None,
                  wait_interval=None,
                  client=None):
        stack = fixture_class(stack_name=stack_name,
                              template=template,
                              parameters=parameters,
                              wait_interval=wait_interval,
                              client=client)

        self.assertEqual(
            stack_name or fixture_class.stack_name
            or tobiko.get_fixture_name(stack), stack.stack_name)

        self.check_stack_template(stack=stack, template=template)

        self.assertIsInstance(stack.parameters,
                              _stack.HeatStackParametersFixture)
        self.assertEqual(
            parameters or getattr(fixture_class.parameters, 'parameters', {}),
            stack.parameters.parameters)
        self.assertEqual(wait_interval or fixture_class.wait_interval,
                         stack.wait_interval)
        self.assertIs(client or fixture_class.client, stack.client)
Exemplo n.º 3
0
 def test_get_stack(self):
     self.stack.wait_for_create_complete()
     stack = self.stack.get_stack()
     self.assertIsNotNone(stack)
     self.assertEqual(tobiko.get_fixture_name(MyStack), stack.stack_name)
     self.assertIsInstance(stack.id, str)
     self.assertIsInstance(stack.stack_status, str)
Exemplo n.º 4
0
 def test_servers_creation(self):
     all_servers_ids = {server.id for server in nova.list_servers()}
     stacks = tests.test_servers_creation()
     self.assertEqual(2, len(stacks))
     pid = os.getpid()
     for i, stack in enumerate(stacks):
         self.assertIsInstance(stack, tests.TestServerCreationStack)
         class_name = tobiko.get_fixture_name(tests.TestServerCreationStack)
         self.assertEqual(f"{class_name}-{pid}-{i}", stack.stack_name)
         self.assertNotIn(stack.server_id, all_servers_ids)
         self.assertEqual('ACTIVE', nova.get_server(stack.server_id).status)
Exemplo n.º 5
0
class AfterOperationsTest(OperationTest):

    patch_environ = {
        'TOBIKO_AFTER_OPERATIONS': tobiko.get_fixture_name(Operation)
    }

    expect_after_operations = {tobiko.get_operation_name(Operation)}

    def test_operation_config(self):
        config = tobiko.operation_config()
        self.assertFalse(config.run_operations)
        self.assertEqual(self.expect_after_operations,
                         config.after_operations)
Exemplo n.º 6
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
Exemplo n.º 7
0
    def get_credentials(self) -> typing.Optional[KeystoneCredentials]:
        errors = []
        for fixture in self.fixtures:
            try:
                credentials = tobiko.setup_fixture(fixture).credentials
            except Exception as ex:
                LOG.debug("Error getting credentials from %r: %s",
                          tobiko.get_fixture_name(fixture), ex)
                errors.append(tobiko.exc_info())
                continue

            if credentials:
                LOG.info("Got default credentials from fixture %r: %r",
                         fixture, credentials)
                return credentials
            else:
                LOG.debug('Got no credentials from %r', fixture)

        if len(errors) == 1:
            errors[0].reraise()
        elif errors:
            raise testtools.MultipleExceptions(errors)

        raise NoSuchCredentialsError(fixtures=self.fixtures)
Exemplo n.º 8
0
 def actor_name(self) -> str:
     return tobiko.get_fixture_name(self)
Exemplo n.º 9
0
 def test_with_instance(self):
     fixture = MyFixture()
     result = tobiko.get_fixture_name(fixture)
     self.assertEqual(canonical_name(MyFixture), result)
Exemplo n.º 10
0
 def zone_name(self) -> str:
     return tobiko.get_fixture_name(self).lower() + '.'
Exemplo n.º 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)