コード例 #1
0
ファイル: test_migration.py プロジェクト: NetApp/manila
    def test_create_instance_and_wait(self):

        host = 'fake_host'

        share_instance_creating = db_utils.create_share_instance(
            share_id=self.share['id'], status=constants.STATUS_CREATING,
            share_network_id='fake_network_id')
        share_instance_available = db_utils.create_share_instance(
            share_id=self.share['id'], status=constants.STATUS_AVAILABLE,
            share_network_id='fake_network_id')

        # mocks
        self.mock_object(share_api.API, 'create_instance',
                         mock.Mock(return_value=share_instance_creating))
        self.mock_object(db, 'share_instance_get',
                         mock.Mock(side_effect=[share_instance_creating,
                                                share_instance_available]))
        self.mock_object(time, 'sleep')

        # run
        self.helper.create_instance_and_wait(
            self.share, host, 'fake_net_id', 'fake_az_id', 'fake_type_id')

        # asserts
        share_api.API.create_instance.assert_called_once_with(
            self.context, self.share, 'fake_net_id', 'fake_host', 'fake_az_id',
            share_type_id='fake_type_id')

        db.share_instance_get.assert_has_calls([
            mock.call(self.context, share_instance_creating['id'],
                      with_share_data=True),
            mock.call(self.context, share_instance_creating['id'],
                      with_share_data=True)])

        time.sleep.assert_called_once_with(1)
コード例 #2
0
    def test_create_instance_and_wait(self):

        host = {'host': 'fake-host'}

        share_instance_creating = db_utils.create_share_instance(
            share_id=self.share['id'],
            status=constants.STATUS_CREATING,
            share_network_id='fake_network_id')
        share_instance_available = db_utils.create_share_instance(
            share_id=self.share['id'],
            status=constants.STATUS_AVAILABLE,
            share_network_id='fake_network_id')

        self.mock_object(share_api.API, 'create_instance',
                         mock.Mock(return_value=share_instance_creating))
        self.mock_object(
            db, 'share_instance_get',
            mock.Mock(side_effect=[
                share_instance_creating, share_instance_available
            ]))
        self.mock_object(time, 'sleep')

        self.helper.create_instance_and_wait(self.context, self.share,
                                             share_instance_creating, host)

        db.share_instance_get.assert_any_call(self.context,
                                              share_instance_creating['id'],
                                              with_share_data=True)
コード例 #3
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'])
コード例 #4
0
ファイル: test_models.py プロジェクト: vkmc/manila
    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'])
コード例 #5
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'])
コード例 #6
0
    def test_instance_and_proxified_properties(self):

        in_sync_replica_instance = db_utils.create_share_instance(
            status=constants.STATUS_AVAILABLE,
            share_id='fake_id',
            replica_state=constants.REPLICA_STATE_IN_SYNC)
        active_replica_instance = db_utils.create_share_instance(
            status=constants.STATUS_AVAILABLE,
            share_id='fake_id',
            replica_state=constants.REPLICA_STATE_ACTIVE)
        out_of_sync_replica_instance = db_utils.create_share_instance(
            status=constants.STATUS_ERROR,
            share_id='fake_id',
            replica_state=constants.REPLICA_STATE_OUT_OF_SYNC)
        non_replica_instance = db_utils.create_share_instance(
            status=constants.STATUS_CREATING, share_id='fake_id')
        share_instances = [
            in_sync_replica_instance,
            active_replica_instance,
            out_of_sync_replica_instance,
            non_replica_instance,
        ]
        share = db_utils.create_share(instances=share_instances)
        snapshot_instance_list = [
            db_utils.create_snapshot_instance(
                'fake_snapshot_id',
                status=constants.STATUS_CREATING,
                share_instance_id=out_of_sync_replica_instance['id']),
            db_utils.create_snapshot_instance(
                'fake_snapshot_id',
                status=constants.STATUS_ERROR,
                share_instance_id=in_sync_replica_instance['id']),
            db_utils.create_snapshot_instance(
                'fake_snapshot_id',
                status=constants.STATUS_AVAILABLE,
                provider_location='hogsmeade:snapshot1',
                progress='87%',
                share_instance_id=active_replica_instance['id']),
            db_utils.create_snapshot_instance(
                'fake_snapshot_id',
                status=constants.STATUS_MANAGING,
                share_instance_id=non_replica_instance['id']),
        ]
        snapshot = db_utils.create_snapshot(id='fake_snapshot_id',
                                            share_id=share['id'],
                                            instances=snapshot_instance_list)

        # Proxified properties
        self.assertEqual(constants.STATUS_AVAILABLE, snapshot['status'])
        self.assertEqual(constants.STATUS_ERROR, snapshot['aggregate_status'])
        self.assertEqual('hogsmeade:snapshot1', snapshot['provider_location'])
        self.assertEqual('87%', snapshot['progress'])

        # Snapshot properties
        expected_share_name = '-'.join(['share', share['id']])
        self.assertEqual(expected_share_name, snapshot['share_name'])
        self.assertEqual(active_replica_instance['id'],
                         snapshot['instance']['share_instance_id'])
