예제 #1
0
def test_proc_mount():
    results = ProcMounts(context_wrap(PROC_MOUNT))
    assert results is not None
    assert len(results) == 20
    sda1 = results.search(mounted_device='/dev/sda1')[0]

    # Test get method
    assert sda1 is not None
    assert sda1['mount_point'] == '/boot'
    assert sda1['filesystem_type'] == 'ext4'
    assert 'rw' in sda1['mount_options']
    assert 'relatime' in sda1['mount_options']
    assert sda1['mount_options']['data'] == 'ordered'
    assert sda1.mount_options.data == 'ordered'
    assert sda1['mount_labels'] == ['0', '0']

    # Test iteration
    for mount in results:
        assert hasattr(mount, 'mounted_device')
        assert hasattr(mount, 'mount_point')
        assert hasattr(mount, 'filesystem_type')
        assert hasattr(mount, 'mount_options')

    # Test getitem
    assert results[8] == sda1
    assert results['/misc'] == results[-1]
    # Index only by string or number
    with pytest.raises(TypeError) as exc:
        assert results[set([1, 2, 3])] is None
    assert 'Mounts can only be indexed by mount string or line number' in str(
        exc)

    # Test mounts dictionary
    assert results.mounts['/boot'] == sda1

    # Test get_dir
    assert results.get_dir('/var/lib/nfs/rpc_pipefs') == results.search(
        mounted_device='sunrpc')[0]
    assert results.get_dir('/etc') == results['/']

    # Test search
    assert results.search(mounted_device='/dev/sda1') == [sda1]
    assert results.search(filesystem_type='nfs') == [
        results.rows[n] for n in (17, 18)
    ]
    assert results.search(mount_options__contains='mode') == [
        results.rows[n] for n in (3, 4)
    ]

    # Test parse failure
    errors = ProcMounts(context_wrap(PROCMOUNT_ERR_DATA))
    assert errors is not None
    assert len(errors) == 2
    assert not hasattr(errors[0], 'parse_error')
    assert errors[0].mounted_device == 'rootfs'
    assert hasattr(errors[1], 'parse_error')
    assert errors[1].parse_error == 'Unable to parse line'
예제 #2
0
def test_doc_examples():
    env = {
        'mnt_info': Mount(context_wrap(MOUNT_DOC)),
        'proc_mnt_info': ProcMounts(context_wrap(PROC_MOUNT_DOC)),
        'mounts': Mount(context_wrap(MOUNT_DOC))
    }
    failed, total = doctest.testmod(mount, globs=env)
    assert failed == 0
예제 #3
0
def test_proc_mount():
    results = ProcMounts(context_wrap(PROC_MOUNT))
    assert results is not None
    assert len(results) == 19
    sda1 = results.search(filesystem='/dev/sda1')[0]

    # Test get method
    assert sda1 is not None
    assert sda1['mount_point'] == '/boot'
    assert sda1['mount_type'] == 'ext4'
    assert 'rw' in sda1['mount_options']
    assert 'relatime' in sda1['mount_options']
    assert sda1['mount_options']['data'] == 'ordered'
    assert sda1.mount_options.data == 'ordered'
    assert sda1['mount_label'] == ['0', '0']

    # Test iteration
    for mnt in results:
        assert hasattr(mnt, 'filesystem')
        assert hasattr(mnt, 'mount_point')
        assert hasattr(mnt, 'mount_type')
        assert hasattr(mnt, 'mount_options')

    # Test getitem
    assert results[7] == sda1
    assert results['/misc'] == results[-1]
    # Index only by string or number
    with pytest.raises(TypeError) as exc:
        assert results[set([1, 2, 3])] is None
    assert 'Mounts can only be indexed by mount string or line number' in str(
        exc)

    # Test mounts dictionary
    assert results.mounts['/boot'] == sda1

    # Test get_dir
    assert results.get_dir('/var/lib/nfs/rpc_pipefs') == results.search(
        filesystem='sunrpc')[0]
    assert results.get_dir('/etc') == results['/']

    # Test search
    assert results.search(filesystem='/dev/sda1') == [sda1]
    assert results.search(mount_type='nfs') == [
        results.rows[n] for n in (16, 17)
    ]
    assert results.search(mount_options__contains='mode') == [
        results.rows[n] for n in (2, 3)
    ]
예제 #4
0
def test_proc_mount_exception3():
    with pytest.raises(ParseException) as pe:
        ProcMounts(context_wrap(PROCMOUNT_ERR_DATA))
    assert 'Unable to parse' in str(pe.value)
예제 #5
0
def test_proc_mount_exception2():
    with pytest.raises(ParseException) as e:
        ProcMounts(context_wrap(PROC_EXCEPTION2))
    assert "Input for mount must contain '/' mount point." in str(e)
예제 #6
0
def test_proc_mount_exception1():
    with pytest.raises(SkipException) as e:
        ProcMounts(context_wrap(PROC_EXCEPTION1))
    assert 'Empty content' in str(e)