def test_notify_tc_delete_base_lun_still_using(self, lun_delete): lun = UnityLun.get(_id='sv_5600', cli=t_rest(version='4.2.0')) TCHelper.notify(lun, ThinCloneActionEnum.TC_DELETE) self.assertFalse(lun.get_id() in TCHelper._tc_cache) self.assertFalse(lun.get_id() in TCHelper._gc_candidates) lun_delete.assert_not_called()
def delete(self, async_mode=False, force_snap_delete=False, force_vvol_delete=False): sr = self.storage_resource if not self.existed or sr is None: raise UnityResourceNotFoundError('cannot find lun {}.'.format( self.get_id())) resp = self._cli.delete(sr.resource_class, self.get_id(), forceSnapDeletion=force_snap_delete, forceVvolDeletion=force_vvol_delete, async_mode=async_mode) try: resp.raise_if_err() except UnityBaseHasThinCloneError: log.warning( 'cannot delete the lun: %s, because it is a base lun ' 'of a thin-clone.', self.get_id()) TCHelper.notify(self, ThinCloneActionEnum.BASE_LUN_DELETE) return RESP_OK if self.is_thin_clone: TCHelper.notify(self, ThinCloneActionEnum.TC_DELETE) return resp
def test_notify_tc_delete_base_lun(self, mocked_put): base_lun = UnityLun.get(_id='sv_5608', cli=t_rest(version='4.2.0')) TCHelper.notify(base_lun, ThinCloneActionEnum.BASE_LUN_DELETE) self.assertTrue(base_lun.get_id() in TCHelper._gc_candidates) mocked_put.assert_called_with(TCHelper._delete_base_lun, base_lun=base_lun)
def test_notify_dd_copy(self): lun = UnityLun.get(_id='sv_2', cli=t_rest(version='4.2.0')) copied_lun = UnityLun.get(_id='sv_3', cli=t_rest(version='4.2.0')) TCHelper.notify(lun, ThinCloneActionEnum.DD_COPY, copied_lun) self.assertTrue(lun.get_id() in TCHelper._tc_cache) self.assertEqual(copied_lun, TCHelper._tc_cache[lun.get_id()]) self.assertFalse(lun.get_id() in TCHelper._gc_candidates)
def test_notify_tc_delete_base_lun_snap_under_destroying(self): lun = UnityLun.get(_id='sv_5606', cli=t_rest(version='4.2.0')) base_lun = UnityLun.get(_id='sv_5607', cli=t_rest(version='4.2.0')) TCHelper._gc_candidates[base_lun.get_id()] = base_lun.get_id() TCHelper.notify(lun, ThinCloneActionEnum.TC_DELETE) self.assertFalse(lun.get_id() in TCHelper._tc_cache) self.assertFalse(lun.get_id() in TCHelper._gc_candidates) self.assertTrue(base_lun.get_id() in TCHelper._gc_candidates)
def test_notify_tc_delete_base_lun_ready_for_gc(self, lun_delete): lun = UnityLun.get(_id='sv_5600', cli=t_rest(version='4.2.0')) base_lun = UnityLun.get(_id='sv_5601', cli=t_rest(version='4.2.0')) TCHelper._gc_candidates[base_lun.get_id()] = base_lun.get_id() TCHelper.notify(lun, ThinCloneActionEnum.TC_DELETE) self.assertFalse(lun.get_id() in TCHelper._tc_cache) self.assertFalse(lun.get_id() in TCHelper._gc_candidates) self.assertFalse(base_lun.get_id() in TCHelper._gc_candidates) lun_delete.assert_called_once()
def test_notify_lun_attach_gc(self, mocked_put): lun = UnityLun.get(_id='sv_2', cli=t_rest(version='4.2.0')) old_lun = UnityLun.get(_id='sv_4', cli=t_rest(version='4.2.0')) TCHelper._tc_cache[lun.get_id()] = old_lun TCHelper.notify(lun, ThinCloneActionEnum.LUN_ATTACH) self.assertFalse(lun.get_id() in TCHelper._tc_cache) self.assertTrue(old_lun.get_id() in TCHelper._gc_candidates) mocked_put.assert_called_with(TCHelper._delete_base_lun, base_lun=old_lun)
def test_notify_tc_delete_base_lun_having_thinclone( self, mocked_put, lun_delete): lun = UnityLun.get(_id='sv_5602', cli=t_rest(version='4.2.0')) base_lun = UnityLun.get(_id='sv_5603', cli=t_rest(version='4.2.0')) TCHelper._gc_candidates[base_lun.get_id()] = base_lun.get_id() TCHelper.notify(lun, ThinCloneActionEnum.TC_DELETE) self.assertFalse(lun.get_id() in TCHelper._tc_cache) self.assertFalse(lun.get_id() in TCHelper._gc_candidates) self.assertTrue(base_lun.get_id() in TCHelper._gc_candidates) lun_delete.assert_not_called()
def test_notify_dd_copy_gc(self, mocked_put): lun = UnityLun.get(_id='sv_2', cli=t_rest(version='4.2.0')) copied_lun = UnityLun.get(_id='sv_3', cli=t_rest(version='4.2.0')) old_lun = UnityLun.get(_id='sv_4', cli=t_rest(version='4.2.0')) TCHelper._tc_cache[lun.get_id()] = old_lun TCHelper.notify(lun, ThinCloneActionEnum.DD_COPY, copied_lun) self.assertTrue(lun.get_id() in TCHelper._tc_cache) self.assertEqual(copied_lun, TCHelper._tc_cache[lun.get_id()]) self.assertTrue(old_lun.get_id() in TCHelper._gc_candidates) mocked_put.assert_called_with(TCHelper._delete_base_lun, base_lun=old_lun)
def attach_to(self, host, access_mask=HostLUNAccessEnum.PRODUCTION): host_access = [{'host': host, 'accessMask': access_mask}] # If this lun has been attached to other host, don't overwrite it. if self.host_access: host_access += [{'host': item.host, 'accessMask': item.access_mask} for item in self.host_access if host.id != item.host.id] resp = self.modify(host_access=host_access) resp.raise_if_err() log.debug('Notify TCHelper the attaching action of lun: %s.', self.get_id()) TCHelper.notify(self, ThinCloneActionEnum.LUN_ATTACH) return resp
def test_thin_clone_snap(self): snap = UnitySnap.get(_id='38654700002', cli=t_rest(version='4.2.0')) cloned = TCHelper.thin_clone(snap._cli, snap, name='test_thin_clone_snap', description='description', io_limit_policy=None) assert_that(cloned.id, equal_to('sv_5557'))
def test_thin_clone_snap_new_tc_base(self): TCHelper._tc_cache['sv_2'] = UnityLun.get(_id='sv_5605', cli=t_rest(version='4.2.0')) lun = UnityLun.get(_id='sv_2', cli=t_rest(version='4.2.0')) cloned = TCHelper.thin_clone(lun._cli, lun, name='test_thin_clone_lun', description='description', io_limit_policy=None) assert_that(cloned.id, equal_to('sv_5556'))
def test_thin_clone_lun(self): lun = UnityLun.get(_id='sv_2', cli=t_rest(version='4.2.0')) cloned = TCHelper.thin_clone(lun._cli, lun, name='test_thin_clone_lun', description='description', io_limit_policy=None) assert_that(cloned.id, equal_to('sv_5555'))
def thin_clone(self, name, io_limit_policy=None, description=None): if self.is_cg_member: raise UnityCGMemberActionNotSupportError() if not self.is_thin_enabled: raise UnityThinCloneNotAllowedError() return TCHelper.thin_clone(self._cli, self, name, io_limit_policy, description)
def thin_clone(self, name, io_limit_policy=None, description=None): """Creates a new thin clone from this snapshot. .. note:: this snapshot should not enable Auto-Delete. """ if self.is_member_snap(): raise UnityCGMemberActionNotSupportError() if self.lun and not self.lun.is_thin_enabled: raise UnityThinCloneNotAllowedError() return TCHelper.thin_clone(self._cli, self, name, io_limit_policy, description)
def test_notify_lun_attach(self): lun = UnityLun.get(_id='sv_2', cli=t_rest(version='4.2.0')) TCHelper.notify(lun, ThinCloneActionEnum.LUN_ATTACH) self.assertFalse(lun.get_id() in TCHelper._tc_cache) self.assertFalse(lun.get_id() in TCHelper._gc_candidates)
sr = self.storage_resource if not self.existed or sr is None: raise UnityResourceNotFoundError('cannot find lun {}.'.format( self.get_id())) resp = self._cli.delete(sr.resource_class, self.get_id(), forceSnapDeletion=force_snap_delete, forceVvolDeletion=force_vvol_delete, async=async) try: resp.raise_if_err() except UnityBaseHasThinCloneError: log.warning( 'cannot delete the lun: %s, because it is a base lun ' 'of a thin-clone.', self.get_id()) TCHelper.notify(self, ThinCloneActionEnum.BASE_LUN_DELETE) return RESP_OK if self.is_thin_clone: TCHelper.notify(self, ThinCloneActionEnum.TC_DELETE) return resp def _attach_to(self, host, access_mask, hlu): host_access = [{'host': host, 'accessMask': access_mask}] if hlu is not None: host_access[0]['hlu'] = hlu # If this lun has been attached to other host, don't overwrite it. if self.host_access: host_access += [{ 'host': item.host, 'accessMask': item.access_mask
def thin_clone(self, name, io_limit_policy=None, description=None): return TCHelper.thin_clone(self._cli, self, name, io_limit_policy, description)
def thin_clone(self, name, io_limit_policy=None, description=None): if self.is_cg_member: raise UnityCGLunActionNotSupportError() return TCHelper.thin_clone(self._cli, self, name, io_limit_policy, description)
def thin_clone(self, name, io_limit_policy=None, description=None): """Creates a new thin clone from this snapshot. .. note:: this snapshot should not enable Auto-Delete. """ return TCHelper.thin_clone(self._cli, self, name, io_limit_policy, description)
def setUp(self): self.path = tempfile.mkdtemp(suffix='storops') TCHelper.set_up(self.path) TCHelper._gc_background.set_interval(0.10) TCHelper._gc_background.MAX_RETRIES = 1
def _inner(): TCHelper.thin_clone(lun._cli, lun, name='test_thin_clone_limit_exceeded', description='This is description.', io_limit_policy=None)
def tearDown(self): shutil.rmtree(self.path, ignore_errors=True) TCHelper.clean_up()