Ejemplo n.º 1
0
def test_get_mount_info(monkeypatch):
    def get_cmd_output_mocked(cmd, delim, expected_len):
        return [
            ['sysfs', 'on', '/sys', 'type', 'sysfs', '(rw,nosuid,nodev,noexec,relatime,seclabel)'],
            ['proc', 'on', '/proc', 'type', 'proc', '(rw,nosuid,nodev,noexec,relatime)'],
            ['tmpfs', 'on', '/dev/shm', 'type', 'tmpfs', '(rw,nosuid,nodev,seclabel)'],
            ['tmpfs', 'on', '/run', 'type', 'tmpfs', '(rw,nosuid,nodev,seclabel,mode=755)']]

    monkeypatch.setattr(library, '_get_cmd_output', get_cmd_output_mocked)
    expected = [
        MountEntry(
            name='sysfs',
            mount='/sys',
            tp='sysfs',
            options='(rw,nosuid,nodev,noexec,relatime,seclabel)'),
        MountEntry(
            name='proc',
            mount='/proc',
            tp='proc',
            options='(rw,nosuid,nodev,noexec,relatime)'),
        MountEntry(
            name='tmpfs',
            mount='/dev/shm',
            tp='tmpfs',
            options='(rw,nosuid,nodev,seclabel)'),
        MountEntry(
            name='tmpfs',
            mount='/run',
            tp='tmpfs',
            options='(rw,nosuid,nodev,seclabel,mode=755)')]
    assert expected == library._get_mount_info()
Ejemplo n.º 2
0
 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)])
Ejemplo n.º 3
0
def test_check_xfs_mount(monkeypatch):
    mount_data_no_xfs = {
        "name": "tmpfs",
        "mount": "/run/snapd/ns",
        "tp": "tmpfs",
        "options": "rw,nosuid,nodev,seclabel,mode=755"}

    mountpoints = library.check_xfs_mount([MountEntry(**mount_data_no_xfs)])
    assert not mountpoints

    mount_data_xfs = {
        "name": "/dev/vda1",
        "mount": "/boot",
        "tp": "xfs",
        "options": "rw,relatime,seclabel,attr2,inode64,noquota"}

    mountpoints = library.check_xfs_mount([MountEntry(**mount_data_xfs)])
    assert mountpoints == {"/boot"}
Ejemplo n.º 4
0
def _get_mount_info():
    ''' Collect storage info from mount command '''
    for entry in _get_cmd_output(['mount'], ' ', 6):
        name, _, mount, _, tp, options = entry
        yield MountEntry(
            name=name,
            mount=mount,
            tp=tp,
            options=options)
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
def _get_mount_info(path):
    """ Collect storage info """
    with open(path, 'r') as fp:
        for line in [l.strip() for l in fp.readlines()]:
            device, mount, tp, options, _, _ = line.split(' ')
            yield MountEntry(
                name=device,
                mount=mount,
                tp=tp,
                options=options
            )
