예제 #1
0
def test_get_lvdisplay_info(monkeypatch):
    def get_cmd_output_mocked(cmd, delim, expected_len):
        return [
            ['root', 'rhel_ibm-p8-kvm-03-guest-02', '-wi-ao----', '37.99g', '', '', '', '', '', '', '', ''],
            ['swap', 'rhel_ibm-p8-kvm-03-guest-02', '-wi-ao----', '1.00g', '', '', '', '', '', '', '', '']]

    monkeypatch.setattr(library, '_get_cmd_output', get_cmd_output_mocked)
    expected = [
        LvdisplayEntry(
            lv='root',
            vg='rhel_ibm-p8-kvm-03-guest-02',
            attr='-wi-ao----',
            lsize='37.99g',
            pool='',
            origin='',
            data='',
            meta='',
            move='',
            log='',
            cpy_sync='',
            convert=''),
        LvdisplayEntry(
            lv='swap',
            vg='rhel_ibm-p8-kvm-03-guest-02',
            attr='-wi-ao----',
            lsize='1.00g',
            pool='',
            origin='',
            data='',
            meta='',
            move='',
            log='',
            cpy_sync='',
            convert='')]
    assert expected == library._get_lvdisplay_info()
예제 #2
0
def _get_lvdisplay_info():
    """ Collect storage info from lvdisplay command """
    for entry in _get_cmd_output(['lvdisplay', '-C', '--noheadings', '--separator', r':'], ':', 12):
        lv, vg, attr, lsize, pool, origin, data, meta, move, log, cpy_sync, convert = entry
        yield LvdisplayEntry(
            lv=lv,
            vg=vg,
            attr=attr,
            lsize=lsize,
            pool=pool,
            origin=origin,
            data=data,
            meta=meta,
            move=move,
            log=log,
            cpy_sync=cpy_sync,
            convert=convert)
예제 #3
0
    def process(self):
        result = StorageInfo()

        partitions_path = '/proc/partitions'
        if self.is_file_readable(partitions_path):
            with open(partitions_path, 'r') as partitions:
                skipped_header = False
                for entry in partitions:
                    if entry.startswith('#'):
                        continue

                    if not skipped_header:
                        skipped_header = True
                        continue

                    entry = entry.strip()
                    if not entry:
                        continue

                    major, minor, blocks, name = entry.split()
                    result.partitions.append(
                        PartitionEntry(major=major,
                                       minor=minor,
                                       blocks=blocks,
                                       name=name))

        fstab_path = '/etc/fstab'
        if self.is_file_readable(fstab_path):
            with open(fstab_path, 'r') as fstab:
                for entry in fstab:
                    if entry.startswith('#'):
                        continue

                    entry = entry.strip()
                    if not entry:
                        continue

                    fs_spec, fs_file, fs_vfstype, fs_mntops, fs_freq, fs_passno = entry.split(
                    )
                    result.fstab.append(
                        FstabEntry(fs_spec=fs_spec,
                                   fs_file=fs_file,
                                   fs_vfstype=fs_vfstype,
                                   fs_mntops=fs_mntops,
                                   fs_freq=fs_freq,
                                   fs_passno=fs_passno))

        for entry in self.get_cmd_output(['mount'], ' ', 6):
            name, _, mount, _, tp, options = entry
            result.mount.append(
                MountEntry(name=name, mount=mount, tp=tp, options=options))

        for entry in self.get_cmd_output(['lsblk', '-r', '--noheadings'], ' ',
                                         7):
            name, maj_min, rm, size, ro, tp, mountpoint = entry
            result.lsblk.append(
                LsblkEntry(name=name,
                           maj_min=maj_min,
                           rm=rm,
                           size=size,
                           ro=ro,
                           tp=tp,
                           mountpoint=mountpoint))

        for entry in self.get_cmd_output(
            ['pvs', '--noheadings', '--separator', r':'], ':', 6):
            pv, vg, fmt, attr, psize, pfree = entry
            result.pvs.append(
                PvsEntry(pv=pv,
                         vg=vg,
                         fmt=fmt,
                         attr=attr,
                         psize=psize,
                         pfree=pfree))

        for entry in self.get_cmd_output(
            ['vgs', '--noheadings', '--separator', r':'], ':', 7):
            vg, pv, lv, sn, attr, vsize, vfree = entry
            result.vgs.append(
                VgsEntry(vg=vg,
                         pv=pv,
                         lv=lv,
                         sn=sn,
                         attr=attr,
                         vsize=vsize,
                         vfree=vfree))

        for entry in self.get_cmd_output(
            ['lvdisplay', '-C', '--noheadings', '--separator', r':'], ':', 12):
            lv, vg, attr, lsize, pool, origin, data, meta, move, log, cpy_sync, convert = entry
            result.lvdisplay.append(
                LvdisplayEntry(lv=lv,
                               vg=vg,
                               attr=attr,
                               lsize=lsize,
                               pool=pool,
                               origin=origin,
                               data=data,
                               meta=meta,
                               move=move,
                               log=log,
                               cpy_sync=cpy_sync,
                               convert=convert))

        self.produce(result)
