Example #1
0
    def test_cg_from_src(self, get_all_for_cgsnapshot, req):
        req.side_effect = xms_request
        d = self.data

        self.assertRaises(exception.InvalidInput,
                          self.driver.create_consistencygroup_from_src,
                          d.context, d.group, [], None, None, None, None)

        snapshot_obj = fake_snapshot.fake_snapshot_obj(d.context)
        snapshot_obj.consistencygroup_id = d.group['id']
        snapshot_obj.volume_id = d.test_volume['id']
        get_all_for_cgsnapshot.return_value = [snapshot_obj]

        self.driver.create_consistencygroup(d.context, d.group)
        self.driver.create_volume(d.test_volume)
        self.driver.create_cgsnapshot(d.context, d.cgsnapshot, [])
        xms_data['volumes'][2]['ancestor-vol-id'] = (
            xms_data['volumes'][1]['vol-id'])
        snapset_name = self.driver._get_cgsnap_name(d.cgsnapshot)

        snapset1 = {
            'vol-list': [xms_data['volumes'][2]['vol-id']],
            'name': snapset_name,
            'index': 1
        }
        xms_data['snapshot-sets'] = {snapset_name: snapset1, 1: snapset1}
        cg_obj = fake_cg.fake_consistencyobject_obj(d.context)
        new_vol1 = fake_volume.fake_volume_obj(d.context)
        snapshot1 = (fake_snapshot.fake_snapshot_obj(
            d.context, volume_id=d.test_volume['id']))
        self.driver.create_consistencygroup_from_src(d.context, cg_obj,
                                                     [new_vol1], d.cgsnapshot,
                                                     [snapshot1])

        new_cg_obj = fake_cg.fake_consistencyobject_obj(
            d.context, id=fake.CONSISTENCY_GROUP2_ID)
        snapset2_name = new_cg_obj.id
        new_vol1.id = '192eb39b-6c2f-420c-bae3-3cfd117f0001'
        new_vol2 = fake_volume.fake_volume_obj(d.context)
        snapset2 = {
            'vol-list': [xms_data['volumes'][2]['vol-id']],
            'name': snapset2_name,
            'index': 1
        }
        xms_data['snapshot-sets'].update({
            5: snapset2,
            snapset2_name: snapset2
        })
        self.driver.create_consistencygroup_from_src(d.context, new_cg_obj,
                                                     [new_vol2], None, None,
                                                     cg_obj, [new_vol1])
Example #2
0
    def test_cg_from_src_snapshot(self, get_all_for_cgsnapshot, req):
        req.side_effect = xms_request
        d = self.data

        snapshot_obj = fake_snapshot.fake_snapshot_obj(d.context)
        snapshot_obj.consistencygroup_id = d.group['id']
        snapshot_obj.volume_id = d.test_volume['id']
        get_all_for_cgsnapshot.return_value = [snapshot_obj]

        self.driver.create_consistencygroup(d.context, d.group)
        self.driver.create_volume(d.test_volume)
        self.driver.create_cgsnapshot(d.context, d.cgsnapshot, [])
        xms_data['volumes'][2]['ancestor-vol-id'] = (xms_data['volumes'][1]
                                                     ['vol-id'])
        snapset_name = self.driver._get_cgsnap_name(d.cgsnapshot)

        snapset1 = {'vol-list': [xms_data['volumes'][2]['vol-id']],
                    'name': snapset_name,
                    'index': 1}
        xms_data['snapshot-sets'] = {snapset_name: snapset1, 1: snapset1}
        cg_obj = fake_cg.fake_consistencyobject_obj(d.context)
        new_vol1 = fake_volume.fake_volume_obj(d.context)
        snapshot1 = (fake_snapshot
                     .fake_snapshot_obj
                     (d.context, volume_id=d.test_volume['id']))
        self.driver.create_consistencygroup_from_src(d.context, cg_obj,
                                                     [new_vol1],
                                                     d.cgsnapshot, [snapshot1])
