def test_services_running(drakmon_vm):
    infos = (
        get_service_info(drakmon_vm, "drak-system.service"),
        get_service_info(drakmon_vm, "drak-minio.service"),
        get_service_info(drakmon_vm, "drak-web.service"),
        get_service_info(drakmon_vm, "redis-server.service"),
    )

    for info in infos:
        assert info["LoadState"] == "loaded"
        assert info["ActiveState"] == "active"
        assert info["SubState"] == "running"
示例#2
0
def start_app(name, num):
    logger.info(" start service")
    print "start_app()"

    time1 = time()
    (code, text) = apicall_claas_service('start_service', name)
    logger.info(" apicall returns (%d, %s)" % (code, text))
    if code < 200 or code >= 300:
        msg = "Error in calling start API {}:{}".format(code, text)
        return {"success": False, "total": msg}

    target = {"status": "Running", "num": num}
    if not get_events(name, "start"):
        return {"success": False, "total": "this action do not have events"}
    isdeploying = is_deploying(name, target, 180, settings.CLAAS_NAMESPACE)
    time2 = time()
    if isdeploying:
        (code, text, obj) = get_service_info(name, 0, settings.CLAAS_NAMESPACE)
        if 'current_status' in obj:
            if obj['current_status'].find('Error') >= 0:
                return {
                    "success": False,
                    "total": "restart {} service status is Error".format(name)
                }
        return {
            "success": False,
            "total": "Timeout in starting {}".format(name)
        }

    logger.info(" ==> Starting service uses {}s".format(time2 - time1))
    obj = {"success": True, "total": time2 - time1}
    return obj
示例#3
0
    def check_status():
        infos = [get_service_info(drakmon_vm, service) for service in DRAKMON_SERVICES]

        for info in infos:
            assert info["LoadState"] == "loaded"
            assert info["ActiveState"] == "active"
            assert info["SubState"] == "running"
示例#4
0
def create_service(name, payload, service_detail='Hello', region='STAGING'):
    delete_app(name, region)
    print "create claas service"
    logger.info(region + " Start creating service")

    time1 = time()
    print payload
    (code, text) = apicall_claas_service('create_service', name, payload)
    logger.info("apicall returns (%d, %s)" % (code, text))
    print("apicall returns (%d, %s)" % (code, text))
    if code < 200 or code >= 300:
        msg = "Error in calling create Claas API {}:{}".format(code, text)
        return {"success": False, "total": msg}
    if not get_events(name, "create"):
        return {"success": False, "total": "this action do not have events"}

    # test if at least 1 instance is running
    target = {"status": "Running", "text": service_detail}
    isdeploying = is_deploying(name, target, 200, settings.CLAAS_NAMESPACE)
    time2 = time()
    logger.info(region + " is_deploying check use {}s".format(time2 - time1))
    if isdeploying:
        (code, text, obj) = get_service_info(name, 0, settings.CLAAS_NAMESPACE)
        if 'current_status' in obj:
            if obj['current_status'].find('Error') >= 0:
                return {
                    "success": False,
                    "total": "create service {} status is Error".format(name)
                }
            if "instance_ports" in json.loads(text) and len(
                    json.loads(text)['instance_ports']):
                if "endpoint_type" in json.loads(text)['instance_ports'][
                        0] and json.loads(text)['instance_ports'][0][
                            'endpoint_type'] == "internal-endpoint":
                    (code, html) = get_service_result(
                        json.loads(text)["instance_ports"][0]
                        ["default_domain"])
                    if code > 300 or code < 200:
                        return {"success": True, "total": time2 - time1}
                    else:
                        return {
                            "success":
                            False,
                            "total":
                            "internal haproxy service should not can visit"
                        }
            flag = can_visit(target, text)
            if not flag and obj['current_status'] == 'Running':
                return {
                    "success": False,
                    "total": "create service {} can not visit".format(name)
                }
        msg = "Timeout in creating {} service".format(name)
        return {"success": False, "total": msg}
    logger.info(region + " create use {}s".format(time2 - time1))

    return {"success": True, "total": time2 - time1}
示例#5
0
def update_service(name, num, size, service_detail='Hello'):
    print "scale_app()"
    logger.info(" Start scaling service {}".format(name))

    time1 = time()
    payload = {
        # "image_tag": "latest",
        "target_num_instances": num,
        "instance_size": size
    }
    (code, text) = apicall_claas_service('modify_service', name, payload)
    logger.info(" apicall returns (%d, %s)" % (code, text))
    if code < 200 or code >= 300:
        msg = "Error in calling scale API {}:{}".format(code, text)
        return {"success": False, "total": msg}
    if not get_events(name, "update"):
        return {"success": False, "total": "this action do not have events"}

    target = {
        "status": "Running",
        "num": num,
        "size": size,
        "text": service_detail
    }
    isdeploying = is_deploying(name, target, 240, settings.CLAAS_NAMESPACE)
    time2 = time()
    if isdeploying:
        (code, text, obj) = get_service_info(name, 0, settings.CLAAS_NAMESPACE)
        if 'current_status' in obj:
            if obj['current_status'].find('Error') >= 0:
                return {
                    "success": False,
                    "total": "update service {} status is Error".format(name)
                }
            flag = can_visit(target, text)
            if not flag and obj['current_status'] == 'Running':
                return {
                    "success": False,
                    "total": "update service {} can not visit".format(name)
                }
        msg = "Timeout in scaling {}".format(name)
        return {"success": False, "total": msg}

    logger.info(" ==> Scaling uses {}s".format(time2 - time1))
    return {"success": True, "total": time2 - time1}