コード例 #1
0
def test_0100_install_select_templates(config, unregister_cse_before_test):
    """Tests template installation.

    Tests that selected template installation is done correctly

    command: cse template install template_name template_revision
        --config cse_test_config.yaml --ssh-key ~/.ssh/id_rsa.pub
        --skip-config-decryption --retain-temp-vapp
    required files: cse_test_config.yaml, ~/.ssh/id_rsa.pub,
        ubuntu/photon init/cust scripts
    expected: cse registered, source ovas exist, k8s templates exist and
        temp vapps exist.
    """
    cmd = f"install --config {env.ACTIVE_CONFIG_FILEPATH} --ssh-key " \
          f"{env.SSH_KEY_FILEPATH} --skip-template-creation " \
          f"--skip-config-decryption"
    result = env.CLI_RUNNER.invoke(cli, cmd.split(), catch_exceptions=False)
    assert result.exit_code == 0,\
        testutils.format_command_info('cse', cmd, result.exit_code,
                                      result.output)

    # check that cse was registered correctly
    env.check_cse_registration(config['amqp']['routing_key'],
                               config['amqp']['exchange'])

    vdc = VDC(env.CLIENT, href=env.VDC_HREF)
    for template_config in env.TEMPLATE_DEFINITIONS:
        # install the template
        cmd = f"template install {template_config['name']} " \
              f"{template_config['revision']} " \
              f"--config {env.ACTIVE_CONFIG_FILEPATH} " \
              f"--ssh-key {env.SSH_KEY_FILEPATH} " \
              f"--skip-config-decryption --force --retain-temp-vapp"
        result = env.CLI_RUNNER.invoke(
            cli, cmd.split(), catch_exceptions=False)
        assert result.exit_code == 0,\
            testutils.format_command_info('cse', cmd, result.exit_code,
                                          result.output)
        # check that source ova file exists in catalog
        assert env.catalog_item_exists(
            template_config['source_ova_name']), \
            'Source ova file does not exists when it should.'

        # check that k8s templates exist
        catalog_item_name = ltm.get_revisioned_template_name(
            template_config['name'], template_config['revision'])
        assert env.catalog_item_exists(catalog_item_name), \
            'k8s template does not exist when it should.'

        # check that temp vapp exists
        temp_vapp_name = testutils.get_temp_vapp_name(
            template_config['name'])
        try:
            vdc.reload()
            vdc.get_vapp(temp_vapp_name)
        except EntityNotFoundException:
            assert False, 'vApp does not exist when it should.'
コード例 #2
0
def _remove_cse_artifacts():
    for template in env.TEMPLATE_DEFINITIONS:
        env.delete_catalog_item(template['source_ova_name'])
        catalog_item_name = ltm.get_revisioned_template_name(
            template['name'], template['revision'])
        env.delete_catalog_item(catalog_item_name)
        temp_vapp_name = testutils.get_temp_vapp_name(template['name'])
        env.delete_vapp(temp_vapp_name)
    env.delete_catalog()
    env.unregister_cse()