コード例 #7
0
ファイル: test_models.py プロジェクト: ISCAS-VDI/manila-base
    def test_instance_and_proxified_properties(self):

        in_sync_replica_instance = db_utils.create_share_instance(
            status=constants.STATUS_AVAILABLE, share_id='fake_id',
            replica_state=constants.REPLICA_STATE_IN_SYNC)
        active_replica_instance = db_utils.create_share_instance(
            status=constants.STATUS_AVAILABLE, share_id='fake_id',
            replica_state=constants.REPLICA_STATE_ACTIVE)
        out_of_sync_replica_instance = db_utils.create_share_instance(
            status=constants.STATUS_ERROR, share_id='fake_id',
            replica_state=constants.REPLICA_STATE_OUT_OF_SYNC)
        non_replica_instance = db_utils.create_share_instance(
            status=constants.STATUS_CREATING, share_id='fake_id')
        share_instances = [
            in_sync_replica_instance, active_replica_instance,
            out_of_sync_replica_instance, non_replica_instance,
        ]
        share = db_utils.create_share(instances=share_instances)
        snapshot_instance_list = [
            db_utils.create_snapshot_instance(
                'fake_snapshot_id',
                status=constants.STATUS_CREATING,
                share_instance_id=out_of_sync_replica_instance['id']),
            db_utils.create_snapshot_instance(
                'fake_snapshot_id',
                status=constants.STATUS_ERROR,
                share_instance_id=in_sync_replica_instance['id']),
            db_utils.create_snapshot_instance(
                'fake_snapshot_id',
                status=constants.STATUS_AVAILABLE,
                provider_location='hogsmeade:snapshot1',
                progress='87%',
                share_instance_id=active_replica_instance['id']),
            db_utils.create_snapshot_instance(
                'fake_snapshot_id',
                status=constants.STATUS_MANAGING,
                share_instance_id=non_replica_instance['id']),
        ]
        snapshot = db_utils.create_snapshot(
            id='fake_snapshot_id', share_id=share['id'],
            instances=snapshot_instance_list)

        # Proxified properties
        self.assertEqual(constants.STATUS_AVAILABLE, snapshot['status'])
        self.assertEqual(constants.STATUS_ERROR, snapshot['aggregate_status'])
        self.assertEqual('hogsmeade:snapshot1', snapshot['provider_location'])
        self.assertEqual('87%', snapshot['progress'])

        # Snapshot properties
        expected_share_name = '-'.join(['share', share['id']])
        self.assertEqual(expected_share_name, snapshot['share_name'])
        self.assertEqual(active_replica_instance['id'],
                         snapshot['instance']['share_instance_id'])
