Exemple #1
0
    def test_request_context_read_deleted(self):
        ctxt = context.RequestContext('111',
                                      '222',
                                      read_deleted='yes')
        self.assertEqual('yes', ctxt.read_deleted)

        ctxt.read_deleted = 'no'
        self.assertEqual('no', ctxt.read_deleted)
Exemple #2
0
    def setUp(self):
        super(MessageApiTest, self).setUp()
        self.controller = messages.MessagesController()

        self.maxDiff = None
        self.ctxt = context.RequestContext('admin', 'fake', True)
        self.mock_object(policy, 'check_policy',
                         mock.Mock(return_value=True))
    def setUp(self):
        super(self.__class__, self).setUp()
        self.controller = share_snapshots.ShareSnapshotsController()
        self.flags(rpc_backend='manila.openstack.common.rpc.impl_fake')
        self.admin_context = context.RequestContext('admin', 'fake', True)
        self.member_context = context.RequestContext('fake', 'fake')

        self.resource_name = self.controller.resource_name
        self.manage_request = fakes.HTTPRequest.blank(
            '/snapshots/manage',
            use_admin_context=True,
            version=MIN_MANAGE_SNAPSHOT_API_VERSION)
        self.snapshot_id = 'fake'
        self.unmanage_request = fakes.HTTPRequest.blank(
            '/snapshots/%s/unmanage' % self.snapshot_id,
            use_admin_context=True,
            version=MIN_MANAGE_SNAPSHOT_API_VERSION)
Exemple #4
0
 def setUp(self):
     super(NovaNetworkPluginTest, self).setUp()
     self.fake_context = context.RequestContext(
         user_id='fake user', project_id='fake project', is_admin=False)
     self.instance = plugin.NovaNetworkPlugin()
     self.share_server = dict(id='fake_share_server_id')
     self.share_network = dict(
         id='fake_sn_id', nova_net_id='fake_nova_net_id')
Exemple #5
0
 def setUp(self):
     super(SchedulerManagerTestCase, self).setUp()
     self.flags(scheduler_driver=self.driver_cls_name)
     self.manager = self.manager_cls()
     self.context = context.RequestContext('fake_user', 'fake_project')
     self.topic = 'fake_topic'
     self.fake_args = (1, 2, 3)
     self.fake_kwargs = {'cat': 'meow', 'dog': 'woof'}
 def setUp(self):
     super(ShareSnapshotInstancesApiTest, self).setUp()
     self.controller = (
         share_snapshot_instances.ShareSnapshotInstancesController())
     self.resource_name = self.controller.resource_name
     self.api_version = '2.19'
     self.snapshot_instances_req = fakes.HTTPRequest.blank(
         '/snapshot-instances', version=self.api_version)
     self.admin_context = context.RequestContext('admin', 'fake', True)
     self.member_context = context.RequestContext('fake', 'fake')
     self.snapshot_instances_req.environ['manila.context'] = (
         self.admin_context)
     self.snapshot_instances_req_admin = fakes.HTTPRequest.blank(
         '/snapshot-instances',
         version=self.api_version,
         use_admin_context=True)
     self.mock_policy_check = self.mock_object(policy, 'check_policy')
Exemple #7
0
    def setUp(self):
        super(DefaultPolicyTestCase, self).setUp()
        policy.reset()
        policy.init()

        self.rules = {"default": [], "example:exist": "false:false"}
        self._set_rules('default')
        self.context = context.RequestContext('fake', 'fake')
Exemple #8
0
 def test_ignore_case_role_check(self):
     lowercase_action = "test:lowercase_admin"
     uppercase_action = "test:uppercase_admin"
     admin_context = context.RequestContext('admin',
                                            'fake',
                                            roles=['AdMiN'])
     policy.authorize(admin_context, lowercase_action, self.target)
     policy.authorize(admin_context, uppercase_action, self.target)
    def test_index_with_unsupported_versions(self, version, controller):
        ctxt = context.RequestContext("admin", "fake", True)
        req = fakes.HTTPRequest.blank('/shares', version=version)
        req.environ['manila.context'] = ctxt
        az_controller = controller()

        self.assertRaises(exception.VersionNotFoundForAPIMethod,
                          az_controller.index, req)
    def _host_passes_filters_setup(self, mock_obj):
        sched = fakes.FakeFilterScheduler()
        sched.host_manager = fakes.FakeHostManager()
        fake_context = context.RequestContext('user', 'project', is_admin=True)

        fakes.mock_host_manager_db_calls(mock_obj)

        return (sched, fake_context)