コード例 #3
0
def _install_template(client, remote_template_manager, template, org_name,
                      vdc_name, catalog_name, network_name, ip_allocation_mode,
                      storage_profile, force_update, retain_temp_vapp, ssh_key,
                      msg_update_callback):
    remote_template_manager.download_template_scripts(
        template_name=template[RemoteTemplateKey.NAME],
        revision=template[RemoteTemplateKey.REVISION],
        force_overwrite=force_update)
    catalog_item_name = ltm.get_revisioned_template_name(
        template[RemoteTemplateKey.NAME], template[RemoteTemplateKey.REVISION])

    # remote template data is a super set of local template data, barring
    # the key 'catalog_item_name'
    template_data = dict(template)
    template_data[LocalTemplateKey.CATALOG_ITEM_NAME] = catalog_item_name

    missing_keys = [k for k in LocalTemplateKey if k not in template_data]
    if len(missing_keys) > 0:
        raise ValueError(f"Invalid template data. Missing keys: {missing_keys}"
                         )  # noqa: E501

    build_params = {
        'template_name': template[RemoteTemplateKey.NAME],
        'template_revision': template[RemoteTemplateKey.REVISION],
        'source_ova_name':
        template[RemoteTemplateKey.SOURCE_OVA_NAME],  # noqa: E501
        'source_ova_href':
        template[RemoteTemplateKey.SOURCE_OVA_HREF],  # noqa: E501
        'source_ova_sha256':
        template[RemoteTemplateKey.SOURCE_OVA_SHA256],  # noqa: E501
        'org_name': org_name,
        'vdc_name': vdc_name,
        'catalog_name': catalog_name,
        'catalog_item_name': catalog_item_name,
        'catalog_item_description':
        template[RemoteTemplateKey.DESCRIPTION],  # noqa: E501
        'temp_vapp_name':
        template[RemoteTemplateKey.NAME] + '_temp',  # noqa: E501
        'cpu': template[RemoteTemplateKey.CPU],
        'memory': template[RemoteTemplateKey.MEMORY],
        'network_name': network_name,
        'ip_allocation_mode': ip_allocation_mode,  # noqa: E501
        'storage_profile': storage_profile
    }
    builder = TemplateBuilder(client,
                              client,
                              build_params,
                              ssh_key=ssh_key,
                              logger=LOGGER,
                              msg_update_callback=msg_update_callback)
    builder.build(force_recreate=force_update,
                  retain_temp_vapp=retain_temp_vapp)

    ltm.save_metadata(client, org_name, catalog_name, catalog_item_name,
                      template_data)
コード例 #4
0
def test_0090_install_all_templates(config, unregister_cse_before_test):
    """Test install.

    Installation options: '--ssh-key', '--retain-temp-vapp',
        '--skip-config-decryption'.

    Tests that installation:
    - downloads/uploads ova file,
    - creates photon temp vapp,
    - creates k8s templates
    - skips deleting the temp vapp
    - checks that proper packages are installed in the vm in temp vApp

    command: cse install --config cse_test_config.yaml --retain-temp-vapp
        --skip-config-decryption --ssh-key ~/.ssh/id_rsa.pub
    required files: ~/.ssh/id_rsa.pub, cse_test_config.yaml
    expected: cse registered, catalog exists, source ovas exist,
        temp vapps exist, k8s templates exist.
    """
    cmd = f"install --config {env.ACTIVE_CONFIG_FILEPATH} --ssh-key " \
          f"{env.SSH_KEY_FILEPATH} --retain-temp-vapp --skip-config-decryption"
    result = env.CLI_RUNNER.invoke(cli, cmd.split(),
                                   catch_exceptions=False)
    assert result.exit_code == 0,\
        testutils.format_command_info('cse', cmd, result.exit_code,
                                      result.output)

    # check that cse was registered correctly
    env.check_cse_registration(config['amqp']['routing_key'],
                               config['amqp']['exchange'])

    vdc = VDC(env.CLIENT, href=env.VDC_HREF)
    for template_config in env.TEMPLATE_DEFINITIONS:
        # check that source ova file exists in catalog
        assert env.catalog_item_exists(
            template_config['source_ova_name']), \
            'Source ova file does not exist when it should.'

        # check that k8s templates exist
        catalog_item_name = ltm.get_revisioned_template_name(
            template_config['name'], template_config['revision'])
        assert env.catalog_item_exists(catalog_item_name), \
            'k8s template does not exist when it should.'

        # check that temp vapp exists
        temp_vapp_name = testutils.get_temp_vapp_name(
            template_config['name'])
        try:
            vdc.reload()
            vdc.get_vapp(temp_vapp_name)
        except EntityNotFoundException:
            assert False, 'vApp does not exist when it should.'