Example #3
0
    def test_create_consistencygroup_exceptions(self):
        with mock.patch.object(filter_scheduler.FilterScheduler,
                               'schedule_create_consistencygroup') as mock_cg:
            original_driver = self.manager.driver
            consistencygroup_obj = \
                fake_consistencygroup.fake_consistencyobject_obj(self.context)
            self.manager.driver = filter_scheduler.FilterScheduler
            LOG = self.mock_object(manager, 'LOG')
            self.mock_object(db, 'consistencygroup_update')

            ex = exception.CinderException('test')
            mock_cg.side_effect = ex
            group_id = fake.CONSISTENCY_GROUP_ID
            self.assertRaises(exception.CinderException,
                              self.manager.create_consistencygroup,
                              self.context, 'volume', consistencygroup_obj)
            self.assertGreater(LOG.exception.call_count, 0)
            db.consistencygroup_update.assert_called_once_with(
                self.context, group_id,
                {'status': (fields.ConsistencyGroupStatus.ERROR)})

            mock_cg.reset_mock()
            LOG.exception.reset_mock()
            db.consistencygroup_update.reset_mock()

            mock_cg.side_effect = exception.NoValidHost(
                reason="No weighed hosts available")
            self.manager.create_consistencygroup(self.context, 'volume',
                                                 consistencygroup_obj)
            self.assertGreater(LOG.error.call_count, 0)
            db.consistencygroup_update.assert_called_once_with(
                self.context, group_id,
                {'status': (fields.ConsistencyGroupStatus.ERROR)})

            self.manager.driver = original_driver
Example #4
0
    def test_create_consistencygroup_exceptions(self):
        with mock.patch.object(filter_scheduler.FilterScheduler, "schedule_create_consistencygroup") as mock_cg:
            original_driver = self.manager.driver
            consistencygroup_obj = fake_consistencygroup.fake_consistencyobject_obj(self.context)
            self.manager.driver = filter_scheduler.FilterScheduler
            LOG = self.mock_object(manager, "LOG")
            self.mock_object(db, "consistencygroup_update")

            ex = exception.CinderException("test")
            mock_cg.side_effect = ex
            group_id = fake.CONSISTENCY_GROUP_ID
            self.assertRaises(
                exception.CinderException, self.manager.create_consistencygroup, self.context, consistencygroup_obj
            )
            self.assertGreater(LOG.exception.call_count, 0)
            db.consistencygroup_update.assert_called_once_with(
                self.context, group_id, {"status": (fields.ConsistencyGroupStatus.ERROR)}
            )

            mock_cg.reset_mock()
            LOG.exception.reset_mock()
            db.consistencygroup_update.reset_mock()

            mock_cg.side_effect = exception.NoValidHost(reason="No weighed hosts available")
            self.manager.create_consistencygroup(self.context, consistencygroup_obj)
            self.assertGreater(LOG.error.call_count, 0)
            db.consistencygroup_update.assert_called_once_with(
                self.context, group_id, {"status": (fields.ConsistencyGroupStatus.ERROR)}
            )

            self.manager.driver = original_driver
Example #5
0
    def test_cg_from_src_snapshot(self, get_all_for_cgsnapshot, req):
        req.side_effect = xms_request
        d = self.data

        snapshot_obj = fake_snapshot.fake_snapshot_obj(d.context)
        snapshot_obj.consistencygroup_id = d.group['id']
        snapshot_obj.volume_id = d.test_volume['id']
        get_all_for_cgsnapshot.return_value = [snapshot_obj]

        self.driver.create_consistencygroup(d.context, d.group)
        self.driver.create_volume(d.test_volume)
        self.driver.create_cgsnapshot(d.context, d.cgsnapshot, [])
        xms_data['volumes'][2]['ancestor-vol-id'] = (
            xms_data['volumes'][1]['vol-id'])
        snapset_name = self.driver._get_cgsnap_name(d.cgsnapshot)

        snapset1 = {
            'vol-list': [xms_data['volumes'][2]['vol-id']],
            'name': snapset_name,
            'index': 1
        }
        xms_data['snapshot-sets'] = {snapset_name: snapset1, 1: snapset1}
        cg_obj = fake_cg.fake_consistencyobject_obj(d.context)
        new_vol1 = fake_volume.fake_volume_obj(d.context)
        snapshot1 = (fake_snapshot.fake_snapshot_obj(
            d.context, volume_id=d.test_volume['id']))
        self.driver.create_consistencygroup_from_src(d.context, cg_obj,
                                                     [new_vol1], d.cgsnapshot,
                                                     [snapshot1])