コード例 #8
0
ファイル: test_models.py プロジェクト: tpsilva/manila
    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'])
コード例 #9
0
ファイル: test_models.py プロジェクト: tpsilva/manila
    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'])
コード例 #10
0
ファイル: test_models.py プロジェクト: ISCAS-VDI/manila-base
    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'])
コード例 #11
0
ファイル: test_models.py プロジェクト: ISCAS-VDI/manila-base
    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'])
コード例 #12
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'])
コード例 #13
0
ファイル: test_migration.py プロジェクト: NetApp/manila
    def test_create_instance_and_wait_status_error(self):

        host = 'fake_host'

        share_instance_error = db_utils.create_share_instance(
            share_id=self.share['id'], status=constants.STATUS_ERROR,
            share_network_id='fake_network_id')

        # mocks
        self.mock_object(share_api.API, 'create_instance',
                         mock.Mock(return_value=share_instance_error))
        self.mock_object(self.helper, 'cleanup_new_instance')
        self.mock_object(db, 'share_instance_get',
                         mock.Mock(return_value=share_instance_error))

        # run
        self.assertRaises(
            exception.ShareMigrationFailed,
            self.helper.create_instance_and_wait, self.share,
            host, 'fake_net_id', 'fake_az_id', 'fake_type_id')

        # asserts
        share_api.API.create_instance.assert_called_once_with(
            self.context, self.share, 'fake_net_id', 'fake_host', 'fake_az_id',
            share_type_id='fake_type_id')

        db.share_instance_get.assert_called_once_with(
            self.context, share_instance_error['id'], with_share_data=True)

        self.helper.cleanup_new_instance.assert_called_once_with(
            share_instance_error)
コード例 #14
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)
コード例 #15
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)
コード例 #16
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)
コード例 #17
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)
コード例 #18
0
    def test_create_instance_and_wait_timeout(self):

        host = {'host': 'fake-host'}

        share_instance_creating = db_utils.create_share_instance(
            share_id=self.share['id'],
            status=constants.STATUS_CREATING,
            share_network_id='fake_network_id')

        self.mock_object(share_api.API, 'create_instance',
                         mock.Mock(return_value=share_instance_creating))
        self.mock_object(db, 'share_instance_get',
                         mock.Mock(return_value=share_instance_creating))
        self.mock_object(time, 'sleep')

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

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

        self.assertRaises(exception.ShareMigrationFailed,
                          self.helper.create_instance_and_wait, self.context,
                          self.share, share_instance_creating, host)

        db.share_instance_get.assert_called_once_with(
            self.context, share_instance_creating['id'], with_share_data=True)
コード例 #19
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)
        ])
コード例 #20
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)
コード例 #21
0
    def test_create_instance_and_wait_status_error(self):

        host = 'fake_host'

        share_instance_error = db_utils.create_share_instance(
            share_id=self.share['id'],
            status=constants.STATUS_ERROR,
            share_network_id='fake_network_id')

        # mocks
        self.mock_object(share_api.API, 'create_instance',
                         mock.Mock(return_value=share_instance_error))
        self.mock_object(self.helper, 'cleanup_new_instance')
        self.mock_object(db, 'share_instance_get',
                         mock.Mock(return_value=share_instance_error))

        # run
        self.assertRaises(exception.ShareMigrationFailed,
                          self.helper.create_instance_and_wait, self.share,
                          host, 'fake_net_id', 'fake_az_id', 'fake_type_id')

        # asserts
        share_api.API.create_instance.assert_called_once_with(
            self.context,
            self.share,
            'fake_net_id',
            'fake_host',
            'fake_az_id',
            share_type_id='fake_type_id')

        db.share_instance_get.assert_called_once_with(
            self.context, share_instance_error['id'], with_share_data=True)

        self.helper.cleanup_new_instance.assert_called_once_with(
            share_instance_error)
