Esempio n. 1
0
    def test__linux_lvm(self):
        """
        Test grains._linux_lvm, normal return
        Should return a populated dictionary
        """

        vgs_out = "  vg00\n  vg01"
        lvs_out_vg00 = "  root\n  swap\n  tmp \n  usr \n  var"
        lvs_out_vg01 = "  opt \n"
        cmd_out = MagicMock(autospec=True,
                            side_effect=[vgs_out, lvs_out_vg00, lvs_out_vg01])

        patch_which = patch("salt.utils.path.which",
                            autospec=True,
                            return_value="/usr/sbin/lvm")
        patch_cmd_lvm = patch.dict(lvm.__salt__, {"cmd.run": cmd_out})
        with patch_which, patch_cmd_lvm:
            ret = lvm._linux_lvm()

        assert ret == {
            "lvm": {
                "vg00": ["root", "swap", "tmp", "usr", "var"],
                "vg01": ["opt"]
            }
        }, ret
Esempio n. 2
0
    def test__linux_lvm_with_non_zero_exit_codes(self):
        """
        Test grains._linux_lvm, with non-zero exit codes for lvm command
        Should return a populated dictionary
        """

        vgs_out = {
            "pid": 123,
            "retcode": 5,
            "stdout": "  vg00\n  vg01",
            "stderr": "  Skipping clustered volume vgcluster\n  Skipping volume group vgcluster",
        }
        lvs_out_vg00 = {
            "pid": 456,
            "retcode": 0,
            "stdout": "  root\n  swap\n  tmp \n  usr \n  var",
            "stderr": "",
        }
        lvs_out_vg01 = {"pid": 789, "retcode": 0, "stdout": "  opt", "stderr": ""}
        cmd_out = MagicMock(
            autospec=True, side_effect=[vgs_out, lvs_out_vg00, lvs_out_vg01]
        )

        patch_which = patch(
            "salt.utils.path.which", autospec=True, return_value="/usr/sbin/lvm"
        )
        patch_cmd_lvm = patch.dict(lvm.__salt__, {"cmd.run_all": cmd_out})
        with patch_which, patch_cmd_lvm:
            ret = lvm._linux_lvm()

        assert ret == {
            "lvm": {"vg00": ["root", "swap", "tmp", "usr", "var"], "vg01": ["opt"]}
        }, ret
Esempio n. 3
0
    def test__linux_lvm_no_logical_volumes(self):
        """
        Test grains._linux_lvm, lvm is installed but no volumes
        Should return a dictionary only with the header
        """

        vgs_out = ""
        cmd_out = MagicMock(autospec=True, side_effect=[vgs_out])

        patch_which = patch("salt.utils.path.which",
                            autospec=True,
                            return_value="/usr/sbin/lvm")
        patch_cmd_lvm = patch.dict(lvm.__salt__, {"cmd.run": cmd_out})
        with patch_which, patch_cmd_lvm:
            ret = lvm._linux_lvm()

        assert ret == {"lvm": {}}, ret
Esempio n. 4
0
    def test__linux_lvm_no_volume_groups(self):
        """
        Test grains._linux_lvm, lvm is installed but no volume groups created.
        Should return a dictionary only with the header
        """

        vgs_out = {"pid": 123, "retcode": 0, "stdout": "", "stderr": ""}
        cmd_out = MagicMock(autospec=True, side_effect=[vgs_out])

        patch_which = patch(
            "salt.utils.path.which", autospec=True, return_value="/usr/sbin/lvm"
        )
        patch_cmd_lvm = patch.dict(lvm.__salt__, {"cmd.run_all": cmd_out})
        with patch_which, patch_cmd_lvm:
            ret = lvm._linux_lvm()

        assert ret == {"lvm": {}}, ret
Esempio n. 5
0
    def test__linux_lvm_no_lvm(self):
        """
        Test grains._linux_lvm, no lvm installed
        Should return nothing
        """

        vgs_out = "  vg00\n  vg01"
        lvs_out_vg00 = "  root\n  swap\n  tmp \n  usr \n  var"
        lvs_out_vg01 = "  opt \n"
        cmd_out = MagicMock(autospec=True,
                            side_effect=[vgs_out, lvs_out_vg00, lvs_out_vg01])

        patch_which = patch("salt.utils.path.which",
                            autospec=True,
                            return_value="")
        patch_cmd_lvm = patch.dict(lvm.__salt__, {"cmd.run": cmd_out})
        with patch_which, patch_cmd_lvm:
            ret = lvm._linux_lvm()

        assert ret is None, ret
Esempio n. 6
0
    def test__linux_lvm_with_WARNINGs(self):
        """
        Test grains._linux_lvm, with WARNINGs in lvm command output
        Should return a populated dictionary
        """

        vgs_out = {
            "pid": 123,
            "retcode": 0,
            "stdout": "  vg00\n  vg01",
            "stderr": "WARNING: Something wrong is not right",
        }
        lvs_out_vg00 = {
            "pid": 456,
            "retcode": 0,
            "stdout": "  root\n  swap\n  tmp \n  usr \n  var",
            "stderr": "WARNING: Something wrong is not right",
        }
        lvs_out_vg01 = {
            "pid": 789,
            "retcode": 0,
            "stdout": "  opt",
            "stderr": "WARNING: Something wrong is not right",
        }
        cmd_out = MagicMock(
            autospec=True, side_effect=[vgs_out, lvs_out_vg00, lvs_out_vg01]
        )

        patch_which = patch(
            "salt.utils.path.which", autospec=True, return_value="/usr/sbin/lvm"
        )
        patch_cmd_lvm = patch.dict(lvm.__salt__, {"cmd.run_all": cmd_out})
        with patch_which, patch_cmd_lvm:
            ret = lvm._linux_lvm()

        assert ret == {
            "lvm": {"vg00": ["root", "swap", "tmp", "usr", "var"], "vg01": ["opt"]}
        }, ret
Esempio n. 7
0
    def test__linux_lvm_no_lvm(self):
        """
        Test grains._linux_lvm, no lvm installed
        Should return nothing
        """

        vgs_out = {"pid": 123, "retcode": 0, "stdout": "  vg00\n  vg01", "stderr": ""}
        lvs_out_vg00 = {
            "pid": 456,
            "retcode": 0,
            "stdout": "  root\n  swap\n  tmp \n  usr \n  var",
            "stderr": "",
        }
        lvs_out_vg01 = {"pid": 789, "retcode": 0, "stdout": "  opt", "stderr": ""}
        cmd_out = MagicMock(
            autospec=True, side_effect=[vgs_out, lvs_out_vg00, lvs_out_vg01]
        )

        patch_which = patch("salt.utils.path.which", autospec=True, return_value="")
        patch_cmd_lvm = patch.dict(lvm.__salt__, {"cmd.run_all": cmd_out})
        with patch_which, patch_cmd_lvm:
            ret = lvm._linux_lvm()

        assert ret is None, ret