Example #6
0
    def test_cg_from_src(self, get_all_for_cgsnapshot, req):
        req.side_effect = xms_request
        d = self.data

        self.assertRaises(exception.InvalidInput,
                          self.driver.create_consistencygroup_from_src,
                          d.context, d.group, [], None, None, None, None)

        snapshot_obj = fake_snapshot.fake_snapshot_obj(d.context)
        snapshot_obj.consistencygroup_id = d.group['id']
        snapshot_obj.volume_id = d.test_volume['id']
        get_all_for_cgsnapshot.return_value = [snapshot_obj]

        self.driver.create_consistencygroup(d.context, d.group)
        self.driver.create_volume(d.test_volume)
        self.driver.create_cgsnapshot(d.context, d.cgsnapshot, [])
        xms_data['volumes'][2]['ancestor-vol-id'] = (xms_data['volumes'][1]
                                                     ['vol-id'])
        snapset_name = self.driver._get_cgsnap_name(d.cgsnapshot)

        snapset1 = {'vol-list': [xms_data['volumes'][2]['vol-id']],
                    'name': snapset_name,
                    'index': 1}
        xms_data['snapshot-sets'] = {snapset_name: snapset1, 1: snapset1}
        cg_obj = fake_cg.fake_consistencyobject_obj(d.context)
        new_vol1 = fake_volume.fake_volume_obj(d.context)
        snapshot1 = (fake_snapshot
                     .fake_snapshot_obj
                     (d.context, volume_id=d.test_volume['id']))
        self.driver.create_consistencygroup_from_src(d.context, cg_obj,
                                                     [new_vol1],
                                                     d.cgsnapshot, [snapshot1])

        new_cg_obj = fake_cg.fake_consistencyobject_obj(
            d.context, id=fake.CONSISTENCY_GROUP2_ID)
        snapset2_name = new_cg_obj.id
        new_vol1.id = '192eb39b-6c2f-420c-bae3-3cfd117f0001'
        new_vol2 = fake_volume.fake_volume_obj(d.context)
        snapset2 = {'vol-list': [xms_data['volumes'][2]['vol-id']],
                    'name': snapset2_name,
                    'index': 1}
        xms_data['snapshot-sets'].update({5: snapset2,
                                          snapset2_name: snapset2})
        self.driver.create_consistencygroup_from_src(d.context, new_cg_obj,
                                                     [new_vol2],
                                                     None, None,
                                                     cg_obj, [new_vol1])
Example #7
0
 def test_save_error(self):
     db_volume = fake_volume.fake_db_volume()
     volume = objects.Volume._from_db_object(self.context, objects.Volume(),
                                             db_volume)
     volume.display_name = 'foobar'
     volume.consistencygroup = (
         fake_consistencygroup.fake_consistencyobject_obj(self.context))
     self.assertRaises(exception.ObjectActionError, volume.save)
Example #8
0
 def test_save_error(self):
     db_volume = fake_volume.fake_db_volume()
     volume = objects.Volume._from_db_object(self.context,
                                             objects.Volume(), db_volume)
     volume.display_name = 'foobar'
     volume.consistencygroup = (
         fake_consistencygroup.fake_consistencyobject_obj(self.context))
     self.assertRaises(exception.ObjectActionError,
                       volume.save)
    def test_cast_create_volume(self, consistencygroup_get_by_id, mock_time,
                                mock_extract_host, volume_get_by_id):
        mock_time.side_effect = self.time_inc
        volume = fake_volume.fake_volume_obj(self.ctxt)
        volume_get_by_id.return_value = volume
        props = {}
        cg_obj = (fake_consistencygroup.fake_consistencyobject_obj(
            self.ctxt, consistencygroup_id=1, host='host@backend#pool'))
        consistencygroup_get_by_id.return_value = cg_obj
        spec = {
            'volume_id': None,
            'volume': None,
            'source_volid': None,
            'snapshot_id': None,
            'image_id': None,
            'source_replicaid': None,
            'consistencygroup_id': None,
            'cgsnapshot_id': None,
            'group_id': None,
        }

        # Fake objects assert specs
        task = create_volume.VolumeCastTask(
            fake_volume_api.FakeSchedulerRpcAPI(spec, self),
            fake_volume_api.FakeVolumeAPI(spec, self),
            fake_volume_api.FakeDb())

        task._cast_create_volume(self.ctxt, spec, props)

        spec = {
            'volume_id': volume.id,
            'volume': volume,
            'source_volid': 2,
            'snapshot_id': 3,
            'image_id': 4,
            'source_replicaid': 5,
            'consistencygroup_id': 5,
            'cgsnapshot_id': None,
            'group_id': None,
        }

        # Fake objects assert specs
        task = create_volume.VolumeCastTask(
            fake_volume_api.FakeSchedulerRpcAPI(spec, self),
            fake_volume_api.FakeVolumeAPI(spec, self),
            fake_volume_api.FakeDb())

        task._cast_create_volume(self.ctxt, spec, props)
        consistencygroup_get_by_id.assert_called_once_with(self.ctxt, 5)
        mock_extract_host.assert_called_once_with('host@backend#pool')