Exemple #11
0
 def setUp(self):
     super(ShareInstanceExportLocationsAPITest, self).setUp()
     self.controller = (
         export_locations.ShareInstanceExportLocationController())
     self.resource_name = self.controller.resource_name
     self.ctxt = {
         'admin': context.RequestContext('admin', 'fake', True),
         'user': context.RequestContext('fake', 'fake'),
     }
     self.mock_policy_check = self.mock_object(policy, 'check_policy',
                                               mock.Mock(return_value=True))
     self.share = db_utils.create_share()
     self.share_instance_id = self.share.instance.id
     self.req = self._get_request()
     paths = ['fake1/1/', 'fake2/2', 'fake3/3']
     db.share_export_locations_update(self.ctxt['admin'],
                                      self.share_instance_id, paths, False)
Exemple #12
0
 def setUp(self):
     super(SchedulerStatsControllerTestCase, self).setUp()
     self.flags(host='fake')
     self.controller = scheduler_stats.SchedulerStatsController()
     self.resource_name = self.controller.resource_name
     self.ctxt = context.RequestContext('admin', 'fake', True)
     self.mock_policy_check = self.mock_object(
         policy, 'check_policy', mock.Mock(return_value=True))
    def setUp(self):
        super(ShareSnapshotAdminActionsAPITest, self).setUp()
        self.controller = share_snapshots.ShareSnapshotsController()
        self.flags(transport_url='rabbit://*****:*****@mqhost:5672')
        self.admin_context = context.RequestContext('admin', 'fake', True)
        self.member_context = context.RequestContext('fake', 'fake')

        self.resource_name = self.controller.resource_name
        self.manage_request = fakes.HTTPRequest.blank(
            '/v2/fake/snapshots/manage',
            use_admin_context=True,
            version=MIN_MANAGE_SNAPSHOT_API_VERSION)
        self.snapshot_id = 'fake'
        self.unmanage_request = fakes.HTTPRequest.blank(
            '/v2/fake/snapshots/%s/unmanage' % self.snapshot_id,
            use_admin_context=True,
            version=MIN_MANAGE_SNAPSHOT_API_VERSION)
Exemple #14
0
 def _get_all_filter_metadata_or_extra_specs_invalid(self, key):
     self.stubs.Set(db_driver, 'share_get_all_by_project',
                    mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[0]))
     ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=False)
     search_opts = {key: "{'foo': 'bar'}"}
     self.assertRaises(exception.InvalidInput, self.api.get_all, ctx,
                       search_opts=search_opts)
     share_api.policy.check_policy.assert_called_once_with(
         ctx, 'share', 'get_all')
Exemple #15
0
 def test_request_context_elevated(self):
     user_context = context.RequestContext(
         'fake_user', 'fake_project', admin=False)
     self.assertFalse(user_context.is_admin)
     admin_context = user_context.elevated()
     self.assertFalse(user_context.is_admin)
     self.assertTrue(admin_context.is_admin)
     self.assertFalse('admin' in user_context.roles)
     self.assertTrue('admin' in admin_context.roles)
Exemple #16
0
    def test_create_cg_no_hosts(self):
        # Ensure empty hosts/child_zones result in NoValidHosts exception.
        sched = fakes.FakeFilterScheduler()
        fake_context = context.RequestContext('user', 'project')
        request_spec = {'share_types': [{'id': 'NFS'}]}

        self.assertRaises(exception.NoValidHost,
                          sched.schedule_create_consistency_group,
                          fake_context, 'fake_id', request_spec, {})
Exemple #17
0
    def test_request_context_read_deleted_invalid(self):
        self.assertRaises(ValueError,
                          context.RequestContext,
                          '111',
                          '222',
                          read_deleted=True)

        ctxt = context.RequestContext('111', '222')
        self.assertRaises(ValueError, setattr, ctxt, 'read_deleted', True)
Exemple #18
0
 def test_get_all_admin_filter_by_all_tenants(self):
     ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=True)
     self.stubs.Set(db_driver, 'share_get_all',
                    mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES))
     shares = self.api.get_all(ctx, {'all_tenants': 1})
     share_api.policy.check_policy.assert_called_once_with(
         ctx, 'share', 'get_all')
     db_driver.share_get_all.assert_called_once_with(ctx)
     self.assertEqual(shares, _FAKE_LIST_OF_ALL_SHARES)
