Exemple #1
0
    def zap(self, args):
        device = args.device
        lv = api.get_lv_from_argument(device)
        if lv:
            # we are zapping a logical volume
            path = lv.lv_path
        else:
            # we are zapping a partition
            #TODO: ensure device is a partition
            path = device

        mlogger.info("Zapping: %s", path)

        # check if there was a pv created with the
        # name of device
        pv = api.get_pv(pv_name=device)
        if pv:
            vg_name = pv.vg_name
            lv = api.get_lv(vg_name=vg_name)

        dmcrypt = False
        dmcrypt_uuid = None
        if lv:
            osd_path = "/var/lib/ceph/osd/{}-{}".format(lv.tags['ceph.cluster_name'], lv.tags['ceph.osd_id'])
            dmcrypt_uuid = lv.lv_uuid
            dmcrypt = lv.encrypted
            if system.path_is_mounted(osd_path):
                mlogger.info("Unmounting %s", osd_path)
                system.unmount(osd_path)
        else:
            # we're most likely dealing with a partition here, check to
            # see if it was encrypted
            partuuid = disk.get_partuuid(device)
            if encryption.status("/dev/mapper/{}".format(partuuid)):
                dmcrypt_uuid = partuuid
                dmcrypt = True

        if dmcrypt and dmcrypt_uuid:
            dmcrypt_path = "/dev/mapper/{}".format(dmcrypt_uuid)
            mlogger.info("Closing encrypted path %s", dmcrypt_path)
            encryption.dmcrypt_close(dmcrypt_path)

        if args.destroy and pv:
            logger.info("Found a physical volume created from %s, will destroy all it's vgs and lvs", device)
            vg_name = pv.vg_name
            mlogger.info("Destroying volume group %s because --destroy was given", vg_name)
            api.remove_vg(vg_name)
            mlogger.info("Destroying physical volume %s because --destroy was given", device)
            api.remove_pv(device)
        elif args.destroy and not pv:
            mlogger.info("Skipping --destroy because no associated physical volumes are found for %s", device)

        wipefs(path)
        zap_data(path)

        if lv and not pv:
            # remove all lvm metadata
            lv.clear_tags()

        terminal.success("Zapping successful for: %s" % path)
Exemple #2
0
 def test_mapper_exists(self, fake_run, fake_filesystem):
     file_name = fake_filesystem.create_file('mapper-device')
     encryption.dmcrypt_close(file_name.path)
     arguments = fake_run.calls[0]['args'][0]
     assert arguments[0] == 'cryptsetup'
     assert arguments[1] == 'remove'
     assert arguments[2].startswith('/')
Exemple #3
0
 def test_mapper_exists(self, fake_run, tmpfile):
     file_name = tmpfile(name='mapper-device')
     encryption.dmcrypt_close(file_name)
     arguments = fake_run.calls[0]['args'][0]
     assert arguments[0] == 'cryptsetup'
     assert arguments[1] == 'remove'
     assert arguments[2].startswith('/')
 def test_mapper_exists(self, fake_run, tmpfile):
     file_name = tmpfile(name='mapper-device')
     encryption.dmcrypt_close(file_name)
     arguments = fake_run.calls[0]['args'][0]
     assert arguments[0] == 'cryptsetup'
     assert arguments[1] == 'remove'
     assert arguments[2].startswith('/')
Exemple #5
0
 def __exit__(self, exc_type, exc_val, exc_tb):
     process.run([
         'umount',
         '-v',
         self.path
     ])
     if self.encrypted:
         # avoid a circular import from the encryption module
         from ceph_volume.util import encryption
         encryption.dmcrypt_close(self.device)
Exemple #6
0
 def __exit__(self, exc_type, exc_val, exc_tb):
     process.run([
         'umount',
         '-v',
         self.path
     ])
     if self.encrypted:
         # avoid a circular import from the encryption module
         from ceph_volume.util import encryption
         encryption.dmcrypt_close(self.device)
