Commit 9581508f authored by Sigmund Augdal's avatar Sigmund Augdal

Stop having bfd monitor check haproxy since it is no longer in use

parent cb2229de
import requests
import os.path
import subprocess
import logging
ADMIN_DOWN_MARKER = "/etc/admin_down"
HAPROXY_CHECK_URL = "http://localhost:1936/haproxy_up"
BFDD_CONTROL = "/usr/local/bin/bfdd-control"
......@@ -12,11 +10,6 @@ def check_state(interface):
"""
Checks downstream status to determine which state we should announce upstream
"""
try:
response = requests.get(HAPROXY_CHECK_URL, timeout=1)
response.raise_for_status()
except:
return "down"
ifstate_filename = "/sys/class/net/{}/operstate".format(interface)
if not os.path.exists(ifstate_filename) or open(ifstate_filename).read().strip() != "up":
return "down"
......
......@@ -125,44 +125,28 @@ def mock_os_path(files):
class TestCheckState(object):
@mock.patch('requests.get')
def test_haproxy_request_error(self, get):
get.side_effect = Exception("Request failed")
assert bfd.check_state("eth0") == "down"
@mock.patch('requests.get')
def test_haproxy_reports_failure(self, get):
response = mock.Mock()
response.raise_for_status.side_effect = Exception("server error")
get.return_value = response
assert bfd.check_state("eth0") == "down"
@mock.patch('requests.get')
@mock.patch('os.path.exists')
def test_nic_missing(self, exists, get):
def test_nic_missing(self, exists):
exists.side_effect = mock_os_path([])
assert bfd.check_state("eth0") == "down"
@mock.patch('nova_router.bfd.open', create=True)
@mock.patch('requests.get')
@mock.patch('os.path.exists')
def test_link_down(self, exists, get, open):
def test_link_down(self, exists, open):
exists.side_effect = mock_os_path(['/sys/class/net/eth0/operstate'])
mock.mock_open(open, "down")
assert bfd.check_state("eth0") == "down"
@mock.patch('nova_router.bfd.open', create=True)
@mock.patch('requests.get')
@mock.patch('os.path.exists')
def test_admin_down(self, exists, get, open):
def test_admin_down(self, exists, open):
exists.side_effect = mock_os_path(['/sys/class/net/eth0/operstate', '/etc/admin_down'])
mock.mock_open(open, "up\n")
assert bfd.check_state("eth0") == "admin"
@mock.patch('nova_router.bfd.open', create=True)
@mock.patch('requests.get')
@mock.patch('os.path.exists')
def test_up(self, exists, get, open):
def test_up(self, exists, open):
exists.side_effect = mock_os_path(['/sys/class/net/eth0/operstate'])
mock.mock_open(open, "up\n")
assert bfd.check_state("eth0") == "up"
......@@ -194,6 +178,7 @@ Session 1
id=1 local=128.39.70.133 (a) remote=128.39.70.131 state=Down
"""
class TestGetUpstreamState(object):
@mock.patch('subprocess.check_output')
def test_all_up(self, call):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment