Exemplo n.º 1
0
    def test_share_instance_prefer_active_instance(self):

        instance_list = [
            db_utils.create_share_instance(
                status=constants.STATUS_AVAILABLE,
                share_id='fake_id',
                replica_state=constants.REPLICA_STATE_IN_SYNC),
            db_utils.create_share_instance(
                status=constants.STATUS_CREATING,
                share_id='fake_id',
                replica_state=constants.REPLICA_STATE_OUT_OF_SYNC),
            db_utils.create_share_instance(
                status=constants.STATUS_ERROR, share_id='fake_id',
                replica_state=constants.REPLICA_STATE_ACTIVE),
            db_utils.create_share_instance(
                status=constants.STATUS_MANAGING, share_id='fake_id',
                replica_state=constants.REPLICA_STATE_ACTIVE),
        ]

        share1 = db_utils.create_share(instances=instance_list)
        share2 = db_utils.create_share(instances=list(reversed(instance_list)))

        self.assertEqual(
            constants.STATUS_ERROR, share1.instance['status'])
        self.assertEqual(
            constants.STATUS_ERROR, share2.instance['status'])
Exemplo n.º 2
0
    def test_share_filter_by_host_with_pools(self):
        shares = [[db_api.share_create(self.ctxt, {'host': value})
                   for value in ('foo', 'foo#pool0')]]

        db_utils.create_share()
        self._assertEqualListsOfObjects(shares[0],
                                        db_api.share_get_all_by_host(
                                            self.ctxt, 'foo'),
                                        ignored_keys=['share_type',
                                                      'share_type_id',
                                                      'export_locations'])
Exemplo n.º 3
0
    def test_share_instance_not_transitional(self, status, trans_status):

        instance_list = [
            db_utils.create_share_instance(status=status, share_id='fake_id'),
            db_utils.create_share_instance(status=trans_status,
                                           share_id='fake_id')
        ]

        share1 = db_utils.create_share(instances=instance_list)
        share2 = db_utils.create_share(instances=list(reversed(instance_list)))

        self.assertEqual(status, share1.instance['status'])
        self.assertEqual(status, share2.instance['status'])
Exemplo n.º 4
0
    def test_share_instance_available(self, status):

        instance_list = [
            db_utils.create_share_instance(status=constants.STATUS_AVAILABLE,
                                           share_id='fake_id'),
            db_utils.create_share_instance(status=status, share_id='fake_id')
        ]

        share1 = db_utils.create_share(instances=instance_list)
        share2 = db_utils.create_share(instances=list(reversed(instance_list)))

        self.assertEqual(constants.STATUS_AVAILABLE, share1.instance['status'])
        self.assertEqual(constants.STATUS_AVAILABLE, share2.instance['status'])
Exemplo n.º 5
0
    def test_share_instance_not_transitional(self, status, trans_status):

        instance_list = [
            db_utils.create_share_instance(status=status,
                                           share_id='fake_id'),
            db_utils.create_share_instance(status=trans_status,
                                           share_id='fake_id')
        ]

        share1 = db_utils.create_share(instances=instance_list)
        share2 = db_utils.create_share(instances=list(reversed(instance_list)))

        self.assertEqual(status, share1.instance['status'])
        self.assertEqual(status, share2.instance['status'])
Exemplo n.º 6
0
    def test_share_instance_available(self, status):

        instance_list = [
            db_utils.create_share_instance(status=constants.STATUS_AVAILABLE,
                                           share_id='fake_id'),
            db_utils.create_share_instance(status=status,
                                           share_id='fake_id')
        ]

        share1 = db_utils.create_share(instances=instance_list)
        share2 = db_utils.create_share(instances=list(reversed(instance_list)))

        self.assertEqual(constants.STATUS_AVAILABLE, share1.instance['status'])
        self.assertEqual(constants.STATUS_AVAILABLE, share2.instance['status'])
Exemplo n.º 7
0
    def test_share_instance_reverting(self, status):

        instance_list = [
            db_utils.create_share_instance(status=constants.STATUS_REVERTING,
                                           share_id='fake_id'),
            db_utils.create_share_instance(status=status, share_id='fake_id'),
            db_utils.create_share_instance(
                status=constants.STATUS_ERROR_DELETING, share_id='fake_id'),
        ]

        share1 = db_utils.create_share(instances=instance_list)
        share2 = db_utils.create_share(instances=list(reversed(instance_list)))

        self.assertEqual(constants.STATUS_REVERTING, share1.instance['status'])
        self.assertEqual(constants.STATUS_REVERTING, share2.instance['status'])
Exemplo n.º 8
0
 def _setup_share_instance_data(self, instance=None):
     if instance is None:
         instance = db_utils.create_share(status=constants.STATUS_AVAILABLE,
                                          size='1').instance
     req = webob.Request.blank(
         '/v2/fake/share_instances/%s/action' % instance['id'])
     return instance, req
Exemplo n.º 9
0
    def test_copy_share_data_access_rule_invalid(self):

        fake_share = db_utils.create_share(id='fakeid',
                                           status=constants.STATUS_AVAILABLE,
                                           host='fake_host')

        share_driver = self._setup_mocks_copy_share_data()
        remote = {
            'access': {
                'access_to': None
            },
            'mount': 'fake_mount',
            'umount': 'fake_umount'
        }
        local = {
            'access': {
                'access_to': '192.168.1.1'
            },
            'mount': 'fake_mount',
            'umount': 'fake_umount'
        }

        driver.CONF.set_default('migration_tmp_location', '/fake/path')

        self.assertRaises(exception.ShareMigrationFailed,
                          share_driver.copy_share_data, 'ctx', None,
                          fake_share, None, None, None, None, local, remote)
Exemplo n.º 10
0
    def test_share_access_mapping_state(self, expected_status):
        ctxt = context.get_admin_context()

        share = db_utils.create_share()
        share_instances = [
            share.instance,
            db_utils.create_share_instance(share_id=share['id']),
            db_utils.create_share_instance(share_id=share['id']),
            db_utils.create_share_instance(share_id=share['id']),
        ]
        access_rule = db_utils.create_access(share_id=share['id'])

        # Update the access mapping states
        db_api.share_instance_access_update(
            ctxt, access_rule['id'], share_instances[0]['id'],
            {'state': constants.ACCESS_STATE_ACTIVE})
        db_api.share_instance_access_update(
            ctxt, access_rule['id'], share_instances[1]['id'],
            {'state': expected_status})
        db_api.share_instance_access_update(
            ctxt, access_rule['id'], share_instances[2]['id'],
            {'state': constants.ACCESS_STATE_ACTIVE})
        db_api.share_instance_access_update(
            ctxt, access_rule['id'], share_instances[3]['id'],
            {'deleted': 'True', 'state': constants.STATUS_DELETED})

        access_rule = db_api.share_access_get(ctxt, access_rule['id'])

        self.assertEqual(expected_status, access_rule['state'])