コード例 #5
0
def test_0080_install_skip_template_creation(config,
                                             unregister_cse_before_test):
    """Test install.

    Installation options: '--ssh-key', '--skip-create-templates',
    '--skip-config-decryption'

    Tests that installation:
    - registers CSE, without installing the templates

    command: cse install --config cse_test_config.yaml
        --ssh-key ~/.ssh/id_rsa.pub --skip-config-decryption
        --skip-create-templates
    required files: ~/.ssh/id_rsa.pub, cse_test_config.yaml,
    expected: cse registered, catalog exists, source ovas do not exist,
        temp vapps do not exist, k8s templates do not exist.
    """
    cmd = f"install --config {env.ACTIVE_CONFIG_FILEPATH} --ssh-key " \
          f"{env.SSH_KEY_FILEPATH} --skip-template-creation " \
          f"--skip-config-decryption"
    result = env.CLI_RUNNER.invoke(cli, cmd.split(), catch_exceptions=False)
    assert result.exit_code == 0,\
        testutils.format_command_info('cse', cmd, result.exit_code,
                                      result.output)

    # check that cse was registered correctly
    env.check_cse_registration(config['amqp']['routing_key'],
                               config['amqp']['exchange'])

    for template_config in env.TEMPLATE_DEFINITIONS:
        # check that source ova file does not exist in catalog
        assert not env.catalog_item_exists(
            template_config['source_ova_name']), \
            'Source ova file exists when it should not.'

        # check that k8s templates does not exist
        catalog_item_name = ltm.get_revisioned_template_name(
            template_config['name'], template_config['revision'])
        assert not env.catalog_item_exists(catalog_item_name), \
            'k8s templates exist when they should not.'

        # check that temp vapp does not exists
        temp_vapp_name = testutils.get_temp_vapp_name(template_config['name'])
        assert not env.vapp_exists(temp_vapp_name), \
            'vApp exists when it should not.'
コード例 #6
0
def test_0100_install_force_update(config, unregister_cse_before_test):
    """Tests installation option: '--force-update'.

    Tests that installation:
    - creates all templates correctly,
    - customizes temp vapps correctly.

    command: cse install --config cse_test_config.yaml
        --ssh-key ~/.ssh/id_rsa.pub --force-update --skip-config-decryption
    required files: cse_test_config.yaml, ~/.ssh/id_rsa.pub,
        ubuntu/photon init/cust scripts
    expected: cse registered, source ovas exist, k8s templates exist and
        temp vapps don't exist.
    """
    cmd = f"install --config {env.ACTIVE_CONFIG_FILEPATH} --ssh-key " \
          f"{env.SSH_KEY_FILEPATH} --force-update --skip-config-decryption"
    result = env.CLI_RUNNER.invoke(cli, cmd.split(), catch_exceptions=False)
    assert result.exit_code == 0,\
        testutils.format_command_info('cse', cmd, result.exit_code,
                                      result.output)

    # check that cse was registered correctly
    env.check_cse_registration(config['amqp']['routing_key'],
                               config['amqp']['exchange'])

    for template_config in env.TEMPLATE_DEFINITIONS:
        # check that source ova file exists in catalog
        assert env.catalog_item_exists(
            template_config['source_ova_name']), \
            'Source ova file does not exists when it should.'

        # check that k8s templates exist
        catalog_item_name = ltm.get_revisioned_template_name(
            template_config['name'], template_config['revision'])
        assert env.catalog_item_exists(catalog_item_name), \
            'k8s template does not exist when it should.'

        # check that temp vapp does not exists
        temp_vapp_name = testutils.get_temp_vapp_name(template_config['name'])
        assert not env.vapp_exists(temp_vapp_name), \
            'vApp exists when it should not.'