コード例 #22
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)
コード例 #23
0
ファイル: test_access.py プロジェクト: ponychou/manila
    def test_update_access_rules_invalid_access_keys(self, maintenance_mode,
                                                     access_keys):
        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)

        rules = [self.rule]
        add_rules = [] if maintenance_mode else 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=rules))
        self.mock_object(db, "share_instance_update_access_status",
                         mock.Mock())
        self.mock_object(self.driver, "update_access",
                         mock.Mock(return_value=access_keys))

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

        self.driver.update_access.assert_called_once_with(
            self.context, share_instance, rules, add_rules=add_rules,
            delete_rules=[], share_server=None)
コード例 #24
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)
コード例 #25
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)
コード例 #26
0
ファイル: test_migration.py プロジェクト: jkasarherou/manila
    def test_create_instance_and_wait_timeout(self):

        host = {'host': 'fake-host'}

        share_instance_creating = db_utils.create_share_instance(
            share_id=self.share['id'], status=constants.STATUS_CREATING,
            share_network_id='fake_network_id')

        self.mock_object(share_api.API, 'create_instance',
                         mock.Mock(return_value=share_instance_creating))
        self.mock_object(db, 'share_instance_get',
                         mock.Mock(return_value=share_instance_creating))
        self.mock_object(time, 'sleep')

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

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

        self.assertRaises(exception.ShareMigrationFailed,
                          self.helper.create_instance_and_wait,
                          self.context, self.share, share_instance_creating,
                          host)

        db.share_instance_get.assert_called_once_with(
            self.context, share_instance_creating['id'], with_share_data=True)
コード例 #27
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)
        ])
コード例 #28
0
ファイル: test_models.py プロジェクト: vkmc/manila
    def test_access_rules_status(self, access_status):
        instances = [
            db_utils.create_share_instance(
                share_id='fake_id', status=constants.STATUS_ERROR,
                access_rules_status=constants.STATUS_ACTIVE),
            db_utils.create_share_instance(
                share_id='fake_id', status=constants.STATUS_AVAILABLE,
                access_rules_status=constants.STATUS_ACTIVE),
            db_utils.create_share_instance(
                share_id='fake_id', status=constants.STATUS_AVAILABLE,
                access_rules_status=access_status),
        ]

        share = db_utils.create_share(instances=instances)

        self.assertEqual(access_status, share.access_rules_status)
コード例 #29
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)
コード例 #30
0
    def test_create_instance_and_wait(self):

        host = 'fake_host'

        share_instance_creating = db_utils.create_share_instance(
            share_id=self.share['id'],
            status=constants.STATUS_CREATING,
            share_network_id='fake_network_id')
        share_instance_available = db_utils.create_share_instance(
            share_id=self.share['id'],
            status=constants.STATUS_AVAILABLE,
            share_network_id='fake_network_id')

        # mocks
        self.mock_object(share_api.API, 'create_instance',
                         mock.Mock(return_value=share_instance_creating))
        self.mock_object(
            db, 'share_instance_get',
            mock.Mock(side_effect=[
                share_instance_creating, share_instance_available
            ]))
        self.mock_object(time, 'sleep')

        # run
        self.helper.create_instance_and_wait(self.share, host, 'fake_net_id',
                                             'fake_az_id', 'fake_type_id')

        # asserts
        share_api.API.create_instance.assert_called_once_with(
            self.context,
            self.share,
            'fake_net_id',
            'fake_host',
            'fake_az_id',
            share_type_id='fake_type_id')

        db.share_instance_get.assert_has_calls([
            mock.call(self.context,
                      share_instance_creating['id'],
                      with_share_data=True),
            mock.call(self.context,
                      share_instance_creating['id'],
                      with_share_data=True)
        ])

        time.sleep.assert_called_once_with(1)
