Example #1
0
def compare_version_candidate_installed(host_name='eng'):
    """Check candidate version is different from installed"""
    if not show_version(action='check', host=host_name):
        installed_version, candidate_version = show_version(action='get', host=host_name)
        message = "Candidate {} version ({}) is older or the same than " \
                  "the installed one ({})."\
            .format(host_app_mapping[host_name], candidate_version, installed_version)
        abort(message)
Example #2
0
def check_dead_instances():
    dead = 0
    threshold = env.kraken_threshold * len(env.instances)
    for instance in env.instances.values():
        for host in instance.kraken_engines_url:
            request = 'http://{}:{}/{}/?instance={}'.format(
                host, env.kraken_monitor_port, env.kraken_monitor_location_dir,
                instance.name)
            result = _test_kraken(request, fail_if_error=False)
            if not result or result[
                    'status'] == 'timeout' or result['loaded'] is False:
                dead += 1
    if dead >= int(threshold):
        print(
            red("The threshold of allowed dead instance is exceeded."
                "There are {} dead instances.".format(dead)))
        exit(1)

    installed_kraken, candidate_kraken = show_version(action='get')
    if installed_kraken != candidate_kraken:
        # if update of packages did not work
        print(
            red("Installed kraken version ({}) is different "
                "than the candidate kraken version ({})".format(
                    installed_kraken, candidate_kraken)))
        exit(1)
Example #3
0
def check_kraken_jormun_after_deploy(show=False):
    headers = {"Host": env.jormungandr_url}

    request_str = "http://{}{}/v1/status".format(env.jormungandr_url, env.jormungandr_url_prefix)
    print ("request_str: {}".format(request_str))

    try:
        response = requests.get(request_str, headers=headers, auth=HTTPBasicAuth(env.token, ""))
        if response.status_code != 200:
            print (red("Request not successful : {}".format(str(response))))
            return
    except (ConnectionError, HTTPError) as e:
        print (red("HTTP Error %s: %s" % (e.code, e.readlines()[0])))
        return
    except Exception as e:
        print (red("Error when connecting to %s: %s" % (env.jormungandr_url, e)))
        return

    try:
        result = response.json()
    except JSONDecodeError:
        print (red("cannot read json response : {}".format(response.text)))
        return

    candidate_kraken_version = "v" + show_version(action="get")[1]
    warn_dict = dict()
    warn_dict["jormungandr"] = (
        result["jormungandr_version"] if candidate_kraken_version != result["jormungandr_version"] else None
    )
    warn_dict["kraken"] = warn_list = list()

    for item in result["regions"]:
        if item["region_id"] not in env.instances:
            continue
        if item["status"] == "dead":
            warn_list.append(dict(status="dead", region_id=item["region_id"], kraken_version=None))
        elif item["kraken_version"] != candidate_kraken_version:
            warn_list.append(
                dict(status=item["status"], region_id=item["region_id"], kraken_version=item["kraken_version"])
            )
        elif item["status"] == "no_data":
            warn_list.append(
                dict(status="no_data", region_id=item["region_id"], kraken_version=candidate_kraken_version)
            )

    if show:
        if warn_dict["jormungandr"]:
            print (yellow("Jormungandr version={}".format(warn_dict["jormungandr"])))
        for item in warn_list:
            print (yellow("status={status} | region_id={region_id} | kraken_version={kraken_version}".format(**item)))

    return warn_dict
Example #4
0
def check_kraken_jormun_after_deploy(show=False):
    headers = {'Host': env.jormungandr_url}

    request_str = 'http://{}{}/v1/status'.format(env.jormungandr_url, env.jormungandr_url_prefix)
    print("request_str: {}".format(request_str))

    try:
        response = requests.get(request_str, headers=headers, auth=HTTPBasicAuth(env.token, ''))
        if response.status_code != 200:
            print(red("Request not successful : {}".format(str(response))))
            return
    except (ConnectionError, HTTPError) as e:
        print(red("HTTP Error %s: %s" % (e.code, e.readlines()[0])))
        return
    except Exception as e:
        print(red("Error when connecting to %s: %s" % (env.jormungandr_url, e)))
        return

    try:
        result = response.json()
    except JSONDecodeError:
        print(red("cannot read json response : {}".format(response.text)))
        return

    candidate_kraken_version = "v" + show_version(action='get')[1]
    warn_dict = dict()
    warn_dict['jormungandr'] = result['jormungandr_version'] if candidate_kraken_version != result['jormungandr_version'] else None
    warn_dict['kraken'] = warn_list = list()

    for item in result['regions']:
        if item['region_id'] not in env.instances:
            continue
        if item['status'] == "dead":
            warn_list.append(dict(status='dead', region_id=item['region_id'], kraken_version=None))
        elif item['kraken_version'] != candidate_kraken_version:
            warn_list.append(dict(status=item['status'], region_id=item['region_id'], kraken_version=item['kraken_version']))
        elif item['status'] == "no_data":
            warn_list.append(dict(status='no_data', region_id=item['region_id'], kraken_version=candidate_kraken_version))

    if show:
        if warn_dict['jormungandr']:
            print(yellow("Jormungandr version={}".format(warn_dict['jormungandr'])))
        for item in warn_list:
            print(yellow("status={status} | region_id={region_id} | kraken_version={kraken_version}".format(**item)))

    return warn_dict
