Ejemplo n.º 1
0
 def test_with_alternate_context(self):
     context1 = magnum_context.RequestContext('foo', 'foo')
     context2 = magnum_context.RequestContext('bar', project_id='alternate')
     obj = MyObj.query(context1)
     obj.update_test(context2)
     self.assertEqual('alternate-context', obj.bar)
     self.assertRemotes()
Ejemplo n.º 2
0
    def test_upgrade_cluster_as_admin(self):
        token_info = {
            'token': {
                'project': {
                    'id': 'fake_project_1'
                },
                'user': {
                    'id': 'fake_user_1'
                }
            }
        }
        user_context = magnum_context.RequestContext(
            auth_token_info=token_info,
            project_id='fake_project_1',
            user_id='fake_user_1',
            is_admin=False)
        cluster_uuid = uuidutils.generate_uuid()
        cluster_template_uuid = uuidutils.generate_uuid()
        obj_utils.create_test_cluster_template(user_context,
                                               public=True,
                                               uuid=cluster_template_uuid)
        obj_utils.create_test_cluster(
            user_context,
            uuid=cluster_uuid,
            cluster_template_id=cluster_template_uuid)

        cluster_upgrade_req = {"cluster_template": "test_2"}
        self.context.is_admin = True
        response = self.post_json(
            '/clusters/%s/actions/upgrade' % cluster_uuid,
            cluster_upgrade_req,
            headers={"Openstack-Api-Version": "container-infra 1.8"})

        self.assertEqual(202, response.status_int)
Ejemplo n.º 3
0
 def test_check_is_admin_with_admin_context_succeeds(self):
     ctx = magnum_context.RequestContext(user='******',
                                         project_id='test-project-id',
                                         is_admin=True)
     # explicitly set admin role as this test checks for admin role
     # with the policy engine
     ctx.roles = ['admin']
     self.assertTrue(policy.check_is_admin(ctx))
Ejemplo n.º 4
0
        def make_context(*args, **kwargs):
            # If context hasn't been constructed with token_info
            if not kwargs.get('auth_token_info'):
                kwargs['auth_token_info'] = copy.deepcopy(token_info)
            if not kwargs.get('project_id'):
                kwargs['project_id'] = 'fake_project'
            if not kwargs.get('user_id'):
                kwargs['user_id'] = 'fake_user'

            context = magnum_context.RequestContext(*args, **kwargs)
            return magnum_context.RequestContext.from_dict(context.to_dict())
Ejemplo n.º 5
0
    def setUp(self):
        super(TestCase, self).setUp()
        token_info = {
            'token': {
                'project': {
                    'id': 'fake_project'
                },
                'user': {
                    'id': 'fake_user'
                }
            }
        }
        self.context = magnum_context.RequestContext(
            auth_token_info=token_info,
            project_id='fake_project',
            user_id='fake_user')

        self.policy = self.useFixture(policy_fixture.PolicyFixture())

        self.useFixture(
            fixtures.MockPatchObject(oslo_messaging, 'Notifier',
                                     fake_notifier.FakeNotifier))
        self.addCleanup(fake_notifier.reset)

        def make_context(*args, **kwargs):
            # If context hasn't been constructed with token_info
            if not kwargs.get('auth_token_info'):
                kwargs['auth_token_info'] = copy.deepcopy(token_info)
            if not kwargs.get('project_id'):
                kwargs['project_id'] = 'fake_project'
            if not kwargs.get('user_id'):
                kwargs['user_id'] = 'fake_user'

            context = magnum_context.RequestContext(*args, **kwargs)
            return magnum_context.RequestContext.from_dict(context.to_dict())

        p = mock.patch.object(magnum_context,
                              'make_context',
                              side_effect=make_context)
        self.mock_make_context = p.start()
        self.addCleanup(p.stop)

        self.useFixture(conf_fixture.ConfFixture())
        self.useFixture(fixtures.NestedTempfile())

        self._base_test_obj_backup = copy.copy(
            objects_base.MagnumObjectRegistry._registry._obj_classes)
        self.addCleanup(self._restore_obj_registry)

        def reset_pecan():
            pecan.set_config({}, overwrite=True)

        self.addCleanup(reset_pecan)
Ejemplo n.º 6
0
 def _create_context(self, roles=None):
     return magnum_context.RequestContext(auth_token='auth_token1',
                                          auth_url='auth_url1',
                                          domain_id='domain_id1',
                                          domain_name='domain_name1',
                                          user_name='user1',
                                          user_id='user-id1',
                                          project_name='tenant1',
                                          project_id='tenant-id1',
                                          roles=roles,
                                          is_admin=True,
                                          read_only=True,
                                          show_deleted=True,
                                          request_id='request_id1',
                                          trust_id='trust_id1',
                                          auth_token_info='token_info1')
