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 consume_ignored_xfs_message_mocked(*models): mount_data = { "name": "/dev/vda1", "mount": "/boot", "tp": "xfs", "options": "rw,relatime,seclabel,attr2,inode64,noquota"} yield StorageInfo(mount=[MountEntry(**mount_data)])
def test_actor_with_luks(current_actor_context): with_luks = [LsblkEntry(name='luks-132', maj_min='253:0', rm='0', size='10G', ro='0', tp='crypt', mountpoint='' )] current_actor_context.feed(StorageInfo(lsblk=with_luks)) current_actor_context.run() assert current_actor_context.consume(Inhibitor)
def test_actor_without_luks(current_actor_context): without_luks = [LsblkEntry(name='sda1', maj_min='8:0', rm='0', size='10G', ro='0', tp='part', mountpoint='/boot' )] current_actor_context.feed(StorageInfo(lsblk=without_luks)) current_actor_context.run() assert not current_actor_context.consume(Inhibitor)
def process(self): xfs_info = next(self.consume(XFSPresence), XFSPresence()) storage_info = next(self.consume(StorageInfo), StorageInfo()) used_repos = self.consume(UsedTargetRepositories) tasks = next(self.consume(FilteredRpmTransactionTasks), FilteredRpmTransactionTasks()) target_userspace_info = next(self.consume(TargetUserSpaceInfo), None) dnfplugin.perform_rpm_download(tasks=tasks, used_repos=used_repos, target_userspace_info=target_userspace_info, xfs_info=xfs_info, storage_info=storage_info)
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 get_storage_info(): """ Collect multiple info about storage and return it """ return StorageInfo(partitions=_get_partitions_info('/proc/partitions'), fstab=_get_fstab_info('/etc/fstab'), mount=_get_mount_info('/proc/mounts'), lsblk=_get_lsblk_info(), pvs=_get_pvs_info(), vgs=_get_vgs_info(), lvdisplay=_get_lvdisplay_info(), systemdmount=_get_systemd_mount_info())
def test_actor_without_mount_share(current_actor_context): without_mount_share = [ MountEntry(name="tmpfs", mount="/run/snapd/ns", tp="tmpfs", options="rw,nosuid,nodev,seclabel,mode=755") ] current_actor_context.feed(StorageInfo(mount=without_mount_share)) current_actor_context.run() assert not current_actor_context.consume(Report)
def test_actor_with_mount_share(current_actor_context): with_mount_share = [ MountEntry( name="nfs", mount="/mnt/data", tp="nfs", options="rw,nosuid,nodev,relatime,user_id=1000,group_id=1000") ] current_actor_context.feed(StorageInfo(mount=with_mount_share)) current_actor_context.run() assert 'inhibitor' in current_actor_context.consume(Report)[0].flags
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 process(self): xfs_info = next(self.consume(XFSPresence), XFSPresence()) storage_info = next(self.consume(StorageInfo), StorageInfo()) used_repos = self.consume(UsedTargetRepositories) plugin_info = list(self.consume(DNFPluginTask)) tasks = next(self.consume(FilteredRpmTransactionTasks), FilteredRpmTransactionTasks()) target_userspace_info = next(self.consume(TargetUserSpaceInfo), None) if target_userspace_info: dnfplugin.perform_transaction_check( tasks=tasks, used_repos=used_repos, target_userspace_info=target_userspace_info, xfs_info=xfs_info, storage_info=storage_info, plugin_info=plugin_info )
def test_actor_without_systemdmount_entry(current_actor_context): without_systemdmount_entry = [ SystemdMountEntry(node="/dev/sda1", path="pci-0000:00:17.0-ata-2", model="TOSHIBA_THNSNJ512GDNU_A", wwn="0x500080d9108e8753", fs_type="ext4", label="n/a", uuid="5675d309-eff7-4eb1-9c27-58bc5880ec72") ] current_actor_context.feed( StorageInfo(systemdmount=without_systemdmount_entry)) current_actor_context.run() assert not current_actor_context.consume(Report)
def test_actor_with_systemdmount_entry(current_actor_context): with_systemdmount_entry = [ SystemdMountEntry(node="nfs", path="n/a", model="n/a", wwn="n/a", fs_type="nfs", label="n/a", uuid="n/a") ] current_actor_context.feed( StorageInfo(systemdmount=with_systemdmount_entry)) current_actor_context.run() assert 'inhibitor' in current_actor_context.consume(Report)[0].flags
def test_actor_with_systemdmount_entry(current_actor_context, nfs_fstype): with_systemdmount_entry = [ SystemdMountEntry(node="nfs", path="n/a", model="n/a", wwn="n/a", fs_type=nfs_fstype, label="n/a", uuid="n/a") ] current_actor_context.feed( StorageInfo(systemdmount=with_systemdmount_entry)) current_actor_context.run() report_fields = current_actor_context.consume(Report)[0].report assert 'inhibitor' in report_fields['flags']
def test_actor_with_luks(current_actor_context): with_luks = [ LsblkEntry(name='luks-132', maj_min='253:0', rm='0', size='10G', ro='0', tp='crypt', mountpoint='') ] current_actor_context.feed(StorageInfo(lsblk=with_luks)) current_actor_context.run() assert current_actor_context.consume(Report) report_fields = current_actor_context.consume(Report)[0].report assert 'inhibitor' in report_fields['flags']
def process(self): xfs_info = next(self.consume(XFSPresence), XFSPresence()) storage_info = next(self.consume(StorageInfo), StorageInfo()) used_repos = self.consume(UsedTargetRepositories) plugin_info = list(self.consume(DNFPluginTask)) tasks = next(self.consume(FilteredRpmTransactionTasks), FilteredRpmTransactionTasks()) target_userspace_info = next(self.consume(TargetUserSpaceInfo), None) rhui_info = next(self.consume(RHUIInfo), None) on_aws = bool(rhui_info and rhui_info.provider == 'aws') dnfplugin.perform_dry_run(tasks=tasks, used_repos=used_repos, target_userspace_info=target_userspace_info, xfs_info=xfs_info, storage_info=storage_info, plugin_info=plugin_info, on_aws=on_aws) self.produce(TransactionDryRun())
def process(self): xfs_info = next(self.consume(XFSPresence), XFSPresence()) storage_info = next(self.consume(StorageInfo), StorageInfo()) used_repos = self.consume(UsedTargetRepositories) plugin_info = list(self.consume(DNFPluginTask)) tasks = next(self.consume(FilteredRpmTransactionTasks), FilteredRpmTransactionTasks()) target_userspace_info = next(self.consume(TargetUserSpaceInfo), None) rhui_info = next(self.consume(RHUIInfo), None) # there are several "variants" related to the *AWS* provider (aws, aws-sap) on_aws = bool(rhui_info and rhui_info.provider.startswith('aws')) dnfplugin.perform_rpm_download( tasks=tasks, used_repos=used_repos, target_userspace_info=target_userspace_info, xfs_info=xfs_info, storage_info=storage_info, plugin_info=plugin_info, on_aws=on_aws)
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 test_removed_xfs_option(fstab, current_actor_context): current_actor_context.feed(StorageInfo(fstab=fstab)) current_actor_context.run() report = current_actor_context.consume(Report) assert report and len(report) == 1 assert 'inhibitor' in report[0].report['flags']
def consume_no_xfs_message_mocked(*models): yield StorageInfo()
def test_no_xfs_option(fstab, current_actor_context): current_actor_context.feed(StorageInfo(fstab=fstab)) current_actor_context.run() report = current_actor_context.consume(Report) assert not report
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)