def _get_remote_script_url(self, template_name, revision,
                               script_file_name):
        """.

        The scripts of all templates are kept relative to templates.yaml,
        under the 'scripts' folder. Scripts of a particular template is kept
        inside a sub-directory of 'scripts' named after the revisioned
        template.

        e.g.
        templates.yaml is kept at <base_url>/templates.yaml
        * Template X at revision 2 will have it's scripts under
        <base_url>/scripts/X_rev2/...
        * Template Y at revision 6 will have it's scripts under
        <base_url>/scripts/Y_rev6/...

        :param str template_name:
        :param str revision:
        :param str script_file_name:
        """
        base_url = self._get_base_url_from_remote_template_cookbook_url()
        revisioned_template_name = \
            ltm.get_revisioned_template_name(template_name, revision)
        return base_url + \
            f"/{self.scripts_directory_path}" \
            f"/{revisioned_template_name}" \
            f"/{script_file_name}"
Пример #2
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)
    PYTEST_LOGGER.debug(f"Executing command: {cmd}")
    PYTEST_LOGGER.debug(f"Exit code: {result.exit_code}")
    PYTEST_LOGGER.debug(f"Output: {result.output}")
    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_as_mqtt_extension()
    remote_template_keys = server_utils.get_template_descriptor_keys(
        env.TEMPLATE_COOKBOOK_VERSION)

    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[remote_template_keys.SOURCE_OVA_NAME],
            logger=PYTEST_LOGGER), \
            'Source ova file does not exist when it should.'

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

        # check that temp vapp exists
        temp_vapp_name = testutils.get_temp_vapp_name(
            template_config[remote_template_keys.NAME])
        try:
            vdc.reload()
            vdc.get_vapp(temp_vapp_name)
        except EntityNotFoundException:
            assert False, 'vApp does not exist when it should.'
Пример #3
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.'
Пример #4
0
def test_0100_install_select_templates(config):
    """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.
    """
    # check that cse was registered correctly
    env.check_cse_registration_as_mqtt_extension()
    remote_template_keys = server_utils.get_template_descriptor_keys(
        env.TEMPLATE_COOKBOOK_VERSION)

    vdc = VDC(env.CLIENT, href=env.VDC_HREF)
    for template_config in env.TEMPLATE_DEFINITIONS:
        # install the template
        cmd = f"template install {template_config[remote_template_keys.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"  # noqa: E501
        result = env.CLI_RUNNER.invoke(
            cli, cmd.split(), catch_exceptions=False)
        PYTEST_LOGGER.debug(f"Executing command: {cmd}")
        PYTEST_LOGGER.debug(f"Exit code: {result.exit_code}")
        PYTEST_LOGGER.debug(f"Output: {result.output}")
        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[remote_template_keys.SOURCE_OVA_NAME],
            logger=PYTEST_LOGGER), \
            'Source ova file does not exists when it should.'

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

        # check that temp vapp exists
        temp_vapp_name = testutils.get_temp_vapp_name(
            template_config[remote_template_keys.NAME])
        try:
            vdc.reload()
            vdc.get_vapp(temp_vapp_name)
        except EntityNotFoundException:
            assert False, 'vApp does not exist when it should.'
Пример #5
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, vdc_href=env.VDC_HREF)
    env.delete_catalog()
    env.unregister_cse()
Пример #6
0
def test_0080_install_skip_template_creation(config,
                                             unregister_cse_before_test,
                                             publish_native_right_bundle):
    """Test install.

    Installation options: '--ssh-key', '--skip-template-creation',
    '--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)
    PYTEST_LOGGER.debug(f"Executing command: {cmd}")
    PYTEST_LOGGER.debug(f"Exit code: {result.exit_code}")
    PYTEST_LOGGER.debug(f"Output: {result.output}")
    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_as_mqtt_extension(logger=PYTEST_LOGGER)
    remote_template_keys = server_utils.get_template_descriptor_keys(
        env.TEMPLATE_COOKBOOK_VERSION)

    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[remote_template_keys.SOURCE_OVA_NAME],
            logger=PYTEST_LOGGER), \
            '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[remote_template_keys.NAME],
            template_config[remote_template_keys.REVISION])
        assert not env.catalog_item_exists(
            catalog_item_name,
            logger=PYTEST_LOGGER), 'k8s templates exist when they should not.'

        # check that temp vapp does not exists
        temp_vapp_name = testutils.get_temp_vapp_name(
            template_config[remote_template_keys.NAME])
        assert not env.vapp_exists(
            temp_vapp_name, vdc_href=env.VDC_HREF, logger=PYTEST_LOGGER), \
            'vApp exists when it should not.'
Пример #7
0
def _remove_cse_artifacts():
    for template in env.TEMPLATE_DEFINITIONS:
        env.delete_catalog_item(template['source_ova_name'],
                                logger=PYTEST_LOGGER)
        catalog_item_name = ltm.get_revisioned_template_name(
            template['name'], template['revision'])
        env.delete_catalog_item(catalog_item_name, logger=PYTEST_LOGGER)
        temp_vapp_name = testutils.get_temp_vapp_name(template['name'])
        env.delete_vapp(temp_vapp_name, vdc_href=env.VDC_HREF)
    env.delete_catalog(logger=PYTEST_LOGGER)
    env.unregister_cse_in_mqtt(logger=PYTEST_LOGGER)
    env.cleanup_rde_artifacts(logger=PYTEST_LOGGER)
    env.cleanup_roles_and_users(logger=PYTEST_LOGGER)
Пример #8
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.'
Пример #9
0
def test_0080_install_skip_template_creation(config,
                                             unregister_cse_before_test):
    """Test install.

    Installation options: '--ssh-key', '--skip-template-creation',
    '--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, vdc_href=env.VDC_HREF), \
            'vApp exists when it should not.'