def test_0100_vcd_cse_cluster_config(test_runner_username): cmd_binder = collections.namedtuple( 'UserCmdBinder', 'cmd exit_code validate_output_func ' 'test_user') print(f"Running cluster config operation for {test_runner_username} on " f"{env.USERNAME_TO_CLUSTER_NAME[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"cse cluster config {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]}", # noqa 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) print( f"Successful cluster config on {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]}." ) # noqa
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 """ template_name = env.TEMPLATE_DEFINITIONS[0]['name'] template_revision = env.TEMPLATE_DEFINITIONS[0]['revision'] # 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 -t {template_name}" f" -r {template_revision}", 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 -t {template_name}" f" -r {template_revision} --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_0110_vcd_cse_cluster_resize(test_runner_username, config): """Test 'vcd cse cluster resize ...' commands.""" node_pattern = r'(node-\S+)' cmd_binder = collections.namedtuple( 'UserCmdBinder', 'cmd exit_code validate_output_func ' 'test_user') print(f"Running cluster info 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 info {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]}", # noqa exit_code=0, validate_output_func=None, test_user=test_runner_username) ] cmd_results = execute_commands(cmd_list) num_nodes = len(re.findall(node_pattern, cmd_results[-1].output)) print(f"Running cluster resize operation for {test_runner_username}") cmd_list = [ cmd_binder( cmd= f"cse cluster resize -N {num_nodes+1} -n {config['broker']['network']}" # noqa f" {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]}", # noqa: E501 exit_code=0, validate_output_func=generate_validate_node_count_func(num_nodes + 1), # noqa test_user=test_runner_username), cmd_binder( cmd= f"cse cluster resize -N 0 -n {config['broker']['network']}" # noqa f" {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]}", # noqa: E501 exit_code=0, validate_output_func=generate_validate_node_count_func(0), # noqa test_user=test_runner_username) ] execute_commands(cmd_list) print( f"Successful cluster resize on {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]}." ) # noqa
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_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_0050_vcd_cse_delete_nfs(test_runner_username): """Test delete nfs node command.""" cluster_name = env.USERNAME_TO_CLUSTER_NAME[test_runner_username] cmd_list = [ testutils.CMD_BINDER( cmd=env.USERNAME_TO_LOGIN_CMD[test_runner_username], # noqa: E501 exit_code=0, validate_output_func=None, test_user=test_runner_username), testutils.CMD_BINDER(cmd=f"org use {env.TEST_ORG}", exit_code=0, validate_output_func=None, test_user=test_runner_username), testutils.CMD_BINDER(cmd=f"vdc use {env.TEST_VDC}", exit_code=0, validate_output_func=None, test_user=test_runner_username) ] testutils.execute_commands(cmd_list, logger=PYTEST_LOGGER) cmd_list = [ testutils.CMD_BINDER( cmd= f"cse cluster info {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]}", # noqa: E501 exit_code=0, validate_output_func=None, test_user=test_runner_username) ] cmd_results = testutils.execute_commands(cmd_list, logger=PYTEST_LOGGER) nfs_node = get_nfs_node(cmd_results[0].output) cmd_list = [ testutils.CMD_BINDER( cmd= f"cse cluster delete-nfs {cluster_name} {nfs_node}", # noqa: E501 exit_code=0, validate_output_func=None, test_user=test_runner_username), testutils.CMD_BINDER( cmd=f"cse cluster info {cluster_name}", exit_code=0, validate_output_func=validate_if_node_not_present( nfs_node), # noqa: E501 test_user=test_runner_username) ] testutils.execute_commands(cmd_list, logger=PYTEST_LOGGER)
def _get_cluster_phase(cluster_name, test_runner_username, org_name=None, vdc_name=None): # noqa: E501 if not org_name and not vdc_name: org_name = env.TEST_ORG vdc_name = env.TEST_VDC cmd_list = [ testutils.CMD_BINDER( cmd=env.USERNAME_TO_LOGIN_CMD[test_runner_username], exit_code=0, validate_output_func=None, test_user=test_runner_username), testutils.CMD_BINDER( cmd=f"cse cluster info {cluster_name} -o {org_name} -v {vdc_name}", exit_code=0, validate_output_func=None, test_user=test_runner_username), ] result = testutils.execute_commands(cmd_list=cmd_list, logger=PYTEST_LOGGER)[-1] # noqa: E501 if result.exit_code != 0: raise Exception("Cluster {cluster_name} not found.") match = re.search(r'phase: (\w+:\w+)', result.output) return match[1]
def test_0080_vcd_cse_cluster_list(test_runner_username): cmd_binder = collections.namedtuple('UserCmdBinder', 'cmd exit_code validate_output_func ' 'test_user') print(f"Running cluster list 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"cse cluster list", exit_code=0, validate_output_func=list_cluster_output_validator, 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) print(f"Successfully listed cluster for {test_runner_username}.")
def test_0060_vcd_cse_cluster_list(test_runner_username): cmd_list = [ testutils.CMD_BINDER( cmd=env.USERNAME_TO_LOGIN_CMD[test_runner_username], # noqa: E501 exit_code=0, validate_output_func=None, test_user=test_runner_username), testutils.CMD_BINDER(cmd="cse cluster list", exit_code=0, validate_output_func=None, test_user=test_runner_username), testutils.CMD_BINDER(cmd=env.USER_LOGOUT_CMD, exit_code=0, validate_output_func=None, test_user=test_runner_username) ] testutils.execute_commands(cmd_list, logger=PYTEST_LOGGER)
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_0110_vcd_cse_cluster_resize(test_runner_username, config): """Test 'vcd cse cluster resize ...' commands.""" node_pattern = r'(node-\S+)' 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 info 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 info {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]}", # noqa exit_code=0, validate_output_func=None, test_user=test_runner_username) ] cmd_results = execute_commands(cmd_list) num_nodes = len(re.findall(node_pattern, cmd_results[-1].output)) print(f"Running cluster resize operation for {test_runner_username}") cmd_list = [ cmd_binder(cmd=f"cse cluster resize -N {num_nodes+1} -n {env.TEST_NETWORK}" # noqa f" {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]}" f" -t {template_name} -r {template_revision}", exit_code=0, validate_output_func=generate_validate_node_count_func(num_nodes+1), # noqa test_user=test_runner_username), cmd_binder(cmd=f"cse cluster resize -N 0 -n {env.TEST_NETWORK}" # noqa f" {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]}", # noqa: E501 exit_code=0, validate_output_func=generate_validate_node_count_func(0), # noqa test_user=test_runner_username) ] execute_commands(cmd_list) print(f"Successful cluster resize on {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]}.") # noqa
def test_0080_vcd_cse_cluster_config(test_runner_username): cmd_list = [ testutils.CMD_BINDER( cmd=env.USERNAME_TO_LOGIN_CMD[test_runner_username], # noqa: E501 exit_code=0, validate_output_func=None, test_user=test_runner_username), testutils.CMD_BINDER( cmd= f"cse cluster config {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]}", # noqa: E501 exit_code=0, validate_output_func=testutils.validate_yaml_output( ), # noqa: E501 test_user=test_runner_username), testutils.CMD_BINDER(cmd=env.USER_LOGOUT_CMD, exit_code=0, validate_output_func=None, test_user=test_runner_username) ] testutils.execute_commands(cmd_list, logger=PYTEST_LOGGER)
def test_0030_vcd_cse_system_toggle( system_toggle_test_case: SYSTEM_TOGGLE_TEST_PARAM): # noqa: E501 """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 """ cmd_list = [ testutils.CMD_BINDER(cmd="cse system disable", exit_code=0, validate_output_func=None, test_user=system_toggle_test_case.user), testutils.CMD_BINDER(cmd=f"cse cluster apply {env.APPLY_SPEC_PATH}", exit_code=2, validate_output_func=None, test_user=system_toggle_test_case.user), testutils.CMD_BINDER(cmd="cse system enable", exit_code=0, validate_output_func=None, test_user=system_toggle_test_case.user), testutils.CMD_BINDER( cmd=f"cse cluster apply {env.APPLY_SPEC_PATH} ", exit_code=0, validate_output_func=_follow_apply_output( expect_failure=True), # noqa: E501 test_user=system_toggle_test_case.user) ] testutils.execute_commands(cmd_list, logger=PYTEST_LOGGER)
def validator(output, test_runner_username): cmd_binder = collections.namedtuple('UserCmdBinder', 'cmd exit_code validate_output_func ' # noqa: E501 'test_user') print(f"Running cluster info operation for {test_runner_username}") cmd_list = [ cmd_binder(cmd=f"cse cluster info {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]}", # noqa exit_code=0, validate_output_func=None, test_user=test_runner_username) ] cmd_results = execute_commands(cmd_list) return len(re.findall(node_pattern, cmd_results[0].output)) == expected_nodes # noqa
def test_0110_vcd_cse_node_operation(test_runner_username, config): """Test 'vcd cse node create/list/info/delete ...' commands. Test node creation from different persona's- sys_admin, org_admin and vapp_author. Created nodes will remain in the system for further command tests - list and delete. :param config: cse config file for vcd configuration :param test_runner_username: parameterized persona to run tests with different users """ node_pattern = r'(node-\S+)' num_nodes = 1 cmd_binder = collections.namedtuple( 'UserCmdBinder', 'cmd exit_code validate_output_func ' 'test_user') print(f"Running node add 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 node create {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]}" # noqa f" -n {config['broker']['network']}", exit_code=0, validate_output_func=None, test_user=test_runner_username) ] execute_commands(cmd_list) # Increase Node count by 1 num_nodes += 1 print(f"Successfully added node to cluster " f"{env.USERNAME_TO_CLUSTER_NAME[test_runner_username]}") print(f"Running node list operation for {test_runner_username}") cmd_list = [ cmd_binder( cmd= f"cse node list {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]}", # noqa exit_code=0, validate_output_func=None, test_user=test_runner_username) ] cmd_results = execute_commands(cmd_list) assert len(re.findall(node_pattern, cmd_results[0].output)) == num_nodes print( f"Successful node list on cluster {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]}." ) # noqa # Get cse node name to be used for info and delete node_names = list(re.findall(node_pattern, cmd_results[0].output)) node_name = node_names[0] print(f"Running node info operation on cluster " f"{env.USERNAME_TO_CLUSTER_NAME[test_runner_username]} for" f" node {node_name}") cmd_list = [ cmd_binder( cmd= f"cse node info {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]} " # noqa f"{node_name}", exit_code=0, validate_output_func=None, test_user=test_runner_username) ] execute_commands(cmd_list) print(f"Successful node info on {node_name}.") # noqa print(f"Running node delete operation for {test_runner_username} on " f"cluster {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]} " f"to delete node {node_name}") cmd_list = [ cmd_binder( cmd= f"cse node delete {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]} " # noqa f"{node_name}", exit_code=0, validate_output_func=None, test_user=test_runner_username), ] execute_commands(cmd_list) # Decrease Node count by 1 num_nodes -= 1 print(f"Successfully deleted node {node_name} from " f"{env.USERNAME_TO_CLUSTER_NAME[test_runner_username]}") cmd_list = [ cmd_binder( cmd= f"cse node list {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]} ", # noqa 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) ] cmd_results = execute_commands(cmd_list) assert len(re.findall(node_pattern, cmd_results[0].output)) == num_nodes print( f"Successful node list on cluster {env.USERNAME_TO_CLUSTER_NAME[test_runner_username]}." ) # noqa
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)