Example #10
0
    def test_create_consistencygroup_exceptions(self):
        with mock.patch.object(filter_scheduler.FilterScheduler,
                               'schedule_create_consistencygroup') as mock_cg:
            original_driver = self.manager.driver
            consistencygroup_obj = \
                fake_consistencygroup.fake_consistencyobject_obj(self.context)
            self.manager.driver = filter_scheduler.FilterScheduler
            LOG = self.mock_object(manager, 'LOG')
            self.stubs.Set(db, 'consistencygroup_update', mock.Mock())

            ex = exception.CinderException('test')
            mock_cg.side_effect = ex
            group_id = fake.CONSISTENCY_GROUP_ID
            self.assertRaises(exception.CinderException,
                              self.manager.create_consistencygroup,
                              self.context,
                              'volume',
                              consistencygroup_obj)
            self.assertTrue(LOG.exception.call_count > 0)
            db.consistencygroup_update.assert_called_once_with(
                self.context, group_id, {'status': (
                    fields.ConsistencyGroupStatus.ERROR)})

            mock_cg.reset_mock()
            LOG.exception.reset_mock()
            db.consistencygroup_update.reset_mock()

            mock_cg.side_effect = exception.NoValidHost(
                reason="No weighed hosts available")
            self.manager.create_consistencygroup(
                self.context, 'volume', consistencygroup_obj)
            self.assertTrue(LOG.error.call_count > 0)
            db.consistencygroup_update.assert_called_once_with(
                self.context, group_id, {'status': (
                    fields.ConsistencyGroupStatus.ERROR)})

            self.manager.driver = original_driver
Example #11
0
    def setUp(self):
        """Setup a test case environment.

        Creates a fake volume object and sets up the required API responses.
        """
        super(TestConsistencyGroups, self).setUp()
        self.ctx = context.RequestContext('fake', 'fake', auth_token=True)
        self.consistency_group = (
            fake_consistencygroup.fake_consistencyobject_obj(
                self.ctx, **{'id': fake.CONSISTENCY_GROUP_ID}))
        fake_volume1 = fake_volume.fake_volume_obj(
            self.ctx, **{
                'id': fake.VOLUME_ID,
                'provider_id': fake.PROVIDER_ID
            })
        fake_volume2 = fake_volume.fake_volume_obj(
            self.ctx, **{
                'id': fake.VOLUME2_ID,
                'provider_id': fake.PROVIDER2_ID
            })
        fake_volume3 = fake_volume.fake_volume_obj(
            self.ctx, **{
                'id': fake.VOLUME3_ID,
                'provider_id': fake.PROVIDER3_ID
            })
        fake_volume4 = fake_volume.fake_volume_obj(
            self.ctx, **{
                'id': fake.VOLUME4_ID,
                'provider_id': fake.PROVIDER4_ID
            })
        self.volumes = [fake_volume1, fake_volume2]
        self.volumes2 = [fake_volume3, fake_volume4]
        fake_snapshot1 = fake_snapshot.fake_snapshot_obj(
            self.ctx, **{
                'id': fake.SNAPSHOT_ID,
                'volume_id': fake.VOLUME_ID,
                'volume': fake_volume1
            })
        fake_snapshot2 = fake_snapshot.fake_snapshot_obj(
            self.ctx, **{
                'id': fake.SNAPSHOT2_ID,
                'volume_id': fake.VOLUME2_ID,
                'volume': fake_volume2
            })
        self.snapshots = [fake_snapshot1, fake_snapshot2]
        self.snapshot_reply = json.dumps({
            'volumeIdList': ['sid1', 'sid2'],
            'snapshotGroupId': 'sgid1'
        })
        self.HTTPS_MOCK_RESPONSES = {
            self.RESPONSE_MODE.Valid: {
                'instances/Volume::{}/action/removeVolume'.format(fake_volume1['provider_id']):
                fake_volume1['provider_id'],
                'instances/Volume::{}/action/removeVolume'.format(fake_volume2['provider_id']):
                fake_volume2['provider_id'],
                'instances/Volume::{}/action/removeMappedSdc'.format(fake_volume1['provider_id']):
                fake_volume1['provider_id'],
                'instances/Volume::{}/action/removeMappedSdc'.format(fake_volume2['provider_id']):
                fake_volume2['provider_id'],
                'instances/System/action/snapshotVolumes':
                self.snapshot_reply,
            },
            self.RESPONSE_MODE.BadStatus: {
                'instances/Volume::{}/action/removeVolume'.format(fake_volume1['provider_id']):
                mocks.MockHTTPSResponse(
                    {
                        'errorCode': 401,
                        'message': 'BadStatus Volume Test',
                    }, 401),
                'instances/Volume::{}/action/removeVolume'.format(fake_volume2['provider_id']):
                mocks.MockHTTPSResponse(
                    {
                        'errorCode': 401,
                        'message': 'BadStatus Volume Test',
                    }, 401),
                'instances/System/action/snapshotVolumes':
                self.BAD_STATUS_RESPONSE
            },
        }