Ejemplo n.º 7
0
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
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
def test_get_mount_info(monkeypatch):
    expected = [
        MountEntry(name='sysfs',
                   mount='/sys',
                   tp='sysfs',
                   options='rw,seclabel,nosuid,nodev,noexec,relatime'),
        MountEntry(name='proc',
                   mount='/proc',
                   tp='proc',
                   options='rw,nosuid,nodev,noexec,relatime'),
        MountEntry(
            name='devtmpfs',
            mount='/dev',
            tp='devtmpfs',
            options=
            'rw,seclabel,nosuid,size=16131092k,nr_inodes=4032773,mode=755'),
        MountEntry(name='securityfs',
                   mount='/sys/kernel/security',
                   tp='securityfs',
                   options='rw,nosuid,nodev,noexec,relatime'),
        MountEntry(name='tmpfs',
                   mount='/dev/shm',
                   tp='tmpfs',
                   options='rw,seclabel,nosuid,nodev'),
        MountEntry(
            name='devpts',
            mount='/dev/pts',
            tp='devpts',
            options=
            'rw,seclabel,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000'),
        MountEntry(name='tmpfs',
                   mount='/run',
                   tp='tmpfs',
                   options='rw,seclabel,nosuid,nodev,mode=755'),
        MountEntry(name='tmpfs',
                   mount='/sys/fs/cgroup',
                   tp='tmpfs',
                   options='ro,seclabel,nosuid,nodev,noexec,mode=755'),
        MountEntry(
            name='cgroup2',
            mount='/sys/fs/cgroup/unified',
            tp='cgroup2',
            options='rw,seclabel,nosuid,nodev,noexec,relatime,nsdelegate'),
        MountEntry(
            name='cgroup',
            mount='/sys/fs/cgroup/systemd',
            tp='cgroup',
            options=
            'rw,seclabel,nosuid,nodev,noexec,relatime,xattr,name=systemd'),
        MountEntry(name='pstore',
                   mount='/sys/fs/pstore',
                   tp='pstore',
                   options='rw,seclabel,nosuid,nodev,noexec,relatime'),
        MountEntry(name='bpf',
                   mount='/sys/fs/bpf',
                   tp='bpf',
                   options='rw,nosuid,nodev,noexec,relatime,mode=700'),
        MountEntry(name='cgroup',
                   mount='/sys/fs/cgroup/cpuset',
                   tp='cgroup',
                   options='rw,seclabel,nosuid,nodev,noexec,relatime,cpuset'),
        MountEntry(
            name='cgroup',
            mount='/sys/fs/cgroup/net_cls,net_prio',
            tp='cgroup',
            options='rw,seclabel,nosuid,nodev,noexec,relatime,net_cls,net_prio'
        ),
        MountEntry(name='cgroup',
                   mount='/sys/fs/cgroup/hugetlb',
                   tp='cgroup',
                   options='rw,seclabel,nosuid,nodev,noexec,relatime,hugetlb'),
        MountEntry(name='cgroup',
                   mount='/sys/fs/cgroup/pids',
                   tp='cgroup',
                   options='rw,seclabel,nosuid,nodev,noexec,relatime,pids'),
        MountEntry(name='cgroup',
                   mount='/sys/fs/cgroup/freezer',
                   tp='cgroup',
                   options='rw,seclabel,nosuid,nodev,noexec,relatime,freezer'),
        MountEntry(name='cgroup',
                   mount='/sys/fs/cgroup/blkio',
                   tp='cgroup',
                   options='rw,seclabel,nosuid,nodev,noexec,relatime,blkio'),
        MountEntry(name='cgroup',
                   mount='/sys/fs/cgroup/devices',
                   tp='cgroup',
                   options='rw,seclabel,nosuid,nodev,noexec,relatime,devices'),
        MountEntry(
            name='cgroup',
            mount='/sys/fs/cgroup/cpu,cpuacct',
            tp='cgroup',
            options='rw,seclabel,nosuid,nodev,noexec,relatime,cpu,cpuacct'),
        MountEntry(name='cgroup',
                   mount='/sys/fs/cgroup/memory',
                   tp='cgroup',
                   options='rw,seclabel,nosuid,nodev,noexec,relatime,memory'),
        MountEntry(
            name='cgroup',
            mount='/sys/fs/cgroup/perf_event',
            tp='cgroup',
            options='rw,seclabel,nosuid,nodev,noexec,relatime,perf_event'),
        MountEntry(name='configfs',
                   mount='/sys/kernel/config',
                   tp='configfs',
                   options='rw,relatime'),
        MountEntry(name='/dev/mapper/fedora-root',
                   mount='/',
                   tp='ext4',
                   options='rw,seclabel,relatime'),
        MountEntry(name='selinuxfs',
                   mount='/sys/fs/selinux',
                   tp='selinuxfs',
                   options='rw,relatime'),
        MountEntry(name='debugfs',
                   mount='/sys/kernel/debug',
                   tp='debugfs',
                   options='rw,seclabel,relatime'),
        MountEntry(name='hugetlbfs',
                   mount='/dev/hugepages',
                   tp='hugetlbfs',
                   options='rw,seclabel,relatime,pagesize=2M'),
        MountEntry(
            name='systemd-1',
            mount='/proc/sys/fs/binfmt_misc',
            tp='autofs',
            options=
            'rw,relatime,fd=38,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=14019'
        ),
        MountEntry(name='mqueue',
                   mount='/dev/mqueue',
                   tp='mqueue',
                   options='rw,seclabel,relatime'),
        MountEntry(name='fusectl',
                   mount='/sys/fs/fuse/connections',
                   tp='fusectl',
                   options='rw,relatime'),
        MountEntry(name='tmpfs',
                   mount='/tmp',
                   tp='tmpfs',
                   options='rw,seclabel,nosuid,nodev'),
        MountEntry(name='/dev/nvme0n1p1',
                   mount='/boot',
                   tp='ext4',
                   options='rw,seclabel,relatime'),
        MountEntry(name='/dev/mapper/fedora-home',
                   mount='/home',
                   tp='ext4',
                   options='rw,seclabel,relatime'),
        MountEntry(name='sunrpc',
                   mount='/var/lib/nfs/rpc_pipefs',
                   tp='rpc_pipefs',
                   options='rw,relatime'),
        MountEntry(
            name='tmpfs',
            mount='/run/user/1000',
            tp='tmpfs',
            options=
            'rw,seclabel,nosuid,nodev,relatime,size=3229704k,mode=700,uid=1000,gid=1000'
        ),
        MountEntry(
            name='tmpfs',
            mount='/run/user/42',
            tp='tmpfs',
            options=
            'rw,seclabel,nosuid,nodev,relatime,size=3229704k,mode=700,uid=42,gid=42'
        ),
        MountEntry(
            name='gvfsd-fuse',
            mount='/run/user/1000/gvfs',
            tp='fuse.gvfsd-fuse',
            options='rw,nosuid,nodev,relatime,user_id=1000,group_id=1000'),
        MountEntry(
            name='/dev/loop2p1',
            mount='/mnt/foo\\040bar',
            tp='iso9660',
            options=
            'ro,nosuid,nodev,relatime,nojoliet,check=s,map=n,blocksize=2048')
    ]

    assert expected == library._get_mount_info('tests/files/mounts')
Ejemplo n.º 10
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)