Example #5
0
def check_dead_instances():
    dead = 0
    threshold = env.kraken_threshold * len(env.instances)
    for instance in env.instances.values():
        for host in instance.kraken_engines_url:
            request = 'http://{}:{}/{}/?instance={}'.format(host,
                env.kraken_monitor_port, env.kraken_monitor_location_dir, instance.name)
            result = _test_kraken(request, fail_if_error=False)
            if not result or result['status'] == 'timeout' or result['loaded'] is False:
                dead += 1
    if dead > int(threshold):
        print(red("The threshold of allowed dead instances is exceeded: "
                  "Found {} dead instances out of {}.".format(dead, len(env.instances))))
        exit(1)

    installed_kraken, candidate_kraken = show_version(action='get')
    if installed_kraken != candidate_kraken:
        # if update of packages did not work
        print(red("Installed kraken version ({}) is different "
                  "than the candidate kraken version ({})"
                  .format(installed_kraken, candidate_kraken)))
        exit(1)
Example #6
0
def check_dead_instances():
    dead = 0
    threshold = env.kraken_threshold * len(env.instances.values())
    for instance in env.instances.values():
        # env.host will call the monitor kraken on the current host
        request = Request('http://{}:{}/{}/?instance={}'.format(env.host,
            env.kraken_monitor_port, env.kraken_monitor_location_dir, instance.name))
        result = _test_kraken(request, fail_if_error=False)
        if not result or result['status'] == 'timeout' or result['loaded'] is False:
            dead += 1
    if dead >= int(threshold):
        print(red("The threshold of allowed dead instance is exceeded."
                  "There are {} dead instances.".format(dead)))
        exit(1)

    installed_kraken, candidate_kraken = show_version(action='get')
    if installed_kraken != candidate_kraken:
        # if update of packages did not work
        print(red("Installed kraken version ({}) is different "
                  "than the candidate kraken version ({})"
                  .format(installed_kraken, candidate_kraken)))
        exit(1)
Example #7
0
def check_kraken_jormun_after_deploy(show=False):

    headers = {'Host': env.jormungandr_url}
    request_str = 'http://{}{}/v1/status'.format(env.jormungandr_url,
                                                 env.jormungandr_url_prefix)

    print("request_str: {}".format(request_str))

    try:
        # Send HTTP GET requests
        response = requests.get(request_str,
                                headers=headers,
                                auth=HTTPBasicAuth(env.token, ''))

        # If HTTP status_code Erreur.
        if response.status_code != 200:
            print(red("Request not successful : {}".format(str(response))))
            return None

        result = response.json()

    except (ConnectionError, HTTPError) as e:
        print(red("HTTP Error {}: {}".format(e.code, e.readlines()[0])))
        return None
    except JSONDecodeError as e:
        print(red("cannot read json response : {}".format(e)))
        return None
    except Exception as e:
        print(
            red("Error when connecting to {}: {}".format(
                env.jormungandr_url, e)))
        return None

    warn_dict = {'jormungandr': None, 'kraken': []}

    if re.match(r"v{}".format(show_version(action='get')[1]),
                result['jormungandr_version']):
        warn_dict['jormungandr'] = result['jormungandr_version']

    for item in result['regions']:

        kraken_warn = {
            'status': item['status'],
            'region_id': item['region_id']
        }

        if item['status'] == "dead":
            kraken_warn['kraken_version'] = None
        elif item['kraken_version'] != warn_dict['jormungandr']:
            kraken_warn['kraken_version'] = item['kraken_version']
        elif item['status'] == "no_data":
            kraken_warn['kraken_version'] = warn_dict['jormungandr']

        if 'kraken_version' in kraken_warn.keys():
            warn_dict['kraken'].append(kraken_warn)

    if show:
        if warn_dict['jormungandr']:
            print(
                yellow("Jormungandr version={}".format(
                    warn_dict['jormungandr'])))
        for item in warn_dict['kraken']:
            print(
                yellow(
                    "status={status} | region_id={region_id} | kraken_version={kraken_version}"
                    .format(**item)))

    return warn_dict