コード例 #1
0
ファイル: test_access.py プロジェクト: vast-data/manila
    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)
コード例 #2
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)
コード例 #3
0
ファイル: test_access.py プロジェクト: ponychou/manila
    def test_update_access_rules_fallback(self):
        add_rules = [db_utils.create_access(share_id=self.share['id'])]
        delete_rules = [db_utils.create_access(share_id=self.share['id'])]
        original_rules = [db_utils.create_access(share_id=self.share['id'])]

        self.mock_object(db, "share_instance_get", mock.Mock(
            return_value=self.share_instance))
        self.mock_object(db, "share_access_get_all_for_share",
                         mock.Mock(return_value=original_rules))
        self.mock_object(db, "share_access_get_all_for_instance",
                         mock.Mock(return_value=original_rules))
        self.mock_object(db, "share_instance_update_access_status",
                         mock.Mock())
        self.mock_object(self.driver, "update_access",
                         mock.Mock(side_effect=NotImplementedError))
        self.mock_object(self.driver, "allow_access",
                         mock.Mock())
        self.mock_object(self.driver, "deny_access",
                         mock.Mock())

        self.share_access_helper.update_access_rules(self.context,
                                                     self.share_instance['id'],
                                                     add_rules, delete_rules)

        self.driver.update_access.assert_called_with(
            self.context, self.share_instance, original_rules,
            add_rules=add_rules, delete_rules=[], share_server=None)
        self.driver.allow_access.assert_called_with(self.context,
                                                    self.share_instance,
                                                    add_rules[0],
                                                    share_server=None)
        self.assertFalse(self.driver.deny_access.called)
        db.share_instance_update_access_status.assert_called_with(
            self.context, self.share_instance['id'], constants.STATUS_ACTIVE)
コード例 #4
0
ファイル: test_access.py プロジェクト: openstack/manila
    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)
コード例 #5
0
ファイル: test_migration.py プロジェクト: jkasarherou/manila
    def test_wait_for_allow_access_error(self):

        access_new = db_utils.create_access(state=constants.STATUS_NEW,
                                            share_id=self.share['id'])
        access_error = db_utils.create_access(state=constants.STATUS_ERROR,
                                              share_id=self.share['id'])

        self.mock_object(self.helper.api, 'access_get',
                         mock.Mock(return_value=access_error))

        self.assertRaises(exception.ShareMigrationFailed,
                          self.helper.wait_for_allow_access, access_new)
コード例 #6
0
    def test_wait_for_allow_access_error(self):

        access_new = db_utils.create_access(state=constants.STATUS_NEW,
                                            share_id=self.share['id'])
        access_error = db_utils.create_access(state=constants.STATUS_ERROR,
                                              share_id=self.share['id'])

        self.mock_object(self.helper.api, 'access_get',
                         mock.Mock(return_value=access_error))

        self.assertRaises(exception.ShareMigrationFailed,
                          self.helper.wait_for_allow_access, access_new)
コード例 #7
0
ファイル: test_access.py プロジェクト: vast-data/manila
    def test_get_and_update_all_access_rules_just_get(self):
        share = db_utils.create_share(status=constants.STATUS_AVAILABLE)
        rule_1 = db_utils.create_access(share_id=share['id'])
        rule_2 = db_utils.create_access(share_id=share['id'])
        self.mock_object(db, 'share_instance_access_update')

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

        self.assertEqual(2, len(rules))
        rule_ids = [r['access_id'] for r in rules]
        self.assertIn(rule_1['id'], rule_ids)
        self.assertIn(rule_2['id'], rule_ids)
        self.assertFalse(db.share_instance_access_update.called)
コード例 #8
0
ファイル: test_access.py プロジェクト: openstack/manila
    def test_get_and_update_all_access_rules_just_get(self):
        share = db_utils.create_share(status=constants.STATUS_AVAILABLE)
        rule_1 = db_utils.create_access(share_id=share['id'])
        rule_2 = db_utils.create_access(share_id=share['id'])
        self.mock_object(db, 'share_instance_access_update')

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

        self.assertEqual(2, len(rules))
        rule_ids = [r['access_id'] for r in rules]
        self.assertIn(rule_1['id'], rule_ids)
        self.assertIn(rule_2['id'], rule_ids)
        self.assertFalse(db.share_instance_access_update.called)
コード例 #9
0
ファイル: test_migration.py プロジェクト: jkasarherou/manila
    def test_wait_for_allow_access(self):

        access_active = db_utils.create_access(state=constants.STATUS_ACTIVE,
                                               share_id=self.share['id'])
        access_new = db_utils.create_access(state=constants.STATUS_NEW,
                                            share_id=self.share['id'])

        self.mock_object(time, 'sleep')

        self.mock_object(self.helper.api, 'access_get',
                         mock.Mock(side_effect=[access_new, access_active]))

        result = self.helper.wait_for_allow_access(access_new)

        self.assertEqual(access_active, result)
コード例 #10
0
    def test_wait_for_allow_access(self):

        access_active = db_utils.create_access(state=constants.STATUS_ACTIVE,
                                               share_id=self.share['id'])
        access_new = db_utils.create_access(state=constants.STATUS_NEW,
                                            share_id=self.share['id'])

        self.mock_object(time, 'sleep')

        self.mock_object(self.helper.api, 'access_get',
                         mock.Mock(side_effect=[access_new, access_active]))

        result = self.helper.wait_for_allow_access(access_new)

        self.assertEqual(access_active, result)