コード例 #31
0
ファイル: test_migration.py プロジェクト: ponychou/manila
 def setUp(self):
     super(ShareMigrationHelperTestCase, self).setUp()
     self.share = db_utils.create_share()
     self.share_instance = db_utils.create_share_instance(
         share_id=self.share['id'], share_network_id='fake_network_id')
     self.context = context.get_admin_context()
     self.helper = migration.ShareMigrationHelper(self.context, db,
                                                  self.share)
コード例 #32
0
ファイル: test_models.py プロジェクト: tpsilva/manila
    def test_share_instance_replication_change(self, status):

        instance_list = [
            db_utils.create_share_instance(
                status=constants.STATUS_REPLICATION_CHANGE,
                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_REPLICATION_CHANGE,
                         share1.instance['status'])
        self.assertEqual(constants.STATUS_REPLICATION_CHANGE,
                         share2.instance['status'])
コード例 #33
0
ファイル: test_migration.py プロジェクト: NetApp/manila
 def setUp(self):
     super(ShareMigrationHelperTestCase, self).setUp()
     self.share = db_utils.create_share()
     self.share_instance = db_utils.create_share_instance(
         share_id=self.share['id'],
         share_network_id='fake_network_id')
     self.context = context.get_admin_context()
     self.helper = migration.ShareMigrationHelper(
         self.context, db, self.share)
コード例 #34
0
ファイル: test_access.py プロジェクト: Nexenta/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
     )
コード例 #35
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)
コード例 #36
0
ファイル: test_models.py プロジェクト: ISCAS-VDI/manila-base
    def test_share_instance_replication_change(self, status):

        instance_list = [
            db_utils.create_share_instance(
                status=constants.STATUS_REPLICATION_CHANGE,
                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_REPLICATION_CHANGE, share1.instance['status'])
        self.assertEqual(
            constants.STATUS_REPLICATION_CHANGE, share2.instance['status'])
コード例 #37
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)
コード例 #38
0
 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)
コード例 #39
0
ファイル: test_models.py プロジェクト: vponomaryov/manila
    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'])
コード例 #40
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)
コード例 #41
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)
コード例 #42
0
ファイル: test_migration.py プロジェクト: jkasarherou/manila
    def test_create_instance_and_wait(self):

        host = {'host': 'fake-host'}

        share_instance_creating = db_utils.create_share_instance(
            share_id=self.share['id'], status=constants.STATUS_CREATING,
            share_network_id='fake_network_id')
        share_instance_available = db_utils.create_share_instance(
            share_id=self.share['id'], status=constants.STATUS_AVAILABLE,
            share_network_id='fake_network_id')

        self.mock_object(share_api.API, 'create_instance',
                         mock.Mock(return_value=share_instance_creating))
        self.mock_object(db, 'share_instance_get',
                         mock.Mock(side_effect=[share_instance_creating,
                                                share_instance_available]))
        self.mock_object(time, 'sleep')

        self.helper.create_instance_and_wait(
            self.context, self.share, share_instance_creating, host)

        db.share_instance_get.assert_any_call(
            self.context, share_instance_creating['id'], with_share_data=True)
コード例 #43
0
ファイル: test_access.py プロジェクト: NetApp/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)
コード例 #44
0
    def _setup_snapshot_instance_data(self, instance=None):
        if instance is None:
            share_instance = db_utils.create_share_instance(
                status=constants.STATUS_AVAILABLE, share_id='fake_share_id_1')
            instance = db_utils.create_snapshot_instance(
                'fake_snapshot_id_1',
                status=constants.STATUS_AVAILABLE,
                share_instance_id=share_instance['id'])

        req = fakes.HTTPRequest.blank('/v2/fake/snapshot-instances/%s/action' %
                                      instance['id'],
                                      version=self.api_version)
        req.method = 'POST'
        req.headers['content-type'] = 'application/json'
        req.headers['X-Openstack-Manila-Api-Version'] = self.api_version

        return instance, req
