Exemplo n.º 1
0
    def setUp(self):
        super(FlavorAccessTestV21, self).setUp()
        self.flavor_controller = flavors_api.FlavorsController()
        # We need to stub out verify_project_id so that it doesn't
        # generate an EndpointNotFound exception and result in a
        # server error.
        self.stub_out('nova.api.openstack.identity.verify_project_id',
                      lambda ctx, project_id: True)

        self.req = FakeRequest()
        self.req.environ = {
            "nova.context": context.RequestContext('fake_user', 'fake')
        }
        self.stub_out('nova.db.flavor_get_by_flavor_id',
                      fake_get_flavor_by_flavor_id)
        self.stub_out('nova.db.flavor_get_all',
                      fake_get_all_flavors_sorted_list)
        self.stub_out('nova.db.flavor_access_get_by_flavor_id',
                      fake_get_flavor_access_by_flavor_id)
        # Simulate no API flavors right now
        self.stub_out('nova.objects.flavor._flavor_get_all_from_db',
                      lambda *a, **k: [])
        self.stub_out('nova.objects.Flavor.in_api', False)
        self.stub_out('nova.objects.flavor._get_projects_from_db',
                      fake_get_flavor_projects_from_db)

        self.flavor_access_controller = self.FlavorAccessController()
        self.flavor_action_controller = self.FlavorActionController()
Exemplo n.º 2
0
    def setUp(self):
        super(FlavorAccessTestV21, self).setUp()
        self.flavor_controller = flavors_api.FlavorsController()
        self.req = FakeRequest()
        self.req.environ = {"nova.context": context.RequestContext('fake_user',
                                                                   'fake')}
        self.stub_out('nova.db.flavor_get_by_flavor_id',
                      fake_get_flavor_by_flavor_id)
        self.stub_out('nova.db.flavor_get_all',
                      fake_get_all_flavors_sorted_list)
        self.stub_out('nova.db.flavor_access_get_by_flavor_id',
                      fake_get_flavor_access_by_flavor_id)
        # Simulate no API flavors right now
        self.stub_out('nova.objects.flavor._flavor_get_all_from_db',
                      lambda *a, **k: [])
        self.stub_out('nova.objects.Flavor.in_api', False)
        self.stub_out('nova.objects.flavor._get_projects_from_db',
                      fake_get_flavor_projects_from_db)

        self.flavor_access_controller = self.FlavorAccessController()
        self.flavor_action_controller = self.FlavorActionController()
Exemplo n.º 3
0
    def setUp(self):
        super(FlavorExtraSpecsPolicyTest, self).setUp()
        self.controller = flavors_extraspecs.FlavorExtraSpecsController()
        self.flavor_ctrl = flavors.FlavorsController()
        self.fm_ctrl = flavor_manage.FlavorManageController()
        self.req = fakes.HTTPRequest.blank('')

        def get_flavor_extra_specs(context, flavor_id):
            return fake_flavor.fake_flavor_obj(
                self.project_member_context,
                id=1,
                uuid=uuids.fake_id,
                project_id=self.project_id,
                is_public=False,
                extra_specs={'hw:cpu_policy': 'shared'},
                expected_attrs='extra_specs')

        self.stub_out('nova.api.openstack.common.get_flavor',
                      get_flavor_extra_specs)

        # In the base/legacy case, all project and system contexts are
        # authorized in the "anyone" case.
        self.all_authorized_contexts = (self.all_project_contexts
                                        | self.all_system_contexts)

        # In the base/legacy case, all project and system contexts are
        # authorized in the case of things that distinguish between
        # scopes, since scope checking is disabled.
        self.all_system_authorized_contexts = (self.all_project_contexts
                                               | self.all_system_contexts)

        # In the base/legacy case, any admin is an admin.
        self.admin_authorized_contexts = set([
            self.project_admin_context, self.system_admin_context,
            self.legacy_admin_context
        ])
    def setUp(self):
        super(FlavorExtraSpecsPolicyTest, self).setUp()
        self.controller = flavors_extraspecs.FlavorExtraSpecsController()
        self.flavor_ctrl = flavors.FlavorsController()
        self.fm_ctrl = flavor_manage.FlavorManageController()
        self.server_ctrl = servers.ServersController()
        self.req = fakes.HTTPRequest.blank('')
        self.server_ctrl._view_builder._add_security_grps = mock.MagicMock()
        self.server_ctrl._view_builder._get_metadata = mock.MagicMock()
        self.server_ctrl._view_builder._get_addresses = mock.MagicMock()
        self.server_ctrl._view_builder._get_host_id = mock.MagicMock()
        self.server_ctrl._view_builder._get_fault = mock.MagicMock()
        self.server_ctrl._view_builder._add_host_status = mock.MagicMock()

        self.instance = fake_instance.fake_instance_obj(
            self.project_member_context,
            id=1,
            uuid=uuids.fake_id,
            project_id=self.project_id,
            vm_state=vm_states.ACTIVE)

        self.mock_get = self.useFixture(
            fixtures.MockPatch('nova.api.openstack.common.get_instance')).mock
        self.mock_get.return_value = self.instance

        fakes.stub_out_secgroup_api(self,
                                    security_groups=[{
                                        'name': 'default'
                                    }])
        self.mock_get_all = self.useFixture(
            fixtures.MockPatchObject(self.server_ctrl.compute_api,
                                     'get_all')).mock
        self.mock_get_all.return_value = objects.InstanceList(
            objects=[self.instance])

        def get_flavor_extra_specs(context, flavor_id):
            return fake_flavor.fake_flavor_obj(
                self.project_member_context,
                id=1,
                uuid=uuids.fake_id,
                project_id=self.project_id,
                is_public=False,
                extra_specs={'hw:cpu_policy': 'shared'},
                expected_attrs='extra_specs')

        self.stub_out('nova.api.openstack.common.get_flavor',
                      get_flavor_extra_specs)

        # Check that all are able to get flavor extra specs.
        self.all_authorized_contexts = [
            self.legacy_admin_context, self.system_admin_context,
            self.project_admin_context, self.project_member_context,
            self.project_reader_context, self.project_foo_context,
            self.system_member_context, self.system_reader_context,
            self.system_foo_context, self.other_project_member_context,
            self.other_project_reader_context
        ]
        self.all_unauthorized_contexts = []
        # Check that all system scoped are able to get flavor extra specs.
        self.all_system_authorized_contexts = [
            self.legacy_admin_context, self.system_admin_context,
            self.project_admin_context, self.project_member_context,
            self.project_reader_context, self.project_foo_context,
            self.system_member_context, self.system_reader_context,
            self.system_foo_context, self.other_project_member_context,
            self.other_project_reader_context
        ]
        self.all_system_unauthorized_contexts = []

        # Check that admin is able to create, update and delete flavor
        # extra specs.
        self.admin_authorized_contexts = [
            self.legacy_admin_context, self.system_admin_context,
            self.project_admin_context
        ]
        # Check that non-admin is not able to create, update and
        # delete flavor extra specs.
        self.admin_unauthorized_contexts = [
            self.system_member_context, self.system_reader_context,
            self.system_foo_context, self.project_member_context,
            self.project_reader_context, self.project_foo_context,
            self.other_project_member_context,
            self.other_project_reader_context
        ]
Exemplo n.º 5
0
 def setUp(self):
     super(FlavorsPolicyEnforcementV21, self).setUp()
     self.flavor_controller = flavors_v21.FlavorsController()
     fakes.stub_out_flavor_get_by_flavor_id(self)
     fakes.stub_out_flavor_get_all(self)
     self.req = fakes.HTTPRequest.blank('')