Exemple #19
0
    def test_get_pools_with_filters(self):
        fake_context = context.RequestContext('user', 'project')
        self.mock_object(utils, 'service_is_up', mock.Mock(return_value=True))
        self.mock_object(
            db, 'service_get_all_by_topic',
            mock.Mock(return_value=fakes.SHARE_SERVICES_WITH_POOLS))
        host_manager.LOG.warning = mock.Mock()

        with mock.patch.dict(self.host_manager.service_states,
                             fakes.SHARE_SERVICE_STATES_WITH_POOLS):

            res = self.host_manager.get_pools(context=fake_context,
                                              filters={
                                                  'host': 'host2',
                                                  'pool': 'pool*',
                                                  'capabilities': {
                                                      'dedupe': 'False'
                                                  }
                                              })

            expected = [
                {
                    'name': 'host2@BBB#pool2',
                    'host': 'host2',
                    'backend': 'BBB',
                    'pool': 'pool2',
                    'capabilities': {
                        'pool_name': 'pool2',
                        'timestamp': None,
                        'driver_handles_share_servers': False,
                        'snapshot_support': True,
                        'create_share_from_snapshot_support': True,
                        'revert_to_snapshot_support': False,
                        'mount_snapshot_support': False,
                        'share_backend_name': 'BBB',
                        'free_capacity_gb': 42,
                        'driver_version': None,
                        'total_capacity_gb': 52,
                        'reserved_percentage': 0,
                        'provisioned_capacity_gb': 60,
                        'max_over_subscription_ratio': 2.0,
                        'thin_provisioning': True,
                        'vendor_name': None,
                        'storage_protocol': None,
                        'dedupe': False,
                        'compression': False,
                        'replication_type': None,
                        'replication_domain': None,
                        'sg_consistent_snapshot_support': None,
                    },
                },
            ]
            self.assertTrue(isinstance(res, list))
            self.assertEqual(len(expected), len(res))
            for pool in expected:
                self.assertIn(pool, res)
Exemple #20
0
 def test_ignore_case_role_check(self):
     lowercase_action = "example:lowercase_admin"
     uppercase_action = "example:uppercase_admin"
     # NOTE(dprince) we mix case in the Admin role here to ensure
     # case is ignored
     admin_context = context.RequestContext('admin',
                                            'fake',
                                            roles=['AdMiN'])
     policy.enforce(admin_context, lowercase_action, self.target)
     policy.enforce(admin_context, uppercase_action, self.target)
Exemple #21
0
 def test_create_share_no_hosts(self):
     # Ensure empty hosts/child_zones result in NoValidHosts exception.
     sched = fakes.FakeFilterScheduler()
     fake_context = context.RequestContext('user', 'project')
     request_spec = {
         'share_properties': {'project_id': 1, 'size': 1},
         'share_type': {'name': 'LVM_NFS'},
         'share_id': ['fake-id1'],
     }
     self.assertRaises(exception.NoValidHost, sched.schedule_create_share,
                       fake_context, request_spec, {})
Exemple #22
0
 def setUp(self):
     super(ShareGroupAPITest, self).setUp()
     self.controller = share_groups.ShareGroupController()
     self.resource_name = self.controller.resource_name
     self.fake_share_type = {'id': uuidutils.generate_uuid()}
     self.fake_share_group_type = {'id': uuidutils.generate_uuid()}
     self.api_version = '2.34'
     self.request = fakes.HTTPRequest.blank('/share-groups',
                                            version=self.api_version,
                                            experimental=True)
     self.flags(transport_url='rabbit://*****:*****@mqhost:5672')
     self.admin_context = context.RequestContext('admin', 'fake', True)
     self.member_context = context.RequestContext('fake', 'fake')
     self.mock_policy_check = self.mock_object(policy, 'check_policy',
                                               mock.Mock(return_value=True))
     self.context = self.request.environ['manila.context']
     self.mock_object(share_group_types, 'get_default',
                      mock.Mock(return_value=self.fake_share_group_type))
     self.mock_object(share_types, 'get_default_share_type',
                      mock.Mock(return_value=self.fake_share_type))
Exemple #23
0
 def test_get_all_admin_filter_by_status(self):
     ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=True)
     self.stubs.Set(db_driver, 'share_get_all_by_project',
                    mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[1:]))
     shares = self.api.get_all(ctx, {'status': 'active'})
     share_api.policy.check_policy.assert_has_calls([
         mock.call(ctx, 'share', 'get_all'),
     ])
     db_driver.share_get_all_by_project.assert_called_once_with(
         ctx, 'fake_pid_2')
     self.assertEqual(shares, _FAKE_LIST_OF_ALL_SHARES[2::4])