コード例 #45
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'])
コード例 #46
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'])
コード例 #47
0
    def test_create_instance_and_wait_timeout(self):

        host = 'fake_host'

        share_instance_creating = db_utils.create_share_instance(
            share_id=self.share['id'],
            status=constants.STATUS_CREATING,
            share_network_id='fake_network_id')

        # mocks
        self.mock_object(share_api.API, 'create_instance',
                         mock.Mock(return_value=share_instance_creating))

        self.mock_object(self.helper, 'cleanup_new_instance')

        self.mock_object(db, 'share_instance_get',
                         mock.Mock(return_value=share_instance_creating))
        self.mock_object(time, 'sleep')

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

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

        # run
        self.assertRaises(exception.ShareMigrationFailed,
                          self.helper.create_instance_and_wait, self.share,
                          host, 'fake_net_id', 'fake_az_id', 'fake_type_id')

        # asserts
        share_api.API.create_instance.assert_called_once_with(
            self.context,
            self.share,
            'fake_net_id',
            'fake_host',
            'fake_az_id',
            share_type_id='fake_type_id')

        db.share_instance_get.assert_called_once_with(
            self.context, share_instance_creating['id'], with_share_data=True)

        time.time.assert_has_calls([mock.call(), mock.call()])

        self.helper.cleanup_new_instance.assert_called_once_with(
            share_instance_creating)
コード例 #48
0
    def _setup_snapshot_instance_data(self, instance=None):
        if instance is None:
            share_instance = db_utils.create_share_instance(
                status=constants.STATUS_AVAILABLE,
                share_id='fake_share_id_1')
            instance = db_utils.create_snapshot_instance(
                'fake_snapshot_id_1',
                status=constants.STATUS_AVAILABLE,
                share_instance_id=share_instance['id'])

        path = '/v2/fake/snapshot-instances/%s/action' % instance['id']
        req = fakes.HTTPRequest.blank(path, version=self.api_version,
                                      script_name=path)
        req.method = 'POST'
        req.headers['content-type'] = 'application/json'
        req.headers['X-Openstack-Manila-Api-Version'] = self.api_version

        return instance, req
コード例 #49
0
ファイル: test_access.py プロジェクト: vkmc/manila
    def test_update_access_rules_returns_access_keys(self, access_keys):
        share_instance = db_utils.create_share_instance(
            id='fakeshareinstanceid',
            share_id=self.share['id'],
            access_rules_status=constants.STATUS_ACTIVE)
        rules = [self.rule]

        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(db, "share_access_update_access_key", mock.Mock())
        self.mock_object(self.driver, "update_access",
                         mock.Mock(return_value=access_keys))
        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'],
                                                     add_rules=rules)

        self.driver.update_access.assert_called_once_with(self.context,
                                                          share_instance,
                                                          rules,
                                                          add_rules=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)
        if access_keys:
            db.share_access_update_access_key.assert_called_with(
                self.context, 'fakeaccessid', 'fakeaccesskey')
        else:
            self.assertFalse(db.share_access_update_access_key.called)
        db.share_instance_update_access_status.assert_called_with(
            self.context, share_instance['id'], constants.STATUS_ACTIVE)
コード例 #50
0
ファイル: test_migration.py プロジェクト: jkasarherou/manila
    def test_create_instance_and_wait_status_error(self):

        host = {'host': 'fake-host'}

        share_instance_error = db_utils.create_share_instance(
            share_id=self.share['id'], status=constants.STATUS_ERROR,
            share_network_id='fake_network_id')

        self.mock_object(share_api.API, 'create_instance',
                         mock.Mock(return_value=share_instance_error))
        self.mock_object(db, 'share_instance_get',
                         mock.Mock(return_value=share_instance_error))
        self.mock_object(time, 'sleep')

        self.assertRaises(exception.ShareMigrationFailed,
                          self.helper.create_instance_and_wait,
                          self.context, self.share, share_instance_error, host)

        db.share_instance_get.assert_called_once_with(
            self.context, share_instance_error['id'], with_share_data=True)
