Ejemplo n.º 1
0
def init_environment(config_filepath=BASE_CONFIG_FILEPATH):
    """Set up module variables according to config dict.

    :param str config_filepath:
    """
    global AMQP_USERNAME, AMQP_PASSWORD, CLIENT, ORG_HREF, VDC_HREF, \
        CATALOG_NAME, TEARDOWN_INSTALLATION, TEARDOWN_CLUSTERS, \
        TEMPLATE_DEFINITIONS, TEST_ALL_TEMPLATES, SYS_ADMIN_LOGIN_CMD, \
        ORG_ADMIN_LOGIN_CMD, K8_AUTHOR_LOGIN_CMD, USERNAME_TO_LOGIN_CMD, \
        USERNAME_TO_CLUSTER_NAME, TEST_ORG_HREF, TEST_VDC_HREF, \
        VCD_API_VERSION_TO_USE, TEMPLATE_COOKBOOK_VERSION

    config = testutils.yaml_to_dict(config_filepath)

    rtm = \
        RemoteTemplateManager(config['broker']['remote_template_cookbook_url'],
                              legacy_mode=config['service']['legacy_mode'])
    template_cookbook = rtm.get_filtered_remote_template_cookbook()
    TEMPLATE_COOKBOOK_VERSION = rtm.cookbook_version
    TEMPLATE_DEFINITIONS = template_cookbook['templates']
    rtm.download_all_template_scripts(force_overwrite=True)

    CLIENT = Client(config['vcd']['host'],
                    api_version=config['vcd']['api_version'],
                    verify_ssl_certs=config['vcd']['verify'])
    credentials = BasicLoginCredentials(config['vcd']['username'],
                                        shared_constants.SYSTEM_ORG_NAME,
                                        config['vcd']['password'])
    CLIENT.set_credentials(credentials)

    VCD_API_VERSION_TO_USE = config['vcd']['api_version']
    CATALOG_NAME = config['broker']['catalog']
    AMQP_USERNAME = config['amqp']['username']
    AMQP_PASSWORD = config['amqp']['password']

    SYS_ADMIN_LOGIN_CMD = f"login {config['vcd']['host']} system " \
                          f"{config['vcd']['username']} " \
                          f"-iwp {config['vcd']['password']} " \
                          f"-V {VCD_API_VERSION_TO_USE}"
    ORG_ADMIN_LOGIN_CMD = f"login {config['vcd']['host']} " \
                          f"{TEST_ORG}" \
                          f" {ORG_ADMIN_NAME} -iwp {ORG_ADMIN_PASSWORD} " \
                          f"-V {VCD_API_VERSION_TO_USE}"
    K8_AUTHOR_LOGIN_CMD = f"login {config['vcd']['host']} " \
        f"{TEST_ORG} " \
        f"{K8_AUTHOR_NAME} -iwp {K8_AUTHOR_PASSWORD}" \
        f" -V {VCD_API_VERSION_TO_USE}"

    USERNAME_TO_LOGIN_CMD = {
        'sys_admin': SYS_ADMIN_LOGIN_CMD,
        'org_admin': ORG_ADMIN_LOGIN_CMD,
        'k8_author': K8_AUTHOR_LOGIN_CMD
    }

    USERNAME_TO_CLUSTER_NAME = {
        'sys_admin': SYS_ADMIN_TEST_CLUSTER_NAME,
        'org_admin': ORG_ADMIN_TEST_CLUSTER_NAME,
        'k8_author': K8_AUTHOR_TEST_CLUSTER_NAME
    }
    # hrefs for Org and VDC that hosts the catalog
    org = pyvcloud_utils.get_org(CLIENT, org_name=config['broker']['org'])
    vdc = pyvcloud_utils.get_vdc(CLIENT,
                                 vdc_name=config['broker']['vdc'],
                                 org=org)
    ORG_HREF = org.href
    VDC_HREF = vdc.href

    # hrefs for Org and VDC that tests cluster operations
    test_org = pyvcloud_utils.get_org(CLIENT, org_name=TEST_ORG)
    test_vdc = pyvcloud_utils.get_vdc(CLIENT, vdc_name=TEST_VDC, org=test_org)
    TEST_ORG_HREF = test_org.href
    TEST_VDC_HREF = test_vdc.href
    create_k8_author_role(config['vcd'])