コード例 #11
0
ファイル: test_manager.py プロジェクト: NetApp/manila
    def test__copy_share_data_exception_mount_2(self):

        access = db_utils.create_access(share_id=self.share['id'])

        connection_info_src = {'mount': 'mount_cmd_src',
                               'unmount': 'unmount_cmd_src'}
        connection_info_dest = {'mount': 'mount_cmd_src',
                                'unmount': 'unmount_cmd_src'}

        fake_copy = mock.MagicMock(cancelled=False)

        # mocks
        self.mock_object(db, 'share_update')
        self.mock_object(db, 'share_instance_get',
                         mock.Mock(side_effect=[self.share['instance'],
                                                self.share['instance']]))

        self.mock_object(helper.DataServiceHelper,
                         'allow_access_to_data_service',
                         mock.Mock(return_value=[access]))

        self.mock_object(helper.DataServiceHelper, 'mount_share_instance',
                         mock.Mock(side_effect=[None, Exception('fake')]))

        self.mock_object(helper.DataServiceHelper, 'cleanup_data_access')
        self.mock_object(helper.DataServiceHelper, 'cleanup_temp_folder')
        self.mock_object(helper.DataServiceHelper,
                         'cleanup_unmount_temp_folder')

        # run
        self.assertRaises(exception.ShareDataCopyFailed,
                          self.manager._copy_share_data, self.context,
                          fake_copy, self.share, 'ins1_id', 'ins2_id',
                          connection_info_src, connection_info_dest)

        # asserts
        db.share_update.assert_called_once_with(
            self.context, self.share['id'],
            {'task_state': constants.TASK_STATE_DATA_COPYING_STARTING})

        (helper.DataServiceHelper.allow_access_to_data_service.
            assert_called_once_with(
                self.share['instance'], connection_info_src,
                self.share['instance'], connection_info_dest))

        helper.DataServiceHelper.mount_share_instance.assert_has_calls([
            mock.call(connection_info_src['mount'], '/tmp/',
                      self.share['instance']),
            mock.call(connection_info_dest['mount'], '/tmp/',
                      self.share['instance'])])

        (helper.DataServiceHelper.cleanup_unmount_temp_folder.
            assert_called_once_with(
                connection_info_src['unmount'], '/tmp/', 'ins1_id'))

        helper.DataServiceHelper.cleanup_temp_folder.assert_has_calls([
            mock.call('ins2_id', '/tmp/'), mock.call('ins1_id', '/tmp/')])

        helper.DataServiceHelper.cleanup_data_access.assert_has_calls([
            mock.call([access], 'ins2_id'), mock.call([access], 'ins1_id')])
コード例 #12
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()
コード例 #13
0
ファイル: test_api.py プロジェクト: sajuptpm/manila
    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)
コード例 #14
0
ファイル: test_rpcapi.py プロジェクト: vkmc/manila
 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 = '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_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()
コード例 #15
0
ファイル: test_rpcapi.py プロジェクト: JosonYuan/manila
 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()
コード例 #16
0
ファイル: test_migration.py プロジェクト: NetApp/manila
    def test_apply_new_access_rules(self):

        new_share_instance = db_utils.create_share_instance(
            share_id=self.share['id'], status=constants.STATUS_AVAILABLE,
            access_rules_status='active')

        access = db_utils.create_access(share_id=self.share['id'],
                                        access_to='fake_ip',
                                        access_level='rw')

        # mocks
        self.mock_object(db, 'share_instance_get',
                         mock.Mock(return_value=new_share_instance))
        self.mock_object(db, 'share_instance_access_copy')
        self.mock_object(db, 'share_access_get_all_for_instance',
                         mock.Mock(return_value=[access]))
        self.mock_object(share_api.API, 'allow_access_to_instance')
        self.mock_object(utils, 'wait_for_access_update')

        # run
        self.helper.apply_new_access_rules(new_share_instance)

        # asserts
        db.share_instance_get.assert_called_once_with(
            self.context, new_share_instance['id'], with_share_data=True)
        db.share_instance_access_copy(self.context, self.share['id'],
                                      new_share_instance['id'])
        db.share_access_get_all_for_instance.assert_called_once_with(
            self.context, new_share_instance['id'])
        share_api.API.allow_access_to_instance.assert_called_with(
            self.context, new_share_instance, [access])
        utils.wait_for_access_update.assert_called_with(
            self.context, db, new_share_instance,
            self.helper.migration_wait_access_rules_timeout)
コード例 #17
0
ファイル: test_migration.py プロジェクト: NetApp/manila
    def test_revert_access_rules(self):

        share_instance = db_utils.create_share_instance(
            share_id=self.share['id'], status=constants.STATUS_AVAILABLE)

        access = db_utils.create_access(share_id=self.share['id'],
                                        access_to='fake_ip',
                                        access_level='rw')

        server = db_utils.create_share_server(share_id=self.share['id'])

        # mocks
        share_driver = mock.Mock()
        self.mock_object(share_driver, 'update_access')

        self.mock_object(db, 'share_access_get_all_for_instance',
                         mock.Mock(return_value=[access]))

        # run
        self.helper.revert_access_rules(share_instance, server, share_driver)

        # asserts
        db.share_access_get_all_for_instance.assert_called_once_with(
            self.context, share_instance['id'])
        share_driver.update_access.assert_called_once_with(
            self.context, share_instance, [access], add_rules=[],
            delete_rules=[], share_server=server)
