Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Osypenko <[email protected]>
  • Loading branch information
DanielOsypenko committed Jul 29, 2024
1 parent cf87a64 commit 0338af9
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 39 deletions.
2 changes: 1 addition & 1 deletion ocs_ci/deployment/helpers/hypershift_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def get_random_hosted_cluster_name():
Returns:
str: random cluster name
"""
# getting the cluster name from the env data, fo instance "ibm_cloud_baremetal3; mandatory conf field"
# getting the cluster name from the env data, for instance "ibm_cloud_baremetal3; mandatory conf field"
bm_name = config.ENV_DATA.get("baremetal").get("env_name")
ocp_version = get_latest_release_version()
hcp_version = "".join([c for c in ocp_version if c.isdigit()][:3])
Expand Down
3 changes: 3 additions & 0 deletions ocs_ci/deployment/hosted_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ def storage_installation_requested(self, cluster_name):
Args:
cluster_name: str: Name of the cluster
Returns:
bool: True if the storage client installation was requested, False otherwise
"""
return (
config.ENV_DATA.get("clusters", {})
Expand Down
19 changes: 19 additions & 0 deletions ocs_ci/ocs/resources/catalog_source.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
CatalogSource related functionalities
"""

import logging
from time import sleep

Expand Down Expand Up @@ -180,3 +181,21 @@ def enable_specific_source(source_name):
)
logger.info(f"Waiting 20 seconds after enabling source: {source_name}")
sleep(20)


def get_odf_tag_from_redhat_catsrc():
"""
Get the ODF tag from the default redhat-operators Catalog Source
Returns:
str: ODF tag from redhat-operators Catalog Source
"""
from ocs_ci.ocs.ocp import OCP

catsrc_data = OCP(
kind=constants.CATSRC,
namespace=constants.MARKETPLACE_NAMESPACE,
resource_name="redhat-operators",
).get()
regestry_image = catsrc_data.get("spec").get("image")
return regestry_image.split(":")[-1]
19 changes: 19 additions & 0 deletions ocs_ci/utility/json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import json


class SetToListJSONEncoder(json.JSONEncoder):
"""
The CustomJSONEncoder class is a subclass of json.JSONEncoder designed to handle the serialization of Python
objects into JSON format, with a specific focus on converting set objects into lists.
This is necessary because the default JSON encoder in Python does not support set objects, which are not a valid
JSON data type.
This way we avoid "TypeError: Object of type set is not JSON serializable"
Usage:
json.dumps(data, cls=SetToListJSONEncoder)
"""

def default(self, obj):
if isinstance(obj, set):
return list(obj)
return super().default(obj)
29 changes: 0 additions & 29 deletions ocs_ci/utility/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5040,32 +5040,3 @@ def sum_of_two_storage_sizes(storage_size1, storage_size2, convert_size=1024):
size = size1 + size2
new_storage_size = f"{size}{unit}"
return new_storage_size


class CustomJSONEncoder(json.JSONEncoder):
"""
Custom JSON encoder to handle set objects
"""

def default(self, obj):
if isinstance(obj, set):
return list(obj)
return super().default(obj)


def get_odf_tag_from_redhat_catsrc():
"""
Get the ODF tag from the default redhat-operators Catalog Source
Returns:
str: ODF tag from redhat-operators Catalog Source
"""
from ocs_ci.ocs.ocp import OCP

catsrc_data = OCP(
kind=constants.CATSRC,
namespace=constants.MARKETPLACE_NAMESPACE,
resource_name="redhat-operators",
).get()
regestry_image = catsrc_data.get("spec").get("image")
return regestry_image.split(":")[-1]
16 changes: 8 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
get_status_before_execution,
get_status_after_execution,
)
from ocs_ci.utility.json import SetToListJSONEncoder
from ocs_ci.utility.resource_check import (
create_resource_dct,
get_environment_status_after_execution,
Expand Down Expand Up @@ -151,7 +152,6 @@
skipif_ui_not_support,
run_cmd,
ceph_health_check_multi_storagecluster_external,
CustomJSONEncoder,
)
from ocs_ci.helpers import helpers, dr_helpers
from ocs_ci.helpers.helpers import (
Expand Down Expand Up @@ -6713,9 +6713,11 @@ def factory(
workload_pvc_selector=workload_details[
"dr_workload_app_pvc_selector"
],
appset_model=workload_details["appset_model"]
if workload_type == constants.APPLICATION_SET
else None,
appset_model=(
workload_details["appset_model"]
if workload_type == constants.APPLICATION_SET
else None
),
)
instances.append(workload)
total_pvc_count += workload_details["pvc_count"]
Expand Down Expand Up @@ -7533,7 +7535,6 @@ def finalizer():

@pytest.fixture(scope="session")
def scale_noobaa_resources_session(request):

"""
Session scoped fixture to scale noobaa resources
Expand All @@ -7551,7 +7552,6 @@ def scale_noobaa_resources_fixture(request):


def scale_noobaa_resources(request):

"""
Scale the noobaa pod resources and scale endpoint count
Expand Down Expand Up @@ -7971,7 +7971,7 @@ def factory(
log.info(
"Creating a hosted clusters with following deployment config: \n%s",
json.dumps(
hosted_cluster_conf_on_provider, indent=4, cls=CustomJSONEncoder
hosted_cluster_conf_on_provider, indent=4, cls=SetToListJSONEncoder
),
)
ocsci_config.update(hosted_cluster_conf_on_provider)
Expand Down Expand Up @@ -8009,7 +8009,7 @@ def factory(

log.debug(
"Inserting new hosted cluster config to Multicluster Config "
f"\n{json.dumps(vars(cluster_config), indent=4, cls=CustomJSONEncoder)}"
f"\n{json.dumps(vars(cluster_config), indent=4, cls=SetToListJSONEncoder)}"
)
ocsci_config.insert_cluster_config(
ocsci_config.nclusters, cluster_config
Expand Down
2 changes: 1 addition & 1 deletion tests/libtest/test_provider_create_hosted_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
runs_on_provider,
)
from ocs_ci.ocs.ocp import OCP
from ocs_ci.ocs.resources.catalog_source import get_odf_tag_from_redhat_catsrc
from ocs_ci.utility.utils import (
get_latest_release_version,
get_odf_tag_from_redhat_catsrc,
)
from ocs_ci.utility.version import get_ocs_version_from_csv
from ocs_ci.framework import config as ocsci_config
Expand Down

0 comments on commit 0338af9

Please sign in to comment.