Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hci cluster switch check #8897

Merged
merged 6 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ocs_ci/framework/pytest_customization/marks.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@
reason="Test runs ONLY on OSD or ROSA cluster",
)

hci_required = pytest.mark.skipif(
Copy link
Contributor

@suchita-g suchita-g Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does requirement not work with hci_provider_and_client_required , do we need this explicitly.

hci_provider_and_client_required = pytest.mark.skipif(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if no to the above comment then maybe rename it as hci_pc_platform_required or `hci_pc_cluster_required

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right, it would work as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, I would prefer to keep the logic of at least one hci cluster being present for the test not to be skipped, for better awareness of possible issues.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setup is invalid when no provider or no client is present, right? Maybe it would be better to have only one marker for hci platform to prevent redundancy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

(config.ENV_DATA["platform"].lower() not in HCI_PROVIDER_CLIENT_PLATFORMS),
reason="Test runs ONLY on hci provider or client cluster",
)

provider_client_ms_platform_required = pytest.mark.skipif(
not (
(config.ENV_DATA["platform"].lower() not in HCI_PROVIDER_CLIENT_PLATFORMS)
Expand Down
13 changes: 13 additions & 0 deletions ocs_ci/ocs/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -2188,6 +2188,19 @@ def is_managed_service_cluster():
return config.ENV_DATA["platform"].lower() in constants.MANAGED_SERVICE_PLATFORMS


def is_hci_cluster():
"""
Check if the cluster is an hci provider or client cluster

Returns:
bool: True, if the cluster is an hci cluster. False, otherwise

"""
return (
config.ENV_DATA["platform"].lower() in constants.HCI_PROVIDER_CLIENT_PLATFORMS
)


def is_ms_consumer_cluster():
"""
Check if the cluster is a managed service consumer cluster
Expand Down
24 changes: 22 additions & 2 deletions ocs_ci/ocs/managedservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
from ocs_ci.framework import config
from ocs_ci.ocs import constants, ocp
from ocs_ci.helpers import helpers
from ocs_ci.ocs.constants import MS_CONSUMER_TYPE, MS_PROVIDER_TYPE, NON_MS_CLUSTER_TYPE
from ocs_ci.ocs.constants import (
MS_CONSUMER_TYPE,
MS_PROVIDER_TYPE,
NON_MS_CLUSTER_TYPE,
HCI_PROVIDER,
HCI_CLIENT,
)
from ocs_ci.ocs.resources.catalog_source import CatalogSource, disable_specific_source
from ocs_ci.ocs.resources.pod import get_ceph_tools_pod, get_pods_having_label, Pod
from ocs_ci.utility import templating
Expand Down Expand Up @@ -386,6 +392,8 @@ def check_switch_to_correct_cluster_at_setup(cluster_type=None):
is_ms_consumer_cluster,
is_ms_provider_cluster,
is_managed_service_cluster,
is_hci_client_cluster,
is_hci_provider_cluster,
)

logger.info(f"The cluster type is: {cluster_type}")
Expand All @@ -396,7 +404,13 @@ def check_switch_to_correct_cluster_at_setup(cluster_type=None):
)
return

valid_cluster_types = [MS_CONSUMER_TYPE, MS_PROVIDER_TYPE, NON_MS_CLUSTER_TYPE]
valid_cluster_types = [
MS_CONSUMER_TYPE,
MS_PROVIDER_TYPE,
NON_MS_CLUSTER_TYPE,
HCI_PROVIDER,
HCI_CLIENT,
]
assert (
cluster_type in valid_cluster_types
), f"The cluster type {cluster_type} does not appear in the correct cluster types {valid_cluster_types}"
Expand All @@ -407,6 +421,12 @@ def check_switch_to_correct_cluster_at_setup(cluster_type=None):
elif cluster_type == MS_PROVIDER_TYPE:
assert is_ms_provider_cluster(), "The cluster is not an MS provider cluster"
logger.info("The cluster is an MS provider cluster as expected")
elif cluster_type == HCI_CLIENT:
assert is_hci_client_cluster(), "The cluster is not an HCI client cluster"
logger.info("The cluster is an HCI client cluster as expected")
elif cluster_type == HCI_PROVIDER:
assert is_hci_provider_cluster(), "The cluster is not an HCI provider cluster"
logger.info("The cluster is an HCI provider cluster as expected")
elif cluster_type == NON_MS_CLUSTER_TYPE:
assert (
not is_managed_service_cluster()
Expand Down
4 changes: 2 additions & 2 deletions ocs_ci/utility/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4356,7 +4356,7 @@ def switch_to_correct_cluster_at_setup(request):
request (_pytest.fixtures.SubRequest'): The pytest request fixture

"""
from ocs_ci.ocs.cluster import is_managed_service_cluster
from ocs_ci.ocs.cluster import is_managed_service_cluster, is_hci_cluster

cluster_type = get_pytest_fixture_value(request, "cluster_type")
if not cluster_type:
Expand All @@ -4366,7 +4366,7 @@ def switch_to_correct_cluster_at_setup(request):
)
return

if not is_managed_service_cluster():
if not (is_managed_service_cluster() or is_hci_cluster()):
if cluster_type == constants.NON_MS_CLUSTER_TYPE:
log.info(
"The cluster is a non-MS cluster. Continue the test with the current cluster"
Expand Down
25 changes: 24 additions & 1 deletion tests/managed-service/test_switch_to_correct_index_at_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@
libtest,
ManageTest,
managed_service_required,
hci_required,
)
from ocs_ci.ocs.cluster import (
is_managed_service_cluster,
is_hci_cluster,
)
from ocs_ci.utility.utils import switch_to_correct_cluster_at_setup
from ocs_ci.helpers.sanity_helpers import Sanity, SanityManagedService
from ocs_ci.ocs.constants import MS_CONSUMER_TYPE, MS_PROVIDER_TYPE, NON_MS_CLUSTER_TYPE
from ocs_ci.ocs.constants import (
MS_CONSUMER_TYPE,
MS_PROVIDER_TYPE,
HCI_CLIENT,
HCI_PROVIDER,
NON_MS_CLUSTER_TYPE,
)

from ocs_ci.ocs.managedservice import (
check_switch_to_correct_cluster_at_setup,
Expand All @@ -39,6 +47,9 @@ def setup(self, create_scale_pods_and_pvcs_using_kube_job_on_ms_consumers, reque
self.sanity_helpers = SanityManagedService(
create_scale_pods_and_pvcs_using_kube_job_on_ms_consumers
)
elif is_hci_cluster:
# TODO: implement hci sanity helpers
pass
else:
self.sanity_helpers = Sanity()

Expand All @@ -54,6 +65,18 @@ def test_switch_to_correct_cluster_with_ms_cluster_types(self, cluster_type):
"""
check_switch_to_correct_cluster_at_setup(cluster_type)

@hci_required
@pytest.mark.parametrize(
"cluster_type",
[HCI_CLIENT, HCI_PROVIDER],
)
def test_switch_to_correct_cluster_with_hci_cluster_types(self, cluster_type):
"""
Test switch to the correct cluster index at setup, when we have hci cluster types

"""
check_switch_to_correct_cluster_at_setup(cluster_type)

@managed_service_required
@pytest.mark.parametrize(
"cluster_type",
Expand Down
Loading