From b63cd66ac3b9c294cdc4b04998ca577512eae97c Mon Sep 17 00:00:00 2001 From: suchita-g Date: Thu, 9 Nov 2023 15:29:56 +0530 Subject: [PATCH] Adding Markers for FUSION HCI Provider Client Platform Signed-off-by: suchita-g --- ocs_ci/framework/__init__.py | 24 ++++- .../framework/pytest_customization/marks.py | 47 +++++++++ ocs_ci/ocs/cluster.py | 28 ++++++ ocs_ci/ocs/constants.py | 5 + .../test_hci_pc_markers.py | 96 +++++++++++++++++++ 5 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 tests/hci_provider_client/test_hci_pc_markers.py diff --git a/ocs_ci/framework/__init__.py b/ocs_ci/framework/__init__.py index f6f9430496f6..87b03dfac542 100644 --- a/ocs_ci/framework/__init__.py +++ b/ocs_ci/framework/__init__.py @@ -355,7 +355,7 @@ def current_cluster_name(self): def is_provider_exist(self): """ - Check if the provider cluster exists in the clusters + Check ifq the provider cluster exists in the clusters Returns: bool: True, if the provider cluster exists in the clusters. False, otherwise. @@ -375,6 +375,28 @@ def is_consumer_exist(self): cluster_types = [cluster.ENV_DATA["cluster_type"] for cluster in self.clusters] return "consumer" in cluster_types + def is_hci_client_exist(self): + """ + Check if the hci_client cluster exists in the clusters + + Returns: + bool: True, if the hci_client cluster exists in the clusters. False, otherwise. + + """ + cluster_types = [cluster.ENV_DATA["cluster_type"] for cluster in self.clusters] + return "hci_client" in cluster_types + + def is_hci_provider_exist(self): + """ + Check if the provider cluster exists in the clusters + + Returns: + bool: True, if the provider cluster exists in the clusters. False, otherwise. + + """ + cluster_types = [cluster.ENV_DATA["cluster_type"] for cluster in self.clusters] + return "provider" in cluster_types + def is_cluster_type_exist(self, cluster_type): """ Check if the given cluster type exists in the clusters diff --git a/ocs_ci/framework/pytest_customization/marks.py b/ocs_ci/framework/pytest_customization/marks.py index 215738adc176..0587f2720bd0 100644 --- a/ocs_ci/framework/pytest_customization/marks.py +++ b/ocs_ci/framework/pytest_customization/marks.py @@ -25,6 +25,7 @@ OPENSHIFT_DEDICATED_PLATFORM, MANAGED_SERVICE_PLATFORMS, HPCS_KMS_PROVIDER, + HCI_PROVIDER_CLIENT_PLATFORMS, ) from ocs_ci.utility import version from ocs_ci.utility.aws import update_config_from_s3 @@ -274,6 +275,31 @@ reason="Test runs ONLY on Managed service with provider and consumer clusters", ) +hci_client_required = pytest.mark.skipif( + not ( + config.default_cluster_ctx.ENV_DATA["platform"].lower() + in HCI_PROVIDER_CLIENT_PLATFORMS + and config.default_cluster_ctx.ENV_DATA["cluster_type"].lower() == "hci_client" + ), + reason="Test runs ONLY on Fusion HCI Client cluster", +) + +hci_provider_required = pytest.mark.skipif( + not ( + config.default_cluster_ctx.ENV_DATA["platform"].lower() + in HCI_PROVIDER_CLIENT_PLATFORMS + and config.default_cluster_ctx.ENV_DATA["cluster_type"].lower() == "provider" + ), + reason="Test runs ONLY on Fusion HCI Provider cluster", +) +hci_provider_and_client_required = pytest.mark.skipif( + not ( + config.ENV_DATA["platform"].lower() in HCI_PROVIDER_CLIENT_PLATFORMS + and config.is_hci_provider_exist() + and config.is_hci_client_exist() + ), + reason="Test runs ONLY on Fusion HCI provider and client clusters", +) kms_config_required = pytest.mark.skipif( ( config.ENV_DATA["KMS_PROVIDER"].lower() != HPCS_KMS_PROVIDER @@ -342,6 +368,27 @@ reason="Test will not run on Managed service with provider and consumer clusters", ) +skipif_hci_provider = pytest.mark.skipif( + config.default_cluster_ctx.ENV_DATA["platform"].lower() + in HCI_PROVIDER_CLIENT_PLATFORMS + and config.default_cluster_ctx.ENV_DATA["cluster_type"].lower() == "provider", + reason="Test will not run on Fusion HCI provider cluster", +) + +skipif_hci_client = pytest.mark.skipif( + config.default_cluster_ctx.ENV_DATA["platform"].lower() + in HCI_PROVIDER_CLIENT_PLATFORMS + and config.default_cluster_ctx.ENV_DATA["cluster_type"].lower() == "hci_client", + reason="Test will not run on Fusion HCI client cluster", +) + +skipif_hci_provider_and_client = pytest.mark.skipif( + config.ENV_DATA["platform"].lower() in HCI_PROVIDER_CLIENT_PLATFORMS + and config.is_hci_provider_exist() + and config.is_hci_client_exist(), + reason="Test will not run on Fusion HCI provider and Client clusters", +) + skipif_rosa = pytest.mark.skipif( config.ENV_DATA["platform"].lower() == ROSA_PLATFORM, reason="Test will not run on ROSA cluster", diff --git a/ocs_ci/ocs/cluster.py b/ocs_ci/ocs/cluster.py index f5978df66333..301c2d657cfc 100644 --- a/ocs_ci/ocs/cluster.py +++ b/ocs_ci/ocs/cluster.py @@ -2202,6 +2202,20 @@ def is_ms_consumer_cluster(): ) +def is_hci_client_cluster(): + """ + Check if the cluster is a Fusion HCI Client cluster + + Returns: + bool: True, if the cluster is a Fusion HCI client cluster. False, otherwise + + """ + return ( + config.ENV_DATA["platform"].lower() in constants.HCI_PROVIDER_CLIENT_PLATFORMS + and config.ENV_DATA["cluster_type"].lower() == "hci_client" + ) + + def is_ms_provider_cluster(): """ Check if the cluster is a managed service provider cluster @@ -2216,6 +2230,20 @@ def is_ms_provider_cluster(): ) +def is_hci_provider_cluster(): + """ + Check if the cluster is a Fusion HCI provider cluster + + Returns: + bool: True, if the cluster is a Fusion HCI provider cluster. False, otherwise + + """ + return ( + config.ENV_DATA["platform"].lower() in constants.HCI_PROVIDER_CLIENT_PLATFORMS + and config.ENV_DATA["cluster_type"].lower() == "provider" + ) + + def get_osd_dump(pool_name): """ Get the osd dump part of a given pool diff --git a/ocs_ci/ocs/constants.py b/ocs_ci/ocs/constants.py index ce61a2b851b5..a865a48147e1 100644 --- a/ocs_ci/ocs/constants.py +++ b/ocs_ci/ocs/constants.py @@ -1010,6 +1010,11 @@ FUSIONAAS_PLATFORM, ] BAREMETAL_PLATFORMS = [BAREMETAL_PLATFORM, BAREMETALPSI_PLATFORM] +HCI_PROVIDER_CLIENT_PLATFORMS = [ + BAREMETAL_PLATFORM, + VSPHERE_PLATFORM, + IBMCLOUD_PLATFORM, +] # AWS i3 worker instance for LSO AWS_LSO_WORKER_INSTANCE = "i3en.2xlarge" diff --git a/tests/hci_provider_client/test_hci_pc_markers.py b/tests/hci_provider_client/test_hci_pc_markers.py new file mode 100644 index 000000000000..36dc66340ab5 --- /dev/null +++ b/tests/hci_provider_client/test_hci_pc_markers.py @@ -0,0 +1,96 @@ +import logging +import pytest + +from ocs_ci.framework.pytest_customization.marks import yellow_squad +from ocs_ci.framework.testlib import ( + libtest, + ManageTest, + ignore_leftovers, + hci_provider_and_client_required, + skipif_hci_client, + skipif_hci_provider, + runs_on_provider, +) +from ocs_ci.ocs.cluster import ( + is_hci_client_cluster, + is_hci_provider_cluster, +) +from ocs_ci.ocs.managedservice import check_and_change_current_index_to_default_index + +logger = logging.getLogger(__name__) + + +@yellow_squad +@libtest +@hci_provider_and_client_required +@ignore_leftovers +class TestHCIProviderClientMarkers(ManageTest): + """ + Test that the HCI Provider Client markers work as expected + """ + + @pytest.mark.first + def test_default_cluster_context_index_equal_to_current_index(self): + """ + Test that the default cluster index is equal to the current cluster index. This test should run first + """ + assert ( + check_and_change_current_index_to_default_index() + ), "The default cluster index is different from the current cluster index" + logger.info( + "The default cluster index is equal to the current cluster index as expected" + ) + + @skipif_hci_client + def test_marker_skipif_hci_client(self): + """ + Test that the 'skipif_hci_client' marker work as expected + """ + assert ( + not is_hci_client_cluster() + ), "The cluster is a HCI Client cluster, even though we have the marker 'skipif_hci_client'" + logger.info("The cluster is not a HCI Client cluster as expected") + + assert check_and_change_current_index_to_default_index() + logger.info( + "The default cluster index is equal to the current cluster index as expected" + ) + + @skipif_hci_provider + def test_marker_skipif_hci_provider(self): + """ + Test that the 'skipif_hci_provider' marker work as expected + """ + assert ( + not is_hci_provider_cluster() + ), "The cluster is a HCI provider cluster, even though we have the marker 'skipif_hci_provider'" + logger.info("The cluster is not a HCI provider cluster as expected") + + assert check_and_change_current_index_to_default_index() + logger.info( + "The default cluster index is equal to the current cluster index as expected" + ) + + @runs_on_provider + @pytest.mark.second_to_last + def test_runs_on_provider_marker(self): + """ + Test that the 'runs_on_provider' marker work as expected + """ + assert ( + is_hci_provider_cluster() + ), "The cluster is not a HCI provider cluster, even though we have the marker 'runs_on_provider'" + logger.info("The cluster is a provider cluster as expected") + + @pytest.mark.last + def test_current_index_not_change_after_using_runs_on_provider(self): + """ + Test that the current cluster index didn't change after using the 'runs_on_provider' + marker in the previous test. + """ + assert ( + check_and_change_current_index_to_default_index() + ), "The current cluster index has changed after using the 'runs_on_provider' marker" + logger.info( + "The current cluster index didn't change after using the 'runs_on_provider' marker" + )