def test_scan_xfs_fstab(monkeypatch): fstab_data_no_xfs = { "fs_spec": "/dev/mapper/fedora-home", "fs_file": "/home", "fs_vfstype": "ext4", "fs_mntops": "defaults,x-systemd.device-timeout=0", "fs_freq": "1", "fs_passno": "2" } mountpoints = xfsinfoscanner.scan_xfs_fstab( [FstabEntry(**fstab_data_no_xfs)]) assert not mountpoints fstab_data_xfs = { "fs_spec": "/dev/mapper/rhel-root", "fs_file": "/", "fs_vfstype": "xfs", "fs_mntops": "defaults", "fs_freq": "0", "fs_passno": "0" } mountpoints = xfsinfoscanner.scan_xfs_fstab([FstabEntry(**fstab_data_xfs)]) assert mountpoints == {"/"}
def test_get_fstab_info(monkeypatch): def is_file_readable_mocked(path): return False expected = [ FstabEntry(fs_spec='/dev/mapper/rhel_ibm--p8--kvm--03--guest--02-root', fs_file='/', fs_vfstype='xfs', fs_mntops='defaults', fs_freq='0', fs_passno='0'), FstabEntry(fs_spec='UUID=0a5215ef-1fb4-4b1b-8860-be4baa9e624c', fs_file='/boot', fs_vfstype='xfs', fs_mntops='defaults', fs_freq='0', fs_passno='0'), FstabEntry(fs_spec='/dev/mapper/rhel_ibm--p8--kvm--03--guest--02-swap', fs_file='swap', fs_vfstype='swap', fs_mntops='defaults', fs_freq='0', fs_passno='0') ] assert expected == library._get_fstab_info('tests/files/fstab') monkeypatch.setattr('library._is_file_readable', is_file_readable_mocked) assert [] == library._get_fstab_info('unreadable_file')
def test_actor_with_fstab_entry(current_actor_context): with_fstab_entry = [ FstabEntry( fs_spec="//10.20.30.42/share1", fs_file="/mnt/win_share1", fs_vfstype="cifs", fs_mntops= "credentials=/etc/win-credentials,file_mode=0755,dir_mode=0755", fs_freq="0", fs_passno="0"), FstabEntry( fs_spec="//10.20.30.42/share2", fs_file="/mnt/win_share2", fs_vfstype="cifs", fs_mntops= "credentials=/etc/win-credentials,file_mode=0755,dir_mode=0755", fs_freq="0", fs_passno="0"), FstabEntry(fs_spec="/dev/mapper/fedora-home", fs_file="/home", fs_vfstype="ext4", fs_mntops="defaults,x-systemd.device-timeout=0", fs_freq="1", fs_passno="2") ] current_actor_context.feed(StorageInfo(fstab=with_fstab_entry)) current_actor_context.run() report_fields = current_actor_context.consume(Report)[0].report assert 'inhibitor' in report_fields['flags'] assert report_fields['severity'] == 'high' assert report_fields[ 'title'] == "Use of CIFS detected. Upgrade can't proceed"
def _get_fstab_info(fstab_path): """ Collect storage info from /etc/fstab file """ if _is_file_readable(fstab_path): with open(fstab_path, 'r') as fstab: for line, entry in enumerate(fstab, 1): if entry.startswith('#'): continue entry = entry.strip() if not entry: continue entries = entry.split() if len(entries) == 4: entries.append('0') if len(entries) == 5: entries.append('0') if len(entries) != 6: if any(value.startswith('#') for value in entries): remediation = ( 'Comments in the /etc/fstab file must be at the beginning of the line, your file has a' ' comment at the end of the line at line {}, please edit and fix this, for further' ' information read fstab man page (man 5 fstab).'.format(line) ) else: remediation = ( 'The /etc/fstab file must have at least 4 values and at most 6 per line, your file on the' ' line: {} have {} values, please edit and fix this, for further information read' ' fstab man page (man 5 fstab). '.format(line, len(entries)) ) summary = ( 'The fstab configuration file seems to be invalid. You need to fix it to be able to proceed' ' with the upgrade process.' ) reporting.create_report([ reporting.Title('Problems with parsing data in /etc/fstab'), reporting.Summary(summary), reporting.Severity(reporting.Severity.HIGH), reporting.Tags([reporting.Tags.FILESYSTEM]), reporting.Flags([reporting.Flags.INHIBITOR]), reporting.Remediation(hint=remediation), reporting.RelatedResource('file', '/etc/fstab') ]) api.current_logger().error(summary) break fs_spec, fs_file, fs_vfstype, fs_mntops, fs_freq, fs_passno = entries yield 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)
def consume_xfs_without_ftype_message_mocked(*models): fstab_data = { "fs_spec": "/dev/mapper/rhel-root", "fs_file": "/var", "fs_vfstype": "xfs", "fs_mntops": "defaults", "fs_freq": "0", "fs_passno": "0"} yield StorageInfo(fstab=[FstabEntry(**fstab_data)])
def _gen_fs_ent(fstype='ext4', mntops='auto', val=_myint_gen()): return FstabEntry( fs_spec='/path/spec/{}'.format(next(val)), fs_file='/path/file/{}'.format(next(val)), fs_vfstype=fstype, fs_mntops=mntops, fs_freq='1', fs_passno='1', )
def test_actor_without_fstab_entry(current_actor_context): without_fstab_entry = [ FstabEntry(fs_spec="/dev/mapper/fedora-home", fs_file="/home", fs_vfstype="ext4", fs_mntops="defaults,x-systemd.device-timeout=0", fs_freq="1", fs_passno="2") ] current_actor_context.feed(StorageInfo(fstab=without_fstab_entry)) current_actor_context.run() assert not current_actor_context.consume(Report)
def test_actor_with_fstab_entry(current_actor_context): with_fstab_entry = [ FstabEntry(fs_spec="lithium:/mnt/data", fs_file="/mnt/data", fs_vfstype="nfs", fs_mntops="noauto,noatime,rsize=32768,wsize=32768", fs_freq="0", fs_passno="0") ] current_actor_context.feed(StorageInfo(fstab=with_fstab_entry)) current_actor_context.run() assert 'inhibitor' in current_actor_context.consume(Report)[0].flags
def test_get_fstab_info(monkeypatch): expected = [ FstabEntry( fs_spec='/dev/mapper/rhel_ibm--p8--kvm--03--guest--02-root', fs_file='/', fs_vfstype='xfs', fs_mntops='defaults', fs_freq='0', fs_passno='0'), FstabEntry( fs_spec='UUID=0a5215ef-1fb4-4b1b-8860-be4baa9e624c', fs_file='/boot', fs_vfstype='xfs', fs_mntops='defaults', fs_freq='0', fs_passno='1'), FstabEntry( fs_spec='UUID=acf9f525-3691-429f-96d7-3f8530227062', fs_file='/var', fs_vfstype='xfs', fs_mntops='defaults', fs_freq='0', fs_passno='0'), FstabEntry( fs_spec='UUID=d74186c9-21d5-4549-ae26-91ca9ed36f56', fs_file='/tmp', fs_vfstype='ext4', fs_mntops='defaults,nodev,nosuid,noexec', fs_freq='1', fs_passno='0'), FstabEntry( fs_spec='/dev/mapper/rhel_ibm--p8--kvm--03--guest--02-swap', fs_file='swap', fs_vfstype='swap', fs_mntops='defaults', fs_freq='0', fs_passno='0')] assert expected == library._get_fstab_info('tests/files/fstab') monkeypatch.setattr(library, '_is_file_readable', lambda dummy: False) assert [] == library._get_fstab_info('unreadable_file')
def _get_fstab_info(fstab_path): ''' Collect storage info from /etc/fstab file ''' if _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( ) yield 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)
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)