Exemplo n.º 11
0
    def test_index_with_limit(self):
        req = self._get_request('/share_instances')
        req_context = req.environ['manila.context']
        share_instances_count = 3
        test_instances = [
            db_utils.create_share(size=s + 1).instance
            for s in range(0, share_instances_count)
        ]
        expect_links = [
            {
                'href': (
                    'http://localhost/v1/fake/share_instances?'
                    'limit=3&marker=%s' % test_instances[2]['id']),
                'rel': 'next',
            }
        ]

        url = 'share_instances?limit=3'
        req = self._get_request(url)
        actual_result = self.controller.index(req)

        self._validate_ids_in_share_instances_list(
            test_instances, actual_result['share_instances'])
        self.assertEqual(expect_links, actual_result['share_instances_links'])
        self.mock_policy_check.assert_called_once_with(
            req_context, self.resource_name, 'index')
Exemplo n.º 12
0
    def test_custom_query(self):
        share = db_utils.create_share()
        share_access = db_utils.create_access(share_id=share['id'])

        db_api.share_access_delete(self.ctxt, share_access.id)
        self.assertRaises(exception.NotFound, db_api.share_access_get,
                          self.ctxt, share_access.id)
Exemplo n.º 13
0
 def setUp(self):
     super(ShareRpcAPITestCase, self).setUp()
     self.context = context.get_admin_context()
     share = db_utils.create_share(
         availability_zone=CONF.storage_availability_zone,
         status=constants.STATUS_AVAILABLE
     )
     access = db_utils.create_access(share_id=share['id'])
     snapshot = db_utils.create_snapshot(share_id=share['id'])
     share_replica = db_utils.create_share_replica(
         id='fake_replica',
         share_id='fake_share_id',
         host='fake_host',
     )
     share_server = db_utils.create_share_server()
     cg = {'id': 'fake_cg_id', 'host': 'fake_host'}
     cgsnapshot = {'id': 'fake_cg_id'}
     host = {'host': 'fake_host', 'capabilities': 1}
     self.fake_share = jsonutils.to_primitive(share)
     # mock out the getattr on the share db model object since jsonutils
     # doesn't know about those extra attributes to pull in
     self.fake_share['instance'] = jsonutils.to_primitive(share.instance)
     self.fake_share_replica = jsonutils.to_primitive(share_replica)
     self.fake_access = jsonutils.to_primitive(access)
     self.fake_snapshot = jsonutils.to_primitive(snapshot)
     self.fake_share_server = jsonutils.to_primitive(share_server)
     self.fake_cg = jsonutils.to_primitive(cg)
     self.fake_cgsnapshot = jsonutils.to_primitive(cgsnapshot)
     self.fake_host = jsonutils.to_primitive(host)
     self.ctxt = context.RequestContext('fake_user', 'fake_project')
     self.rpcapi = share_rpcapi.ShareAPI()
Exemplo n.º 14
0
 def setUp(self):
     super(DataManagerTestCase, self).setUp()
     self.manager = manager.DataManager()
     self.context = context.get_admin_context()
     self.topic = 'fake_topic'
     self.share = db_utils.create_share()
     manager.CONF.set_default('migration_tmp_location', '/tmp/')
Exemplo n.º 15
0
    def test_copy_share_data_remote_access_exception(self):
        fake_share = db_utils.create_share(
            id='fakeid', status=constants.STATUS_AVAILABLE, host='fake_host')
        fake_share_instance = {'id': 'fake_id', 'host': 'fake_host'}
        share_driver = self._setup_mocks_copy_share_data()
        remote = {'access': {'access_to': '192.168.0.1'},
                  'mount': 'fake_mount',
                  'umount': 'fake_umount'}
        local = {'access': {'access_to': '192.168.1.1'},
                 'mount': 'fake_mount',
                 'umount': 'fake_umount'}
        helper = migration.ShareMigrationHelper(None, None, None, None, None)

        driver.CONF.set_default('migration_tmp_location', '/fake/path')
        driver.CONF.set_default('migration_ignore_files', None)

        self.mock_object(migration.ShareMigrationHelper,
                         'deny_migration_access')
        self.mock_object(
            migration.ShareMigrationHelper,
            'allow_migration_access',
            mock.Mock(side_effect=[None,
                                   exception.ShareMigrationFailed(
                                       reason='fake')]))
        self.mock_object(migration.ShareMigrationHelper,
                         'cleanup_migration_access')
        self.assertRaises(exception.ShareMigrationFailed,
                          share_driver.copy_share_data, 'ctx', helper,
                          fake_share, fake_share_instance, None,
                          fake_share_instance, None, local, remote)

        args = ((None, local['access'], False),
                (None, remote['access'], False))
        migration.ShareMigrationHelper.deny_migration_access.assert_has_calls(
            [mock.call(*a) for a in args])
Exemplo n.º 16
0
    def test_show_access_not_authorized(self):
        share = db_utils.create_share(
            project_id='c3c5ec1ccc4640d0af1914cbf11f05ad', is_public=False)
        access = db_utils.create_access(
            id='76699c6b-f3da-47d7-b468-364f1347ba04', share_id=share['id'])
        req = fakes.HTTPRequest.blank('/v2/share-access-rules/%s' %
                                      access['id'],
                                      version="2.45")
        self.mock_object(
            policy, 'check_policy',
            mock.Mock(side_effect=[None, None, exception.NotAuthorized]))

        self.assertRaises(exception.NotAuthorized, self.controller.show, req,
                          access['id'])
        policy.check_policy.assert_has_calls([
            mock.call(req.environ['manila.context'], 'share_access_rule',
                      'get'),
            mock.call(req.environ['manila.context'], 'share', 'access_get'),
            mock.call(req.environ['manila.context'], 'share', 'get', mock.ANY)
        ])
        policy_check_call_args_list = policy.check_policy.call_args_list[2][0]
        share_being_checked = policy_check_call_args_list[3]
        self.assertEqual('c3c5ec1ccc4640d0af1914cbf11f05ad',
                         share_being_checked['project_id'])
        self.assertIs(False, share_being_checked['is_public'])
