def is_healthy_in_haproxy(local_port, backends): local_ip = gethostbyname(gethostname()) for backend in backends: ip, port, _ = ip_port_hostname_from_svname(backend['svname']) if ip == local_ip and port == local_port: if backend_is_up(backend): log.debug("Found a healthy local backend: %s" % backend) return True else: log.debug("Found a unhealthy local backend: %s" % backend) return False log.debug("Couldn't find any haproxy backend listening on %s" % local_port) return False
def test_ip_port_hostname_from_svname_old_format(): assert ( "10.85.5.101", 3744, "myhost") == ip_port_hostname_from_svname("10.85.5.101:3744_myhost")
def test_ip_port_hostname_from_svname_new_format(): assert ( "10.40.10.155", 31219, "myhost") == ip_port_hostname_from_svname("myhost_10.40.10.155:31219")
def test_ip_port_hostname_from_svname(): assert ("1.2.3.4", 5, "six") == ip_port_hostname_from_svname("1.2.3.4:5_six")