Exemple #7
0
def deactivate_osd(osd_id=None, osd_uuid=None):

    lvs = []
    if osd_uuid is not None:
        lvs = get_lvs_by_tag('ceph.osd_fsid={}'.format(osd_uuid))
        osd_id = next(lv.tags['ceph.osd_id'] for lv in lvs)
    else:
        lvs = get_lvs_by_tag('ceph.osd_id={}'.format(osd_id))

    data_lv = next(lv for lv in lvs
                   if lv.tags['ceph.type'] in ['data', 'block'])

    conf.cluster = data_lv.tags['ceph.cluster_name']
    logger.debug('Found cluster name {}'.format(conf.cluster))

    tmpfs_path = '/var/lib/ceph/osd/{}-{}'.format(conf.cluster, osd_id)
    system.unmount_tmpfs(tmpfs_path)

    for lv in lvs:
        if lv.tags.get('ceph.encrypted', '0') == '1':
            encryption.dmcrypt_close(lv.lv_uuid)
Exemple #8
0
 def dmcrypt_close(self, dmcrypt_uuid):
     dmcrypt_path = "/dev/mapper/{}".format(dmcrypt_uuid)
     mlogger.info("Closing encrypted path %s", dmcrypt_path)
     encryption.dmcrypt_close(dmcrypt_path)
Exemple #9
0
 def dmcrypt_close(self, dmcrypt_uuid):
     dmcrypt_path = "/dev/mapper/{}".format(dmcrypt_uuid)
     mlogger.info("Closing encrypted path %s", dmcrypt_path)
     encryption.dmcrypt_close(dmcrypt_path)
Exemple #10
0
 def test_mapper_does_not_exist(self, fake_run):
     file_name = '/path/does/not/exist'
     encryption.dmcrypt_close(file_name)
     assert fake_run.calls == []
Exemple #11
0
 def test_mapper_does_not_exist(self, fake_run):
     file_name = '/path/does/not/exist'
     encryption.dmcrypt_close(file_name)
     assert fake_run.calls == []
Exemple #12
0
    def zap(self, args):
        device = args.device
        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
        else:
            # we are zapping a partition
            #TODO: ensure device is a partition
            path = device

        mlogger.info("Zapping: %s", path)

        # check if there was a pv created with the
        # name of device
        pv = api.get_pv(pv_name=device)
        if pv:
            vg_name = pv.vg_name
            lv = api.get_lv(vg_name=vg_name)

        dmcrypt = False
        dmcrypt_uuid = None
        if lv:
            if lv.tags.get('ceph.cluster_name') and lv.tags.get('ceph.osd_id'):
                lv_path = "/var/lib/ceph/osd/{}-{}".format(
                    lv.tags['ceph.cluster_name'], lv.tags['ceph.osd_id'])
            else:
                lv_path = lv.path
            dmcrypt_uuid = lv.lv_uuid
            dmcrypt = lv.encrypted
            if system.path_is_mounted(lv_path):
                mlogger.info("Unmounting %s", lv_path)
                system.unmount(lv_path)
        else:
            # we're most likely dealing with a partition here, check to
            # see if it was encrypted
            partuuid = disk.get_partuuid(device)
            if encryption.status("/dev/mapper/{}".format(partuuid)):
                dmcrypt_uuid = partuuid
                dmcrypt = True

        if dmcrypt and dmcrypt_uuid:
            dmcrypt_path = "/dev/mapper/{}".format(dmcrypt_uuid)
            mlogger.info("Closing encrypted path %s", dmcrypt_path)
            encryption.dmcrypt_close(dmcrypt_path)

        if args.destroy and pv:
            logger.info(
                "Found a physical volume created from %s, will destroy all it's vgs and lvs",
                device)
            vg_name = pv.vg_name
            mlogger.info(
                "Destroying volume group %s because --destroy was given",
                vg_name)
            api.remove_vg(vg_name)
            mlogger.info(
                "Destroying physical volume %s because --destroy was given",
                device)
            api.remove_pv(device)
        elif args.destroy and not pv:
            mlogger.info(
                "Skipping --destroy because no associated physical volumes are found for %s",
                device)

        wipefs(path)
        zap_data(path)

        if lv and not pv:
            # remove all lvm metadata
            lv.clear_tags()

        terminal.success("Zapping successful for: %s" % path)