Exemplo n.º 17
0
    def test_share_access_mapping_state(self, expected_status):
        ctxt = context.get_admin_context()

        share = db_utils.create_share()
        share_instances = [
            share.instance,
            db_utils.create_share_instance(share_id=share['id']),
            db_utils.create_share_instance(share_id=share['id']),
            db_utils.create_share_instance(share_id=share['id']),
        ]
        access_rule = db_utils.create_access(share_id=share['id'])

        # Update the access mapping states
        db_api.share_instance_access_update(
            ctxt, access_rule['id'], share_instances[0]['id'],
            {'state': constants.ACCESS_STATE_ACTIVE})
        db_api.share_instance_access_update(
            ctxt, access_rule['id'], share_instances[1]['id'],
            {'state': expected_status})
        db_api.share_instance_access_update(
            ctxt, access_rule['id'], share_instances[2]['id'],
            {'state': constants.ACCESS_STATE_ACTIVE})
        db_api.share_instance_access_update(
            ctxt, access_rule['id'], share_instances[3]['id'],
            {'deleted': 'True', 'state': constants.STATUS_DELETED})

        access_rule = db_api.share_access_get(ctxt, access_rule['id'])

        self.assertEqual(expected_status, access_rule['state'])
Exemplo n.º 18
0
 def setUp(self):
     super(ShareRpcAPITestCase, self).setUp()
     self.context = context.get_admin_context()
     share = db_utils.create_share(
         availability_zone=CONF.storage_availability_zone,
         status=constants.STATUS_AVAILABLE)
     access = db_utils.create_access(share_id=share['id'])
     snapshot = db_utils.create_snapshot(share_id=share['id'])
     share_replica = db_utils.create_share_replica(
         id='fake_replica',
         share_id='fake_share_id',
     )
     share_server = db_utils.create_share_server()
     cg = {'id': 'fake_cg_id', 'host': 'fake_host'}
     cgsnapshot = {'id': 'fake_cg_id'}
     host = {'host': 'fake_host', 'capabilities': 1}
     self.fake_share = jsonutils.to_primitive(share)
     self.fake_share_replica = jsonutils.to_primitive(share_replica)
     self.fake_access = jsonutils.to_primitive(access)
     self.fake_snapshot = jsonutils.to_primitive(snapshot)
     self.fake_share_server = jsonutils.to_primitive(share_server)
     self.fake_cg = jsonutils.to_primitive(cg)
     self.fake_cgsnapshot = jsonutils.to_primitive(cgsnapshot)
     self.fake_host = jsonutils.to_primitive(host)
     self.ctxt = context.RequestContext('fake_user', 'fake_project')
     self.rpcapi = share_rpcapi.ShareAPI()
    def test_show(self):
        test_instance = db_utils.create_share(size=1).instance
        id = test_instance['id']

        actual_result = self.controller.show(self._get_request('fake'), id)

        self.assertEqual(id, actual_result['share_instance']['id'])
Exemplo n.º 20
0
    def test_index(self, version):
        url = '/share_instances'
        if (api_version_request.APIVersionRequest(version) >=
                api_version_request.APIVersionRequest('2.35')):
            url += "?export_location_path=/admin/export/location"
        req = self._get_request(url, version=version)
        req_context = req.environ['manila.context']
        share_instances_count = 3
        test_instances = [
            db_utils.create_share(size=s + 1).instance
            for s in range(0, share_instances_count)
        ]

        db.share_export_locations_update(
            self.admin_context, test_instances[0]['id'],
            '/admin/export/location', False)

        actual_result = self.controller.index(req)

        if (api_version_request.APIVersionRequest(version) >=
                api_version_request.APIVersionRequest('2.35')):
            test_instances = test_instances[:1]
        self._validate_ids_in_share_instances_list(
            test_instances, actual_result['share_instances'])
        self.mock_policy_check.assert_called_once_with(
            req_context, self.resource_name, 'index')
Exemplo n.º 21
0
 def setUp(self):
     super(ShareRpcAPITestCase, self).setUp()
     self.context = context.get_admin_context()
     share = db_utils.create_share(
         availability_zone=CONF.storage_availability_zone,
         status=constants.STATUS_AVAILABLE)
     snapshot = db_utils.create_snapshot(share_id=share['id'])
     share_replica = db_utils.create_share_replica(
         id='fake_replica',
         share_id='fake_share_id',
         host='fake_host',
     )
     share_server = db_utils.create_share_server()
     share_group = {'id': 'fake_share_group_id', 'host': 'fake_host'}
     share_group_snapshot = {'id': 'fake_share_group_id'}
     host = 'fake_host'
     self.fake_share = jsonutils.to_primitive(share)
     # mock out the getattr on the share db model object since jsonutils
     # doesn't know about those extra attributes to pull in
     self.fake_share['instance'] = jsonutils.to_primitive(share.instance)
     self.fake_share_replica = jsonutils.to_primitive(share_replica)
     self.fake_snapshot = jsonutils.to_primitive(snapshot)
     self.fake_snapshot['share_instance'] = jsonutils.to_primitive(
         snapshot.instance)
     self.fake_share_server = jsonutils.to_primitive(share_server)
     self.fake_share_group = jsonutils.to_primitive(share_group)
     self.fake_share_group_snapshot = jsonutils.to_primitive(
         share_group_snapshot)
     self.fake_host = jsonutils.to_primitive(host)
     self.ctxt = context.RequestContext('fake_user', 'fake_project')
     self.rpcapi = share_rpcapi.ShareAPI()
Exemplo n.º 22
0
    def test_deny_access_access_rule_not_found(self):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])
        access = db_utils.create_snapshot_access(
            share_snapshot_id=snapshot['id'])
        wrong_access = {
            'access_type': 'fake_type',
            'access_to': 'fake_IP',
            'share_snapshot_id': 'fake_id'
        }

        get = self.mock_object(share_api.API, 'get',
                               mock.Mock(return_value=share))
        get_snapshot = self.mock_object(share_api.API, 'get_snapshot',
                                        mock.Mock(return_value=snapshot))
        access_get = self.mock_object(share_api.API, 'snapshot_access_get',
                                      mock.Mock(return_value=wrong_access))

        body = {'deny_access': {'access_id': access.id}}
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.deny_access, req, snapshot['id'],
                          body)
        get.assert_called_once_with(utils.IsAMatcher(context.RequestContext),
                                    share['id'])
        get_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot['id'])
        access_get.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext),
            body['deny_access']['access_id'])
Exemplo n.º 23
0
 def _setup_share_data(self, share=None):
     if share is None:
         share = db_utils.create_share(status=constants.STATUS_AVAILABLE,
                                       size='1',
                                       override_defaults=True)
     req = webob.Request.blank('/v2/fake/shares/%s/action' % share['id'])
     return share, req
