Exemple #1
0
def test_diskusage_windows_match_regex(windows_stub_disk_usage,
                                       windows_stub_disk_partition):
    disk_usage_mock = Mock(return_value=windows_stub_disk_usage)
    with patch("salt.utils.platform.is_windows", MagicMock(return_value=True)):
        with patch(
                "psutil.disk_partitions",
                MagicMock(return_value=windows_stub_disk_partition),
        ), patch("psutil.disk_usage", disk_usage_mock):
            config = [{"^[a-zA-Z]:\\": "50%"}]

            ret = diskusage.validate(config)
            assert ret == (True, "Valid beacon configuration")

            ret = diskusage.beacon(config)
            _expected = [
                {
                    "diskusage": 50,
                    "mount": "C:\\"
                },
                {
                    "diskusage": 50,
                    "mount": "D:\\"
                },
            ]
            assert ret == _expected
def test_diskusage_nomatch(stub_disk_usage, stub_disk_partition):
    disk_usage_mock = Mock(side_effect=stub_disk_usage)
    with patch("salt.utils.platform.is_windows", MagicMock(return_value=False)), patch(
        "psutil.disk_partitions", MagicMock(return_value=stub_disk_partition)
    ), patch("psutil.disk_usage", disk_usage_mock):
        config = [{"/": "70%"}]

        ret = diskusage.validate(config)
        assert ret == (True, "Valid beacon configuration")

        ret = diskusage.beacon(config)
        assert ret != [{"diskusage": 50, "mount": "/"}]
    def test_diskusage_match_regex(self):
        with patch('psutil.disk_partitions',
                   MagicMock(return_value=[STUB_DISK_PARTITION])), \
                patch('psutil.disk_usage',
                      MagicMock(return_value=STUB_DISK_USAGE)):
            config = [{r'^\/': '50%'}]

            ret = diskusage.validate(config)

            self.assertEqual(ret, (True, 'Valid beacon configuration'))

            ret = diskusage.beacon(config)
            self.assertEqual(ret, [{'diskusage': 50, 'mount': '/'}])
Exemple #4
0
    def test_diskusage_nomatch(self):
        disk_usage_mock = Mock(side_effect=STUB_DISK_USAGE)
        with patch('psutil.disk_partitions',
                   MagicMock(return_value=STUB_DISK_PARTITION)), \
                patch('psutil.disk_usage', disk_usage_mock):
            config = [{'/': '70%'}]

            ret = diskusage.validate(config)

            self.assertEqual(ret, (True, 'Valid beacon configuration'))

            ret = diskusage.beacon(config)
            self.assertNotEqual(ret, [{'diskusage': 50, 'mount': '/'}])
Exemple #5
0
    def test_diskusage_match_regex(self):
        disk_usage_mock = Mock(side_effect=STUB_DISK_USAGE)
        with patch('salt.utils.platform.is_windows',
                   MagicMock(return_value=False)),\
                patch('psutil.disk_partitions',
                      MagicMock(return_value=STUB_DISK_PARTITION)), \
                patch('psutil.disk_usage', disk_usage_mock):
            config = [{r'^\/': '50%'}]

            ret = diskusage.validate(config)

            self.assertEqual(ret, (True, 'Valid beacon configuration'))

            ret = diskusage.beacon(config)
            self.assertEqual(ret, [{'diskusage': 50, 'mount': '/'}])
Exemple #6
0
    def test_diskusage_windows(self):
        disk_usage_mock = Mock(return_value=WINDOWS_STUB_DISK_USAGE)
        with patch('salt.utils.platform.is_windows',
                   MagicMock(return_value=True)):
            with patch('psutil.disk_partitions',
                       MagicMock(return_value=WINDOWS_STUB_DISK_PARTITION)), \
                    patch('psutil.disk_usage', disk_usage_mock):
                config = [{'C:\\': '50%'}]

                ret = diskusage.validate(config)

                self.assertEqual(ret, (True, 'Valid beacon configuration'))

                ret = diskusage.beacon(config)
                self.assertEqual(ret, [{'diskusage': 50, 'mount': 'C:\\'}])