예제 #4
0
    def process(self):
        result = StorageInfo()

        partitions_path = '/proc/partitions'
        if self.is_file_readable(partitions_path):
            with open(partitions_path, 'r') as partitions:
                skipped_header = False
                for entry in partitions:
                    if entry.startswith('#'):
                        continue

                    if not skipped_header:
                        skipped_header = True
                        continue

                    entry = entry.strip()
                    if not entry:
                        continue

                    major, minor, blocks, name = entry.split()
                    result.partitions.append(PartitionEntry(
                        major=major,
                        minor=minor,
                        blocks=blocks,
                        name=name))

        fstab_path = '/etc/fstab'
        if self.is_file_readable(fstab_path):
            with open(fstab_path, 'r') as fstab:
                for entry in fstab:
                    if entry.startswith('#'):
                        continue

                    entry = entry.strip()
                    if not entry:
                        continue

                    fs_spec, fs_file, fs_vfstype, fs_mntops, fs_freq, fs_passno = entry.split()
                    result.fstab.append(FstabEntry(
                        fs_spec=fs_spec,
                        fs_file=fs_file,
                        fs_vfstype=fs_vfstype,
                        fs_mntops=fs_mntops,
                        fs_freq=fs_freq,
                        fs_passno=fs_passno))

        for entry in self.get_cmd_output(['mount'], ' ', 6):
            name, _, mount, _, tp, options = entry
            result.mount.append(MountEntry(
                name=name,
                mount=mount,
                tp=tp,
                options=options))

        for entry in self.get_cmd_output(['lsblk', '-r', '--noheadings'], ' ', 7):
            name, maj_min, rm, size, ro, tp, mountpoint = entry
            result.lsblk.append(LsblkEntry(
                name=name,
                maj_min=maj_min,
                rm=rm,
                size=size,
                ro=ro,
                tp=tp,
                mountpoint=mountpoint))

        for entry in self.get_cmd_output(['pvs', '--noheadings', '--separator', r':'], ':', 6):
            pv, vg, fmt, attr, psize, pfree = entry
            result.pvs.append(PvsEntry(
                pv=pv,
                vg=vg,
                fmt=fmt,
                attr=attr,
                psize=psize,
                pfree=pfree))

        for entry in self.get_cmd_output(['vgs', '--noheadings', '--separator', r':'], ':', 7):
            vg, pv, lv, sn, attr, vsize, vfree = entry
            result.vgs.append(VgsEntry(
                vg=vg,
                pv=pv,
                lv=lv,
                sn=sn,
                attr=attr,
                vsize=vsize,
                vfree=vfree))

        for entry in self.get_cmd_output(['lvdisplay', '-C', '--noheadings', '--separator', r':'], ':', 12):
            lv, vg, attr, lsize, pool, origin, data, meta, move, log, cpy_sync, convert = entry
            result.lvdisplay.append(LvdisplayEntry(
                lv=lv,
                vg=vg,
                attr=attr,
                lsize=lsize,
                pool=pool,
                origin=origin,
                data=data,
                meta=meta,
                move=move,
                log=log,
                cpy_sync=cpy_sync,
                convert=convert))

        for entry in self.get_cmd_output(['systemd-mount', '--list'], ' ', 7):
            # We need to filter the entry because there is a ton of whitespace.
            node, path, model, wwn, fs_type, label, uuid = list(filter(lambda x: x != '', entry))
            if node == "NODE":
                # First row of the "systemd-mount --list" output is a header.
                # Just skip it.
                continue
            result.systemdmount.append(SystemdMountEntry(
                node=node,
                path=path,
                model=model,
                wwn=wwn,
                fs_type=fs_type,
                label=label,
                uuid=uuid))

        self.produce(result)