Exemplo n.º 24
0
    def test_allow_access_share_without_mount_snap_support(self):
        share = db_utils.create_share(mount_snapshot_support=False)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])

        access = {
            'id': 'fake_id',
            'access_type': 'ip',
            'access_to': '1.1.1.1',
            'state': 'new',
        }

        get_snapshot = self.mock_object(share_api.API, 'get_snapshot',
                                        mock.Mock(return_value=snapshot))
        get = self.mock_object(share_api.API, 'get',
                               mock.Mock(return_value=share))

        body = {'allow_access': access}
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.allow_access, req,
                          snapshot['id'], body)

        get.assert_called_once_with(utils.IsAMatcher(context.RequestContext),
                                    share['id'])
        get_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot['id'])
Exemplo n.º 25
0
    def test_allow_access_exists_exception(self):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')
        access = {
            'id': 'fake_id',
            'access_type': 'ip',
            'access_to': '1.1.1.1',
            'state': 'new',
        }
        msg = "Share snapshot access exists."

        get = self.mock_object(share_api.API, 'get', mock.Mock(
            return_value=share))
        get_snapshot = self.mock_object(share_api.API, 'get_snapshot',
                                        mock.Mock(return_value=snapshot))
        allow_access = self.mock_object(
            share_api.API, 'snapshot_allow_access', mock.Mock(
                side_effect=exception.ShareSnapshotAccessExists(msg)))

        body = {'allow_access': access}

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.allow_access, req,
                          snapshot['id'], body)

        get.assert_called_once_with(utils.IsAMatcher(context.RequestContext),
                                    share['id'])
        get_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot['id'])
        allow_access.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot,
            access['access_type'], access['access_to'])
Exemplo n.º 26
0
    def test_deny_access(self):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])
        access = db_utils.create_snapshot_access(
            share_snapshot_id=snapshot['id'])

        get = self.mock_object(share_api.API, 'get',
                               mock.Mock(return_value=share))
        get_snapshot = self.mock_object(share_api.API, 'get_snapshot',
                                        mock.Mock(return_value=snapshot))
        access_get = self.mock_object(share_api.API, 'snapshot_access_get',
                                      mock.Mock(return_value=access))
        deny_access = self.mock_object(share_api.API, 'snapshot_deny_access')

        body = {'deny_access': {'access_id': access.id}}
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')

        resp = self.controller.deny_access(req, snapshot['id'], body)

        self.assertEqual(202, resp.status_int)
        get.assert_called_once_with(utils.IsAMatcher(context.RequestContext),
                                    share['id'])
        get_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot['id'])
        access_get.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext),
            body['deny_access']['access_id'])
        deny_access.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot, access)
Exemplo n.º 27
0
    def test_migrate_share_to_host(self):

        class fake_host(object):
            host = 'fake@backend#pool'

        share = db_utils.create_share()
        host = fake_host()

        self.mock_object(db, 'share_get', mock.Mock(return_value=share))
        self.mock_object(share_rpcapi.ShareAPI, 'migration_start',
                         mock.Mock(side_effect=TypeError))
        self.mock_object(base.Scheduler,
                         'host_passes_filters',
                         mock.Mock(return_value=host))

        self.assertRaises(
            TypeError, self.manager.migrate_share_to_host,
            self.context, share['id'], 'fake@backend#pool', False, True, True,
            False, True, 'fake_net_id', 'fake_type_id', {}, None)

        db.share_get.assert_called_once_with(self.context, share['id'])
        base.Scheduler.host_passes_filters.assert_called_once_with(
            self.context, 'fake@backend#pool', {}, None)
        share_rpcapi.ShareAPI.migration_start.assert_called_once_with(
            self.context, share, host.host, False, True, True, False, True,
            'fake_net_id', 'fake_type_id')
Exemplo n.º 28
0
    def test_get_and_update_access_rules_status_conditionally_change(
            self, initial_status, change_allowed):
        share = db_utils.create_share(access_rules_status=initial_status,
                                      status=constants.STATUS_AVAILABLE)
        share = db.share_get(self.context, share['id'])
        self.assertEqual(initial_status, share['access_rules_status'])

        conditionally_change = {
            constants.SHARE_INSTANCE_RULES_SYNCING: constants.STATUS_ACTIVE,
        }

        updated_instance = (
            self.access_helper.
            get_and_update_share_instance_access_rules_status(
                self.context, conditionally_change=conditionally_change,
                share_instance_id=share['instance']['id'])
        )

        share = db.share_get(self.context, share['id'])
        if change_allowed:
            self.assertEqual(constants.STATUS_ACTIVE,
                             share['access_rules_status'])
            self.assertIsNotNone(updated_instance)
        else:
            self.assertEqual(initial_status, share['access_rules_status'])
            self.assertIsNone(updated_instance)
Exemplo n.º 29
0
 def _setup_share_instance_data(self, instance=None, version='2.7'):
     if instance is None:
         instance = db_utils.create_share(status=constants.STATUS_AVAILABLE,
                                          size='1').instance
     path = '/v2/fake/share_instances/%s/action' % instance['id']
     req = fakes.HTTPRequest.blank(path, script_name=path, version=version)
     return instance, req
Exemplo n.º 30
0
    def test_migrate_share_to_host_exception(self, exc):

        share = db_utils.create_share(status=constants.STATUS_MIGRATING)
        host = 'fake@backend#pool'
        request_spec = {'share_id': share['id']}

        self.mock_object(db, 'share_get', mock.Mock(return_value=share))
        self.mock_object(base.Scheduler, 'host_passes_filters',
                         mock.Mock(side_effect=exc))
        self.mock_object(db, 'share_update')
        self.mock_object(db, 'share_instance_update')

        capture = (exception.NoValidHost
                   if isinstance(exc, exception.NoValidHost) else TypeError)

        self.assertRaises(capture, self.manager.migrate_share_to_host,
                          self.context, share['id'], host, False, True, True,
                          False, True, 'fake_net_id', 'fake_type_id',
                          request_spec, None)

        base.Scheduler.host_passes_filters.assert_called_once_with(
            self.context, host, request_spec, None)
        db.share_get.assert_called_once_with(self.context, share['id'])
        db.share_update.assert_called_once_with(
            self.context, share['id'],
            {'task_state': constants.TASK_STATE_MIGRATION_ERROR})
        db.share_instance_update.assert_called_once_with(
            self.context, share.instance['id'],
            {'status': constants.STATUS_AVAILABLE})
