def test_thin_clone(self): lun_id = 'lun_60' src_snap_id = 'snap_61' volume = MockOSResource(name=lun_id, id=lun_id, size=1, provider_location=get_snap_lun_pl(lun_id)) src_snap = test_client.MockResource(name=src_snap_id, _id=src_snap_id) ret = self.adapter._thin_clone(volume, src_snap) self.assertEqual(IdMatcher(test_client.MockResource(_id=lun_id)), ret)
def get_lun(name=None, lun_id=None): if lun_id is None: lun_id = 'lun_4' if name == 'not_exists': ret = test_client.MockResource(name=lun_id) ret.existed = False else: ret = test_client.MockResource(_id=lun_id) return ret
def test_thin_clone_thick(self): lun_id = 'lun_70' src_snap_id = 'snap_71' volume = MockOSResource(name=lun_id, id=lun_id, size=1, provider_location=get_snap_lun_pl(lun_id)) src_snap = test_client.MockResource(name=src_snap_id, _id=src_snap_id) new_dd_lun = test_client.MockResource(name='lun_73') with patch_storops(), patch_dd_copy(new_dd_lun) as dd: vol_params = adapter.VolumeParams(self.adapter, volume) ret = self.adapter._thin_clone(vol_params, src_snap) dd.assert_called_with(vol_params, src_snap, src_lun=None) self.assertEqual(ret, new_dd_lun)
def get_lun(name=None, lun_id=None): if lun_id is None: lun_id = 'lun_4' if lun_id in ('lun_43', ): # for thin clone cases return test_client.MockResource(_id=lun_id, name=name) if name == 'not_exists': ret = test_client.MockResource(name=lun_id) ret.existed = False else: if name is None: name = lun_id ret = test_client.MockResource(_id=lun_id, name=name) return ret
def test_create_cloned_volume_attached(self): lun_id = 'lun_51' src_lun_id = 'lun_53' volume = MockOSResource(name=lun_id, id=lun_id, host='unity#pool1') src_vref = MockOSResource(id=src_lun_id, name=src_lun_id, provider_location=get_lun_pl(src_lun_id), volume_attachment=['not_care']) with patch_dd_copy(test_client.MockResource(_id=lun_id)) as dd: ret = self.adapter.create_cloned_volume(volume, src_vref) dd.assert_called_with( adapter.VolumeParams(self.adapter, volume), IdMatcher(test_client.MockResource( _id='snap_clone_{}'.format(src_lun_id))), src_lun=IdMatcher(test_client.MockResource(_id=src_lun_id))) self.assertEqual(get_lun_pl(lun_id), ret['provider_location'])
def get_snap(name=None): snap = test_client.MockResource(name=name) if name is not None: ret = snap else: ret = [snap] return ret
def test_initialize_connection_for_resource(self): snap = test_client.MockResource(_id='snap_1') connector = {'host': 'host1'} data = self.adapter._initialize_connection(snap, connector, 'snap_1')['data'] self.assertTrue(data['target_discovered']) self.assertEqual('snap_1', data['volume_id'])
def create_lun(name, size, pool, description=None, io_limit_policy=None, is_thin=None, is_compressed=None): lun_id = name if is_thin is not None and not is_thin: lun_id += '_thick' return test_client.MockResource(_id=lun_id, name=name)
def thin_clone(obj, name, io_limit_policy, description, new_size_gb): if (obj.name, name) in (('snap_61', 'lun_60'), ('lun_63', 'lun_60')): return test_client.MockResource(_id=name) elif (obj.name, name) in (('snap_71', 'lun_70'), ('lun_72', 'lun_70')): raise ex.UnityThinCloneNotAllowedError() else: raise ex.UnityThinCloneLimitExceededError
def test_dd_copy_wo_src_lun(self): lun_id = 'lun_58' src_lun_id = 'lun_59' src_snap_id = 'snap_59' volume = MockOSResource(name=lun_id, id=lun_id, host='unity#pool1', provider_location=get_lun_pl(lun_id)) src_snap = test_client.MockResource(name=src_snap_id, _id=src_snap_id) src_snap.storage_resource = test_client.MockResource(name=src_lun_id, _id=src_lun_id) with patch_copy_volume() as copy_volume: ret = self.adapter._dd_copy( adapter.VolumeParams(self.adapter, volume), src_snap) copy_volume.assert_called_with('dev', 'dev', 5120, '1M', sparse=True) self.assertEqual(IdMatcher(test_client.MockResource(_id=lun_id)), ret)
def test_create_cloned_volume_available(self): lun_id = 'lun_54' src_lun_id = 'lun_55' volume = MockOSResource(id=lun_id, host='unity#pool1', size=3, provider_location=get_lun_pl(lun_id)) src_vref = MockOSResource(id=src_lun_id, name=src_lun_id, provider_location=get_lun_pl(src_lun_id), volume_attachment=None) with patch_thin_clone(test_client.MockResource(_id=lun_id)) as tc: ret = self.adapter.create_cloned_volume(volume, src_vref) tc.assert_called_with( adapter.VolumeParams(self.adapter, volume), IdMatcher(test_client.MockResource( _id='snap_clone_{}'.format(src_lun_id))), src_lun=IdMatcher(test_client.MockResource(_id=src_lun_id))) self.assertEqual(get_snap_lun_pl(lun_id), ret['provider_location'])
def test_dd_copy_with_src_lun(self): lun_id = 'lun_56' src_lun_id = 'lun_57' src_snap_id = 'snap_57' volume = MockOSResource(name=lun_id, id=lun_id, host='unity#pool1', provider_location=get_lun_pl(lun_id)) src_snap = test_client.MockResource(name=src_snap_id, _id=src_snap_id) src_lun = test_client.MockResource(name=src_lun_id, _id=src_lun_id) src_lun.size_total = 6 * units.Gi with patch_copy_volume() as copy_volume: ret = self.adapter._dd_copy( adapter.VolumeParams(self.adapter, volume), src_snap, src_lun=src_lun) copy_volume.assert_called_with('dev', 'dev', 6144, '1M', sparse=True) self.assertEqual(IdMatcher(test_client.MockResource(_id=lun_id)), ret)
def test_get_connection_info_auto_zone_disabled(self): self.adapter.lookup_service = None host = test_client.MockResource('host1') connector = {'wwpns': 'abcdefg'} ret = self.adapter.get_connection_info(10, host, connector) self.assertEqual(10, ret['target_lun']) wwns = ['8899AABBCCDDEEFF', '8899AABBCCDDFFEE'] self.assertListEqual(wwns, ret['target_wwn'])
def get_snap(name=None): if name in ('snap_50', ): # for thin clone cases return name snap = test_client.MockResource(name=name, _id=name) if name is not None: ret = snap else: ret = [snap] return ret
def test_create_volume_from_snapshot(self): lun_id = 'lun_50' volume = MockOSResource(name=lun_id, id=lun_id, host='unity#pool1') snap_id = 'snap_50' snap = MockOSResource(name=snap_id) with patch_thin_clone(test_client.MockResource(_id=lun_id)) as tc: ret = self.adapter.create_volume_from_snapshot(volume, snap) self.assertEqual(get_snap_lun_pl(lun_id), ret['provider_location']) tc.assert_called_with(adapter.VolumeParams(self.adapter, volume), snap_id)
def test_dd_copy_raise(self): lun_id = 'lun_58' src_snap_id = 'snap_59' volume = MockOSResource(name=lun_id, id=lun_id, host='unity#pool1', provider_location=get_lun_pl(lun_id)) src_snap = test_client.MockResource(name=src_snap_id, _id=src_snap_id) with patch_copy_volume() as copy_volume: copy_volume.side_effect = AttributeError self.assertRaises(AttributeError, self.adapter._dd_copy, volume, src_snap)
def test_thin_clone_downgraded_wo_src_lun(self): lun_id = 'lun_60' src_snap_id = 'snap_62' volume = MockOSResource(name=lun_id, id=lun_id, size=1, provider_location=get_snap_lun_pl(lun_id)) src_snap = test_client.MockResource(name=src_snap_id, _id=src_snap_id) new_dd_lun = test_client.MockResource(name='lun_63') with patch_storops() as mocked_storops, \ patch_dd_copy(new_dd_lun) as dd: ret = self.adapter._thin_clone( adapter.VolumeParams(self.adapter, volume), src_snap) vol_params = adapter.VolumeParams(self.adapter, volume) vol_params.name = 'hidden-{}'.format(volume.name) vol_params.description = 'hidden-{}'.format(volume.description) dd.assert_called_with(vol_params, src_snap, src_lun=None) mocked_storops.TCHelper.notify.assert_called_with(src_snap, 'DD_COPY', new_dd_lun) self.assertEqual(IdMatcher(test_client.MockResource(_id=lun_id)), ret)
def test_get_connection_info_auto_zone_enabled(self): host = test_client.MockResource('host1') connector = {'wwpns': 'abcdefg'} ret = self.adapter.get_connection_info(10, host, connector) target_wwns = ['100000051e55a100', '100000051e55a121'] self.assertListEqual(target_wwns, ret['target_wwn']) init_target_map = { '200000051e55a100': ('100000051e55a100', '100000051e55a121'), '200000051e55a121': ('100000051e55a100', '100000051e55a121')} self.assertDictEqual(init_target_map, ret['initiator_target_map']) self.assertEqual(10, ret['target_lun'])
def get_host(name): return test_client.MockResource(name=name)
def f(): host = test_client.MockResource('no_target') self.adapter.get_connection_info(12, host, {})
def restore_snapshot(self, snap_name): return test_client.MockResource(name="back_snap")
def create_host_wo_lock(name): return test_client.MockResource(name=name)
def create_snap(src_lun_id, name=None): if src_lun_id in ('lun_53', 'lun_55'): # for thin clone cases return test_client.MockResource( _id='snap_clone_{}'.format(src_lun_id)) return test_client.MockResource(name=name, _id=src_lun_id)
def create_lun(name, size, pool, description=None, io_limit_policy=None): return test_client.MockResource(_id='lun_3')
def f(): connector = {'host': 'host1'} snap = test_client.MockResource(_id='snap_0') self.adapter._terminate_connection(snap, connector)
def create_snap(src_lun_id, name=None): return test_client.MockResource(name=name, _id=src_lun_id)
def create_host(name, uids): return test_client.MockResource(name=name)