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 all 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
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
30 changes: 27 additions & 3 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,17 +404,33 @@ 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}"

if cluster_type == MS_CONSUMER_TYPE:
assert is_ms_consumer_cluster(), "The cluster is not an MS consumer cluster"
logger.info("The cluster is an MS consumer cluster as expected")
elif cluster_type == MS_PROVIDER_TYPE:
elif cluster_type == MS_PROVIDER_TYPE and (
config.ENV_DATA["platform"].lower()
not in constants.HCI_PROVIDER_CLIENT_PLATFORMS
):
# MS_PROVIDER_TYPE and HCI_PROVIDER are both "provider"
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_provider_and_client_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_provider_and_client_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