Ejemplo n.º 2
0
def init_rde_environment(config_filepath=BASE_CONFIG_FILEPATH,
                         logger=NULL_LOGGER):  # noqa: E501
    """Set up module variables according to config dict.

    :param str config_filepath:
    """
    global CLIENT, ORG_HREF, VDC_HREF, \
        CATALOG_NAME, TEARDOWN_INSTALLATION, TEARDOWN_CLUSTERS, \
        TEMPLATE_DEFINITIONS, TEST_ALL_TEMPLATES, SYS_ADMIN_LOGIN_CMD, \
        CLUSTER_ADMIN_LOGIN_CMD, CLUSTER_AUTHOR_LOGIN_CMD, \
        USERNAME_TO_LOGIN_CMD, USERNAME_TO_CLUSTER_NAME, TEST_ORG_HREF, \
        TEST_VDC_HREF, VCD_API_VERSION_TO_USE

    logger.debug("Setting RDE environement")
    config = testutils.yaml_to_dict(config_filepath)
    logger.debug(f"Config file used: {config}")

    # download all remote template scripts
    rtm = RemoteTemplateManager(
        config['broker']['remote_template_cookbook_url'],
        legacy_mode=config['service']['legacy_mode'])
    template_cookbook = rtm.get_filtered_remote_template_cookbook()
    TEMPLATE_DEFINITIONS = template_cookbook['templates']
    rtm.download_all_template_scripts(force_overwrite=True)

    sysadmin_client = Client(config['vcd']['host'],
                             verify_ssl_certs=config['vcd']['verify'])
    sysadmin_client.set_credentials(
        BasicLoginCredentials(config['vcd']['username'],
                              shared_constants.SYSTEM_ORG_NAME,
                              config['vcd']['password']))

    vcd_supported_api_versions = \
        set(sysadmin_client.get_supported_versions_list())
    cse_supported_api_versions = set(
        shared_constants.SUPPORTED_VCD_API_VERSIONS)  # noqa: E501
    common_supported_api_versions = \
        list(cse_supported_api_versions.intersection(vcd_supported_api_versions))  # noqa: E501
    common_supported_api_versions.sort()
    max_api_version = get_max_api_version(common_supported_api_versions)
    CLIENT = Client(config['vcd']['host'],
                    api_version=max_api_version,
                    verify_ssl_certs=config['vcd']['verify'])
    credentials = BasicLoginCredentials(config['vcd']['username'],
                                        shared_constants.SYSTEM_ORG_NAME,
                                        config['vcd']['password'])
    CLIENT.set_credentials(credentials)
    VCD_API_VERSION_TO_USE = max_api_version
    logger.debug(f"Using VCD api version: {VCD_API_VERSION_TO_USE}")

    CATALOG_NAME = config['broker']['catalog']

    SYS_ADMIN_LOGIN_CMD = f"login {config['vcd']['host']} system " \
                          f"{config['vcd']['username']} " \
                          f"-iwp {config['vcd']['password']} " \
                          f"-V {VCD_API_VERSION_TO_USE}"
    CLUSTER_ADMIN_LOGIN_CMD = f"login {config['vcd']['host']} " \
                              f"{TEST_ORG}" \
                              f" {CLUSTER_ADMIN_NAME} " \
                              f"-iwp {CLUSTER_ADMIN_PASSWORD} " \
                              f"-V {VCD_API_VERSION_TO_USE}"
    CLUSTER_AUTHOR_LOGIN_CMD = f"login {config['vcd']['host']} " \
                               f"{TEST_ORG}" \
                               f" {CLUSTER_AUTHOR_NAME} " \
                               f"-iwp {CLUSTER_AUTHOR_PASSWORD} " \
                               f"-V {VCD_API_VERSION_TO_USE}"

    USERNAME_TO_LOGIN_CMD = {
        SYS_ADMIN_NAME: SYS_ADMIN_LOGIN_CMD,
        CLUSTER_ADMIN_NAME: CLUSTER_ADMIN_LOGIN_CMD,
        CLUSTER_AUTHOR_NAME: CLUSTER_AUTHOR_LOGIN_CMD
    }

    # hrefs for Org and VDC that hosts the catalog
    org = pyvcloud_utils.get_org(CLIENT, org_name=config['broker']['org'])
    vdc = pyvcloud_utils.get_vdc(CLIENT,
                                 vdc_name=config['broker']['vdc'],
                                 org=org)
    ORG_HREF = org.href
    VDC_HREF = vdc.href

    logger.debug(f"Using template org {org.get_name()} with href {ORG_HREF}")
    logger.debug(f"Using template vdc {vdc.name} with href {VDC_HREF}")

    # hrefs for Org and VDC that tests cluster operations
    test_org = pyvcloud_utils.get_org(CLIENT, org_name=TEST_ORG)
    test_vdc = pyvcloud_utils.get_vdc(CLIENT, vdc_name=TEST_VDC, org=test_org)
    TEST_ORG_HREF = test_org.href
    TEST_VDC_HREF = test_vdc.href

    logger.debug(f"Using test org {test_org.get_name()} "
                 f"with href {TEST_ORG_HREF}")
    logger.debug(f"Using test vdc {test_vdc.name} with href {TEST_VDC_HREF}")

    create_cluster_admin_role(config['vcd'], logger=logger)
    create_cluster_author_role(config['vcd'], logger=logger)