def test_read_composite_gapped_suffix(self):
     """
     If we have a hap on the suffix, values after the gap won't be read.
     """
     os.environ['HOLLOWMAN_FILTER_DNS_FOO_0'] = "abc"
     os.environ['HOLLOWMAN_FILTER_DNS_FOO_1'] = "ab1"
     os.environ['HOLLOWMAN_FILTER_DNS_FOO_2'] = "ab2"
     os.environ['HOLLOWMAN_FILTER_DNS_FOO_4'] = "ab4"
     self.assertEquals(["abc", "ab1", "ab2"],
                       get_option("filter", "dns_foo"))
     self.assertEquals(["abc"], get_option("filter", "dns_foo_0"))
Exemple #2
0
def _build_addresses(namespace, option_name, default_address):
    addresses = {
        addr.rstrip("/")
        for addr in get_option(namespace, option_name)
    }
    final_addresses = sorted(list(addresses))
    if not final_addresses:
        final_addresses = [default_address]
    return final_addresses
 def test_read_composite_mixed_numeric_suffix(self):
     """
     Tests if we can read both envs: with and without numerix suffix
     When we have both envs, we join then on the result, so:
         HOLLOWMAN_FILTER_DNS_PARAM_FOO = "abc"
         HOLLOWMAN_FILTER_DNS_PARAM_FOO_0 = "xyz"
     results in: ["abc", "xyz"] when calling get_option("dns", "foo")
     """
     os.environ['HOLLOWMAN_FILTER_DNS_BAR'] = "abc"
     os.environ['HOLLOWMAN_FILTER_DNS_BAR_0'] = "xyz"
     self.assertEquals(["abc", "xyz"], get_option("filter", "dns_bar"))
Exemple #4
0
def masters_alive():
    mesos_addresses = options.get_option("MESOS", "ADDRESS")
    result = {
        addr: int(mesos_asgard_sdk.is_master_healthy(addr))
        for addr in mesos_addresses
    }
    all_ok = all([result[key] for key in result.keys()])
    masters_down = len(list(filter(lambda r: r[1] == 0, result.items())))

    result['all_ok'] = int(all_ok)
    result['masters_down'] = masters_down
    return Response(dumps(result), mimetype='application/json')
Exemple #5
0
def get_mesos_leader_address():
    for mesos_address in get_option("MESOS", "ADDRESS"):
        try:
            response = requests.get(f"{mesos_address}/redirect",
                                    timeout=2,
                                    allow_redirects=False)
            if response.headers.get("Location"):
                leader_ip = response.headers.get("Location").split("//")[1]
                # config.logger.debug({"action": "find-mesos-leader", "try-address": mesos_address, "exception": False, "leader-ip": leader_ip})
                return f"http://{leader_ip}"
        except requests.exceptions.ConnectionError as ConErr:
            pass
Exemple #6
0
def zk_leader():
    zk_ips = get_option("metrics", "zk_id")
    data = []
    for ip in zk_ips:
        metrics = parse_stat_output(
            send_command(ip, 2181, "stat").decode("utf8"))
        data.append(metrics)

    all_modes = [metric.get("mode") == "leader" for metric in data]
    if any(all_modes):
        return json.dumps({"leader": all_modes.index(True) + 1})

    return json.dumps({"leader": 0})
 def test_read_different_namespace(self):
     os.environ['HOLLOWMAN_METRICS_ZK_SERVER_ID_0'] = "a"
     os.environ['HOLLOWMAN_METRICS_ZK_SERVER_ID_1'] = "b"
     os.environ['HOLLOWMAN_METRICS_ZK_SERVER_ID_2'] = "c"
     self.assertEquals(["a", "b", "c"], get_option("metrics",
                                                   "zk_server_id"))
 def test_read_simple_option(self):
     os.environ['HOLLOWMAN_FILTER_DNS_TIMEOUT'] = "10"
     self.assertEquals(["10"], get_option("filter", "DNS_TIMEOUT"))
     self.assertEquals(["10"], get_option("filter", "dns_timeout"))
 def test_read_empty_option(self):
     self.assertEquals([], get_option("dns", "MYPARAM"))