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_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_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_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 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_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(config, unregister_cse_before_test): """Test install. Installation options: '--skip-config-decryption' Tests that installation: - registers CSE command: cse install --config cse_test_config.yaml --skip-config-decryption required files: cse_test_config.yaml, expected: cse registered, catalog exists. """ cmd = f"install --config {env.ACTIVE_CONFIG_FILEPATH} " \ "--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'])
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()
def test_0100_install_update(config, unregister_cse): """Tests installation option: '--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 --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. """ result = env.CLI_RUNNER.invoke(cli, [ 'install', '--config', env.ACTIVE_CONFIG_FILEPATH, '--ssh-key', env.SSH_KEY_FILEPATH, '--update', '--no-capture' ], catch_exceptions=False) assert result.exit_code == 0 vdc = VDC(env.CLIENT, href=env.VDC_HREF) # check that cse was registered correctly env.check_cse_registration(config['amqp']['routing_key'], config['amqp']['exchange']) # 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()