Ejemplo n.º 7
0
    def setUp(self):
        super(TestCase, self).setUp()
        self.app = testing.load_test_app(
            os.path.join(os.path.dirname(__file__), 'config.py'))
        token_info = {
            'token': {
                'project': {
                    'id': 'fake_project'
                },
                'user': {
                    'id': 'fake_user'
                }
            }
        }
        self.context = magnum_context.RequestContext(
            auth_token_info=token_info,
            project_id='fake_project',
            user_id='fake_user')

        def make_context(*args, **kwargs):
            # If context hasn't been constructed with token_info
            if not kwargs.get('auth_token_info'):
                kwargs['auth_token_info'] = copy.deepcopy(token_info)
            if not kwargs.get('project_id'):
                kwargs['project_id'] = 'fake_project'
            if not kwargs.get('user_id'):
                kwargs['user_id'] = 'fake_user'

            context = magnum_context.RequestContext(*args, **kwargs)
            return magnum_context.RequestContext.from_dict(context.to_dict())

        p = mock.patch.object(magnum_context,
                              'make_context',
                              side_effect=make_context)
        self.mock_make_context = p.start()
        self.addCleanup(p.stop)

        self.useFixture(conf_fixture.ConfFixture(cfg.CONF))

        self._base_test_obj_backup = copy.copy(
            objects_base.MagnumObject._obj_classes)
        self.addCleanup(self._restore_obj_registry)
Ejemplo n.º 8
0
 def test_check_is_admin_with_user_context_fails(self):
     ctx = magnum_context.RequestContext(user='******',
                                         project_id='test-project-id')
     # there is no admin role set in the context, so check_is_admin
     # should return False
     self.assertFalse(policy.check_is_admin(ctx))
Ejemplo n.º 9
0
def get_admin_clients():
    global _ADMIN_OSC
    if not _ADMIN_OSC:
        _ADMIN_OSC = clients.OpenStackClients(
            context.RequestContext(is_admin=True))
    return _ADMIN_OSC
Ejemplo n.º 10
0
def dummy_context(user='******', project_id='test_tenant_id'):
    return magnum_context.RequestContext(user=user, project_id=project_id)
Ejemplo n.º 11
0
    def setUp(self):
        super(TestCase, self).setUp()
        token_info = {
            'token': {
                'project': {
                    'id': 'fake_project'
                },
                'user': {
                    'id': 'fake_user'
                }
            }
        }

        trustee_domain_id = '12345678-9012-3456-7890-123456789abc'

        self.context = magnum_context.RequestContext(
            auth_token_info=token_info,
            project_id='fake_project',
            user_id='fake_user',
            is_admin=False)

        self.global_mocks = {}

        self.keystone_client = magnum_keystone.KeystoneClientV3(self.context)

        self.policy = self.useFixture(policy_fixture.PolicyFixture())

        self.output = self.useFixture(output_fixture.OutputStreamCapture())

        self.useFixture(fixtures.MockPatchObject(
            oslo_messaging, 'Notifier',
            fake_notifier.FakeNotifier))
        self.addCleanup(fake_notifier.reset)

        def make_context(*args, **kwargs):
            # If context hasn't been constructed with token_info
            if not kwargs.get('auth_token_info'):
                kwargs['auth_token_info'] = copy.deepcopy(token_info)
            if not kwargs.get('project_id'):
                kwargs['project_id'] = 'fake_project'
            if not kwargs.get('user_id'):
                kwargs['user_id'] = 'fake_user'
            if not kwargs.get('is_admin'):
                kwargs['is_admin'] = False

            context = magnum_context.RequestContext(*args, **kwargs)
            return magnum_context.RequestContext.from_dict(context.to_dict())

        p = mock.patch.object(magnum_context, 'make_context',
                              side_effect=make_context)

        self.global_mocks['magnum.common.context.make_context'] = p

        q = mock.patch.object(magnum_keystone.KeystoneClientV3,
                              'trustee_domain_id',
                              return_value=trustee_domain_id)

        self.global_mocks[
            'magnum.common.keystone.KeystoneClientV3.trustee_domain_id'] = q

        self.mock_make_context = p.start()
        self.addCleanup(p.stop)

        self.mock_make_trustee_domain_id = q.start()
        self.addCleanup(q.stop)

        self.useFixture(conf_fixture.ConfFixture())
        self.useFixture(fixtures.NestedTempfile())

        self._base_test_obj_backup = copy.copy(
            objects_base.MagnumObjectRegistry._registry._obj_classes)
        self.addCleanup(self._restore_obj_registry)

        def reset_pecan():
            pecan.set_config({}, overwrite=True)

        self.addCleanup(reset_pecan)
Ejemplo n.º 12
0
                           **kwargs):
        collection = ContainerCollection()
        collection.containers = [
            Container.convert_with_links(p, expand) for p in rpc_containers
        ]
        collection.next = collection.get_next(limit, url=url, **kwargs)
        return collection

    @classmethod
    def sample(cls):
        sample = cls()
        sample.containers = [Container.sample(expand=False)]
        return sample


backend_api = api.API(context=magnum_context.RequestContext())


class StartController(object):
    @wsme_pecan.wsexpose(wtypes.text, wtypes.text)
    def _default(self, container_uuid):
        if pecan.request.method != 'PUT':
            pecan.abort(
                405, ('HTTP method %s is not allowed' % pecan.request.method))
        LOG.debug('Calling backend_api.container_start with %s' %
                  container_uuid)
        return backend_api.container_start(container_uuid)


class StopController(object):
    @wsme_pecan.wsexpose(wtypes.text, wtypes.text)