def test_fails_to_remove_lv(self, monkeypatch): def mock_call(cmd, **kw): return ('', '', 1) monkeypatch.setattr(process, 'call', mock_call) with pytest.raises(RuntimeError): api.remove_lv("vg/lv")
def zap_lv(self, device): """ Device examples: vg-name/lv-name, /dev/vg-name/lv-name Requirements: Must be a logical volume (LV) """ lv = api.get_lv(lv_name=device.lv_name, vg_name=device.vg_name) self.unmount_lv(lv) wipefs(device.abspath) zap_data(device.abspath) if self.args.destroy: lvs = api.Volumes() lvs.filter(vg_name=device.vg_name) if len(lvs) <= 1: mlogger.info( 'Only 1 LV left in VG, will proceed to destroy volume group %s', device.vg_name) api.remove_vg(device.vg_name) else: mlogger.info( 'More than 1 LV left in VG, will proceed to destroy LV only' ) mlogger.info('Removing LV because --destroy was given: %s', device.abspath) api.remove_lv(device.abspath) elif lv: # just remove all lvm metadata, leaving the LV around lv.clear_tags()
def zap_lv(self, device): """ Device examples: vg-name/lv-name, /dev/vg-name/lv-name Requirements: Must be a logical volume (LV) """ lv = api.get_single_lv(filters={ 'lv_name': device.lv_name, 'vg_name': device.vg_name }) pv = api.get_single_pv(filters={'lv_uuid': lv.lv_uuid}) self.unmount_lv(lv) wipefs(device.abspath) zap_data(device.abspath) if self.args.destroy: lvs = api.get_lvs(filters={'vg_name': device.vg_name}) if lvs == []: mlogger.info('No LVs left, exiting', device.vg_name) return elif len(lvs) <= 1: mlogger.info( 'Only 1 LV left in VG, will proceed to destroy ' 'volume group %s', device.vg_name) api.remove_vg(device.vg_name) api.remove_pv(pv.pv_name) else: mlogger.info('More than 1 LV left in VG, will proceed to ' 'destroy LV only') mlogger.info('Removing LV because --destroy was given: %s', device.abspath) api.remove_lv(device.abspath) elif lv: # just remove all lvm metadata, leaving the LV around lv.clear_tags()
def test_removes_lv_object(self, fake_call): foo_volume = api.Volume(lv_name='foo', lv_path='/path', vg_name='foo_group', lv_tags='') api.remove_lv(foo_volume) # last argument from the list passed to process.call assert fake_call.calls[0]['args'][0][-1] == '/path'
def zap_lv(self, device): """ Device examples: vg-name/lv-name, /dev/vg-name/lv-name Requirements: Must be a logical volume (LV) """ lv = api.get_lv(lv_name=device.lv_name, vg_name=device.vg_name) self.unmount_lv(lv) wipefs(device.abspath) zap_data(device.abspath) if self.args.destroy: lvs = api.Volumes() lvs.filter(vg_name=device.vg_name) if len(lvs) <= 1: mlogger.info('Only 1 LV left in VG, will proceed to destroy volume group %s', device.vg_name) api.remove_vg(device.vg_name) else: mlogger.info('More than 1 LV left in VG, will proceed to destroy LV only') mlogger.info('Removing LV because --destroy was given: %s', device.abspath) api.remove_lv(device.abspath) elif lv: # just remove all lvm metadata, leaving the LV around lv.clear_tags()
def test_removes_lv(self, monkeypatch): def mock_call(cmd, **kw): return ('', '', 0) monkeypatch.setattr(process, 'call', mock_call) assert api.remove_lv("vg/lv")
def test_fails_to_remove_lv(self, monkeypatch): def mock_call(cmd, **kw): return ('', '', 1) monkeypatch.setattr(process, 'call', mock_call) with pytest.raises(RuntimeError): api.remove_lv("vg/lv")
def test_removes_lv(self, monkeypatch): def mock_call(cmd, **kw): return ('', '', 0) monkeypatch.setattr(process, 'call', mock_call) assert api.remove_lv("vg/lv")
def test_removes_lv_object(self, fake_call): foo_volume = api.Volume(lv_name='foo', lv_path='/path', vg_name='foo_group', lv_tags='') api.remove_lv(foo_volume) # last argument from the list passed to process.call assert fake_call.calls[0]['args'][0][-1] == '/path'
def zap(self, args): for device in args.devices: if disk.is_mapper_device(device): terminal.error( "Refusing to zap the mapper device: {}".format(device)) raise SystemExit(1) lv = api.get_lv_from_argument(device) if lv: # we are zapping a logical volume path = lv.lv_path self.unmount_lv(lv) else: # we are zapping a partition #TODO: ensure device is a partition path = device # check to if it is encrypted to close partuuid = disk.get_partuuid(device) if encryption.status("/dev/mapper/{}".format(partuuid)): dmcrypt_uuid = partuuid self.dmcrypt_close(dmcrypt_uuid) mlogger.info("Zapping: %s", path) # check if there was a pv created with the # name of device pvs = api.PVolumes() pvs.filter(pv_name=device) vgs = set([pv.vg_name for pv in pvs]) for pv in pvs: vg_name = pv.vg_name lv = None if pv.lv_uuid: lv = api.get_lv(vg_name=vg_name, lv_uuid=pv.lv_uuid) if lv: self.unmount_lv(lv) if args.destroy: for vg_name in vgs: mlogger.info( "Destroying volume group %s because --destroy was given", vg_name) api.remove_vg(vg_name) if not lv: mlogger.info( "Destroying physical volume %s because --destroy was given", device) api.remove_pv(device) wipefs(path) zap_data(path) if lv and not pvs: if args.destroy: lvs = api.Volumes() lvs.filter(vg_name=lv.vg_name) if len(lvs) <= 1: mlogger.info( 'Only 1 LV left in VG, will proceed to destroy volume group %s', lv.vg_name) api.remove_vg(lv.vg_name) else: mlogger.info( 'More than 1 LV left in VG, will proceed to destroy LV only' ) mlogger.info( 'Removing LV because --destroy was given: %s', lv) api.remove_lv(lv) else: # just remove all lvm metadata, leaving the LV around lv.clear_tags() terminal.success("Zapping successful for: %s" % ", ".join(args.devices))