コード例 #18
0
ファイル: test_migration.py プロジェクト: vponomaryov/manila
    def test_apply_new_access_rules_there_are_rules(self, prior_rules):

        new_share_instance = db_utils.create_share_instance(
            share_id=self.share['id'], status=constants.STATUS_AVAILABLE,
            access_rules_status='active')
        rules = None
        if prior_rules:
            rules = [
                db_utils.create_access(
                    share_id=self.share['id'], access_to='fake_ip')
            ]

        # mocks
        self.mock_object(db, 'share_instance_access_copy', mock.Mock(
            return_value=rules))
        self.mock_object(share_api.API, 'allow_access_to_instance')
        self.mock_object(utils, 'wait_for_access_update')

        # run
        self.helper.apply_new_access_rules(new_share_instance)

        # asserts
        db.share_instance_access_copy.assert_called_once_with(
            self.context, self.share['id'], new_share_instance['id'])
        if prior_rules:
            share_api.API.allow_access_to_instance.assert_called_with(
                self.context, new_share_instance)
            utils.wait_for_access_update.assert_called_with(
                self.context, db, new_share_instance,
                self.helper.migration_wait_access_rules_timeout)
        else:
            self.assertFalse(share_api.API.allow_access_to_instance.called)
            self.assertFalse(utils.wait_for_access_update.called)
コード例 #19
0
ファイル: test_migration.py プロジェクト: vponomaryov/manila
    def test_revert_access_rules(self):

        share_instance = db_utils.create_share_instance(
            share_id=self.share['id'], status=constants.STATUS_AVAILABLE)

        access = db_utils.create_access(share_id=self.share['id'],
                                        access_to='fake_ip',
                                        access_level='rw')

        server = db_utils.create_share_server(share_id=self.share['id'])

        # mocks
        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(return_value=[access]))

        # run
        self.helper.revert_access_rules(share_instance, server)

        # asserts
        get_and_update_call.assert_called_once_with(
            self.context, share_instance_id=share_instance['id'],
            updates={'state': constants.ACCESS_STATE_QUEUED_TO_APPLY})
        self.access_helper.update_access_rules.assert_called_once_with(
            self.context, share_instance['id'], share_server=server)
コード例 #20
0
    def test__copy_share_data_exception_mount_2(self):

        access = db_utils.create_access(share_id=self.share['id'])

        migration_info_src = {
            'mount': 'mount_cmd_src',
            'unmount': 'unmount_cmd_src'
        }
        migration_info_dest = {
            'mount': 'mount_cmd_src',
            'unmount': 'unmount_cmd_src'
        }

        fake_copy = mock.MagicMock(cancelled=False)

        # mocks
        self.mock_object(db, 'share_update')

        self.mock_object(helper.DataServiceHelper,
                         'allow_access_to_data_service',
                         mock.Mock(return_value=access))

        self.mock_object(helper.DataServiceHelper, 'mount_share_instance',
                         mock.Mock(side_effect=[None, Exception('fake')]))

        self.mock_object(helper.DataServiceHelper, 'cleanup_data_access')
        self.mock_object(helper.DataServiceHelper, 'cleanup_temp_folder')
        self.mock_object(helper.DataServiceHelper,
                         'cleanup_unmount_temp_folder')

        # run
        self.assertRaises(exception.ShareDataCopyFailed,
                          self.manager._copy_share_data, self.context,
                          fake_copy, self.share, 'ins1_id', 'ins2_id',
                          migration_info_src, migration_info_dest)

        # asserts
        db.share_update.assert_called_once_with(
            self.context, self.share['id'],
            {'task_state': constants.TASK_STATE_DATA_COPYING_STARTING})

        helper.DataServiceHelper.allow_access_to_data_service.\
            assert_called_once_with(self.share, 'ins1_id', 'ins2_id')

        helper.DataServiceHelper.mount_share_instance.assert_has_calls([
            mock.call(migration_info_src['mount'], '/tmp/', 'ins1_id'),
            mock.call(migration_info_dest['mount'], '/tmp/', 'ins2_id')
        ])

        helper.DataServiceHelper.cleanup_unmount_temp_folder.\
            assert_called_once_with(
                migration_info_src['unmount'], '/tmp/', 'ins1_id')

        helper.DataServiceHelper.cleanup_temp_folder.assert_has_calls(
            [mock.call('ins2_id', '/tmp/'),
             mock.call('ins1_id', '/tmp/')])

        helper.DataServiceHelper.cleanup_data_access.assert_has_calls(
            [mock.call(access, 'ins2_id'),
             mock.call(access, 'ins1_id')])
コード例 #21
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'])
コード例 #22
0
ファイル: test_access.py プロジェクト: petrutlucian94/manila
    def test_update_access_rules_recursive_call(self):
        share_instance = db_utils.create_share_instance(
            access_rules_status=constants.STATUS_ACTIVE,
            share_id=self.share['id'])
        add_rules = [db_utils.create_access(
            share_id=self.share['id'])]
        original_rules = []

        self.mock_object(db, "share_instance_get", mock.Mock(
            return_value=share_instance))
        self.mock_object(db, "share_access_get_all_for_instance",
                         mock.Mock(return_value=original_rules))
        mock_update_access = self.mock_object(self.driver, "update_access")
        self.mock_object(self.share_access_helper, '_check_needs_refresh',
                         mock.Mock(side_effect=[True, False]))

        self.share_access_helper.update_access_rules(self.context,
                                                     share_instance['id'],
                                                     add_rules=add_rules)

        mock_update_access.assert_has_calls([
            mock.call(self.context, share_instance, original_rules,
                      add_rules=add_rules, delete_rules=[], share_server=None),
            mock.call(self.context, share_instance, original_rules,
                      add_rules=[], delete_rules=[], share_server=None)
        ])
コード例 #23
0
    def test_revert_access_rules(self):

        share_instance = db_utils.create_share_instance(
            share_id=self.share['id'], status=constants.STATUS_AVAILABLE)

        access = db_utils.create_access(share_id=self.share['id'],
                                        access_to='fake_ip',
                                        access_level='rw')

        server = db_utils.create_share_server(share_id=self.share['id'])

        # mocks
        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(return_value=[access]))

        # run
        self.helper.revert_access_rules(share_instance, server)

        # asserts
        get_and_update_call.assert_called_once_with(
            self.context,
            share_instance_id=share_instance['id'],
            updates={'state': constants.ACCESS_STATE_QUEUED_TO_APPLY})
        self.access_helper.update_access_rules.assert_called_once_with(
            self.context, share_instance['id'], share_server=server)
