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

Adding support in creation of bucket class with mcg cli and a new test case for creation of rgw namespacestore using mcg-cli #11119

Merged
merged 7 commits into from
Jan 16, 2025
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
32 changes: 19 additions & 13 deletions ocs_ci/ocs/resources/bucketclass.py
Copy link
Contributor

Choose a reason for hiding this comment

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

@ypersky1980 , Just for safer side, please validate there is no need to change any code or change is required on below mentioned line

# TODO: Implement support for Single-tiered NS bucketclass

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@udaysk23 Thank you for noticiting, this comment is obsolete now, removed it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for pointing this out, @udaysk23 . This line now is obsolete, removed it.

Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ def bucket_class_factory(
backingstore_factory: Factory for backing store creation

"""
interfaces = {
"oc": mcg_obj.oc_create_bucketclass,
"cli": mcg_obj.cli_create_bucketclass,
}
interfaces = ["oc", "cli"]
created_bucket_classes = []

def _create_bucket_class(bucket_class_dict):
Expand Down Expand Up @@ -108,7 +105,7 @@ def _create_bucket_class(bucket_class_dict):
"""
if "interface" in bucket_class_dict:
interface = bucket_class_dict["interface"]
if interface.lower() not in interfaces.keys():
if interface.lower() not in interfaces:
raise RuntimeError(
f"Invalid interface type received: {interface}. "
f'available types: {", ".join(interfaces)}'
Expand Down Expand Up @@ -143,7 +140,6 @@ def _create_bucket_class(bucket_class_dict):
},
}
else:
# TODO: Implement support for Single-tiered NS bucketclass
namespace_policy["read_resources"] = [
nss.name for nss in namespacestores
]
Expand Down Expand Up @@ -206,13 +202,23 @@ def _create_bucket_class(bucket_class_dict):
bucket_class_name = create_unique_resource_name(
resource_description="bucketclass", resource_type=interface.lower()
)
interfaces[interface.lower()](
name=bucket_class_name,
backingstores=backingstores,
placement_policy=placement_policy,
namespace_policy=namespace_policy,
replication_policy=replication_policy,
)
if interface.lower() == "oc":
mcg_obj.oc_create_bucketclass(
bucket_class_name,
backingstores,
placement_policy,
namespace_policy,
replication_policy,
)
elif interface.lower() == "cli" and backingstores:
mcg_obj.cli_create_bucketclass_over_backingstores(
bucket_class_name, backingstores, placement_policy, replication_policy
)
else:
mcg_obj.cli_create_bucketclass_over_namespacestores(
bucket_class_name, namespacestores, namespace_policy
)

bucket_class_object = BucketClass(
bucket_class_name,
backingstores,
Expand Down
42 changes: 36 additions & 6 deletions ocs_ci/ocs/resources/mcg.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,28 +689,25 @@ def oc_create_bucketclass(

return create_resource(**bc_data)

def cli_create_bucketclass(
def cli_create_bucketclass_over_backingstores(
self,
name,
backingstores,
placement_policy,
namespace_policy=None,
replication_policy=None,
):
"""
Creates a new NooBaa bucket class using the noobaa cli
Creates a new NooBaa bucket class using the noobaa cli over backingstores
Args:
name (str): The name to be given to the bucket class
backingstores (list): The backing stores to use as part of the policy
backingstores (list): The backing stores to use as part of the policy.
placement_policy (str): The placement policy to be used - Mirror | Spread
namespace_policy (dict): The namespace policy to be used
replication_policy (dict): The replication policy dictionary

Returns:
OCS: The bucket class resource

"""
# TODO: Implement CLI namespace bucketclass support
backingstore_name_list = [backingstore.name for backingstore in backingstores]
backingstores = f" --backingstores {','.join(backingstore_name_list)}"
placement_policy = f" --placement {placement_policy}"
Expand Down Expand Up @@ -739,6 +736,39 @@ def cli_create_bucketclass(
f"bucketclass create {placement_type}{name}{backingstores}{placement_policy}{replication_policy}"
)

def cli_create_bucketclass_over_namespacestores(
self,
name,
namespacestores,
namespace_policy,
):
"""
Creates a new NooBaa bucket class using the noobaa cli over namespace stores
Args:
name (str): The name to be given to the bucket class
namespacestores (list): The namespaces stores to use as part of the policy
namespace_policy (dict): The namespace policy to be used
udaysk23 marked this conversation as resolved.
Show resolved Hide resolved

Returns:
OCS: The bucket class resource

"""
namestores_name_list = [
namespacestore.name for namespacestore in namespacestores
]
namestores_name_str = f"{','.join(namestores_name_list)}"
namespace_policy_type = namespace_policy["type"].lower()
if namespace_policy_type != constants.NAMESPACE_POLICY_TYPE_SINGLE.lower():
raise NotImplementedError(
f"Cli creating of bucketclass on namespacestore "
f"with policy {namespace_policy_type} is not implemented yet"
)

self.exec_mcg_cmd(
f"bucketclass create namespace-bucketclass {namespace_policy_type} "
f"--resource={namestores_name_str} {name}"
)
sagihirshfeld marked this conversation as resolved.
Show resolved Hide resolved

def check_if_mirroring_is_done(self, bucket_name, timeout=300):
"""
Check whether all object chunks in a bucket
Expand Down
15 changes: 15 additions & 0 deletions tests/functional/object/mcg/test_namespace_crd.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ def deprecated_test_namespace_store_creation_crd(
pytest.mark.polarion_id("OCS-2407"),
],
),
pytest.param(
{
"interface": "CLI",
"namespace_policy_dict": {
"type": "Single",
"namespacestore_dict": {"rgw": [(1, None)]},
},
},
marks=[
tier1,
on_prem_platform_required,
pytest.mark.polarion_id("OCS-2407"),
sagihirshfeld marked this conversation as resolved.
Show resolved Hide resolved
],
),
pytest.param(
{
"interface": "OC",
Expand Down Expand Up @@ -203,6 +217,7 @@ def deprecated_test_namespace_store_creation_crd(
"AWS-OC-Single",
"Azure-OC-Single",
"RGW-OC-Single",
"RGW-CLI-Single",
"IBM-OC-Single",
"AWS+Azure-OC-Multi",
"AWS+AWS-OC-Multi",
Expand Down
Loading