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.'
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.'
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.'
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.'
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.'
def test_0050_install_no_capture(config, blank_cust_scripts, unregister_cse): """Test install. Installation options: '--config', '--template', '--ext skip', '--ssh-key', '--no-capture'. Tests that installation: - downloads/uploads ova file, - creates photon temp vapp, - skips cse registration, - skips temp vapp capture. command: cse install --config cse_test_config.yaml --template photon-v2 --ext skip --ssh-key ~/.ssh/id_rsa.pub --no-capture required files: ~/.ssh/id_rsa.pub, cse_test_config.yaml, photon-v2 init, photon-v2 cust (blank) expected: cse not registered, catalog exists, photon-v2 ova exists, temp vapp does not exist, template does not exist. """ template_config = None for template_dict in config['broker']['templates']: if template_dict['name'] == env.PHOTON_TEMPLATE_NAME: template_config = template_dict break assert template_config is not None, \ 'Target template not found in config file' result = env.CLI_RUNNER.invoke(cli, ['install', '--config', env.ACTIVE_CONFIG_FILEPATH, '--ssh-key', env.SSH_KEY_FILEPATH, '--template', env.PHOTON_TEMPLATE_NAME, '--ext', 'skip', '--no-capture'], catch_exceptions=False) assert result.exit_code == 0 # check that cse was not registered assert not env.is_cse_registered(), \ 'CSE is registered as an extension when it should not be.' # 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 vapp templates do not exist assert not env.catalog_item_exists(template_config['catalog_item']), \ 'vApp templates exist when they should not (--no-capture was used).' # check that temp vapp exists (--no-capture) assert env.vapp_exists(template_config['temp_vapp']), \ 'vApp does not exist when it should (--no-capture).'
def test_0110_install_cleanup_true(config, blank_cust_scripts, unregister_cse): """Tests that installation deletes temp vapps when 'cleanup' is True. command: cse install --config cse_test_config.yaml expected: temp vapps are deleted """ # set cleanup to true in config file for template_config in config['broker']['templates']: template_config['cleanup'] = True testutils.dict_to_yaml_file(config, env.ACTIVE_CONFIG_FILEPATH) result = env.CLI_RUNNER.invoke( cli, ['install', '--config', env.ACTIVE_CONFIG_FILEPATH], catch_exceptions=False) assert result.exit_code == 0 # check that cse was registered correctly env.check_cse_registration(config['amqp']['routing_key'], config['amqp']['exchange']) for template_config in config['broker']['templates']: # check that vapp templates exists assert env.catalog_item_exists(template_config['catalog_item']), \ 'vApp template does not exist when it should.' # check that temp vapps do not exist (cleanup: true) assert not env.vapp_exists(template_config['temp_vapp']), \ 'Temp vapp exists when it should not (cleanup: True).'
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.'
def cse_server(): """Fixture to ensure that CSE is installed and running before client tests. This fixture executes automatically for this module's setup and teardown. Setup tasks: - If templates do not exist, install CSE using `--upgrade` - Run `cse install` to ensure that CSE is registered and AMQP exchange exists. - Run CSE server as a subprocess Teardown tasks: - Stop CSE server """ config = testutils.yaml_to_dict(env.BASE_CONFIG_FILEPATH) install_cmd = ['install', '--config', env.ACTIVE_CONFIG_FILEPATH, '--ssh-key', env.SSH_KEY_FILEPATH] for template in config['broker']['templates']: if not env.catalog_item_exists(template['catalog_item']): install_cmd.append('--update') break env.setup_active_config() result = env.CLI_RUNNER.invoke(cli, install_cmd, input='y', catch_exceptions=False) assert result.exit_code == 0 # start cse server as subprocess cmd = f"cse run -c {env.ACTIVE_CONFIG_FILEPATH}" p = subprocess.Popen(cmd.split(), stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) time.sleep(env.WAIT_INTERVAL) # server takes a little time to set up # enable kubernetes functionality on our ovdc # by default, an ovdc cannot deploy kubernetes clusters # TODO() this should be removed once this behavior is changed cmd = f"login {config['vcd']['host']} {utils.SYSTEM_ORG_NAME} " \ f"{config['vcd']['username']} -iwp {config['vcd']['password']}" result = env.CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=False) assert result.exit_code == 0 cmd = f"org use {config['broker']['org']}" result = env.CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=False) assert result.exit_code == 0 cmd = f"cse ovdc enablek8s {config['broker']['vdc']} -c vcd" result = env.CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=False) assert result.exit_code == 0 result = env.CLI_RUNNER.invoke(vcd, 'logout', catch_exceptions=False) yield # terminate cse server subprocess try: p.terminate() except OSError: pass
def test_0080_install_no_capture(config, blank_cust_scripts, unregister_cse): """Test install. Installation options: '--config', '--template', '--ssh-key', '--no-capture'. Tests that installation: - downloads/uploads ova file, - creates photon temp vapp, - skips temp vapp capture. command: cse install --config cse_test_config.yaml --template photon-v2 --ssh-key ~/.ssh/id_rsa.pub --no-capture required files: ~/.ssh/id_rsa.pub, cse_test_config.yaml, photon-v2 init, photon-v2 cust (blank) expected: cse registered, catalog exists, photon-v2 ova exists, temp vapp does not exist, template does not exist. """ template_config = testutils.get_default_template_config(config) result = env.CLI_RUNNER.invoke(cli, [ 'install', '--config', env.ACTIVE_CONFIG_FILEPATH, '--ssh-key', env.SSH_KEY_FILEPATH, '--template', template_config['name'], '--no-capture' ], catch_exceptions=False) assert result.exit_code == 0 # check that cse was registered correctly env.check_cse_registration(config['amqp']['routing_key'], config['amqp']['exchange']) # 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 vapp templates do not exist assert not env.catalog_item_exists(template_config['catalog_item']), \ 'vApp templates exist when they should not (--no-capture was used).' # check that temp vapp exists (--no-capture) assert env.vapp_exists(template_config['temp_vapp']), \ 'vApp does not exist when it should (--no-capture).'
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.'
def test_0060_install_temp_vapp_already_exists(config, blank_cust_scripts, unregister_cse): """Test installation when temp vapp already exists. Tests that installation: - skips cse registration (answering no to prompt), - captures temp vapp as template correctly, - does not delete temp_vapp when config file 'cleanup' property is false. command: cse install --config cse_test_config.yaml --template photon-v2 required files: cse_test_config.yaml expected: cse not registered, photon-v2 template exists, temp-vapp exists """ template_config = None # set cleanup to false for this test for i, template_dict in enumerate(config['broker']['templates']): config['broker']['templates'][i]['cleanup'] = False if template_dict['name'] == env.PHOTON_TEMPLATE_NAME: template_config = template_dict break assert template_config is not None, \ 'Target template not found in config file' testutils.dict_to_yaml_file(config, env.ACTIVE_CONFIG_FILEPATH) res = env.CLI_RUNNER.invoke(cli, ['install', '--config', env.ACTIVE_CONFIG_FILEPATH, '--template', env.PHOTON_TEMPLATE_NAME], input='N\nN', catch_exceptions=False) assert res.exit_code == 0 # check that cse was not registered assert not env.is_cse_registered(), \ 'CSE is registered as an extension when it should not be.' # check that vapp template exists in catalog assert env.catalog_item_exists(template_config['catalog_item']), \ 'vApp template does not exist when it should.' # check that temp vapp exists (cleanup: false) assert env.vapp_exists(template_config['temp_vapp']), \ 'vApp does not exist when it should (cleanup: false).'
def cse_server(): """Fixture to ensure that CSE is installed before client tests. This function will execute once for this module. Setup tasks: - If templates do not exist, install CSE using `--upgrade` - If CSE is not registered properly, install CSE normally """ config = testutils.yaml_to_dict(env.BASE_CONFIG_FILEPATH) install_cmd = [ 'install', '--config', env.ACTIVE_CONFIG_FILEPATH, '--ssh-key', env.SSH_KEY_FILEPATH ] installation_exists = True for template in config['broker']['templates']: if not env.catalog_item_exists(template['catalog_item']): installation_exists = False install_cmd.append('--update') break env.setup_active_config() if not installation_exists \ or not env.is_cse_registration_valid(config['amqp']['routing_key'], config['amqp']['exchange']): result = env.CLI_RUNNER.invoke(cli, install_cmd, input='y', catch_exceptions=False) assert result.exit_code == 0 # start cse server as subprocess cmd = f"cse run -c {env.ACTIVE_CONFIG_FILEPATH}" p = subprocess.Popen(cmd.split(), stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) time.sleep(10) yield # terminate cse server subprocess p.terminate()
def test_0090_install_temp_vapp_already_exists(config, blank_cust_scripts, unregister_cse): """Test installation when temp vapp already exists. Tests that installation: - captures temp vapp as template correctly, - does not delete temp_vapp when config file 'cleanup' property is false. command: cse install --config cse_test_config.yaml --template photon-v2 required files: cse_test_config.yaml expected: cse not registered, photon-v2 template exists, temp-vapp exists """ # set cleanup to false for this test for i, template_dict in enumerate(config['broker']['templates']): config['broker']['templates'][i]['cleanup'] = False template_config = testutils.get_default_template_config(config) testutils.dict_to_yaml_file(config, env.ACTIVE_CONFIG_FILEPATH) result = env.CLI_RUNNER.invoke(cli, [ 'install', '--config', env.ACTIVE_CONFIG_FILEPATH, '--template', template_config['name'] ], catch_exceptions=False) assert result.exit_code == 0 # check that cse was registered correctly env.check_cse_registration(config['amqp']['routing_key'], config['amqp']['exchange']) # check that vapp template exists in catalog assert env.catalog_item_exists(template_config['catalog_item']), \ 'vApp template does not exist when it should.' # check that temp vapp exists (cleanup: false) assert env.vapp_exists(template_config['temp_vapp']), \ 'vApp does not exist when it should (cleanup: false).'
def test_0080_install_cleanup_true(config, blank_cust_scripts, unregister_cse): """Tests that installation deletes temp vapps when 'cleanup' is True. Also tests that '--ext config' registers cse. command: cse install --config cse_test_config.yaml expected: temp vapps are deleted """ for template_config in config['broker']['templates']: assert template_config['cleanup'], \ "'cleanup' key in template config should be True" result = env.CLI_RUNNER.invoke(cli, ['install', '--config', env.ACTIVE_CONFIG_FILEPATH, '--ext', 'config'], catch_exceptions=False) assert result.exit_code == 0 # check that cse was registered correctly is_cse_registered = env.is_cse_registered() assert is_cse_registered, \ 'CSE is not registered as an extension when it should be.' if is_cse_registered: assert env.is_cse_registration_valid(config['amqp']['routing_key'], config['amqp']['exchange']), \ 'CSE is registered as an extension, but the extension settings ' \ 'on vCD are not the same as config settings.' for template_config in config['broker']['templates']: # check that vapp templates exists assert env.catalog_item_exists(template_config['catalog_item']), \ 'vApp template does not exist when it should.' # check that temp vapps do not exist (cleanup: true) assert not env.vapp_exists(template_config['temp_vapp']), \ 'Temp vapp exists when it should not (cleanup: True).'
def test_0070_install_update(config, blank_cust_scripts, unregister_cse): """Tests installation option: '--update'. Tests that installation: - registers cse (when answering yes to prompt), - creates all templates correctly, - customizes temp vapps correctly. command: cse install --config cse_test_config.yaml --ssh-key ~/.ssh/id_rsa.pub --update --no-capture required files: cse_test_config.yaml, ~/.ssh/id_rsa.pub, ubuntu/photon init/cust scripts expected: cse registered, ubuntu/photon ovas exist, temp vapps exist, templates exist. """ env.prepare_customization_scripts() result = env.CLI_RUNNER.invoke(cli, ['install', '--config', env.ACTIVE_CONFIG_FILEPATH, '--ssh-key', env.SSH_KEY_FILEPATH, '--update', '--no-capture'], input='y\ny', catch_exceptions=False) assert result.exit_code == 0 vdc = VDC(env.CLIENT, href=env.VDC_HREF) # check that cse was registered correctly is_cse_registered = env.is_cse_registered() assert is_cse_registered, \ 'CSE is not registered as an extension when it should be.' if is_cse_registered: assert env.is_cse_registration_valid(config['amqp']['routing_key'], config['amqp']['exchange']), \ 'CSE is registered as an extension, but the extension settings ' \ 'on vCD are not the same as config settings.' # ssh into vms to check for installed software ssh_client = paramiko.SSHClient() ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # check that ova files and temp vapps exist for template_config in config['broker']['templates']: assert env.catalog_item_exists(template_config['source_ova_name']), \ 'Source ova files do not exist when they should.' temp_vapp_name = template_config['temp_vapp'] try: vapp_resource = vdc.get_vapp(temp_vapp_name) except EntityNotFoundException: assert False, 'vApp does not exist when it should (--no-capture)' vapp = VApp(env.CLIENT, resource=vapp_resource) ip = vapp.get_primary_ip(temp_vapp_name) try: ssh_client.connect(ip, username='******') # run different commands depending on OS if 'photon' in temp_vapp_name: script = utils.get_data_file(env.STATIC_PHOTON_CUST_SCRIPT) 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 = utils.get_data_file(env.STATIC_UBUNTU_CUST_SCRIPT) pattern = r'((kubernetes|docker\S*|kubelet|kubeadm|kubectl)\S*=\S*)' # noqa packages = [tup[0] for tup in re.findall(pattern, script)] cmd = "dpkg -l | grep '^ii' | 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: ssh_client.close()
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()