示例#1
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 == []
示例#2
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"}])
示例#3
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, [])