def verify_installation(deployment_id):
    logger.info("Verifying installation")

    exec_client = utils.get_cfy_client().executions
    executions = exec_client.list(deployment_id=deployment_id)
    check(len(executions) > 0, "No executions listed.")

    failed_executions = [e for e in executions if e.status == "failed"]
    check(len(failed_executions) == 0, "Execution failed.")

    install_execs = [e for e in executions if e.workflow_id == "install"]
    check(len(install_execs) == 1, "There is more than one install execution.")
    check(install_execs[0].status == "terminated",
          "Installation terminated in error.")

    outputs = get_outputs(deployment_id)
    check(len(outputs) > 0, "No outputs available")
    check("http_endpoint" in outputs, "No http endpoint present in outputs.")

    http_endpoint = outputs["http_endpoint"]
    m = re.match("https?://[^:]+(:[0-9]+)?", http_endpoint)
    check(m is not None, "Bad URL in outputs: {}.".format(http_endpoint))

    r = requests.get("{}/heartbeat/".format(http_endpoint))
    check(r.status_code == 200,
          "API not available. Got {} heartbeat.".format(r.status_code))

    r = requests.get(http_endpoint)
    check(r.status_code == 200,
          "GUI not available. Got {} on /.".format(r.status_code))
def delete_blueprint(blueprint_id):
    logger.info("Deleting blueprint.")
    blue_client = utils.get_cfy_client().blueprints

    try:
        blue_client.delete(blueprint_id)
    except CloudifyClientError as e:
        logger.error(e)
def delete_blueprint(blueprint_id):
    logger.info("Deleting blueprint.")
    blue_client = utils.get_cfy_client().blueprints

    try:
        blue_client.delete(blueprint_id)
    except CloudifyClientError as e:
        logger.error(e)
Esempio n. 4
0
    def setUp(self):
        assert os.environ["TEST_DEPLOYMENT_SERVICE_ADDRESS"] is not ""
        assert os.environ["TEST_SUPERUSER_USERNAME"] is not ""
        assert os.environ["TEST_SUPERUSER_PASSWORD"] is not ""
        wait_time = int(os.environ.get("TEST_WAIT_TIME", 30)) * 60

        self.cfy = utils.get_cfy_client()
        self.cleanup_queue = []
        self.end_time = time.time() + wait_time
    def setUp(self):
        assert os.environ["TEST_DEPLOYMENT_SERVICE_ADDRESS"] is not ""
        assert os.environ["TEST_SUPERUSER_USERNAME"] is not ""
        assert os.environ["TEST_SUPERUSER_PASSWORD"] is not ""
        wait_time = int(os.environ.get("TEST_WAIT_TIME", 30)) * 60

        self.cfy = utils.get_cfy_client()
        self.cleanup_queue = []
        self.end_time = time.time() + wait_time
def uninstall(deployment_id):
    logger.info("Uninstalling deployment service.")
    exec_client = utils.get_cfy_client().executions

    executions = exec_client.list(deployment_id=deployment_id)
    installs = [e for e in executions if e.workflow_id == "install"]
    if len(installs) == 0:
        logger.info("No installation present. Skipping.")
        return

    # TODO: Check if we are canceling installation and wait for it.

    logger.info("Running uninstall workflow.")
    execution = exec_client.start(deployment_id=deployment_id,
                                  workflow_id="uninstall")
    while execution.status not in utils.TERMINAL_STATUSES:
        time.sleep(5)
        execution = exec_client.get(execution_id=execution.id)
    logger.info("Uninstall finished.")
def uninstall(deployment_id):
    logger.info("Uninstalling deployment service.")
    exec_client = utils.get_cfy_client().executions

    executions = exec_client.list(deployment_id=deployment_id)
    installs = [e for e in executions if e.workflow_id == "install"]
    if len(installs) == 0:
        logger.info("No installation present. Skipping.")
        return

    # TODO: Check if we are canceling installation and wait for it.

    logger.info("Running uninstall workflow.")
    execution = exec_client.start(deployment_id=deployment_id,
                                  workflow_id="uninstall")
    while execution.status not in utils.TERMINAL_STATUSES:
        time.sleep(5)
        execution = exec_client.get(execution_id=execution.id)
    logger.info("Uninstall finished.")
def wait_for_installation(deployment_id):
    logger.info("Waiting for installation execution to finish.")

    exec_client = utils.get_cfy_client().executions
    executions = exec_client.list(deployment_id=deployment_id)
    non_term_executions = non_terminal_executions(executions)
    if len(non_term_executions) == 0:
        return

    logger.info("Installation still running. Waiting for termination.")
    # we have already waited for 15 minutes. 10 minutes more should
    # be more than enough
    sleep_time = 5
    attempts = 120
    while len(non_term_executions) > 0 and attempts > 0:
        time.sleep(sleep_time)
        executions = exec_client.list(deployment_id=deployment_id)
        non_term_executions = non_terminal_executions(executions)
        attempts -= 1

    if len(non_term_executions) == 0:
        return

    logger.info("Installation has been running too long. Cancelling.")
    exec_client.cancel(execution_id=non_term_executions[0].id)
    # now wait a bit until it is really cancelled
    attempts = 24
    execution = exec_client.get(execution_id=non_term_executions[0].id)
    while execution.status != "cancelled" and attempts > 0:
        time.sleep(sleep_time)
        attempts -= 1
        execution = exec_client.get(execution_id=execution.id)

    if execution.status == "cancelled":
        logger.error("The installation did not finish in due time.")
        sys.exit(EXIT_RECOVERABLE_FAIL)

    logger.error("Installation cannot be cancelled.")
    sys.exit(EXIT_COMPLETE_FAIL)
def delete_deployment(deployment_id):
    logger.info("Deleting deployment.")
    depl_client = utils.get_cfy_client().deployments

    try:
        depl_client.get(deployment_id)
    except CloudifyClientError as e:
        logger.info("No deployment. Skipping.")
        return

    attempts = 20
    while attempts > 0:
        try:
            depl_client.delete(deployment_id)
            break
        except CloudifyClientError as e:
            attempts -= 1
            logger.warning("Failed deleting the deployment. {} attempts left. "
                           "{}".format(attempts, e))
            time.sleep(5)

    if attempts == 0:
        logger.error("Failed to delete deployment.")
        sys.exit(1)
def delete_deployment(deployment_id):
    logger.info("Deleting deployment.")
    depl_client = utils.get_cfy_client().deployments

    try:
        depl_client.get(deployment_id)
    except CloudifyClientError as e:
        logger.info("No deployment. Skipping.")
        return

    attempts = 20
    while attempts > 0:
        try:
            depl_client.delete(deployment_id)
            break
        except CloudifyClientError as e:
            attempts -= 1
            logger.warning("Failed deleting the deployment. {} attempts left. "
                           "{}".format(attempts, e))
            time.sleep(5)

    if attempts == 0:
        logger.error("Failed to delete deployment.")
        sys.exit(1)
Esempio n. 11
0
def get_outputs(deployment_id):
    depl_client = utils.get_cfy_client().deployments
    outputs = depl_client.outputs.get(deployment_id=deployment_id)
    return outputs["outputs"]