def vcd_vapp_author(): """Fixture to ensure that we are logged in to vcd-cli as vapp author. Usage: add the parameter 'vcd_vapp_author' to the test function. User will have the credentials specified in 'system_test_framework/environment.py' Do not use this fixture with the other vcd_role fixtures, as only one user can be logged in at a time. """ config = testutils.yaml_to_dict(env.BASE_CONFIG_FILEPATH) cmd = f"login {config['vcd']['host']} {config['broker']['org']} " \ f"{env.VAPP_AUTHOR_NAME} -iwp {env.VAPP_AUTHOR_PASSWORD}" result = env.CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=False) assert result.exit_code == 0,\ testutils.format_command_info('vcd', cmd, result.exit_code, result.output) # ovdc context may be nondeterministic when there's multiple ovdcs cmd = f"vdc use {config['broker']['vdc']}" result = env.CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=False) assert result.exit_code == 0,\ testutils.format_command_info('vcd', cmd, result.exit_code, result.output) yield result = env.CLI_RUNNER.invoke(vcd, ['logout']) assert result.exit_code == 0,\ testutils.format_command_info('vcd', cmd, result.exit_code, result.output)
def vcd_sys_admin(): """Fixture to ensure that we are logged in to vcd-cli as sys admin. Usage: add the parameter 'vcd_sys_admin' to the test function. User will have the credentials specified in 'system_tests/base_config.yaml' Do not use this fixture with the other vcd_role fixtures, as only one user can be logged in at a time. """ config = testutils.yaml_to_dict(env.BASE_CONFIG_FILEPATH) cmd = f"login {config['vcd']['host']} system " \ f"{config['vcd']['username']} -iwp {config['vcd']['password']} " \ f"-V {config['vcd']['api_version']}" result = env.CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=False) assert result.exit_code == 0,\ testutils.format_command_info('vcd', cmd, result.exit_code, result.output) cmd = f"org use {config['broker']['org']}" result = env.CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=False) assert result.exit_code == 0,\ testutils.format_command_info('vcd', cmd, result.exit_code, result.output) # ovdc context may be nondeterministic when there's multiple ovdcs cmd = f"vdc use {config['broker']['vdc']}" result = env.CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=False) assert result.exit_code == 0,\ testutils.format_command_info('vcd', cmd, result.exit_code, result.output) yield result = env.CLI_RUNNER.invoke(vcd, ['logout'])
def test_0010_cse_sample(): """Test that `cse sample` is a valid command. Test that `cse sample` command along with every option is an actual command. Does not test for validity of sample outputs. """ cmd = "sample" 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) output_filepath = 'dummy-output.yaml' cmd = f'sample --output {output_filepath}' 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) cmd = f'sample --pks-config --output {output_filepath}' 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) if os.path.exists(output_filepath): os.remove(output_filepath)
def test_9999_vcd_cse_system_stop(vcd_sys_admin): """Test `vcd cse system stop -y`. This test shuts down CSE service, so '9999' ensures it runs last. """ # must disable CSE before attempting to stop cmd = 'cse system disable' result = env.CLI_RUNNER.invoke(vcd, 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('vcd', cmd, result.exit_code, result.output) cmd = 'cse system stop' result = env.CLI_RUNNER.invoke(vcd, cmd.split(), input='y', 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('vcd', cmd, result.exit_code, result.output)
def vcd_cluster_admin(): """Fixture to ensure that we are logged in to vcd-cli as cluster admin. Usage: add the parameter 'vcd_cluster_admin' to the test function. User will have the credentials specified in 'system_test_framework/environment.py' Do not use this fixture with the other vcd_role fixtures, as only one user can be logged in at a time. """ config = testutils.yaml_to_dict(env.BASE_CONFIG_FILEPATH) cmd = f"login {config['vcd']['host']} {env.TEST_ORG} " \ f"{env.CLUSTER_ADMIN_NAME} -iwp {env.CLUSTER_ADMIN_PASSWORD} " \ f"-V {env.VCD_API_VERSION_TO_USE}" result = env.CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=False) assert result.exit_code == 0, \ testutils.format_command_info('vcd', cmd, result.exit_code, result.output) # ovdc context may be nondeterministic when there's multiple ovdcs cmd = f"vdc use {env.TEST_VDC}" result = env.CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=False) assert result.exit_code == 0,\ testutils.format_command_info('vcd', cmd, result.exit_code, result.output) PYTEST_LOGGER.debug(f"Logged in as {env.CLUSTER_ADMIN_NAME}") yield result = env.CLI_RUNNER.invoke(vcd, ['logout']) PYTEST_LOGGER.debug(f"Logged out as {env.CLUSTER_ADMIN_NAME}")
def test_0030_vcd_cse_cluster_create_rollback(config, vcd_org_admin, delete_test_cluster): """Test that --disable-rollback option works during cluster creation. commands: $ vcd cse cluster create -n NETWORK -N 1 -t photon-v2 -c 1000 $ vcd cse cluster create -n NETWORK -N 1 -t photon-v2 -c 1000 --disable-rollback """ cmd = f"cse cluster create {env.TEST_CLUSTER_NAME} -n " \ f"{config['broker']['network']} -N 1 -c 1000" result = env.CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=False) assert result.exit_code == 0,\ testutils.format_command_info('vcd', cmd, result.exit_code, result.output) # TODO() make cluster rollback delete call blocking time.sleep(env.WAIT_INTERVAL * 6) # wait for vApp to be deleted assert not env.vapp_exists(env.TEST_CLUSTER_NAME), \ "Cluster exists when it should not." cmd += " --disable-rollback" result = env.CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=False) assert result.exit_code == 0,\ testutils.format_command_info('vcd', cmd, result.exit_code, result.output) assert env.vapp_exists(env.TEST_CLUSTER_NAME), \ "Cluster does not exist when it should."
def test_0030_vcd_cse_cluster_create_rollback(config, vcd_org_admin, delete_test_clusters): """Test that --disable-rollback option works during cluster creation. commands: $ vcd cse cluster create testcluster -n NETWORK -N 1 -c 1000 $ vcd cse cluster create testcluster -n NETWORK -N 1 -c 1000 --disable-rollback """ template_name = env.TEMPLATE_DEFINITIONS[0]['name'] template_revision = env.TEMPLATE_DEFINITIONS[0]['revision'] cmd = f"cse cluster create {env.SYS_ADMIN_TEST_CLUSTER_NAME} -n " \ f"{env.TEST_NETWORK} -N 1 -c 1000 -t {template_name} -r {template_revision}" # noqa: E501 result = env.CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=False) assert result.exit_code == 0, \ testutils.format_command_info('vcd', cmd, result.exit_code, result.output) # TODO: Make cluster rollback delete call blocking time.sleep(env.WAIT_INTERVAL * 2) # wait for vApp to be deleted assert not env.vapp_exists( env.SYS_ADMIN_TEST_CLUSTER_NAME, vdc_href=env.TEST_VDC_HREF), \ "Cluster exists when it should not." cmd += " --disable-rollback" result = env.CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=False) assert result.exit_code == 0,\ testutils.format_command_info('vcd', cmd, result.exit_code, result.output) assert env.vapp_exists(env.SYS_ADMIN_TEST_CLUSTER_NAME, vdc_href=env.TEST_VDC_HREF), \ "Cluster 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_0020_vcd_cse_system_info(vcd_org_admin): """Test vcd cse system info command.""" cmd = "cse system info" result = env.CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=False) assert result.exit_code == 0,\ testutils.format_command_info('vcd', cmd, result.exit_code, result.output)
def check_node_list(): """Use `vcd cse node list` to verify that nodes were added/deleted. Internal function used to count nodes and validate that create/delete commands work as expected. Example: if we add a node to a cluster with 1 node, we expect to have 2 nodes total. If this function finds that only 1 node exists, then this test will fail. :return: list of node names :rtype: List[str] """ node_pattern = r'(node-\S+)' node_list_cmd = f"cse node list {env.TEST_CLUSTER_NAME}" print(f"Running command [vcd {node_list_cmd}]...", end='') node_list_result = env.CLI_RUNNER.invoke(vcd, node_list_cmd.split(), catch_exceptions=False) assert node_list_result.exit_code == 0, \ testutils.format_command_info('vcd', node_list_cmd, node_list_result.exit_code, node_list_result.output) print('SUCCESS') node_list = re.findall(node_pattern, node_list_result.output) assert len(node_list) == num_nodes, \ f"Test cluster has {len(node_list)} nodes, when it should have " \ f"{num_nodes} node(s)." return node_list
def test_0080_install( config, unregister_cse_before_test, publish_native_right_bundle ): """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) 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)
def create_apply_spec(apply_spec_param): """Create apply specification throught cse cluster apply --sample command. :param dict apply_spec_param: Dictionary containing the information that need to be modified in the initial sample command :return the dictionary containing the following - worker count - nfs count - tempalte name - template revision - network - sizing class - storage profile """ # run cse sample to generate apply sepecification cmd = f"cse cluster apply --sample --native -o {env.APPLY_SPEC_PATH}" result = env.CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=False) assert result.exit_code == 0, \ testutils.format_command_info('vcd', cmd, result.exit_code, result.output) PYTEST_LOGGER.debug(f"Using params {apply_spec_param} to create " "apply specification") testutils.modify_cluster_apply_spec(env.APPLY_SPEC_PATH, apply_spec_param)
def test_0010_vcd_cse_version(): """Test vcd cse version command.""" cmd = "cse version" result = env.CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=False) assert result.exit_code == 0,\ testutils.format_command_info('vcd', cmd, result.exit_code, result.output)
def test_0020_cse_version(): """Test that `cse version` is a valid command.""" cmd = "version" 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)
def test_0030_cse_check(config): """Test that `cse check` is a valid command. Test that `cse check` command along with every option is an actual command. Does not test for validity of config files or CSE installations. """ cmd = f"check {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) cmd = f"check {env.ACTIVE_CONFIG_FILEPATH} -i --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)
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): """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_0010_vcd_cse_version(): """Test vcd cse version command.""" cmd = "cse version" result = env.CLI_RUNNER.invoke(vcd, 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('vcd', cmd, result.exit_code, result.output)
def test_0020_cse_version(): """Test that `cse version` is a valid command.""" cmd = "version" 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)
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 create_cluster_admin_role(vcd_config: dict, logger=NULL_LOGGER): """Create cluster_admin role using pre-existing 'vapp author' role. :param dict vcd_config: server config file :param logging.Logger logger: """ logger.debug("Creating cluster admin role.") cmd = f"login {vcd_config['host']} {shared_constants.SYSTEM_ORG_NAME} " \ f"{vcd_config['username']} -iwp {vcd_config['password']} " \ f"-V {VCD_API_VERSION_TO_USE}" result = CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=False) assert result.exit_code == 0 cmd = f"org use {TEST_ORG}" result = CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=False) assert result.exit_code == 0 logger.debug(f"Cloning role {ORG_ADMIN_ROLE_NAME} " f"to create {CLUSTER_ADMIN_ROLE_NAME}") result = CLI_RUNNER.invoke( vcd, ['role', 'clone', ORG_ADMIN_ROLE_NAME, CLUSTER_ADMIN_ROLE_NAME], catch_exceptions=False) role_exists = DUPLICATE_NAME in result.stdout if role_exists: logger.debug(f"Role {CLUSTER_ADMIN_ROLE_NAME} already exists.") assert role_exists or result.exit_code == 0, \ testutils.format_command_info('vcd', cmd, result.exit_code, result.output) # Add View right for other published catalogs logger.debug(f"Publishing {VIEW_PUBLISHED_CATALOG_RIGHT} to " f"the role {CLUSTER_ADMIN_ROLE_NAME}") result = CLI_RUNNER.invoke(vcd, [ 'role', 'add-right', CLUSTER_ADMIN_ROLE_NAME, VIEW_PUBLISHED_CATALOG_RIGHT ], catch_exceptions=False) assert result.exit_code == 0, \ testutils.format_command_info('vcd', cmd, result.exit_code, result.output) logger.debug(f"Successfully created role: {CLUSTER_ADMIN_ROLE_NAME}")
def create_k8_author_role(vcd_config: dict): cmd = f"login {vcd_config['host']} {shared_constants.SYSTEM_ORG_NAME} " \ f"{vcd_config['username']} -iwp {vcd_config['password']} " \ f"-V {VCD_API_VERSION_TO_USE}" result = CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=False) assert result.exit_code == 0 cmd = f"org use {TEST_ORG}" result = CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=False) assert result.exit_code == 0 result = CLI_RUNNER.invoke( vcd, ['role', 'clone', VAPP_AUTHOR_ROLE_NAME, K8_AUTHOR_ROLE_NAME], catch_exceptions=False) assert DUPLICATE_NAME in result.stdout or result.exit_code == 0, \ testutils.format_command_info('vcd', cmd, result.exit_code, result.output) # Add View right for other published catalogs result = CLI_RUNNER.invoke(vcd, [ 'role', 'add-right', K8_AUTHOR_ROLE_NAME, VIEW_PUBLISHED_CATALOG_RIGHT ], catch_exceptions=False) assert result.exit_code == 0, \ testutils.format_command_info('vcd', cmd, result.exit_code, result.output)
def execute_commands(cmd_list): cmd_results = [] for action in cmd_list: cmd = action.cmd expected_exit_code = action.exit_code result = env.CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=False) assert result.exit_code == expected_exit_code, \ testutils.format_command_info( 'vcd', cmd, result.exit_code, result.output) cmd_results.append(result) return cmd_results
def test_0100_vcd_ovdc_disable( ovdc_disable_test_case: OVDC_DISABLE_TEST_PARAM): # noqa: E501 """Test ovdc disable operation. commands: $ vcd cse ovdc disable -n -o TEST_ORG TEST_VDC """ cmd = f"cse ovdc disable {env.TEST_VDC} -n -o {env.TEST_ORG}" result = env.CLI_RUNNER.invoke(vcd, 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 or ovdc_disable_test_case.expect_failure, \ testutils.format_command_info('vcd', cmd, result.exit_code, result.output)
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 execute_commands(cmd_list): cmd_results = [] for action in cmd_list: cmd = action.cmd print(f"Running command [vcd {cmd}]") expected_exit_code = action.exit_code result = env.CLI_RUNNER.invoke(vcd, cmd.split(), input='y', catch_exceptions=False) assert result.exit_code == expected_exit_code, \ testutils.format_command_info( 'vcd', cmd, result.exit_code, result.output) if action.validate_output_func is not None: action.validate_output_func(result.output, action.test_user) cmd_results.append(result) return cmd_results
def test_0020_vcd_ovdc_enable(ovdc_enable_test_case: OVDC_ENABLE_TEST_PARAM): """Test ovdc enable operation. Disabling the test ovdc is necessary to avoid errors if there are clusters left over from previous test execution. commands: $ vcd cse ovdc enable -n -o TEST_ORG TEST_VDC """ cmd = f"cse ovdc enable {ovdc_enable_test_case.ovdc_name} --native --org {ovdc_enable_test_case.org_name}" # noqa: E501 result = env.CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=True) 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 or ovdc_enable_test_case.expect_failure, \ testutils.format_command_info('vcd', cmd, result.exit_code, result.output)
def ovdc_enable_test_case(request): test_case: OVDC_ENABLE_TEST_PARAM = request.param # login user config = testutils.yaml_to_dict(env.BASE_CONFIG_FILEPATH) pwd = test_case.password user = test_case.user org_name = test_case.org_name if test_case.user == env.SYS_ADMIN_NAME: user = config['vcd']['username'] pwd = config['vcd']['password'] org_name = 'system' cmd = f"login {config['vcd']['host']} {org_name} " \ f"{user} -iwp {pwd} " \ f"-V {env.VCD_API_VERSION_TO_USE}" result = env.CLI_RUNNER.invoke(vcd, 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}") PYTEST_LOGGER.debug(f"Logged in as {test_case.user}") assert result.exit_code == 0, \ testutils.format_command_info('vcd', cmd, result.exit_code, result.output) if test_case.disable_before_test: # disable ovdc before test cmd = f"cse ovdc disable --native --org {test_case.org_name} {test_case.ovdc_name} --force" # noqa: E501 env.CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=True) yield test_case # disable ovdc after test cmd = f"cse ovdc disable --native --org {test_case.org_name} {test_case.ovdc_name} --force" # noqa: E501 env.CLI_RUNNER.invoke(vcd, cmd.split(), catch_exceptions=True) # logout env.CLI_RUNNER.invoke(vcd, ['logout']) PYTEST_LOGGER.debug(f"Logged out as {test_case.user}")
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.'