Exemple #7
0
    def test_diskusage_nomatch(self):
        disk_usage_mock = Mock(side_effect=STUB_DISK_USAGE)
        with patch(
            "salt.utils.platform.is_windows", MagicMock(return_value=False)
        ), patch(
            "psutil.disk_partitions", MagicMock(return_value=STUB_DISK_PARTITION)
        ), patch(
            "psutil.disk_usage", disk_usage_mock
        ):
            config = [{"/": "70%"}]

            ret = diskusage.validate(config)

            self.assertEqual(ret, (True, "Valid beacon configuration"))

            ret = diskusage.beacon(config)
            self.assertNotEqual(ret, [{"diskusage": 50, "mount": "/"}])
Exemple #8
0
def test_diskusage_windows_lowercase(windows_stub_disk_usage,
                                     windows_stub_disk_partition):
    r"""
    This tests lowercase drive letter (c:\)
    """
    disk_usage_mock = Mock(return_value=windows_stub_disk_usage)
    with patch("salt.utils.platform.is_windows", MagicMock(return_value=True)):
        with patch(
                "psutil.disk_partitions",
                MagicMock(return_value=windows_stub_disk_partition),
        ), patch("psutil.disk_usage", disk_usage_mock):
            config = [{"c:\\": "50%"}]

            ret = diskusage.validate(config)
            assert ret == (True, "Valid beacon configuration")

            ret = diskusage.beacon(config)
            assert ret == [{"diskusage": 50, "mount": "C:\\"}]
Exemple #9
0
def test_diskusage_windows_double_slash(windows_stub_disk_usage,
                                        windows_stub_disk_partition):
    """
    This tests original behavior (C:\\)
    """
    disk_usage_mock = Mock(return_value=windows_stub_disk_usage)
    with patch("salt.utils.platform.is_windows", MagicMock(return_value=True)):
        with patch(
                "psutil.disk_partitions",
                MagicMock(return_value=windows_stub_disk_partition),
        ), patch("psutil.disk_usage", disk_usage_mock):
            config = [{"C:\\\\": "50%"}]

            ret = diskusage.validate(config)
            assert ret == (True, "Valid beacon configuration")

            ret = diskusage.beacon(config)
            assert ret == [{"diskusage": 50, "mount": "C:\\"}]
Exemple #10
0
    def test_diskusage_windows_lowercase(self):
        r"""
        This tests lowercase drive letter (c:\)
        """
        disk_usage_mock = Mock(return_value=WINDOWS_STUB_DISK_USAGE)
        with patch("salt.utils.platform.is_windows", MagicMock(return_value=True)):
            with patch(
                "psutil.disk_partitions",
                MagicMock(return_value=WINDOWS_STUB_DISK_PARTITION),
            ), patch("psutil.disk_usage", disk_usage_mock):
                config = [{"c:\\": "50%"}]

                ret = diskusage.validate(config)

                self.assertEqual(ret, (True, "Valid beacon configuration"))

                ret = diskusage.beacon(config)
                self.assertEqual(ret, [{"diskusage": 50, "mount": "C:\\"}])
Exemple #11
0
    def test_diskusage_windows_double_slash(self):
        """
        This tests original behavior (C:\\)
        """
        disk_usage_mock = Mock(return_value=WINDOWS_STUB_DISK_USAGE)
        with patch("salt.utils.platform.is_windows", MagicMock(return_value=True)):
            with patch(
                "psutil.disk_partitions",
                MagicMock(return_value=WINDOWS_STUB_DISK_PARTITION),
            ), patch("psutil.disk_usage", disk_usage_mock):
                config = [{"C:\\\\": "50%"}]

                ret = diskusage.validate(config)

                self.assertEqual(ret, (True, "Valid beacon configuration"))

                ret = diskusage.beacon(config)
                self.assertEqual(ret, [{"diskusage": 50, "mount": "C:\\"}])
Exemple #12
0
    def test_diskusage_windows_match_regex(self):
        disk_usage_mock = Mock(return_value=WINDOWS_STUB_DISK_USAGE)
        with patch("salt.utils.platform.is_windows", MagicMock(return_value=True)):
            with patch(
                "psutil.disk_partitions",
                MagicMock(return_value=WINDOWS_STUB_DISK_PARTITION),
            ), patch("psutil.disk_usage", disk_usage_mock):
                config = [{"^[a-zA-Z]:\\": "50%"}]

                ret = diskusage.validate(config)

                self.assertEqual(ret, (True, "Valid beacon configuration"))

                ret = diskusage.beacon(config)
                _expected = [
                    {u"diskusage": 50, u"mount": "C:\\"},
                    {u"diskusage": 50, u"mount": "D:\\"},
                ]
                self.assertEqual(ret, _expected)