From 9c2636c6055d65e336e1e2d58908d5c7bcd7ba19 Mon Sep 17 00:00:00 2001 From: "Francischini de Souza, Gabriel" Date: Wed, 28 May 2025 15:19:53 -0300 Subject: [PATCH] Adding support for power metrics app Change-Id: I493cf7b4f6874c040070108f409f419b59ecaa28 --- config/app/files/default.json5 | 3 +- config/app/objects/app_config.py | 11 ++ .../power_metrics/test_power_metrics.py | 101 ++++++++++++++++++ unit_tests/config/app/app_config_test.py | 2 + unit_tests/config/app/custom_app_config.json5 | 3 +- 5 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 testcases/cloud_platform/apps_setup/power_metrics/test_power_metrics.py diff --git a/config/app/files/default.json5 b/config/app/files/default.json5 index 92abeefe..1936f7ce 100644 --- a/config/app/files/default.json5 +++ b/config/app/files/default.json5 @@ -2,5 +2,6 @@ base_application_path: "/usr/local/share/applications/helm/", istio_app_name: "istio", metric_server_app_name: "metrics-server", - oidc_app_name: "oidc-auth-apps" + oidc_app_name: "oidc-auth-apps", + power_metrics_app_name: "power-metrics" } \ No newline at end of file diff --git a/config/app/objects/app_config.py b/config/app/objects/app_config.py index f586af7b..8c3ed7d2 100644 --- a/config/app/objects/app_config.py +++ b/config/app/objects/app_config.py @@ -18,6 +18,7 @@ class AppConfig: self.istio_app_name = app_dict["istio_app_name"] self.metric_server_app_name = app_dict["metric_server_app_name"] self.oidc_app_name = app_dict["oidc_app_name"] + self.power_metrics_app_name = app_dict["power_metrics_app_name"] def get_base_application_path(self) -> str: """ @@ -58,3 +59,13 @@ class AppConfig: """ return self.oidc_app_name + + def get_power_metrics_app_name(self) -> str: + """ + Getter for power metrics app name + + Returns: + str: the power metrics app name path + + """ + return self.power_metrics_app_name diff --git a/testcases/cloud_platform/apps_setup/power_metrics/test_power_metrics.py b/testcases/cloud_platform/apps_setup/power_metrics/test_power_metrics.py new file mode 100644 index 00000000..82582fac --- /dev/null +++ b/testcases/cloud_platform/apps_setup/power_metrics/test_power_metrics.py @@ -0,0 +1,101 @@ +from config.configuration_manager import ConfigurationManager +from keywords.cloud_platform.ssh.lab_connection_keywords import LabConnectionKeywords + +from keywords.cloud_platform.system.application.system_application_list_keywords import SystemApplicationListKeywords +from keywords.cloud_platform.system.application.system_application_upload_keywords import SystemApplicationUploadKeywords +from keywords.cloud_platform.system.application.system_application_apply_keywords import SystemApplicationApplyKeywords +from keywords.cloud_platform.system.application.system_application_remove_keywords import SystemApplicationRemoveKeywords +from keywords.cloud_platform.system.application.system_application_delete_keywords import SystemApplicationDeleteKeywords + +from keywords.cloud_platform.system.application.system_application_upload_keywords import SystemApplicationUploadInput +from keywords.cloud_platform.system.application.system_application_remove_keywords import SystemApplicationRemoveInput +from keywords.cloud_platform.system.application.system_application_delete_keywords import SystemApplicationDeleteInput +from keywords.cloud_platform.system.application.object.system_application_status_enum import SystemApplicationStatusEnum + +from keywords.cloud_platform.system.host.system_host_label_keywords import SystemHostLabelKeywords + +from framework.validation.validation import validate_equals, validate_not_equals + + +def test_install_power_metrics(): + """ + Install (Upload and Apply) Application Power Metrics + + Raises: + Exception: If application Power Metrics failed to upload or apply + """ + + # Setups app configs and lab connection + app_config = ConfigurationManager.get_app_config() + base_path = app_config.get_base_application_path() + power_metrics_name = app_config.get_power_metrics_app_name() + lab_connect_keywords = LabConnectionKeywords() + ssh_connection = lab_connect_keywords.get_active_controller_ssh() + system_host_label_keywords = SystemHostLabelKeywords(ssh_connection) + lab_config = ConfigurationManager.get_lab_config() + nodes = lab_config.get_nodes() + + for node in lab_config.get_nodes(): + system_host_label_keywords.system_host_label_assign(node.get_name(), "power-metrics=enabled") + + # Verifies if the app is present in the system + system_applications = SystemApplicationListKeywords(ssh_connection).get_system_application_list() + validate_equals(system_applications.is_in_application_list(power_metrics_name), False, f"The {power_metrics_name} application should not be already uploaded/applied on the system") + + # Setups the upload input object + system_application_upload_input = SystemApplicationUploadInput() + system_application_upload_input.set_app_name(power_metrics_name) + system_application_upload_input.set_tar_file_path(f"{base_path}{power_metrics_name}*.tgz") + + # Uploads the app file and verifies it + SystemApplicationUploadKeywords(ssh_connection).system_application_upload(system_application_upload_input) + system_applications = SystemApplicationListKeywords(ssh_connection).get_system_application_list() + power_metrics_app_status = system_applications.get_application(power_metrics_name).get_status() + validate_equals(power_metrics_app_status, "uploaded", f"{power_metrics_name} upload status validation") + + # Applies the app to the active controller + system_application_apply_output = SystemApplicationApplyKeywords(ssh_connection).system_application_apply(power_metrics_name) + + # Verifies the app was applied + system_application_object = system_application_apply_output.get_system_application_object() + validate_not_equals(system_application_object, None, f"System application object should not be None") + validate_equals(system_application_object.get_name(), power_metrics_name, f"Application name validation") + validate_equals(system_application_object.get_status(), SystemApplicationStatusEnum.APPLIED.value, f"Application status validation") + + +def test_uninstall_power_metrics(): + """ + Uninstall (Remove and Delete) Application Power Metrics + + Raises: + Exception: If application Power Metrics failed to remove or delete + """ + + # Setups app configs and lab connection + app_config = ConfigurationManager.get_app_config() + power_metrics_name = app_config.get_power_metrics_app_name() + lab_connect_keywords = LabConnectionKeywords() + ssh_connection = lab_connect_keywords.get_active_controller_ssh() + system_host_label_keywords = SystemHostLabelKeywords(ssh_connection) + lab_config = ConfigurationManager.get_lab_config() + + for node in lab_config.get_nodes(): + system_host_label_keywords.system_host_label_remove(node.get_name(), "power-metrics") + + # Verifies if the app is not present in the system + system_applications = SystemApplicationListKeywords(ssh_connection).get_system_application_list() + validate_equals(system_applications.is_in_application_list(power_metrics_name), True, f"The {power_metrics_name} application should be uploaded/applied on the system") + + # Removes the application + system_application_remove_input = SystemApplicationRemoveInput() + system_application_remove_input.set_app_name(power_metrics_name) + system_application_remove_input.set_force_removal(False) + system_application_output = SystemApplicationRemoveKeywords(ssh_connection).system_application_remove(system_application_remove_input) + validate_equals(system_application_output.get_system_application_object().get_status(), SystemApplicationStatusEnum.UPLOADED.value, f"Application removal status validation") + + # Deletes the application + system_application_delete_input = SystemApplicationDeleteInput() + system_application_delete_input.set_app_name(power_metrics_name) + system_application_delete_input.set_force_deletion(False) + delete_msg = SystemApplicationDeleteKeywords(ssh_connection).get_system_application_delete(system_application_delete_input) + validate_equals(delete_msg, f"Application {power_metrics_name} deleted.\n", f"Application deletion message validation") diff --git a/unit_tests/config/app/app_config_test.py b/unit_tests/config/app/app_config_test.py index fc176277..16ea8867 100644 --- a/unit_tests/config/app/app_config_test.py +++ b/unit_tests/config/app/app_config_test.py @@ -17,6 +17,7 @@ def test_default_app_config(): assert default_config.get_istio_app_name() == "istio", "istio default app name was incorrect" assert default_config.get_metric_server_app_name() == "metrics-server", "metric server default name was incorrect" assert default_config.get_oidc_app_name() == "oidc-auth-apps", "oidc default app name was incorrect" + assert default_config.get_power_metrics_app_name() == "power-metrics", "power metrics default app name was incorrect" def test_custom_app_config(): @@ -35,3 +36,4 @@ def test_custom_app_config(): assert custom_config.get_istio_app_name() == "istio_custom", "istio custom app name was incorrect" assert custom_config.get_metric_server_app_name() == "metrics-server_custom", "metric server custom name was incorrect" assert custom_config.get_oidc_app_name() == "oidc-auth-apps_custom", "oidc custom app name was incorrect" + assert custom_config.get_power_metrics_app_name() == "power-metrics_custom", "power metrics custom name was incorrect" diff --git a/unit_tests/config/app/custom_app_config.json5 b/unit_tests/config/app/custom_app_config.json5 index 980875cd..52ef527b 100644 --- a/unit_tests/config/app/custom_app_config.json5 +++ b/unit_tests/config/app/custom_app_config.json5 @@ -2,5 +2,6 @@ base_application_path: "fake_path", istio_app_name: "istio_custom", metric_server_app_name: "metrics-server_custom", - oidc_app_name: "oidc-auth-apps_custom" + oidc_app_name: "oidc-auth-apps_custom", + power_metrics_app_name: "power-metrics_custom" } \ No newline at end of file