Beispiel #1
0
def test_chattr_version_should_return_version_from_tune2fs():
    expected = "1.43.4"
    sample_output = textwrap.dedent(
        """
        tune2fs 1.43.4 (31-Jan-2017)
        Usage: tune2fs [-c max_mounts_count] [-e errors_behavior] [-f] [-g group]
        [-i interval[d|m|w]] [-j] [-J journal_options] [-l]
        [-m reserved_blocks_percent] [-o [^]mount_options[,...]]
        [-p mmp_update_interval] [-r reserved_blocks_count] [-u user]
        [-C mount_count] [-L volume_label] [-M last_mounted_dir]
        [-O [^]feature[,...]] [-Q quota_options]
        [-E extended-option[,...]] [-T last_check_time] [-U UUID]
        [-I new_inode_size] [-z undo_file] device
        """
    )
    patch_which = patch(
        "salt.utils.path.which",
        Mock(return_value="fnord"),
    )
    patch_run = patch.dict(
        filemod.__salt__,
        {"cmd.run": MagicMock(return_value=sample_output)},
    )
    with patch_which, patch_run:
        actual = filemod._chattr_version()
        assert actual == expected
def test_chattr_version_returns_None_if_no_tune2fs_exists():
    patch_which = patch(
        "salt.utils.path.which",
        Mock(return_value=""),
    )
    with patch_which:
        actual = filemod._chattr_version()
        assert actual is None
def test_if_tune2fs_has_no_version_version_should_be_None():
    patch_which = patch(
        "salt.utils.path.which",
        Mock(return_value="fnord"),
    )
    patch_run = patch.dict(
        filemod.__salt__,
        {"cmd.run": MagicMock(return_value="fnord")},
    )
    with patch_which, patch_run:
        actual = filemod._chattr_version()
        assert actual is None
def test_on_aix_chattr_version_should_be_None_even_if_tune2fs_exists():
    patch_which = patch(
        "salt.utils.path.which",
        Mock(return_value="fnord"),
    )
    patch_aix = patch(
        "salt.utils.platform.is_aix",
        Mock(return_value=True),
    )
    mock_run = MagicMock(return_value="fnord")
    patch_run = patch.dict(filemod.__salt__, {"cmd.run": mock_run})
    with patch_which, patch_aix, patch_run:
        actual = filemod._chattr_version()
        assert actual is None
        mock_run.assert_not_called()