Exemplo n.º 31
0
    def test_index(self, version):
        url = '/share_instances'
        if (api_version_request.APIVersionRequest(version) >=
                api_version_request.APIVersionRequest('2.35')):
            url += "?export_location_path=/admin/export/location"
        req = self._get_request(url, version=version)
        req_context = req.environ['manila.context']
        share_instances_count = 3
        test_instances = [
            db_utils.create_share(size=s + 1).instance
            for s in range(0, share_instances_count)
        ]

        db.share_export_locations_update(self.admin_context,
                                         test_instances[0]['id'],
                                         '/admin/export/location', False)

        actual_result = self.controller.index(req)

        if (api_version_request.APIVersionRequest(version) >=
                api_version_request.APIVersionRequest('2.35')):
            test_instances = test_instances[:1]
        self._validate_ids_in_share_instances_list(
            test_instances, actual_result['share_instances'])
        self.mock_policy_check.assert_called_once_with(req_context,
                                                       self.resource_name,
                                                       'index')
Exemplo n.º 32
0
    def test_index_with_limit(self):
        req = self._get_request('/v2/fake/share_instances')
        req_context = req.environ['manila.context']
        share_instances_count = 3
        test_instances = [
            db_utils.create_share(size=s + 1).instance
            for s in range(0, share_instances_count)
        ]
        expect_links = [{
            'href': ('http://localhost/share/v2/fake/share_instances?'
                     'limit=3&marker=%s' % test_instances[2]['id']),
            'rel':
            'next',
        }]

        url = '/v2/fake/share_instances?limit=3'
        req = self._get_request(url)
        actual_result = self.controller.index(req)

        self._validate_ids_in_share_instances_list(
            test_instances, actual_result['share_instances'])
        self.assertEqual(expect_links, actual_result['share_instances_links'])
        self.mock_policy_check.assert_called_once_with(req_context,
                                                       self.resource_name,
                                                       'index')
Exemplo n.º 33
0
 def _setup_share_instance_data(self, instance=None, version='2.7'):
     if instance is None:
         instance = db_utils.create_share(status=constants.STATUS_AVAILABLE,
                                          size='1').instance
     path = '/v2/fake/share_instances/%s/action' % instance['id']
     req = fakes.HTTPRequest.blank(path, script_name=path, version=version)
     return instance, req
Exemplo n.º 34
0
    def test_get_share_instances(self, version):
        test_share = db_utils.create_share(size=1)
        id = test_share['id']
        req = self._get_request('fake', version=version)
        req_context = req.environ['manila.context']
        share_policy_check_call = mock.call(req_context, 'share', 'get',
                                            mock.ANY)
        get_instances_policy_check_call = mock.call(req_context,
                                                    'share_instance', 'index')

        actual_result = self.controller.get_share_instances(req, id)

        self._validate_ids_in_share_instances_list(
            [test_share.instance], actual_result['share_instances'])
        self.assertEqual(1, len(actual_result.get("share_instances", 0)))
        for instance in actual_result["share_instances"]:
            if (api_version_request.APIVersionRequest(version) >
                    api_version_request.APIVersionRequest("2.8")):
                assert_method = self.assertNotIn
            else:
                assert_method = self.assertIn
            assert_method("export_location", instance)
            assert_method("export_locations", instance)
            if (api_version_request.APIVersionRequest(version) >
                    api_version_request.APIVersionRequest("2.10")):
                self.assertIn("replica_state", instance)
        self.mock_policy_check.assert_has_calls(
            [get_instances_policy_check_call, share_policy_check_call])
Exemplo n.º 35
0
 def _setup_share_data(self, share=None):
     if share is None:
         share = db_utils.create_share(status=constants.STATUS_AVAILABLE,
                                       size='1',
                                       override_defaults=True)
     req = webob.Request.blank('/v2/fake/shares/%s/action' % share['id'])
     return share, req
Exemplo n.º 36
0
    def test_get_share_instances(self, version):
        test_share = db_utils.create_share(size=1)
        id = test_share['id']
        req = self._get_request('fake', version=version)
        req_context = req.environ['manila.context']
        share_policy_check_call = mock.call(
            req_context, 'share', 'get', mock.ANY)
        get_instances_policy_check_call = mock.call(
            req_context, 'share_instance', 'index')

        actual_result = self.controller.get_share_instances(req, id)

        self._validate_ids_in_share_instances_list(
            [test_share.instance],
            actual_result['share_instances']
        )
        self.assertEqual(1, len(actual_result.get("share_instances", 0)))
        for instance in actual_result["share_instances"]:
            if (api_version_request.APIVersionRequest(version) >
                    api_version_request.APIVersionRequest("2.8")):
                assert_method = self.assertNotIn
            else:
                assert_method = self.assertIn
            assert_method("export_location", instance)
            assert_method("export_locations", instance)
            if (api_version_request.APIVersionRequest(version) >
                    api_version_request.APIVersionRequest("2.10")):
                self.assertIn("replica_state", instance)
        self.mock_policy_check.assert_has_calls([
            get_instances_policy_check_call, share_policy_check_call])
Exemplo n.º 37
0
    def test_get_and_update_all_access_rules_updates_conditionally_changed(
            self, statuses, changes_allowed):
        share = db_utils.create_share(status=constants.STATUS_AVAILABLE)
        db_utils.create_access(share_id=share['id'], state=statuses[0])
        db_utils.create_access(share_id=share['id'], state=statuses[-1])
        self.mock_object(db, 'share_instance_access_update', mock.Mock(
            side_effect=db.share_instance_access_update))
        updates = {
            'access_key': 'renfrow2stars'
        }
        expected_updates = {
            'access_key': 'renfrow2stars',
            'state': constants.ACCESS_STATE_QUEUED_TO_DENY,
        }
        conditionally_change = {
            constants.ACCESS_STATE_APPLYING:
                constants.ACCESS_STATE_QUEUED_TO_DENY,
            constants.ACCESS_STATE_QUEUED_TO_APPLY:
                constants.ACCESS_STATE_QUEUED_TO_DENY,
        }

        rules = self.access_helper.get_and_update_share_instance_access_rules(
            self.context, share_instance_id=share['instance']['id'],
            updates=updates, conditionally_change=conditionally_change)

        state_changed_rules = [
            r for r in rules if
            r['state'] == constants.ACCESS_STATE_QUEUED_TO_DENY
        ]
        self.assertEqual(changes_allowed, len(state_changed_rules))
        self.assertEqual(2, db.share_instance_access_update.call_count)
        db.share_instance_access_update.assert_has_calls([
            mock.call(self.context, mock.ANY, share['instance']['id'],
                      expected_updates),
        ] * changes_allowed)