コード例 #24
0
ファイル: test_models.py プロジェクト: vponomaryov/manila
    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'])
コード例 #25
0
ファイル: test_migration.py プロジェクト: swipswaps/manila
    def test_apply_new_access_rules(self):

        new_share_instance = db_utils.create_share_instance(
            share_id=self.share['id'],
            status=constants.STATUS_AVAILABLE,
            access_rules_status='active')

        access = db_utils.create_access(share_id=self.share['id'],
                                        access_to='fake_ip',
                                        access_level='rw')

        # mocks
        self.mock_object(db, 'share_instance_access_copy')
        self.mock_object(db, 'share_access_get_all_for_instance',
                         mock.Mock(return_value=[access]))
        self.mock_object(share_api.API, 'allow_access_to_instance')
        self.mock_object(utils, 'wait_for_access_update')

        # run
        self.helper.apply_new_access_rules(new_share_instance)

        # asserts
        db.share_instance_access_copy(self.context, self.share['id'],
                                      new_share_instance['id'])
        db.share_access_get_all_for_instance.assert_called_once_with(
            self.context, new_share_instance['id'])
        share_api.API.allow_access_to_instance.assert_called_with(
            self.context, new_share_instance, [access])
        utils.wait_for_access_update.assert_called_with(
            self.context, db, new_share_instance,
            self.helper.migration_wait_access_rules_timeout)
コード例 #26
0
    def test_apply_new_access_rules_there_are_rules(self, prior_rules):

        new_share_instance = db_utils.create_share_instance(
            share_id=self.share['id'],
            status=constants.STATUS_AVAILABLE,
            access_rules_status='active')
        rules = None
        if prior_rules:
            rules = [
                db_utils.create_access(share_id=self.share['id'],
                                       access_to='fake_ip')
            ]

        # mocks
        self.mock_object(db, 'share_instance_access_copy',
                         mock.Mock(return_value=rules))
        self.mock_object(share_api.API, 'allow_access_to_instance')
        self.mock_object(utils, 'wait_for_access_update')

        # run
        self.helper.apply_new_access_rules(new_share_instance)

        # asserts
        db.share_instance_access_copy.assert_called_once_with(
            self.context, self.share['id'], new_share_instance['id'])
        if prior_rules:
            share_api.API.allow_access_to_instance.assert_called_with(
                self.context, new_share_instance)
            utils.wait_for_access_update.assert_called_with(
                self.context, db, new_share_instance,
                self.helper.migration_wait_access_rules_timeout)
        else:
            self.assertFalse(share_api.API.allow_access_to_instance.called)
            self.assertFalse(utils.wait_for_access_update.called)
コード例 #27
0
ファイル: test_migration.py プロジェクト: ponychou/manila
    def test_revert_access_rules(self):

        share_instance = db_utils.create_share_instance(
            share_id=self.share['id'], status=constants.STATUS_AVAILABLE)

        access = db_utils.create_access(share_id=self.share['id'],
                                        access_to='fake_ip',
                                        access_level='rw')

        server = db_utils.create_share_server(share_id=self.share['id'])

        # mocks
        share_driver = mock.Mock()
        self.mock_object(share_driver, 'update_access')

        self.mock_object(db, 'share_access_get_all_for_instance',
                         mock.Mock(return_value=[access]))

        # run
        self.helper.revert_access_rules(share_instance, server, share_driver)

        # asserts
        db.share_access_get_all_for_instance.assert_called_once_with(
            self.context, share_instance['id'])
        share_driver.update_access.assert_called_once_with(self.context,
                                                           share_instance,
                                                           [access],
                                                           add_rules=[],
                                                           delete_rules=[],
                                                           share_server=server)
コード例 #28
0
ファイル: test_access.py プロジェクト: petrutlucian94/manila
    def test_update_access_rules_exception(self):
        original_rules = []
        add_rules = [db_utils.create_access(share_id=self.share['id'])]
        delete_rules = 'all'

        self.mock_object(db, "share_instance_get", mock.Mock(
            return_value=self.share_instance))
        self.mock_object(db, "share_access_get_all_for_instance",
                         mock.Mock(return_value=original_rules))
        self.mock_object(db, "share_instance_update_access_status",
                         mock.Mock())
        self.mock_object(self.driver, "update_access",
                         mock.Mock(side_effect=exception.ManilaException))

        self.assertRaises(exception.ManilaException,
                          self.share_access_helper.update_access_rules,
                          self.context, self.share_instance['id'], add_rules,
                          delete_rules)

        self.driver.update_access.assert_called_with(
            self.context, self.share_instance, [], add_rules=add_rules,
            delete_rules=original_rules, share_server=None)

        db.share_instance_update_access_status.assert_called_with(
            self.context, self.share_instance['id'], constants.STATUS_ERROR)
コード例 #29
0
ファイル: test_access.py プロジェクト: ponychou/manila
    def test_update_access_rules_exception(self):
        original_rules = []
        add_rules = [db_utils.create_access(share_id=self.share['id'])]
        delete_rules = 'all'

        self.mock_object(db, "share_instance_get", mock.Mock(
            return_value=self.share_instance))
        self.mock_object(db, "share_access_get_all_for_instance",
                         mock.Mock(return_value=original_rules))
        self.mock_object(db, "share_instance_update_access_status",
                         mock.Mock())
        self.mock_object(self.driver, "update_access",
                         mock.Mock(side_effect=exception.ManilaException))

        self.assertRaises(exception.ManilaException,
                          self.share_access_helper.update_access_rules,
                          self.context, self.share_instance['id'], add_rules,
                          delete_rules)

        self.driver.update_access.assert_called_with(
            self.context, self.share_instance, [], add_rules=add_rules,
            delete_rules=original_rules, share_server=None)

        db.share_instance_update_access_status.assert_called_with(
            self.context, self.share_instance['id'], constants.STATUS_ERROR)
