def _get_vgs_info(): """ Collect storage info from vgs command """ for entry in _get_cmd_output(['vgs', '--noheadings', '--separator', r':'], ':', 7): vg, pv, lv, sn, attr, vsize, vfree = entry yield VgsEntry( vg=vg, pv=pv, lv=lv, sn=sn, attr=attr, vsize=vsize, vfree=vfree)
def test_get_vgs_info(monkeypatch): def get_cmd_output_mocked(cmd, delim, expected_len): return [ ['rhel_ibm-p8-kvm-03-guest-02', '1', '2', '0', 'wz--n-', '<39.00g', '4.00m']] monkeypatch.setattr(library, '_get_cmd_output', get_cmd_output_mocked) expected = [ VgsEntry( vg='rhel_ibm-p8-kvm-03-guest-02', pv='1', lv='2', sn='0', attr='wz--n-', vsize='<39.00g', vfree='4.00m')] assert expected == library._get_vgs_info()
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)
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)