Example #1
0
    def test_empty_config(self):
        config = [{}]

        ret = haproxy.validate(config)

        self.assertEqual(ret, (False, 'Configuration for haproxy beacon '
                               'requires backends.'))
Example #2
0
    def test_non_list_config(self):
        config = {}

        ret = haproxy.validate(config)

        self.assertEqual(ret, (False, 'Configuration for haproxy beacon must'
                               ' be a list.'))
Example #3
0
def test_threshold_not_reached():
    config = [{"backends": {"www-backend": {"threshold": 100, "servers": ["web1"]}}}]

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

    mock = MagicMock(return_value=50)
    with patch.dict(haproxy.__salt__, {"haproxy.get_sessions": mock}):
        ret = haproxy.beacon(config)
        assert ret == []
Example #4
0
    def test_threshold_reached(self):
        config = [{"backends": {"www-backend": {"threshold": 45, "servers": ["web1"]}}}]
        ret = haproxy.validate(config)

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

        mock = MagicMock(return_value=46)
        with patch.dict(haproxy.__salt__, {"haproxy.get_sessions": mock}):
            ret = haproxy.beacon(config)
            self.assertEqual(ret, [{"threshold": 45, "scur": 46, "server": "web1"}])
Example #5
0
    def test_threshold_not_reached(self):
        config = [{
            'backends': {
                'www-backend': {
                    'threshold': 100,
                    'servers': ['web1']
                }
            }
        }]
        ret = haproxy.validate(config)

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

        mock = MagicMock(return_value=50)
        with patch.dict(haproxy.__salt__, {'haproxy.get_sessions': mock}):
            ret = haproxy.beacon(config)
            self.assertEqual(ret, [])
Example #6
0
def test_no_servers():
    config = [{"backends": {"www-backend": {"threshold": 45}}}]

    ret = haproxy.validate(config)
    assert ret == (False, "Backends for haproxy beacon require servers.")
Example #7
0
def test_empty_config():
    config = [{}]

    ret = haproxy.validate(config)
    assert ret == (False, "Configuration for haproxy beacon requires backends.")
Example #8
0
def test_non_list_config():
    config = {}

    ret = haproxy.validate(config)
    assert ret == (False, "Configuration for haproxy beacon must be a list.")
Example #9
0
    def test_no_servers(self):
        config = [{'backends': {'www-backend': {'threshold': 45}}}]
        ret = haproxy.validate(config)

        self.assertEqual(ret, (False, 'Backends for haproxy '
                               'beacon require servers.'))
Example #10
0
    def test_no_servers(self):
        config = [{"backends": {"www-backend": {"threshold": 45}}}]
        ret = haproxy.validate(config)

        self.assertEqual(ret, (False, "Backends for haproxy beacon require servers."))