コード例 #30
0
ファイル: test_access.py プロジェクト: ponychou/manila
    def test_update_access_rules_recursive_call(self):
        share_instance = db_utils.create_share_instance(
            access_rules_status=constants.STATUS_ACTIVE,
            share_id=self.share['id'])
        add_rules = [db_utils.create_access(
            share_id=self.share['id'])]
        original_rules = []

        self.mock_object(db, "share_instance_get", mock.Mock(
            return_value=share_instance))
        self.mock_object(db, "share_access_get_all_for_instance",
                         mock.Mock(return_value=original_rules))
        mock_update_access = self.mock_object(self.driver, "update_access",
                                              mock.Mock(return_value=None))
        self.mock_object(self.share_access_helper, '_check_needs_refresh',
                         mock.Mock(side_effect=[True, False]))

        self.share_access_helper.update_access_rules(self.context,
                                                     share_instance['id'],
                                                     add_rules=add_rules)

        mock_update_access.assert_has_calls([
            mock.call(self.context, share_instance, original_rules,
                      add_rules=add_rules, delete_rules=[], share_server=None),
            mock.call(self.context, share_instance, original_rules,
                      add_rules=[], delete_rules=[], share_server=None)
        ])
コード例 #31
0
ファイル: test_access.py プロジェクト: openstack/manila
    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()
コード例 #32
0
ファイル: test_models.py プロジェクト: vast-data/manila
    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'])
コード例 #33
0
ファイル: test_access.py プロジェクト: vast-data/manila
    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()
コード例 #34
0
ファイル: test_access.py プロジェクト: openstack/manila
    def test__update_access_rules_for_migration(self):
        share = db_utils.create_share()
        instance = db_utils.create_share_instance(
            status=constants.STATUS_MIGRATING,
            access_rules_status=constants.STATUS_ACTIVE,
            cast_rules_to_readonly=True,
            share_id=share['id'])
        rule_kwargs = {'share_id': share['id'], 'access_level': 'rw'}
        rule_1 = db_utils.create_access(
            state=constants.ACCESS_STATE_ACTIVE, **rule_kwargs)
        rule_1 = db.share_instance_access_get(
            self.context, rule_1['id'], instance['id'])
        rule_2 = db_utils.create_access(
            state=constants.ACCESS_STATE_APPLYING, share_id=share['id'],
            access_level='ro')
        rule_2 = db.share_instance_access_get(
            self.context, rule_2['id'], instance['id'])

        driver_call = self.mock_object(
            self.access_helper.driver, 'update_access',
            mock.Mock(return_value=None))
        self.mock_object(self.access_helper, '_check_needs_refresh',
                         mock.Mock(return_value=False))

        retval = self.access_helper._update_access_rules(
            self.context, instance['id'], share_server='fake_server')

        call_args = driver_call.call_args_list[0][0]
        call_kwargs = driver_call.call_args_list[0][1]
        access_rules_to_be_on_share = [r['id'] for r in call_args[2]]
        access_levels = [r['access_level'] for r in call_args[2]]
        expected_rules_to_be_on_share = ([rule_1['id'], rule_2['id']])

        self.assertIsNone(retval)
        self.assertEqual(instance['id'], call_args[1]['id'])
        self.assertTrue(isinstance(access_rules_to_be_on_share, list))
        self.assertEqual(len(expected_rules_to_be_on_share),
                         len(access_rules_to_be_on_share))
        for pool in expected_rules_to_be_on_share:
            self.assertIn(pool, access_rules_to_be_on_share)
        self.assertEqual(['ro'] * len(expected_rules_to_be_on_share),
                         access_levels)
        self.assertEqual(0, len(call_kwargs['add_rules']))
        self.assertEqual(0, len(call_kwargs['delete_rules']))
        self.assertEqual('fake_server', call_kwargs['share_server'])
コード例 #35
0
ファイル: test_access.py プロジェクト: vast-data/manila
    def test__update_access_rules_for_migration(self):
        share = db_utils.create_share()
        instance = db_utils.create_share_instance(
            status=constants.STATUS_MIGRATING,
            access_rules_status=constants.STATUS_ACTIVE,
            cast_rules_to_readonly=True,
            share_id=share['id'])
        rule_kwargs = {'share_id': share['id'], 'access_level': 'rw'}
        rule_1 = db_utils.create_access(state=constants.ACCESS_STATE_ACTIVE,
                                        **rule_kwargs)
        rule_1 = db.share_instance_access_get(self.context, rule_1['id'],
                                              instance['id'])
        rule_2 = db_utils.create_access(state=constants.ACCESS_STATE_APPLYING,
                                        share_id=share['id'],
                                        access_level='ro')
        rule_2 = db.share_instance_access_get(self.context, rule_2['id'],
                                              instance['id'])

        driver_call = self.mock_object(self.access_helper.driver,
                                       'update_access',
                                       mock.Mock(return_value=None))
        self.mock_object(self.access_helper, '_check_needs_refresh',
                         mock.Mock(return_value=False))

        retval = self.access_helper._update_access_rules(
            self.context, instance['id'], share_server='fake_server')

        call_args = driver_call.call_args_list[0][0]
        call_kwargs = driver_call.call_args_list[0][1]
        access_rules_to_be_on_share = [r['id'] for r in call_args[2]]
        access_levels = [r['access_level'] for r in call_args[2]]
        expected_rules_to_be_on_share = ([rule_1['id'], rule_2['id']])

        self.assertIsNone(retval)
        self.assertEqual(instance['id'], call_args[1]['id'])
        self.assertTrue(isinstance(access_rules_to_be_on_share, list))
        self.assertEqual(len(expected_rules_to_be_on_share),
                         len(access_rules_to_be_on_share))
        for pool in expected_rules_to_be_on_share:
            self.assertIn(pool, access_rules_to_be_on_share)
        self.assertEqual(['ro'] * len(expected_rules_to_be_on_share),
                         access_levels)
        self.assertEqual(0, len(call_kwargs['add_rules']))
        self.assertEqual(0, len(call_kwargs['delete_rules']))
        self.assertEqual('fake_server', call_kwargs['share_server'])