Exemple #24
0
 def test_get_all_snapshots_with_sorting_valid(self):
     self.stubs.Set(db_driver, 'share_snapshot_get_all_by_project',
                    mock.Mock(return_value=_FAKE_LIST_OF_ALL_SNAPSHOTS[0]))
     ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=False)
     snapshots = self.api.get_all_snapshots(
         ctx, sort_key='status', sort_dir='asc')
     share_api.policy.check_policy.assert_called_once_with(
         ctx, 'share', 'get_all_snapshots')
     db_driver.share_snapshot_get_all_by_project.assert_called_once_with(
         ctx, 'fake_pid_1', sort_dir='asc', sort_key='status', filters={})
     self.assertEqual(_FAKE_LIST_OF_ALL_SNAPSHOTS[0], snapshots)
Exemple #25
0
 def test_get_all_admin_filter_by_status_and_all_tenants(self):
     ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=True)
     self.stubs.Set(db_driver, 'share_get_all',
                    mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES))
     shares = self.api.get_all(ctx, {'status': 'error', 'all_tenants': 1})
     share_api.policy.check_policy.assert_has_calls([
         mock.call(ctx, 'share', 'get_all'),
     ])
     db_driver.share_get_all.assert_called_once_with(
         ctx, sort_dir='desc', sort_key='created_at', filters={})
     self.assertEqual(shares, _FAKE_LIST_OF_ALL_SHARES[1::2])
Exemple #26
0
 def setUp(self):
     super(ShareGroupAPITest, self).setUp()
     self.controller = share_groups.ShareGroupController()
     self.resource_name = self.controller.resource_name
     self.fake_share_type = {'id': six.text_type(uuidutils.generate_uuid())}
     self.fake_share_group_type = {
         'id': six.text_type(uuidutils.generate_uuid())}
     self.api_version = '2.34'
     self.request = fakes.HTTPRequest.blank(
         '/share-groups', version=self.api_version, experimental=True)
     self.flags(rpc_backend='manila.openstack.common.rpc.impl_fake')
     self.admin_context = context.RequestContext('admin', 'fake', True)
     self.member_context = context.RequestContext('fake', 'fake')
     self.mock_policy_check = self.mock_object(
         policy, 'check_policy', mock.Mock(return_value=True))
     self.context = self.request.environ['manila.context']
     self.mock_object(share_group_types, 'get_default',
                      mock.Mock(return_value=self.fake_share_group_type))
     self.mock_object(share_types, 'get_default_share_type',
                      mock.Mock(return_value=self.fake_share_type))
Exemple #27
0
    def test_authorize_does_not_raise_forbidden(self, method):
        self.fixture.config(enforce_scope=False, group='oslo_policy')
        project_context = context.RequestContext(project_id='fake-project-id',
                                                 roles=['bar'])
        policy.reset()
        policy.init()
        rule = common_policy.RuleDefault('foo', 'role:bar',
                                         scope_types=['system'])
        policy._ENFORCER.register_defaults([rule])

        self.assertTrue(getattr(policy, method)(project_context, 'foo', {}))
Exemple #28
0
 def _get_all_filter_metadata_or_extra_specs_valid(self, key):
     self.stubs.Set(db_driver, 'share_get_all_by_project',
                    mock.Mock(return_value=_FAKE_LIST_OF_ALL_SHARES[0]))
     ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=False)
     search_opts = {key: {'foo1': 'bar1', 'foo2': 'bar2'}}
     shares = self.api.get_all(ctx, search_opts=search_opts.copy())
     share_api.policy.check_policy.assert_called_once_with(
         ctx, 'share', 'get_all')
     db_driver.share_get_all_by_project.assert_called_once_with(
         ctx, sort_dir='desc', sort_key='created_at',
         project_id='fake_pid_1', filters=search_opts)
     self.assertEqual(_FAKE_LIST_OF_ALL_SHARES[0], shares)
Exemple #29
0
 def test_get_all_snapshots_sort_dir_invalid(self):
     self.stubs.Set(db_driver, 'share_snapshot_get_all_by_project',
                    mock.Mock(return_value=_FAKE_LIST_OF_ALL_SNAPSHOTS[0]))
     ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=False)
     self.assertRaises(
         exception.InvalidInput,
         self.api.get_all_snapshots,
         ctx,
         sort_dir=1,
     )
     share_api.policy.check_policy.assert_called_once_with(
         ctx, 'share', 'get_all_snapshots')
    def test_access(self, target_method_name, args_count):
        user_context = context.RequestContext('fake', 'fake')
        req = self._get_request('fake', user_context)
        policy_exception = exception.PolicyNotAuthorized(
            action=target_method_name)
        target_method = getattr(self.controller, target_method_name)
        args = [i for i in range(1, args_count)]

        with mock.patch.object(policy, 'check_policy',
                               mock.Mock(side_effect=policy_exception)):
            self.assertRaises(webob_exc.HTTPForbidden, target_method, req,
                              *args)