Example #1
0
def deploy_env(env_id,
               session_id,
               con_ssh=None,
               auth_info=None,
               fail_ok=False):

    code, output = cli.openstack(
        'environment deploy --session-id {} {}'.format(session_id, env_id),
        ssh_client=con_ssh,
        fail_ok=fail_ok,
        auth_info=auth_info)

    if code == 1:
        return 1, output

    table_ = table_parser.table(output)
    deploy_id = table_parser.get_value_two_col_table(table_, 'id')
    if not deploy_id:
        msg = "Fail to get the deploy id; session-id {}; environment " \
              "id {}".format(session_id, env_id)
        if fail_ok:
            return 2, msg
        else:
            raise exceptions.MuranoError(msg)

    return 0, deploy_id
Example #2
0
def create_env(name,
               mgmt_net_id=None,
               mgmt_subnet_id=None,
               con_ssh=None,
               auth_info=None,
               fail_ok=False):
    """
    Create Murano Environment
    Args:
        name: Name of the env to create
        mgmt_subnet_id (str): The ID of tenant1 management subnet
        mgmt_net_id (str): The ID of tenant1 management net
        con_ssh (SSHClient):
        auth_info (dict)
        fail_ok (bool): whether return False or raise exception when some
            services fail to reach enabled-active state

    Returns:
        code, msg: return code and msg

        """

    if name is None:
        raise ValueError("Murano environment name has to be specified.")

    LOG.info("Creating Murano Environment {}".format(name))

    args = ''
    if mgmt_subnet_id:
        args = " --join-subnet-id {}".format(mgmt_subnet_id)
    elif mgmt_net_id:
        args = " --join-net-id {}".format(mgmt_net_id)

    args = '{} {}'.format(args, name)
    code, output = cli.openstack("environment create",
                                 args,
                                 ssh_client=con_ssh,
                                 fail_ok=fail_ok,
                                 auth_info=auth_info)
    if code > 0:
        return 1, output

    table_ = table_parser.table(output)
    env_id = table_parser.get_values(table_, 'ID')
    if len(env_id) > 0:
        return 0, env_id[0]
    else:
        msg = "Fail to get the murano environment id"
        LOG.info(msg)
        if fail_ok:
            return 2, msg
        else:
            raise exceptions.MuranoError(msg)
Example #3
0
def wait_for_environment_status(env_id,
                                status,
                                timeout=180,
                                check_interval=6,
                                fail_ok=False):
    """
     Waits for the  Murano environment deployment status

     Args:
         env_id:
         status:
         timeout:
         check_interval
         fail_ok:

     Returns:

     """
    end_time = time.time() + timeout
    if not status:
        raise ValueError("Expected deployment state(s) has to be specified "
                         "via keyword argument states")
    if isinstance(status, str):
        status = [status]

    status_match = False
    act_status, prev_status = None, None
    while time.time() < end_time:
        act_status = get_environment_status(env_id)
        if act_status != prev_status:
            LOG.info("Current Murano environment deploy status = "
                     "{}".format(act_status))
            prev_status = act_status

        if act_status in status:
            status_match = True
            break
        time.sleep(check_interval)
    msg = "Environment id {} did not reach {} status  within specified " \
          "time ".format(env_id, status)
    if status_match:
        return True, act_status
    else:
        LOG.warning(msg)
        if fail_ok:
            return False, act_status
        else:
            raise exceptions.MuranoError(msg)
Example #4
0
def create_session(env_id, con_ssh=None, auth_info=None, fail_ok=False):
    """
    Create a Murano Session
    Args:
        env_id:
        con_ssh:
        auth_info:
        fail_ok:

    Returns:

    """

    if env_id is None:
        raise ValueError("Murano env id has to be specified.")

    LOG.info("Creating a Murano Session in Environment {}".format(env_id))
    code, output = cli.openstack('environment session create',
                                 env_id,
                                 ssh_client=con_ssh,
                                 fail_ok=fail_ok,
                                 auth_info=auth_info)

    if code > 1:
        return 1, output

    table_ = table_parser.table(output)
    session_id = table_parser.get_value_two_col_table(table_, 'id')
    if session_id != '':
        msg = "Session successfully created session {}".format(session_id)
        LOG.info(msg)
        return 0, session_id
    else:
        msg = "Fail to get Session id: {}".format(output)
        LOG.info(msg)
        if fail_ok:
            return 2, msg
        else:
            raise exceptions.MuranoError(msg)
Example #5
0
def wait_for_environment_delete(env_id,
                                timeout=300,
                                check_interval=6,
                                fail_ok=False):
    """
     Waits for the  Murano environment delete completes

     Args:
         env_id:
         timeout:
         check_interval
         fail_ok

     Returns:

     """
    end_time = time.time() + timeout
    if not env_id:
        raise ValueError("Environment id  has to be specified ")

    status_match = False
    while time.time() < end_time:
        ids = get_environment_list_table()
        if env_id not in ids:
            status_match = True
            break
        time.sleep(check_interval)
    msg = "Fail to delete environment {}  within the specified time ".format(
        env_id)
    if status_match:
        return True, None
    else:
        if fail_ok:
            LOG.warning(msg)
            return False, msg
        else:
            raise exceptions.MuranoError(msg)
Example #6
0
def edit_environment_object_mode(env_id,
                                 session_id=None,
                                 object_model_file=None,
                                 delete_file_after=False,
                                 con_ssh=None,
                                 auth_info=None,
                                 fail_ok=False):
    """
    Edits environment's object model. The object_model_file must be in format:
    [ { "op": "add", "path": "/-",
    "value": { ... your-app object model here ... } }, { "op": "replace",
    "path": "/0/?/name", "value": "new_name" }, ]

    Args:
        env_id:
        session_id:
        object_model_file (str):
        delete_file_after:
        con_ssh:
        auth_info:
        fail_ok:

    Returns:

    """

    if env_id is None:
        raise ValueError("Environment ID has to be specified.")
    if object_model_file is None:
        raise ValueError("The object_model_file  has to be specified.")
    if session_id is None:
        raise ValueError("The session_id  has to be specified.")

    if con_ssh is None:
        con_ssh = ControllerClient.get_active_controller()

    filename = 'object_model_patch.json'
    con_ssh.exec_cmd('cat >{} <<EOL\n{}\nEOL'.format(filename,
                                                     object_model_file))

    rc = con_ssh.exec_cmd("test -f " + HostLinuxUser.get_home() + filename)[0]
    if rc != 0:
        msg = "Fail to save the object model file {}".format(
            HostLinuxUser.get_home() + filename)
        if fail_ok:
            return 1, msg
        else:
            raise exceptions.MuranoError(msg)

    code, output = cli.openstack('environment apps edit',
                                 '--session-id {} {} {}'.format(
                                     session_id, env_id, filename),
                                 ssh_client=con_ssh,
                                 fail_ok=fail_ok,
                                 auth_info=auth_info)
    if code > 0:
        return 1, output

    code, output = cli.openstack('environment show',
                                 '--session-id {} --only-apps {}'.format(
                                     session_id, env_id),
                                 ssh_client=con_ssh,
                                 fail_ok=fail_ok,
                                 auth_info=auth_info)
    if code > 0:
        msg = "Fail to display environment's object model; ID = {}; " \
              "session id = {}: {}"\
            .format(env_id, session_id, output)
        LOG.warning(msg)
        return 2, msg

    if delete_file_after:
        con_ssh.exec_cmd("rm -f " + HostLinuxUser.get_home() + filename)

    return code, output