コード例 #51
0
ファイル: test_migration.py プロジェクト: NetApp/manila
    def test_create_instance_and_wait_timeout(self):

        host = 'fake_host'

        share_instance_creating = db_utils.create_share_instance(
            share_id=self.share['id'], status=constants.STATUS_CREATING,
            share_network_id='fake_network_id')

        # mocks
        self.mock_object(share_api.API, 'create_instance',
                         mock.Mock(return_value=share_instance_creating))

        self.mock_object(self.helper, 'cleanup_new_instance')

        self.mock_object(db, 'share_instance_get',
                         mock.Mock(return_value=share_instance_creating))
        self.mock_object(time, 'sleep')

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

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

        # run
        self.assertRaises(
            exception.ShareMigrationFailed,
            self.helper.create_instance_and_wait,  self.share,
            host, 'fake_net_id', 'fake_az_id', 'fake_type_id')

        # asserts
        share_api.API.create_instance.assert_called_once_with(
            self.context, self.share, 'fake_net_id', 'fake_host', 'fake_az_id',
            share_type_id='fake_type_id')

        db.share_instance_get.assert_called_once_with(
            self.context, share_instance_creating['id'], with_share_data=True)

        time.time.assert_has_calls([mock.call(), mock.call()])

        self.helper.cleanup_new_instance.assert_called_once_with(
            share_instance_creating)
コード例 #52
0
    def test_create_instance_and_wait_status_error(self):

        host = {'host': 'fake-host'}

        share_instance_error = db_utils.create_share_instance(
            share_id=self.share['id'],
            status=constants.STATUS_ERROR,
            share_network_id='fake_network_id')

        self.mock_object(share_api.API, 'create_instance',
                         mock.Mock(return_value=share_instance_error))
        self.mock_object(db, 'share_instance_get',
                         mock.Mock(return_value=share_instance_error))
        self.mock_object(time, 'sleep')

        self.assertRaises(exception.ShareMigrationFailed,
                          self.helper.create_instance_and_wait, self.context,
                          self.share, share_instance_error, host)

        db.share_instance_get.assert_called_once_with(
            self.context, share_instance_error['id'], with_share_data=True)
コード例 #53
0
ファイル: test_access.py プロジェクト: NetApp/manila
    def test_update_access_rules_returns_access_keys(self, access_keys):
        share_instance = db_utils.create_share_instance(
            id='fakeshareinstanceid',
            share_id=self.share['id'],
            access_rules_status=constants.STATUS_ACTIVE)
        rules = [self.rule]

        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(db, "share_access_update_access_key",
                         mock.Mock())
        self.mock_object(self.driver, "update_access",
                         mock.Mock(return_value=access_keys))
        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'], add_rules=rules)

        self.driver.update_access.assert_called_once_with(
            self.context, share_instance, rules, add_rules=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)
        if access_keys:
            db.share_access_update_access_key.assert_called_with(
                self.context, 'fakeaccessid', 'fakeaccesskey')
        else:
            self.assertFalse(db.share_access_update_access_key.called)
        db.share_instance_update_access_status.assert_called_with(
            self.context, share_instance['id'], constants.STATUS_ACTIVE)
コード例 #54
0
    def test_revert_access_rules(self, dest_host):

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

        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]))
        mock_update_access_for_instances = self.mock_object(
            share_rpcapi.ShareAPI, 'update_access_for_instances')

        # run
        self.helper.revert_access_rules([share_instance],
                                        server,
                                        dest_host=dest_host)

        # 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})
        if dest_host:
            mock_update_access_for_instances.assert_called_once_with(
                self.context, dest_host, share_instance_ids, server)
        else:
            self.access_helper.update_access_rules.assert_called_once_with(
                self.context, share_instance['id'], share_server=server)