コード例 #36
0
ファイル: test_helper.py プロジェクト: Nexenta/manila
 def setUp(self):
     super(DataServiceHelperTestCase, self).setUp()
     self.share = db_utils.create_share()
     self.share_instance = db_utils.create_share_instance(
         share_id=self.share["id"], status=constants.STATUS_AVAILABLE
     )
     self.context = context.get_admin_context()
     self.access = db_utils.create_access(share_id=self.share["id"])
     self.helper = data_copy_helper.DataServiceHelper(self.context, db, self.share)
コード例 #37
0
ファイル: test_migration.py プロジェクト: jkasarherou/manila
    def test_add_rules_and_wait(self):

        rules_active = [db_utils.create_access(share_id=self.share['id'],
                        state=constants.STATUS_ACTIVE)]
        rules_new = [db_utils.create_access(share_id=self.share['id'],
                     state=constants.STATUS_NEW)]

        self.mock_object(share_api.API, 'allow_access')
        self.mock_object(db, 'share_access_get_all_for_share',
                         mock.Mock(side_effect=[rules_new,
                                                rules_active]))
        self.mock_object(time, 'sleep')

        self.helper.add_rules_and_wait(self.context, self.share,
                                       rules_active)

        db.share_access_get_all_for_share.assert_any_call(
            self.context, self.share['id'])
コード例 #38
0
 def setUp(self):
     super(DataServiceHelperTestCase, self).setUp()
     self.share = db_utils.create_share()
     self.share_instance = db_utils.create_share_instance(
         share_id=self.share['id'],
         status=constants.STATUS_AVAILABLE)
     self.context = context.get_admin_context()
     self.access = db_utils.create_access(share_id=self.share['id'])
     self.helper = data_copy_helper.DataServiceHelper(
         self.context, db, self.share)
コード例 #39
0
ファイル: test_migration.py プロジェクト: jkasarherou/manila
    def test_wait_for_deny_access(self):

        access_active = db_utils.create_access(state=constants.STATUS_ACTIVE,
                                               share_id=self.share['id'])

        self.mock_object(self.helper.api, 'access_get',
                         mock.Mock(side_effect=[[access_active],
                                                exception.NotFound]))

        self.helper.wait_for_deny_access(access_active)
コード例 #40
0
ファイル: test_access.py プロジェクト: openstack/manila
 def _get_and_update_side_effect(*args, **kwargs):
     # The third call to this method needs to create a new access rule
     mtd = other.get_and_update_share_instance_access_rules
     if get_and_update_count[0] == 3:
         rule_4.append(
             db_utils.create_access(
                 state=constants.ACCESS_STATE_QUEUED_TO_APPLY,
                 share_id=share['id']))
     get_and_update_count[0] += 1
     return mtd(*args, **kwargs)
コード例 #41
0
    def test_wait_for_deny_access(self):

        access_active = db_utils.create_access(state=constants.STATUS_ACTIVE,
                                               share_id=self.share['id'])

        self.mock_object(
            self.helper.api, 'access_get',
            mock.Mock(side_effect=[[access_active], exception.NotFound]))

        self.helper.wait_for_deny_access(access_active)
コード例 #42
0
ファイル: test_access.py プロジェクト: vast-data/manila
 def _get_and_update_side_effect(*args, **kwargs):
     # The third call to this method needs to create a new access rule
     mtd = other.get_and_update_share_instance_access_rules
     if get_and_update_count[0] == 3:
         rule_4.append(
             db_utils.create_access(
                 state=constants.ACCESS_STATE_QUEUED_TO_APPLY,
                 share_id=share['id']))
     get_and_update_count[0] += 1
     return mtd(*args, **kwargs)
コード例 #43
0
ファイル: test_migration.py プロジェクト: tpsilva/manila
    def test_deny_migration_access_not_found(self):

        access = {'access_to': 'fake_ip', 'access_type': 'fake_type'}

        access_active = db_utils.create_access(share_id=self.share['id'],
                                               access_to='fake_ip')

        self.mock_object(self.helper.api, 'access_get',
                         mock.Mock(side_effect=exception.NotFound('fake')))

        self.helper.deny_migration_access(access_active, access)
コード例 #44
0
    def test_add_rules_and_wait(self):

        rules_active = [
            db_utils.create_access(share_id=self.share['id'],
                                   state=constants.STATUS_ACTIVE)
        ]
        rules_new = [
            db_utils.create_access(share_id=self.share['id'],
                                   state=constants.STATUS_NEW)
        ]

        self.mock_object(share_api.API, 'allow_access')
        self.mock_object(db, 'share_access_get_all_for_share',
                         mock.Mock(side_effect=[rules_new, rules_active]))
        self.mock_object(time, 'sleep')

        self.helper.add_rules_and_wait(self.context, self.share, rules_active)

        db.share_access_get_all_for_share.assert_any_call(
            self.context, self.share['id'])