Exemplo n.º 38
0
    def test_copy_share_data_remote_access_exception(self):
        fake_share = db_utils.create_share(
            id='fakeid', status=constants.STATUS_AVAILABLE, host='fake_host')
        fake_share_instance = {'id': 'fake_id', 'host': 'fake_host'}
        share_driver = self._setup_mocks_copy_share_data()
        remote = {'access': {'access_to': '192.168.0.1'},
                  'mount': 'fake_mount',
                  'umount': 'fake_umount'}
        local = {'access': {'access_to': '192.168.1.1'},
                 'mount': 'fake_mount',
                 'umount': 'fake_umount'}
        helper = migration.ShareMigrationHelper(None, None, None, None, None)

        driver.CONF.set_default('migration_tmp_location', '/fake/path')
        driver.CONF.set_default('migration_ignore_files', None)

        self.mock_object(migration.ShareMigrationHelper,
                         'deny_migration_access')
        self.mock_object(
            migration.ShareMigrationHelper,
            'allow_migration_access',
            mock.Mock(side_effect=[None,
                                   exception.ShareMigrationFailed(
                                       reason='fake')]))
        self.mock_object(migration.ShareMigrationHelper,
                         'cleanup_migration_access')
        self.assertRaises(exception.ShareMigrationFailed,
                          share_driver.copy_share_data, 'ctx', helper,
                          fake_share, fake_share_instance, None,
                          fake_share_instance, None, local, remote)

        args = ((None, local['access'], False),
                (None, remote['access'], False))
        migration.ShareMigrationHelper.deny_migration_access.assert_has_calls(
            [mock.call(*a) for a in args])
Exemplo n.º 39
0
    def test_get_and_update_access_rule_updates_conditionally_changed(
            self, initial_state):
        mock_debug_log = self.mock_object(access.LOG, 'debug')
        share = db_utils.create_share(status=constants.STATUS_AVAILABLE)
        rule = db_utils.create_access(share_id=share['id'],
                                      state=initial_state)
        self.mock_object(
            db, 'share_instance_access_update',
            mock.Mock(side_effect=db.share_instance_access_update))
        updates = {'access_key': 'renfrow2stars'}
        conditionally_change = {
            constants.ACCESS_STATE_APPLYING:
            constants.ACCESS_STATE_QUEUED_TO_DENY,
            constants.ACCESS_STATE_DENYING:
            constants.ACCESS_STATE_QUEUED_TO_DENY,
        }

        actual_rule = (
            self.access_helper.get_and_update_share_instance_access_rule(
                self.context,
                rule['id'],
                updates=updates,
                share_instance_id=share['instance']['id'],
                conditionally_change=conditionally_change))
        self.assertEqual(rule['id'], actual_rule['access_id'])
        if 'ing' in initial_state:
            self.assertEqual(constants.ACCESS_STATE_QUEUED_TO_DENY,
                             actual_rule['state'])
            self.assertFalse(mock_debug_log.called)
        else:
            self.assertEqual(initial_state, actual_rule['state'])
            mock_debug_log.assert_called_once()
Exemplo n.º 40
0
    def test_get_and_update_access_rule_updates_conditionally_changed(
            self, initial_state):
        mock_debug_log = self.mock_object(access.LOG, 'debug')
        share = db_utils.create_share(status=constants.STATUS_AVAILABLE)
        rule = db_utils.create_access(share_id=share['id'],
                                      state=initial_state)
        self.mock_object(db, 'share_instance_access_update', mock.Mock(
            side_effect=db.share_instance_access_update))
        updates = {
            'access_key': 'renfrow2stars'
        }
        conditionally_change = {
            constants.ACCESS_STATE_APPLYING:
                constants.ACCESS_STATE_QUEUED_TO_DENY,
            constants.ACCESS_STATE_DENYING:
                constants.ACCESS_STATE_QUEUED_TO_DENY,
        }

        actual_rule = (
            self.access_helper.get_and_update_share_instance_access_rule(
                self.context, rule['id'], updates=updates,
                share_instance_id=share['instance']['id'],
                conditionally_change=conditionally_change)
        )
        self.assertEqual(rule['id'], actual_rule['access_id'])
        if 'ing' in initial_state:
            self.assertEqual(constants.ACCESS_STATE_QUEUED_TO_DENY,
                             actual_rule['state'])
            self.assertFalse(mock_debug_log.called)
        else:
            self.assertEqual(initial_state, actual_rule['state'])
            mock_debug_log.assert_called_once()
Exemplo n.º 41
0
    def test_update_access_rules_an_update_is_in_progress(self, initial_state):
        share = db_utils.create_share(status=constants.STATUS_AVAILABLE)
        share_instance = share['instance']
        db_utils.create_access(share_id=share['id'], state=initial_state)
        mock_debug_log = self.mock_object(access.LOG, 'debug')
        self.mock_object(self.access_helper, '_update_access_rules')
        get_and_update_call = self.mock_object(
            self.access_helper, 'get_and_update_share_instance_access_rules',
            mock.Mock(side_effect=self.access_helper.
                      get_and_update_share_instance_access_rules))

        retval = self.access_helper.update_access_rules(
            self.context, share_instance['id'])

        expected_filters = {
            'state':
            (constants.ACCESS_STATE_APPLYING, constants.ACCESS_STATE_DENYING),
        }
        self.assertIsNone(retval)
        mock_debug_log.assert_called_once()
        get_and_update_call.assert_called_once_with(
            self.context,
            filters=expected_filters,
            share_instance_id=share_instance['id'])
        self.assertFalse(self.access_helper._update_access_rules.called)
Exemplo n.º 42
0
    def test_allow_access(self, ip_address, version):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])

        access = {
            'id': 'fake_id',
            'access_type': 'ip',
            'access_to': ip_address,
            'state': 'new',
        }

        get = self.mock_object(share_api.API, 'get',
                               mock.Mock(return_value=share))
        get_snapshot = self.mock_object(share_api.API, 'get_snapshot',
                                        mock.Mock(return_value=snapshot))
        allow_access = self.mock_object(share_api.API, 'snapshot_allow_access',
                                        mock.Mock(return_value=access))
        body = {'allow_access': access}
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version=version)

        actual = self.controller.allow_access(req, snapshot['id'], body)

        self.assertEqual(access, actual['snapshot_access'])
        get.assert_called_once_with(utils.IsAMatcher(context.RequestContext),
                                    share['id'])
        get_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot['id'])
        allow_access.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot,
            access['access_type'], access['access_to'])
