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 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_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 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
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 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)