コード例 #45
0
ファイル: test_access.py プロジェクト: vast-data/manila
    def test_update_access_rules_nothing_to_update(self):
        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)
        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_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,
        }
        self.assertIsNone(retval)
        mock_debug_log.assert_called_once()
        get_and_update_call.assert_has_calls([
            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.assertFalse(self.access_helper._update_access_rules.called)
コード例 #46
0
    def test_deny_migration_access_not_found(self):

        access = {'access_to': 'fake_ip',
                  'access_type': 'fake_type'}

        access_active = db_utils.create_access(share_id=self.share['id'],
                                               access_to='fake_ip')

        self.mock_object(self.helper.api, 'access_get',
                         mock.Mock(side_effect=exception.NotFound('fake')))

        self.helper.deny_migration_access(access_active, access)
コード例 #47
0
ファイル: test_access.py プロジェクト: openstack/manila
    def test_update_access_rules_nothing_to_update(self):
        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)
        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_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,
        }
        self.assertIsNone(retval)
        mock_debug_log.assert_called_once()
        get_and_update_call.assert_has_calls(
            [
                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.assertFalse(self.access_helper._update_access_rules.called)
コード例 #48
0
ファイル: test_access.py プロジェクト: vkmc/manila
    def test_update_access_rules_maintenance_mode(self, maintenance_mode):
        existing_rules = []
        for i in range(2):
            existing_rules.append(
                db_utils.create_access(
                    id='fakeid%s' % i,
                    share_id=self.share['id'],
                    access_to='fakeip%s' % i,
                ))
        delete_rules = [
            existing_rules[0],
        ]
        rules = [
            existing_rules[1],
        ]
        access_rules_status = (constants.STATUS_ERROR if maintenance_mode else
                               constants.STATUS_ACTIVE)
        share_instance = db_utils.create_share_instance(
            id='fakeid',
            share_id=self.share['id'],
            access_rules_status=access_rules_status)

        self.mock_object(db, "share_instance_get",
                         mock.Mock(return_value=share_instance))
        self.mock_object(db, "share_access_get_all_for_instance",
                         mock.Mock(return_value=existing_rules))
        self.mock_object(db, "share_instance_update_access_status",
                         mock.Mock())
        self.mock_object(self.driver, "update_access",
                         mock.Mock(return_value=None))
        self.mock_object(self.share_access_helper, "_remove_access_rules",
                         mock.Mock())
        self.mock_object(self.share_access_helper, "_check_needs_refresh",
                         mock.Mock(return_value=False))

        self.share_access_helper.update_access_rules(self.context,
                                                     share_instance['id'],
                                                     delete_rules=delete_rules)

        self.driver.update_access.assert_called_once_with(
            self.context,
            share_instance,
            rules,
            add_rules=[],
            delete_rules=([] if maintenance_mode else delete_rules),
            share_server=None)
        self.share_access_helper._remove_access_rules.assert_called_once_with(
            self.context, delete_rules, share_instance['id'])
        self.share_access_helper._check_needs_refresh.assert_called_once_with(
            self.context, rules, share_instance)
        db.share_instance_update_access_status.assert_called_with(
            self.context, share_instance['id'], constants.STATUS_ACTIVE)
コード例 #49
0
ファイル: test_access.py プロジェクト: vast-data/manila
    def test_get_and_update_access_rule_just_get(self):
        share = db_utils.create_share(status=constants.STATUS_AVAILABLE)
        expected_rule = db_utils.create_access(share_id=share['id'])
        self.mock_object(db, 'share_instance_access_update')

        actual_rule = (
            self.access_helper.get_and_update_share_instance_access_rule(
                self.context,
                expected_rule['id'],
                share_instance_id=share['instance']['id']))

        self.assertEqual(expected_rule['id'], actual_rule['access_id'])
        self.assertFalse(db.share_instance_access_update.called)
コード例 #50
0
ファイル: test_access.py プロジェクト: vkmc/manila
 def setUp(self):
     super(ShareInstanceAccessTestCase, self).setUp()
     self.driver = self.mock_class("manila.share.driver.ShareDriver",
                                   mock.Mock())
     self.share_access_helper = access.ShareInstanceAccess(db, self.driver)
     self.context = context.get_admin_context()
     self.share = db_utils.create_share()
     self.share_instance = db_utils.create_share_instance(
         share_id=self.share['id'],
         access_rules_status=constants.STATUS_ERROR)
     self.rule = db_utils.create_access(id='fakeaccessid',
                                        share_id=self.share['id'],
                                        access_to='fakeaccessto')
コード例 #51
0
ファイル: test_access.py プロジェクト: openstack/manila
    def test_get_and_update_access_rule_just_get(self):
        share = db_utils.create_share(status=constants.STATUS_AVAILABLE)
        expected_rule = db_utils.create_access(share_id=share['id'])
        self.mock_object(db, 'share_instance_access_update')

        actual_rule = (
            self.access_helper.get_and_update_share_instance_access_rule(
                self.context, expected_rule['id'],
                share_instance_id=share['instance']['id'])
        )

        self.assertEqual(expected_rule['id'], actual_rule['access_id'])
        self.assertFalse(db.share_instance_access_update.called)
コード例 #52
0
ファイル: test_access.py プロジェクト: vkmc/manila
    def test_update_access_rules_migrating(self, read_only_support):
        def override_conf(conf_name):
            if conf_name == 'migration_readonly_rules_support':
                return read_only_support

        rules = []
        for i in range(2):
            rules.append(
                db_utils.create_access(
                    id='fakeid%s' % i,
                    share_id=self.share['id'],
                    access_to='fakeip%s' % i,
                ))
        driver_rules = [] if not read_only_support else rules
        access_rules_status = constants.STATUS_OUT_OF_SYNC
        share_instance = db_utils.create_share_instance(
            id='fakeid',
            status=constants.STATUS_MIGRATING,
            share_id=self.share['id'],
            access_rules_status=access_rules_status)

        self.mock_object(db, "share_instance_get",
                         mock.Mock(return_value=share_instance))
        self.mock_object(db, "share_access_get_all_for_instance",
                         mock.Mock(return_value=rules))
        self.mock_object(db, "share_instance_update_access_status",
                         mock.Mock())
        self.mock_object(self.driver, "update_access",
                         mock.Mock(return_value=None))
        self.mock_object(self.share_access_helper, "_remove_access_rules",
                         mock.Mock())
        self.mock_object(self.share_access_helper, "_check_needs_refresh",
                         mock.Mock(return_value=False))
        self.mock_object(self.driver.configuration, 'safe_get',
                         mock.Mock(side_effect=override_conf))

        self.share_access_helper.update_access_rules(self.context,
                                                     share_instance['id'])

        self.driver.update_access.assert_called_once_with(self.context,
                                                          share_instance,
                                                          driver_rules,
                                                          add_rules=[],
                                                          delete_rules=[],
                                                          share_server=None)
        self.share_access_helper._remove_access_rules.assert_called_once_with(
            self.context, [], share_instance['id'])
        self.share_access_helper._check_needs_refresh.assert_called_once_with(
            self.context, rules, share_instance)
        db.share_instance_update_access_status.assert_called_with(
            self.context, share_instance['id'], constants.STATUS_ACTIVE)
コード例 #53
0
ファイル: test_access.py プロジェクト: NetApp/manila
 def setUp(self):
     super(ShareInstanceAccessTestCase, self).setUp()
     self.driver = self.mock_class("manila.share.driver.ShareDriver",
                                   mock.Mock())
     self.share_access_helper = access.ShareInstanceAccess(db, self.driver)
     self.context = context.get_admin_context()
     self.share = db_utils.create_share()
     self.share_instance = db_utils.create_share_instance(
         share_id=self.share['id'],
         access_rules_status=constants.STATUS_ERROR)
     self.rule = db_utils.create_access(
         id='fakeaccessid',
         share_id=self.share['id'],
         access_to='fakeaccessto')
コード例 #54
0
ファイル: test_migration.py プロジェクト: jkasarherou/manila
    def test_deny_rules_and_wait(self):
        saved_rules = [db_utils.create_access(share_id=self.share['id'],
                       state=constants.STATUS_ACTIVE)]

        self.mock_object(share_api.API, 'deny_access_to_instance')
        self.mock_object(db, 'share_access_get_all_for_share',
                         mock.Mock(side_effect=[saved_rules, []]))
        self.mock_object(time, 'sleep')

        self.helper.deny_rules_and_wait(
            self.context, self.share, saved_rules)

        db.share_access_get_all_for_share.assert_any_call(
            self.context, self.share['id'])
コード例 #55
0
ファイル: test_access.py プロジェクト: openstack/manila
    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)
コード例 #56
0
ファイル: test_migration.py プロジェクト: jkasarherou/manila
    def test_add_rules_and_wait_access_level(self):

        rules_active = [db_utils.create_access(share_id=self.share['id'],
                        state=constants.STATUS_ACTIVE)]

        self.mock_object(share_api.API, 'allow_access')
        self.mock_object(db, 'share_access_get_all_for_share',
                         mock.Mock(return_value=rules_active))
        self.mock_object(time, 'sleep')

        self.helper.add_rules_and_wait(self.context, self.share,
                                       rules_active, 'access_level')

        db.share_access_get_all_for_share.assert_any_call(
            self.context, self.share['id'])
コード例 #57
0
    def test_deny_rules_and_wait(self):
        saved_rules = [
            db_utils.create_access(share_id=self.share['id'],
                                   state=constants.STATUS_ACTIVE)
        ]

        self.mock_object(share_api.API, 'deny_access_to_instance')
        self.mock_object(db, 'share_access_get_all_for_share',
                         mock.Mock(side_effect=[saved_rules, []]))
        self.mock_object(time, 'sleep')

        self.helper.deny_rules_and_wait(self.context, self.share, saved_rules)

        db.share_access_get_all_for_share.assert_any_call(
            self.context, self.share['id'])
コード例 #58
0
ファイル: test_api.py プロジェクト: alinbalutoiu/manila
    def test_share_access_state(self, statuses, valid):
        share = db_utils.create_share()
        db_utils.create_share_instance(share_id=share['id'])
        db_utils.create_share_instance(share_id=share['id'])

        share = db_api.share_get(self.ctxt, share['id'])
        access = db_utils.create_access(state=constants.STATUS_ACTIVE,
                                        share_id=share['id'])

        for index, mapping in enumerate(access.instance_mappings):
            db_api.share_instance_access_update_state(
                self.ctxt, mapping['id'], statuses[index])

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

        self.assertEqual(valid, access.state)
コード例 #59
0
ファイル: test_migration.py プロジェクト: jkasarherou/manila
    def test_wait_for_allow_access_timeout(self):

        access_new = db_utils.create_access(state=constants.STATUS_NEW,
                                            share_id=self.share['id'])

        self.mock_object(self.helper.api, 'access_get',
                         mock.Mock(return_value=access_new))

        now = time.time()
        timeout = now + 100

        self.mock_object(time, 'time',
                         mock.Mock(side_effect=[now, timeout]))

        self.assertRaises(exception.ShareMigrationFailed,
                          self.helper.wait_for_allow_access, access_new)