コード例 #7
0
def _install_template(client,
                      remote_template_manager,
                      template,
                      org_name,
                      vdc_name,
                      catalog_name,
                      network_name,
                      ip_allocation_mode,
                      storage_profile,
                      force_update,
                      retain_temp_vapp,
                      ssh_key,
                      msg_update_callback=utils.NullPrinter()):
    localTemplateKey = server_constants.LocalTemplateKey
    templateBuildKey = server_constants.TemplateBuildKey
    remote_template_manager.download_template_scripts(
        template_name=template[server_constants.RemoteTemplateKey.NAME],
        revision=template[server_constants.RemoteTemplateKey.REVISION],
        force_overwrite=force_update)
    catalog_item_name = ltm.get_revisioned_template_name(
        template[server_constants.RemoteTemplateKey.NAME],
        template[server_constants.RemoteTemplateKey.REVISION])

    # remote template data is a super set of local template data, barring
    # the key 'catalog_item_name'
    template_data = dict(template)
    template_data[localTemplateKey.CATALOG_ITEM_NAME] = catalog_item_name

    missing_keys = [k for k in localTemplateKey if k not in template_data]
    if len(missing_keys) > 0:
        raise ValueError(f"Invalid template data. Missing keys: {missing_keys}"
                         )  # noqa: E501

    temp_vm_name = \
        f"{template[server_constants.RemoteTemplateKey.OS].replace('.','')}-k8s" \
        f"{template[server_constants.RemoteTemplateKey.KUBERNETES_VERSION].replace('.', '')}" \
        f"-{template[server_constants.RemoteTemplateKey.CNI]}{template[server_constants.RemoteTemplateKey.CNI_VERSION].replace('.','')}-vm" # noqa: E501
    build_params = {
        templateBuildKey.TEMPLATE_NAME:
        template[server_constants.RemoteTemplateKey.NAME],  # noqa: E501
        templateBuildKey.TEMPLATE_REVISION:
        template[server_constants.RemoteTemplateKey.REVISION],  # noqa: E501
        templateBuildKey.SOURCE_OVA_NAME:
        template[
            server_constants.RemoteTemplateKey.SOURCE_OVA_NAME],  # noqa: E501
        templateBuildKey.SOURCE_OVA_HREF:
        template[
            server_constants.RemoteTemplateKey.SOURCE_OVA_HREF],  # noqa: E501
        templateBuildKey.SOURCE_OVA_SHA256:
        template[server_constants.RemoteTemplateKey.
                 SOURCE_OVA_SHA256],  # noqa: E501
        templateBuildKey.ORG_NAME:
        org_name,
        templateBuildKey.VDC_NAME:
        vdc_name,
        templateBuildKey.CATALOG_NAME:
        catalog_name,
        templateBuildKey.CATALOG_ITEM_NAME:
        catalog_item_name,
        templateBuildKey.CATALOG_ITEM_DESCRIPTION:
        template[server_constants.RemoteTemplateKey.DESCRIPTION],  # noqa: E501
        templateBuildKey.TEMP_VAPP_NAME:
        template[server_constants.RemoteTemplateKey.NAME] +
        '_temp',  # noqa: E501
        templateBuildKey.TEMP_VM_NAME:
        temp_vm_name,
        templateBuildKey.CPU:
        template[server_constants.RemoteTemplateKey.CPU],
        templateBuildKey.MEMORY:
        template[server_constants.RemoteTemplateKey.MEMORY],  # noqa: E501
        templateBuildKey.NETWORK_NAME:
        network_name,
        templateBuildKey.IP_ALLOCATION_MODE:
        ip_allocation_mode,  # noqa: E501
        templateBuildKey.STORAGE_PROFILE:
        storage_profile
    }
    builder = TemplateBuilder(client,
                              client,
                              build_params,
                              ssh_key=ssh_key,
                              logger=INSTALL_LOGGER,
                              msg_update_callback=msg_update_callback)
    builder.build(force_recreate=force_update,
                  retain_temp_vapp=retain_temp_vapp)

    ltm.save_metadata(client, org_name, catalog_name, catalog_item_name,
                      template_data)