Exemplo n.º 43
0
    def test_update_access_rules_delete_all_rules(self, delete_all_rules):
        share = db_utils.create_share(status=constants.STATUS_AVAILABLE)
        share_instance = share['instance']
        db_utils.create_access(share_id=share['id'],
                               state=constants.STATUS_ACTIVE)
        db_utils.create_access(share_id=share['id'],
                               state=constants.ACCESS_STATE_QUEUED_TO_APPLY)
        db_utils.create_access(share_id=share['id'],
                               state=constants.ACCESS_STATE_QUEUED_TO_DENY)
        mock_debug_log = self.mock_object(access.LOG, 'debug')
        self.mock_object(self.access_helper, '_update_access_rules')
        get_and_update_call = self.mock_object(
            self.access_helper, 'get_and_update_share_instance_access_rules',
            mock.Mock(side_effect=self.access_helper.
                      get_and_update_share_instance_access_rules))

        retval = self.access_helper.update_access_rules(
            self.context,
            share_instance['id'],
            delete_all_rules=delete_all_rules)

        expected_rule_filter_1 = {
            'state':
            (constants.ACCESS_STATE_APPLYING, constants.ACCESS_STATE_DENYING),
        }
        expected_rule_filter_2 = {
            'state': (constants.ACCESS_STATE_QUEUED_TO_APPLY,
                      constants.ACCESS_STATE_QUEUED_TO_DENY),
        }
        expected_conditionally_change = {
            constants.ACCESS_STATE_QUEUED_TO_APPLY:
            constants.ACCESS_STATE_APPLYING,
            constants.ACCESS_STATE_QUEUED_TO_DENY:
            constants.ACCESS_STATE_DENYING,
        }
        expected_get_and_update_calls = []
        if delete_all_rules:
            deny_all_updates = {
                'state': constants.ACCESS_STATE_QUEUED_TO_DENY,
            }
            expected_get_and_update_calls = [
                mock.call(self.context,
                          updates=deny_all_updates,
                          share_instance_id=share_instance['id']),
            ]
        expected_get_and_update_calls.extend([
            mock.call(self.context,
                      filters=expected_rule_filter_1,
                      share_instance_id=share_instance['id']),
            mock.call(self.context,
                      filters=expected_rule_filter_2,
                      share_instance_id=share_instance['id'],
                      conditionally_change=expected_conditionally_change),
        ])

        self.assertIsNone(retval)
        mock_debug_log.assert_called_once()
        get_and_update_call.assert_has_calls(expected_get_and_update_calls)
        self.access_helper._update_access_rules.assert_called_once_with(
            self.context, share_instance['id'], share_server=None)
Exemplo n.º 44
0
    def test_allow_access_share_without_mount_snap_support(self):
        share = db_utils.create_share(mount_snapshot_support=False)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])

        access = {
            'id': 'fake_id',
            'access_type': 'ip',
            'access_to': '1.1.1.1',
            'state': 'new',
        }

        get_snapshot = self.mock_object(share_api.API, 'get_snapshot',
                                        mock.Mock(return_value=snapshot))
        get = self.mock_object(share_api.API, 'get',
                               mock.Mock(return_value=share))

        body = {'allow_access': access}
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.allow_access, req,
                          snapshot['id'], body)

        get.assert_called_once_with(utils.IsAMatcher(context.RequestContext),
                                    share['id'])
        get_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot['id'])
Exemplo n.º 45
0
    def test_get_and_update_access_rules_status_conditionally_change(
            self, initial_status, change_allowed):
        share = db_utils.create_share(access_rules_status=initial_status,
                                      status=constants.STATUS_AVAILABLE)
        share = db.share_get(self.context, share['id'])
        self.assertEqual(initial_status, share['access_rules_status'])

        conditionally_change = {
            constants.SHARE_INSTANCE_RULES_SYNCING: constants.STATUS_ACTIVE,
        }

        updated_instance = (self.access_helper.
                            get_and_update_share_instance_access_rules_status(
                                self.context,
                                conditionally_change=conditionally_change,
                                share_instance_id=share['instance']['id']))

        share = db.share_get(self.context, share['id'])
        if change_allowed:
            self.assertEqual(constants.STATUS_ACTIVE,
                             share['access_rules_status'])
            self.assertIsNotNone(updated_instance)
        else:
            self.assertEqual(initial_status, share['access_rules_status'])
            self.assertIsNone(updated_instance)
Exemplo n.º 46
0
    def test_deny_access_access_rule_not_found(self):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])
        access = db_utils.create_snapshot_access(
            share_snapshot_id=snapshot['id'])
        wrong_access = {
            'access_type': 'fake_type',
            'access_to': 'fake_IP',
            'share_snapshot_id': 'fake_id'
        }

        get = self.mock_object(share_api.API, 'get',
                               mock.Mock(return_value=share))
        get_snapshot = self.mock_object(share_api.API, 'get_snapshot',
                                        mock.Mock(return_value=snapshot))
        access_get = self.mock_object(share_api.API, 'snapshot_access_get',
                                      mock.Mock(return_value=wrong_access))

        body = {'deny_access': {'access_id': access.id}}
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.deny_access, req, snapshot['id'],
                          body)
        get.assert_called_once_with(utils.IsAMatcher(context.RequestContext),
                                    share['id'])
        get_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot['id'])
        access_get.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext),
            body['deny_access']['access_id'])
Exemplo n.º 47
0
 def setUp(self):
     super(DataManagerTestCase, self).setUp()
     self.manager = manager.DataManager()
     self.context = context.get_admin_context()
     self.topic = 'fake_topic'
     self.share = db_utils.create_share()
     manager.CONF.set_default('migration_tmp_location', '/tmp/')
Exemplo n.º 48
0
    def test_allow_access_exists_exception(self):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')
        access = {
            'id': 'fake_id',
            'access_type': 'ip',
            'access_to': '1.1.1.1',
            'state': 'new',
        }
        msg = "Share snapshot access exists."

        get = self.mock_object(share_api.API, 'get', mock.Mock(
            return_value=share))
        get_snapshot = self.mock_object(share_api.API, 'get_snapshot',
                                        mock.Mock(return_value=snapshot))
        allow_access = self.mock_object(
            share_api.API, 'snapshot_allow_access', mock.Mock(
                side_effect=exception.ShareSnapshotAccessExists(msg)))

        body = {'allow_access': access}

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.allow_access, req,
                          snapshot['id'], body)

        get.assert_called_once_with(utils.IsAMatcher(context.RequestContext),
                                    share['id'])
        get_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot['id'])
        allow_access.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot,
            access['access_type'], access['access_to'])
