Exemple #1
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.'
Exemple #2
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.'
Exemple #3
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.'
Exemple #4
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()
Exemple #5
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.'
Exemple #6
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.'
Exemple #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)
Exemple #8
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.'
Exemple #9
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.'
Exemple #10
0
def test_0090_install_retain_temp_vapp(config, unregister_cse_before_test):
    """Test install.

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

    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
        --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"
    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)
    ssh_client = paramiko.SSHClient()
    ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    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 existswhen it should.'

        # check that k8s templates exist
        catalog_item_name = 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()
            vapp_resource = vdc.get_vapp(temp_vapp_name)
        except EntityNotFoundException:
            assert False, 'vApp does not exist when it should.'

        # ssh into vms to check for installed software
        vapp = VApp(env.CLIENT, resource=vapp_resource)
        # The temp vapp is shutdown before the template is captured, it
        # needs to be powered on before trying to ssh into it.
        task = vapp.power_on()
        env.CLIENT.get_task_monitor().wait_for_success(task)

        # HACK! let the ssh daemon come up
        time.sleep(env.WAIT_INTERVAL)  # 30 seconds

        ip = vapp.get_primary_ip(TEMP_VAPP_VM_NAME)
        try:
            ssh_client.connect(ip, username='******')
            # run different commands depending on OS
            if 'photon' in temp_vapp_name:
                script_filepath = get_local_script_filepath(
                    template_config['name'], template_config['revision'],
                    ScriptFile.CUST)
                script = read_data_file(script_filepath)
                pattern = r'(kubernetes\S*)'
                packages = re.findall(pattern, script)
                stdin, stdout, stderr = ssh_client.exec_command("rpm -qa")
                installed = [line.strip('.x86_64\n') for line in stdout]
                for package in packages:
                    assert package in installed, \
                        f"{package} not found in Photon VM"
            elif 'ubuntu' in temp_vapp_name:
                script_filepath = get_local_script_filepath(
                    template_config['name'], template_config['revision'],
                    ScriptFile.CUST)
                script = read_data_file(script_filepath)
                pattern = r'((kubernetes|docker\S*|kubelet|kubeadm|kubectl)\S*=\S*)'  # noqa: E501
                packages = [tup[0] for tup in re.findall(pattern, script)]
                cmd = "dpkg -l | awk '{print $2\"=\"$3}'"
                stdin, stdout, stderr = ssh_client.exec_command(cmd)
                installed = [line.strip() for line in stdout]
                for package in packages:
                    assert package in installed, \
                        f"{package} not found in Ubuntu VM"
        finally:
            if ssh_client:
                ssh_client.close()