def test_0070_vcd_cse_cluster_create(config, test_runner_username): """Test 'vcd cse cluster create ...' command for various cse users. Test cluster creation from different persona's- sys_admin, org_admin and vapp_author. Created clusters will remain in the system for further command tests - list, resize and delete. :param config: cse config file for vcd configuration :param test_runner_username: parameterized persona to run tests with different users """ cmd_binder = collections.namedtuple( 'UserCmdBinder', 'cmd exit_code validate_output_func ' 'test_user') print(f"Running cluster create operation for {test_runner_username}") cmd_list = [ cmd_binder(cmd=env.USERNAME_TO_LOGIN_CMD[test_runner_username], exit_code=0, validate_output_func=None, test_user=test_runner_username), cmd_binder(cmd=f"org use {config['broker']['org']}", exit_code=0, validate_output_func=None, test_user=test_runner_username), cmd_binder(cmd=f"vdc use {config['broker']['vdc']}", exit_code=0, validate_output_func=None, test_user=test_runner_username), cmd_binder( cmd=f"cse cluster create " f"{env.USERNAME_TO_CLUSTER_NAME[test_runner_username]}" # noqa f" -n {config['broker']['network']} -N 1", exit_code=0, validate_output_func=None, test_user=test_runner_username), cmd_binder(cmd=env.USER_LOGOUT_CMD, exit_code=0, validate_output_func=None, test_user=test_runner_username) ] execute_commands(cmd_list) assert env.vapp_exists( env.USERNAME_TO_CLUSTER_NAME[test_runner_username]),\ f"Cluster {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]} " \ f"should exist" print( f"Successfully created cluster {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]} " # noqa f"for {test_runner_username}")
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 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_50_vcd_cse_system_toggle(config, test_runner_username, delete_test_cluster): """Test `vcd cse system ...` commands. Test that on disabling CSE, cluster deployments are no longer allowed, and on enabling CSE, cluster deployments are allowed again. These commands are combined into 1 test function because only sys admin can modify the state of CSE server, org admin/tenant can test cluster deployment to ensure that CSE is disabled/enabled. Also, this avoids cases such as running the system disable test, and then running the cluster operations test, which would fail due to CSE server being disabled). :param config: cse config file for vcd configuration :param test_runner_username: parameterized persona to run tests with different users """ # Batch cse commands together in a list and then execute them one by one cmd_binder = collections.namedtuple('UserCmdBinder', 'cmd exit_code') cmd_list = [ cmd_binder(cmd=env.SYS_ADMIN_LOGIN_CMD, exit_code=0), cmd_binder(cmd=f"cse system disable", exit_code=0), cmd_binder(cmd=env.USER_LOGIN_CMD_MAP.get(test_runner_username), exit_code=0), cmd_binder(cmd=f"org use {config['broker']['org']}", exit_code=0), cmd_binder(cmd=f"cse cluster create {env.TEST_CLUSTER_NAME} -n " f"{config['broker']['network']} -N 1", exit_code=2), cmd_binder(cmd=env.USER_LOGOUT_CMD, exit_code=0), cmd_binder(cmd=env.SYS_ADMIN_LOGIN_CMD, exit_code=0), cmd_binder(cmd="cse system enable", exit_code=0), cmd_binder(cmd=f"cse cluster create {env.TEST_CLUSTER_NAME} -n " f"{config['broker']['network']} -N 1 -c 1000 " f"--disable-rollback", exit_code=2), cmd_binder(cmd=env.USER_LOGOUT_CMD, exit_code=0) ] execute_commands(cmd_list) assert not env.vapp_exists(env.TEST_CLUSTER_NAME), \ "Cluster exist 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_0090_vcd_cse_cluster_delete( cluster_delete_param: CLUSTER_DELETE_TEST_PARAM): # noqa: E501 """Test 'vcd cse cluster delete ...' command for various cse users. Cluster delete operation on the above create clusters operations- cluster Author can only delete self created clusters. cluster admin can delete all cluster in the organization. :param config: cse config file for vcd configuration """ cmd_list = [ testutils.CMD_BINDER( cmd=env.USER_LOGOUT_CMD[cluster_delete_param.user], # noqa: E501 exit_code=0, validate_output_func=None, test_user=cluster_delete_param.user), testutils.CMD_BINDER(cmd=f"org use {cluster_delete_param.org}", exit_code=0, validate_output_func=None, test_user=env.CLUSTER_ADMIN_NAME), testutils.CMD_BINDER( cmd= f"cse cluster delete {cluster_delete_param.cluster_name}", # noqa: E501 exit_code=2 if cluster_delete_param.expect_failure else 0, # noqa: E501 validate_output_func=_follow_apply_output( expect_failure=cluster_delete_param.expect_failure ), # noqa: E501 test_user=cluster_delete_param.user), testutils.CMD_BINDER(cmd=env.USER_LOGOUT_CMD, exit_code=0, validate_output_func=None, test_user=env.CLUSTER_AUTHOR_NAME), ] testutils.execute_commands(cmd_list, logger=PYTEST_LOGGER) if not cluster_delete_param.expect_failure: assert not env.vapp_exists( cluster_delete_param.cluster_name, vdc_href=env.TEST_VDC_HREF, logger=PYTEST_LOGGER), \ f"Cluster {cluster_delete_param.cluster_name} exists when it should not" # noqa: E501
def test_0070_vcd_cse_cluster_create(config, test_runner_username): """Test 'vcd cse cluster create ...' command for various cse users. Test cluster creation from different persona's- sys_admin, org_admin and k8_author. Created clusters will remain in the system for further command tests - list, resize and delete. :param config: cse config file for vcd configuration :param test_runner_username: parameterized persona to run tests with different users """ template_name = env.TEMPLATE_DEFINITIONS[0]['name'] template_revision = env.TEMPLATE_DEFINITIONS[0]['revision'] cmd_binder = collections.namedtuple('UserCmdBinder', 'cmd exit_code validate_output_func ' 'test_user') print(f"Running cluster create operation for {test_runner_username}") cmd_list = [ cmd_binder(cmd=env.USERNAME_TO_LOGIN_CMD[test_runner_username], exit_code=0, validate_output_func=None, test_user=test_runner_username), cmd_binder(cmd=f"org use {env.TEST_ORG}", exit_code=0, validate_output_func=None, test_user=test_runner_username), cmd_binder(cmd=f"vdc use {env.TEST_VDC}", exit_code=0, validate_output_func=None, test_user=test_runner_username), cmd_binder(cmd=f"cse cluster create " f"{env.USERNAME_TO_CLUSTER_NAME[test_runner_username]}" f" -n {env.TEST_NETWORK} -N 0 -t {template_name}" f" -r {template_revision}", exit_code=0, validate_output_func=None, test_user=test_runner_username), cmd_binder(cmd=env.USER_LOGOUT_CMD, exit_code=0, validate_output_func=None, test_user=test_runner_username) ] execute_commands(cmd_list) assert env.vapp_exists( env.USERNAME_TO_CLUSTER_NAME[test_runner_username], vdc_href=env.TEST_VDC_HREF), \ f"Cluster {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]} " \ f"should exist" print(f"Successfully created cluster {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]} " # noqa f"for {test_runner_username}")
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_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_0040_vcd_cse_cluster_and_node_operations(config, vcd_org_admin, delete_test_cluster): """Test cse cluster/node commands. This test function contains several sub-test blocks that can be commented out or moved around for speed optimization purposes during testing. """ # keeps track of the number of nodes that should exist. # Streamlines assert statements when checking node count num_nodes = 0 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 # vcd cse template list # retrieves template names to test cluster deployment against cmd = 'cse template list' print(f"\nRunning command [vcd {cmd}]...", end='') result = env.CLI_RUNNER.invoke(vcd, ['cse', 'template', 'list'], catch_exceptions=False) assert result.exit_code == 0,\ testutils.format_command_info('vcd', cmd, result.exit_code, result.output) print('SUCCESS') template_names = [config['broker']['default_template']] if env.TEST_ALL_TEMPLATES: template_pattern = r'(True|False)\s*(\S*)' matches = re.findall(template_pattern, result.output) template_names = [match[1] for match in matches] # tests for cluster operations has_run = False # some tests do not need to run for each template for template_name in template_names: print(f'\nTesting cluster operations for template: {template_name}\n') # vcd cse cluster create testcluster -n NETWORK -N 1 -t PHOTON cmd = f"cse cluster create {env.TEST_CLUSTER_NAME} -n " \ f"{config['broker']['network']} -N 1 -t {template_name}" num_nodes += 1 print(f"Running command [vcd {cmd}]...", end='') 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 doesn't exist when it should." print(f"SUCCESS") nodes = check_node_list() # `cluster config`, `cluster info`, `cluster list`, `node info` # only need to run once if not has_run: cmds = [ f"cse cluster config {env.TEST_CLUSTER_NAME}", f"cse cluster info {env.TEST_CLUSTER_NAME}", f"cse cluster list", f"cse node info {env.TEST_CLUSTER_NAME} {nodes[0]}" ] for cmd in cmds: print(f"Running command [vcd {cmd}]...", end='') 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) print('SUCCESS') has_run = True # vcd cse node delete testcluster TESTNODE cmd = f"cse node delete {env.TEST_CLUSTER_NAME} {nodes[0]}" num_nodes -= 1 print(f"Running command [vcd {cmd}]...", end='') result = env.CLI_RUNNER.invoke(vcd, cmd.split(), input='y', catch_exceptions=False) assert result.exit_code == 0,\ testutils.format_command_info('vcd', cmd, result.exit_code, result.output) print('SUCCESS') check_node_list() # vcd cse node create testcluster -n NETWORK -t PHOTON cmd = f"cse node create {env.TEST_CLUSTER_NAME} -n " \ f"{config['broker']['network']} -t {template_name}" num_nodes += 1 print(f"Running command [vcd {cmd}]...", end='') 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) print('SUCCESS') check_node_list() # vcd cse cluster delete testcluster cmd = f"cse cluster delete {env.TEST_CLUSTER_NAME}" print(f"Running command [vcd {cmd}]...", end='') result = env.CLI_RUNNER.invoke(vcd, cmd.split(), input='y', catch_exceptions=False) assert result.exit_code == 0,\ testutils.format_command_info('vcd', cmd, result.exit_code, result.output) assert not env.vapp_exists(env.TEST_CLUSTER_NAME), \ "Cluster exists when it should not" num_nodes = 0 print('SUCCESS')
def test_0130_vcd_cse_cluster_delete(config): """Test 'vcd cse cluster delete ...' command for various cse users. Cluster delete operation on the above create clusters operations- Vapp Author can only delete self created clusters. Org admin can delete all cluster in the organization. :param config: cse config file for vcd configuration """ cmd_binder = collections.namedtuple( 'UserCmdBinder', 'cmd exit_code validate_output_func ' 'test_user') print(f"Running cluster delete operations") cmd_list = [ cmd_binder(cmd=env.VAPP_AUTHOR_LOGIN_CMD, exit_code=0, validate_output_func=None, test_user=env.VAPP_AUTHOR_NAME), cmd_binder( cmd=f"cse cluster delete " f"{env.USERNAME_TO_CLUSTER_NAME[env.SYS_ADMIN_NAME]}", # noqa exit_code=2, validate_output_func=None, test_user=env.VAPP_AUTHOR_NAME), cmd_binder( cmd=f"cse cluster delete " f"{env.USERNAME_TO_CLUSTER_NAME[env.ORG_ADMIN_NAME]}", # noqa exit_code=2, validate_output_func=None, test_user=env.VAPP_AUTHOR_NAME), cmd_binder( cmd=f"cse cluster delete " f"{env.USERNAME_TO_CLUSTER_NAME[env.VAPP_AUTHOR_NAME]}", # noqa exit_code=0, validate_output_func=None, test_user=env.VAPP_AUTHOR_NAME), cmd_binder(cmd=env.USER_LOGOUT_CMD, exit_code=0, validate_output_func=None, test_user=env.VAPP_AUTHOR_NAME), cmd_binder(cmd=env.ORG_ADMIN_LOGIN_CMD, exit_code=0, validate_output_func=None, test_user=env.ORG_ADMIN_NAME), cmd_binder(cmd=f"org use {config['broker']['org']}", exit_code=0, validate_output_func=None, test_user='******'), cmd_binder( cmd=f"cse cluster delete " f"{env.USERNAME_TO_CLUSTER_NAME[env.SYS_ADMIN_NAME]}", # noqa exit_code=0, validate_output_func=None, test_user=env.ORG_ADMIN_NAME), cmd_binder( cmd=f"cse cluster delete " f"{env.USERNAME_TO_CLUSTER_NAME[env.ORG_ADMIN_NAME]}", # noqa exit_code=0, validate_output_func=None, test_user=env.ORG_ADMIN_NAME), cmd_binder(cmd=env.USER_LOGOUT_CMD, exit_code=0, validate_output_func=None, test_user=env.ORG_ADMIN_NAME) ] execute_commands(cmd_list) for cluster_name in env.USERNAME_TO_CLUSTER_NAME.values(): assert not env.vapp_exists(cluster_name), \ f"Cluster {cluster_name} exists when it should not" print(f"Successfully deleted clusters.")
def test_0050_vcd_cse_system_toggle(config, test_runner_username, delete_test_clusters): """Test `vcd cse system ...` commands. Test that on disabling CSE, cluster deployments are no longer allowed, and on enabling CSE, cluster deployments are allowed again. These commands are combined into 1 test function because only sys admin can modify the state of CSE server, org admin/tenant can test cluster deployment to ensure that CSE is disabled/enabled. Also, this avoids cases such as running the system disable test, and then running the cluster operations test, which would fail due to CSE server being disabled). :param config: cse config file for vcd configuration :param test_runner_username: parameterized persona to run tests with different users """ # Batch cse commands together in a list and then execute them one by one cmd_binder = collections.namedtuple( 'UserCmdBinder', 'cmd exit_code validate_output_func' ' test_user') cmd_list = [ cmd_binder(cmd=env.SYS_ADMIN_LOGIN_CMD, exit_code=0, validate_output_func=None, test_user='******'), cmd_binder(cmd="cse system disable", exit_code=0, validate_output_func=None, test_user='******'), cmd_binder(cmd=env.USERNAME_TO_LOGIN_CMD[test_runner_username], exit_code=0, validate_output_func=None, test_user=test_runner_username), cmd_binder(cmd=f"org use {env.TEST_ORG}", exit_code=0, validate_output_func=None, test_user=test_runner_username), cmd_binder(cmd=f"cse cluster create {env.SYS_ADMIN_TEST_CLUSTER_NAME} " f"-n {env.TEST_NETWORK} -N 1", exit_code=2, validate_output_func=None, test_user=test_runner_username), cmd_binder(cmd=env.USER_LOGOUT_CMD, exit_code=0, validate_output_func=None, test_user=test_runner_username), cmd_binder(cmd=env.SYS_ADMIN_LOGIN_CMD, exit_code=0, validate_output_func=None, test_user='******'), cmd_binder(cmd="cse system enable", exit_code=0, validate_output_func=None, test_user='******'), cmd_binder(cmd=f"cse cluster create {env.SYS_ADMIN_TEST_CLUSTER_NAME} " f"-n {env.TEST_NETWORK} -N 1 -c 1000 " f"--disable-rollback", exit_code=2, validate_output_func=None, test_user='******'), cmd_binder(cmd=env.USER_LOGOUT_CMD, exit_code=0, validate_output_func=None, test_user='******') ] execute_commands(cmd_list) assert not env.vapp_exists(env.SYS_ADMIN_TEST_CLUSTER_NAME, vdc_href=env.TEST_VDC_HREF), \ "Cluster exists when it should not."
def test_0040_vcd_cse_cluster_apply( cluster_apply_param: CLUSTER_APPLY_TEST_PARAM): # noqa: E501 """Test 'vcd cse cluster create ...' command for various cse users. Test cluster creation from different persona's- sys_admin, org_admin and k8_author. Created clusters will remain in the system for further command tests - list, resize and delete. :param config: cse config file for vcd configuration :param test_runner_username: parameterized persona to run tests with different users """ print(f"Running cluster create operation for {cluster_apply_param.user}") exit_code = 0 if cluster_apply_param.expected_phase == 'UPDATE:FAILED': # Validation failure during cluster update will fail the command # execution before task is generated. exit_code = 2 expect_failure = "FAILED" in cluster_apply_param.expected_phase cmd_list = [ testutils.CMD_BINDER( cmd=f"cse cluster apply {env.APPLY_SPEC_PATH} ", exit_code=exit_code, validate_output_func=_follow_apply_output( expect_failure=expect_failure), # noqa: E501 test_user=cluster_apply_param.user) ] testutils.execute_commands(cmd_list, logger=PYTEST_LOGGER) created_cluster_name = cluster_apply_param.cluster_name rollback = cluster_apply_param.rollback if "CREATE" in cluster_apply_param.expected_phase: if "SUCCEEDED" in cluster_apply_param.expected_phase: assert env.vapp_exists(created_cluster_name, vdc_href=env.TEST_VDC_HREF), \ f"Expected VApp to be present for cluster {created_cluster_name}" # noqa: E501 assert env.rde_exists(created_cluster_name), \ f"Expected RDE to be present for cluster {created_cluster_name}" # noqa: E501 assert _get_cluster_phase(created_cluster_name, cluster_apply_param.user) == 'CREATE:SUCCEEDED', \ "Expected RDE phase to be 'CREATE:SUCCEEDED'" # noqa: E501 if "FAILED" in cluster_apply_param.expected_phase: if rollback: assert not env.vapp_exists(created_cluster_name, vdc_href=env.TEST_VDC_HREF), \ f"Expected VApp to be present for cluster {created_cluster_name}" # noqa: E501 assert not env.rde_exists(created_cluster_name), \ f"Expected RDE to be present for cluster {created_cluster_name}" # noqa: E501 else: # During failure, cannot garauntee vapp creation assert env.rde_exists(created_cluster_name), \ f"Expected RDE for the cluster {created_cluster_name} to be present" # noqa: E501 assert _get_cluster_phase(created_cluster_name, cluster_apply_param.user) == 'CREATE:FAILED', \ "Expected RDE phase to be 'CREATE:FAILED'" # noqa: E501 if "UPDATE" in cluster_apply_param.expected_phase: if "SUCCEEDED" in cluster_apply_param.expected_phase: cmd_list = [ testutils.CMD_BINDER( cmd=f"cse cluster info {created_cluster_name}", # noqa exit_code=0, validate_output_func=testutils. generate_validate_node_count_func( # noqa: E501 expected_nodes=cluster_apply_param. worker_count, # noqa: E501 rde_version=get_runtime_rde_version_by_vcd_api_version( env.VCD_API_VERSION_TO_USE), # noqa: E501 logger=PYTEST_LOGGER), # noqa: E501 test_user=cluster_apply_param.user) ] testutils.execute_commands(cmd_list, logger=PYTEST_LOGGER) # common for both succeeded and failed conditions assert _get_cluster_phase(created_cluster_name, cluster_apply_param.user) == cluster_apply_param.expected_phase, \ f"Expected RDE phase to be {cluster_apply_param.expected_phase}" # noqa: E501 # logout user env.CLI_RUNNER.invoke(vcd, env.USER_LOGOUT_CMD, catch_exceptions=False)