diff --git a/config/k8s/files/default.json5 b/config/k8s/files/default.json5 index 2b2a66ba..ca2cd8f6 100644 --- a/config/k8s/files/default.json5 +++ b/config/k8s/files/default.json5 @@ -1,4 +1,5 @@ { // KUBECONFIG environment variable on the cloud_platform system. "kubeconfig": "/etc/kubernetes/admin.conf", + "dashboard_port": "8443" } \ No newline at end of file diff --git a/config/k8s/objects/k8s_config.py b/config/k8s/objects/k8s_config.py index 53613450..d185c430 100644 --- a/config/k8s/objects/k8s_config.py +++ b/config/k8s/objects/k8s_config.py @@ -15,10 +15,17 @@ class K8sConfig: raise k8s_dict = json5.load(json_data) - self.kubeconfig = k8s_dict['kubeconfig'] + self.kubeconfig = k8s_dict["kubeconfig"] + self.dashboard_port = k8s_dict["dashboard_port"] def get_kubeconfig(self) -> str: """ Getter for the KUBECONFIG environment variable on the lab where we want to run. """ return self.kubeconfig + + def get_dashboard_port(self) -> str: + """ + Getter for the port on which the K8s dashboard is running. + """ + return self.dashboard_port diff --git a/keywords/cloud_platform/openstack/endpoint/openstack_endpoint_list_keywords.py b/keywords/cloud_platform/openstack/endpoint/openstack_endpoint_list_keywords.py index 257e4045..7581ce59 100644 --- a/keywords/cloud_platform/openstack/endpoint/openstack_endpoint_list_keywords.py +++ b/keywords/cloud_platform/openstack/endpoint/openstack_endpoint_list_keywords.py @@ -1,3 +1,4 @@ +from config.configuration_manager import ConfigurationManager from framework.ssh.ssh_connection import SSHConnection from keywords.base_keyword import BaseKeyword from keywords.cloud_platform.command_wrappers import source_openrc @@ -15,11 +16,21 @@ class OpenStackEndpointListKeywords(BaseKeyword): def endpoint_list(self): """ Keyword for openstack endpoint list - Returns: + Returns: + OpenStackEndpointListOutput object """ - output = self.ssh_connection.send(source_openrc('openstack endpoint list')) + output = self.ssh_connection.send(source_openrc("openstack endpoint list")) self.validate_success_return_code(self.ssh_connection) openstack_endpoint_list_output = OpenStackEndpointListOutput(output) return openstack_endpoint_list_output + + def get_k8s_dashboard_url(self) -> str: + """ + Getter for the URL of the K8s dashboard. + """ + endpoint_output = self.endpoint_list() + url = endpoint_output.get_endpoint("keystone", "public").get_url().rsplit(":", 1)[0] + end_point = f"{url}:{ConfigurationManager.get_k8s_config().get_dashboard_port()}" + return end_point diff --git a/keywords/k8s/secret/kubectl_delete_secret_keywords.py b/keywords/k8s/secret/kubectl_delete_secret_keywords.py index 409047f5..3b7ef068 100644 --- a/keywords/k8s/secret/kubectl_delete_secret_keywords.py +++ b/keywords/k8s/secret/kubectl_delete_secret_keywords.py @@ -1,3 +1,5 @@ +from framework.logging.automation_logger import get_logger +from framework.ssh.ssh_connection import SSHConnection from keywords.base_keyword import BaseKeyword from keywords.k8s.k8s_command_wrapper import export_k8s_config @@ -7,24 +9,44 @@ class KubectlDeleteSecretsKeywords(BaseKeyword): Keywords for delete secrets """ - def __init__(self, ssh_connection): + def __init__(self, ssh_connection: SSHConnection): """ Constructor + Args: - ssh_connection: + ssh_connection (SSHConnection): The SSH connection object """ self.ssh_connection = ssh_connection def delete_secret(self, secret_name: str, namespace: str) -> str: """ - Deletes the secret + Deletes the specified Kubernetes secret in the given namespace. + Args: - secret_name (): the secret - - Returns: the output + secret_name (str): The name of the secret to delete. + namespace (str): The namespace where the secret is located. + Returns: + str: The output from the kubectl delete command. """ output = self.ssh_connection.send(export_k8s_config(f"kubectl delete -n {namespace} secret {secret_name}")) self.validate_success_return_code(self.ssh_connection) return output + + def cleanup_secret(self, secret_name: str, namespace: str) -> str: + """ + This method is intended for use in cleanup operations as it doesn't automatically fail the test. + + Args: + secret_name (str): The name of the secret to delete. + namespace (str): The namespace where the secret is located. + + Returns: + str: The output of the delete operation. + """ + self.ssh_connection.send(export_k8s_config(f"kubectl delete -n {namespace} secret {secret_name}")) + rc = self.ssh_connection.get_return_code() + if rc != 0: + get_logger().log_error(f"Secret {secret_name} failed to delete") + return rc diff --git a/testcases/cloud_platform/regression/containers/test_k8s_dashboard.py b/testcases/cloud_platform/regression/containers/test_k8s_dashboard.py index 849b9901..2a4fd21e 100644 --- a/testcases/cloud_platform/regression/containers/test_k8s_dashboard.py +++ b/testcases/cloud_platform/regression/containers/test_k8s_dashboard.py @@ -9,26 +9,17 @@ from framework.logging.automation_logger import get_logger from framework.resources.resource_finder import get_stx_resource_path from framework.rest.rest_client import RestClient from framework.ssh.ssh_connection import SSHConnection +from keywords.cloud_platform.openstack.endpoint.openstack_endpoint_list_keywords import OpenStackEndpointListKeywords from keywords.cloud_platform.ssh.lab_connection_keywords import LabConnectionKeywords from keywords.files.file_keywords import FileKeywords from keywords.k8s.files.kubectl_file_apply_keywords import KubectlFileApplyKeywords from keywords.k8s.files.kubectl_file_delete_keywords import KubectlFileDeleteKeywords -from keywords.k8s.namespace.kubectl_create_namespace_keywords import ( - KubectlCreateNamespacesKeywords, -) -from keywords.k8s.namespace.kubectl_delete_namespace_keywords import ( - KubectlDeleteNamespaceKeywords, -) -from keywords.k8s.namespace.kubectl_get_namespaces_keywords import ( - KubectlGetNamespacesKeywords, -) +from keywords.k8s.namespace.kubectl_create_namespace_keywords import KubectlCreateNamespacesKeywords +from keywords.k8s.namespace.kubectl_delete_namespace_keywords import KubectlDeleteNamespaceKeywords +from keywords.k8s.namespace.kubectl_get_namespaces_keywords import KubectlGetNamespacesKeywords from keywords.k8s.patch.kubectl_apply_patch_keywords import KubectlApplyPatchKeywords -from keywords.k8s.secret.kubectl_create_secret_keywords import ( - KubectlCreateSecretsKeywords, -) -from keywords.k8s.secret.kubectl_delete_secret_keywords import ( - KubectlDeleteSecretsKeywords, -) +from keywords.k8s.secret.kubectl_create_secret_keywords import KubectlCreateSecretsKeywords +from keywords.k8s.secret.kubectl_delete_secret_keywords import KubectlDeleteSecretsKeywords from keywords.openssl.openssl_keywords import OpenSSLKeywords @@ -105,7 +96,7 @@ def create_k8s_dashboard(request: fixture, namespace: str, con_ssh: SSHConnectio def teardown(): KubectlFileDeleteKeywords(ssh_connection=con_ssh).delete_resources(k8s_dashboard_file_path) # delete created dashboard secret - KubectlDeleteSecretsKeywords(con_ssh).delete_secret(namespace=namespace, secret_name=secrets_name) + KubectlDeleteSecretsKeywords(con_ssh).cleanup_secret(namespace=namespace, secret_name=secrets_name) get_logger().log_info("Deleting k8s_dashboard directory") con_ssh.send(f"rm -rf {home_k8s}") @@ -118,8 +109,7 @@ def create_k8s_dashboard(request: fixture, namespace: str, con_ssh: SSHConnectio time.sleep(30) get_logger().log_info(f"Verify that {name} is working") - end_point = "https://{}:{}".format(sys_domain_name, port) - + end_point = OpenStackEndpointListKeywords(ssh_connection=con_ssh).get_k8s_dashboard_url() status_code, _ = check_url_access(end_point) if not status_code == 200: raise KeywordException(detailed_message=f"Kubernetes dashboard returned status code {status_code}")