Exemplo n.º 49
0
 def setUp(self):
     super(DataRpcAPITestCase, self).setUp()
     share = db_utils.create_share(
         availability_zone=CONF.storage_availability_zone,
         status=constants.STATUS_AVAILABLE
     )
     self.fake_share = jsonutils.to_primitive(share)
Exemplo n.º 50
0
    def test_deny_access(self):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])
        access = db_utils.create_snapshot_access(
            share_snapshot_id=snapshot['id'])

        get = self.mock_object(share_api.API, 'get',
                               mock.Mock(return_value=share))
        get_snapshot = self.mock_object(share_api.API, 'get_snapshot',
                                        mock.Mock(return_value=snapshot))
        access_get = self.mock_object(share_api.API, 'snapshot_access_get',
                                      mock.Mock(return_value=access))
        deny_access = self.mock_object(share_api.API, 'snapshot_deny_access')

        body = {'deny_access': {'access_id': access.id}}
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')

        resp = self.controller.deny_access(req, snapshot['id'], body)

        self.assertEqual(202, resp.status_int)
        get.assert_called_once_with(utils.IsAMatcher(context.RequestContext),
                                    share['id'])
        get_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot['id'])
        access_get.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext),
            body['deny_access']['access_id'])
        deny_access.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot, access)
Exemplo n.º 51
0
    def test_get_and_update_all_access_rules_updates_conditionally_changed(
            self, statuses, changes_allowed):
        share = db_utils.create_share(status=constants.STATUS_AVAILABLE)
        db_utils.create_access(share_id=share['id'], state=statuses[0])
        db_utils.create_access(share_id=share['id'], state=statuses[-1])
        self.mock_object(db, 'share_instance_access_update', mock.Mock(
            side_effect=db.share_instance_access_update))
        updates = {
            'access_key': 'renfrow2stars'
        }
        expected_updates = {
            'access_key': 'renfrow2stars',
            'state': constants.ACCESS_STATE_QUEUED_TO_DENY,
        }
        conditionally_change = {
            constants.ACCESS_STATE_APPLYING:
                constants.ACCESS_STATE_QUEUED_TO_DENY,
            constants.ACCESS_STATE_QUEUED_TO_APPLY:
                constants.ACCESS_STATE_QUEUED_TO_DENY,
        }

        rules = self.access_helper.get_and_update_share_instance_access_rules(
            self.context, share_instance_id=share['instance']['id'],
            updates=updates, conditionally_change=conditionally_change)

        state_changed_rules = [
            r for r in rules if
            r['state'] == constants.ACCESS_STATE_QUEUED_TO_DENY
        ]
        self.assertEqual(changes_allowed, len(state_changed_rules))
        self.assertEqual(2, db.share_instance_access_update.call_count)
        db.share_instance_access_update.assert_has_calls([
            mock.call(self.context, mock.ANY, share['instance']['id'],
                      expected_updates),
        ] * changes_allowed)
Exemplo n.º 52
0
    def test_share_instance_delete_with_share(self):
        share = db_utils.create_share()

        db_api.share_instance_delete(self.ctxt, share.instance['id'])

        self.assertRaises(exception.NotFound, db_api.share_get,
                          self.ctxt, share['id'])
Exemplo n.º 53
0
    def test_migrate_share_to_host_exception(self, exc):

        share = db_utils.create_share(status=constants.STATUS_MIGRATING)
        host = 'fake@backend#pool'
        request_spec = {'share_id': share['id']}

        self.mock_object(db, 'share_get', mock.Mock(return_value=share))
        self.mock_object(
            base.Scheduler, 'host_passes_filters',
            mock.Mock(side_effect=exc))
        self.mock_object(db, 'share_update')
        self.mock_object(db, 'share_instance_update')

        capture = (exception.NoValidHost if
                   isinstance(exc, exception.NoValidHost) else TypeError)

        self.assertRaises(
            capture, self.manager.migrate_share_to_host,
            self.context, share['id'], host, False, True, True, False, True,
            'fake_net_id', 'fake_type_id', request_spec, None)

        base.Scheduler.host_passes_filters.assert_called_once_with(
            self.context, host, request_spec, None)
        db.share_get.assert_called_once_with(self.context, share['id'])
        db.share_update.assert_called_once_with(
            self.context, share['id'],
            {'task_state': constants.TASK_STATE_MIGRATION_ERROR})
        db.share_instance_update.assert_called_once_with(
            self.context, share.instance['id'],
            {'status': constants.STATUS_AVAILABLE})
Exemplo n.º 54
0
 def setUp(self):
     super(DataRpcAPITestCase, self).setUp()
     self.context = context.get_admin_context()
     share = db_utils.create_share(
         availability_zone=CONF.storage_availability_zone,
         status=constants.STATUS_AVAILABLE)
     self.fake_share = jsonutils.to_primitive(share)
Exemplo n.º 55
0
    def test_migrate_share_to_host(self):

        class fake_host(object):
            host = 'fake@backend#pool'

        share = db_utils.create_share()
        host = fake_host()

        self.mock_object(db, 'share_get', mock.Mock(return_value=share))
        self.mock_object(share_rpcapi.ShareAPI, 'migration_start',
                         mock.Mock(side_effect=TypeError))
        self.mock_object(base.Scheduler,
                         'host_passes_filters',
                         mock.Mock(return_value=host))

        self.assertRaises(
            TypeError, self.manager.migrate_share_to_host,
            self.context, share['id'], 'fake@backend#pool', False, True, True,
            False, True, 'fake_net_id', 'fake_type_id', {}, None)

        db.share_get.assert_called_once_with(self.context, share['id'])
        base.Scheduler.host_passes_filters.assert_called_once_with(
            self.context, 'fake@backend#pool', {}, None)
        share_rpcapi.ShareAPI.migration_start.assert_called_once_with(
            self.context, share, host.host, False, True, True, False, True,
            'fake_net_id', 'fake_type_id')
Exemplo n.º 56
0
    def test_show(self):
        test_instance = db_utils.create_share(size=1).instance
        id = test_instance["id"]

        actual_result = self.controller.show(self._get_request("fake"), id)

        self.assertEqual(id, actual_result["share_instance"]["id"])
        self.mock_policy_check.assert_called_once_with(self.admin_context, self.resource_name, "show")
Exemplo n.º 57
0
 def _setup_snapshot_data(self, snapshot=None, version='2.7'):
     if snapshot is None:
         share = db_utils.create_share()
         snapshot = db_utils.create_snapshot(
             status=constants.STATUS_AVAILABLE, share_id=share['id'])
     req = fakes.HTTPRequest.blank('/v2/fake/snapshots/%s/action' %
                                   snapshot['id'], version=version)
     return snapshot, req