Ejemplo n.º 1
0
def test_check_xfs(monkeypatch):
    monkeypatch.setattr(library, "run", run_mocked())

    def consume_no_xfs_message_mocked(*models):
        yield StorageInfo()
    monkeypatch.setattr(api, "consume", consume_no_xfs_message_mocked)
    monkeypatch.setattr(api, "produce", produce_mocked())

    library.check_xfs()
    assert api.produce.called == 1
    assert len(api.produce.model_instances) == 1
    assert isinstance(api.produce.model_instances[0], XFSPresence)
    assert not api.produce.model_instances[0].present
    assert not api.produce.model_instances[0].without_ftype

    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)])
    monkeypatch.setattr(api, "consume", consume_ignored_xfs_message_mocked)
    monkeypatch.setattr(api, "produce", produce_mocked())

    library.check_xfs()
    assert api.produce.called == 1
    assert len(api.produce.model_instances) == 1
    assert isinstance(api.produce.model_instances[0], XFSPresence)
    assert not api.produce.model_instances[0].present
    assert not api.produce.model_instances[0].without_ftype

    def consume_xfs_with_ftype_message_mocked(*models):
        fstab_data = {
            "fs_spec": "/dev/mapper/rhel-root",
            "fs_file": "/",
            "fs_vfstype": "xfs",
            "fs_mntops": "defaults",
            "fs_freq": "0",
            "fs_passno": "0"}
        yield StorageInfo(fstab=[FstabEntry(**fstab_data)])
    monkeypatch.setattr(api, "consume", consume_xfs_with_ftype_message_mocked)
    monkeypatch.setattr(api, "produce", produce_mocked())

    library.check_xfs()
    assert api.produce.called == 1
    assert len(api.produce.model_instances) == 1
    assert isinstance(api.produce.model_instances[0], XFSPresence)
    assert api.produce.model_instances[0].present
    assert not api.produce.model_instances[0].without_ftype

    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)])
    monkeypatch.setattr(api, "consume", consume_xfs_without_ftype_message_mocked)
    monkeypatch.setattr(api, "produce", produce_mocked())

    library.check_xfs()
    assert api.produce.called == 1
    assert len(api.produce.model_instances) == 1
    assert isinstance(api.produce.model_instances[0], XFSPresence)
    assert api.produce.model_instances[0].present
    assert api.produce.model_instances[0].without_ftype

    def consume_no_message_mocked(*models):
        yield None
    monkeypatch.setattr(api, "consume", consume_no_message_mocked)
    monkeypatch.setattr(api, "produce", produce_mocked())

    with pytest.raises(StopActorExecutionError):
        library.check_xfs()
Ejemplo n.º 2
0
 def process(self):
     check_xfs()