Example #12
0
def _fake_cg_wrapper(*args, **kwargs):
    return fake_consistencygroup.fake_consistencyobject_obj(None, **kwargs)
Example #13
0
def _fake_cg_wrapper(*args, **kwargs):
    return fake_consistencygroup.fake_consistencyobject_obj(None, **kwargs)
Example #14
0
    def setUp(self):
        """Setup a test case environment.

        Creates a fake volume object and sets up the required API responses.
        """
        super(TestConsistencyGroups, self).setUp()
        self.ctx = context.RequestContext('fake', 'fake', auth_token=True)
        self.consistency_group = (
            fake_consistencygroup.fake_consistencyobject_obj(
                self.ctx, **{'id': fake.CONSISTENCY_GROUP_ID}))
        fake_volume1 = fake_volume.fake_volume_obj(
            self.ctx,
            **{'id': fake.VOLUME_ID, 'provider_id': fake.PROVIDER_ID})
        fake_volume2 = fake_volume.fake_volume_obj(
            self.ctx,
            **{'id': fake.VOLUME2_ID, 'provider_id': fake.PROVIDER2_ID})
        fake_volume3 = fake_volume.fake_volume_obj(
            self.ctx,
            **{'id': fake.VOLUME3_ID, 'provider_id': fake.PROVIDER3_ID})
        fake_volume4 = fake_volume.fake_volume_obj(
            self.ctx,
            **{'id': fake.VOLUME4_ID, 'provider_id': fake.PROVIDER4_ID})
        self.volumes = [fake_volume1, fake_volume2]
        self.volumes2 = [fake_volume3, fake_volume4]
        fake_snapshot1 = fake_snapshot.fake_snapshot_obj(
            self.ctx,
            **{'id': fake.SNAPSHOT_ID, 'volume_id': fake.VOLUME_ID,
               'volume': fake_volume1})
        fake_snapshot2 = fake_snapshot.fake_snapshot_obj(
            self.ctx,
            **{'id': fake.SNAPSHOT2_ID, 'volume_id': fake.VOLUME2_ID, 'volume':
                fake_volume2})
        self.snapshots = [fake_snapshot1, fake_snapshot2]
        self.snapshot_reply = json.dumps({
            'volumeIdList': ['sid1', 'sid2'],
            'snapshotGroupId': 'sgid1'})
        self.HTTPS_MOCK_RESPONSES = {
            self.RESPONSE_MODE.Valid: {
                'instances/Volume::{}/action/removeVolume'.format(
                    fake_volume1['provider_id']
                ): fake_volume1['provider_id'],
                'instances/Volume::{}/action/removeVolume'.format(
                    fake_volume2['provider_id']
                ): fake_volume2['provider_id'],
                'instances/Volume::{}/action/removeMappedSdc'.format(
                    fake_volume1['provider_id']
                ): fake_volume1['provider_id'],
                'instances/Volume::{}/action/removeMappedSdc'.format(
                    fake_volume2['provider_id']
                ): fake_volume2['provider_id'],
                'instances/System/action/snapshotVolumes':
                    self.snapshot_reply,
            },
            self.RESPONSE_MODE.BadStatus: {
                'instances/Volume::{}/action/removeVolume'.format(
                    fake_volume1['provider_id']
                ): mocks.MockHTTPSResponse(
                    {
                        'errorCode': 401,
                        'message': 'BadStatus Volume Test',
                    }, 401
                ),
                'instances/Volume::{}/action/removeVolume'.format(
                    fake_volume2['provider_id']
                ): mocks.MockHTTPSResponse(
                    {
                        'errorCode': 401,
                        'message': 'BadStatus Volume Test',
                    }, 401
                ),
                'instances/System/action/snapshotVolumes':
                    self.BAD_STATUS_RESPONSE
            },
        }