Exemple #1
0
    def test_salt_proxy_not_running(self):
        is_running_mock = MagicMock(return_value={'result': False})
        configure_mock = MagicMock(
            return_value={
                'result': True,
                'changes': {
                    'new': 'Salt Proxy: Started proxy process for p8000',
                    'old': []
                }
            })
        cmd_run_mock = MagicMock(return_value={
            'pid': 1000,
            'retcode': 0,
            'stderr': '',
            'stdout': ''
        })
        with patch.dict(salt_proxy.__salt__,
                        {'salt_proxy.is_running': is_running_mock}), \
                patch.dict(salt_proxy.__salt__,
                           {'salt_proxy.configure_proxy': configure_mock}), \
                   patch.dict(salt_proxy.__salt__,
                              {'cmd.run_all': cmd_run_mock}):
            config = [{'proxies': {'p8000': ''}}]

            ret = salt_proxy.validate(config)
            self.assertEqual(ret, (True, 'Valid beacon configuration'))

            ret = salt_proxy.beacon(config)
            self.assertEqual(ret, [{'p8000': 'Proxy p8000 was started'}])
Exemple #2
0
    def test_salt_proxy_not_running(self):
        is_running_mock = MagicMock(return_value={"result": False})
        configure_mock = MagicMock(
            return_value={
                "result": True,
                "changes": {
                    "new": "Salt Proxy: Started proxy process for p8000",
                    "old": [],
                },
            })
        cmd_run_mock = MagicMock(return_value={
            "pid": 1000,
            "retcode": 0,
            "stderr": "",
            "stdout": ""
        })
        with patch.dict(
                salt_proxy.__salt__,
            {"salt_proxy.is_running": is_running_mock}), patch.dict(
                salt_proxy.__salt__,
                {"salt_proxy.configure_proxy": configure_mock}), patch.dict(
                    salt_proxy.__salt__, {"cmd.run_all": cmd_run_mock}):
            config = [{"proxies": {"p8000": ""}}]

            ret = salt_proxy.validate(config)
            self.assertEqual(ret, (True, "Valid beacon configuration"))

            ret = salt_proxy.beacon(config)
            self.assertEqual(ret, [{"p8000": "Proxy p8000 was started"}])
Exemple #3
0
def test_salt_proxy_running():
    mock = MagicMock(return_value={"result": True})
    with patch.dict(salt_proxy.__salt__, {"salt_proxy.is_running": mock}):
        config = [{"proxies": {"p8000": ""}}]

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

        ret = salt_proxy.beacon(config)
        assert ret == [{"p8000": "Proxy p8000 is already running"}]
    def test_salt_proxy_running(self):
        mock = MagicMock(return_value={'result': True})
        with patch.dict(salt_proxy.__salt__, {'salt_proxy.is_running': mock}):
            config = [{'proxies': {'p8000': ''}}]

            ret = salt_proxy.validate(config)

            ret = salt_proxy.beacon(config)
            self.assertEqual(ret, [{
                'p8000': 'Proxy p8000 is already running'
            }])