Skip to content

Commit

Permalink
system test
Browse files Browse the repository at this point in the history
Signed-off-by: Mahesh Shetty <[email protected]>
  • Loading branch information
mashetty330 committed Oct 26, 2023
1 parent e5afe38 commit 64a234c
Show file tree
Hide file tree
Showing 6 changed files with 546 additions and 77 deletions.
50 changes: 48 additions & 2 deletions ocs_ci/ocs/bucket_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import boto3
from botocore.handlers import disable_signing

from datetime import date
from ocs_ci.framework import config
from ocs_ci.ocs import constants
from ocs_ci.ocs.exceptions import TimeoutExpiredError, UnexpectedBehaviour
Expand All @@ -20,6 +20,7 @@
from ocs_ci.utility.utils import TimeoutSampler, run_cmd
from ocs_ci.helpers.helpers import create_resource


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -1919,19 +1920,63 @@ def create_aws_bs_using_cli(
)


def expire_objects_in_bucket(bucket_name):
def upload_bulk_buckets(s3_obj, buckets, object_key="obj-key-0", prefix=None):
"""
Upload object to the buckets
"""
for bucket in buckets:
s3_put_object(s3_obj, bucket.name, f"{prefix}/{object_key}", object_key)


def change_expiration_query_interval(new_interval):
"""
Change how often noobaa should check for object expiration
By default it will be 8 hours
Args:
new_interval (int): New interval in minutes
"""

from ocs_ci.ocs.resources.pod import (
get_noobaa_core_pod,
wait_for_pods_to_be_running,
)

nb_core_pod = get_noobaa_core_pod()
new_interval = new_interval * 60 * 1000
params = (
'[{"op": "add", "path": "/spec/template/spec/containers/0/env/-", '
f'"value": {{ "name": "CONFIG_JS_LIFECYCLE_INTERVAL", "value": "{new_interval}" }}}}]'
)
OCP(kind="statefulset", namespace=constants.OPENSHIFT_STORAGE_NAMESPACE).patch(
resource_name=constants.NOOBAA_CORE_STATEFULSET,
params=params,
format_type="json",
)
logger.info(f"Updated the expiration query interval to {new_interval} ms")
nb_core_pod.delete()
wait_for_pods_to_be_running(pod_names=[nb_core_pod.name], timeout=300)


def expire_objects_in_bucket(bucket_name, new_expire_interval=None):

"""
Manually expire the objects in a bucket
Args:
bucket_name (str): Name of the bucket
new_expire_interval (int): New expiration interval
"""

from ocs_ci.ocs.resources.pod import (
get_noobaa_db_pod,
)

if new_expire_interval is not None and isinstance(new_expire_interval, int):
change_expiration_query_interval(new_expire_interval)

creation_time = f"{date.today().year-1}-06-25T14:18:28.712Z"
nb_db_pod = get_noobaa_db_pod()
query = (
Expand Down Expand Up @@ -1988,3 +2033,4 @@ def sample_if_objects_expired(mcg_obj, bucket_name, prefix="", timeout=600, slee

assert sampler.wait_for_func_status(result=True), f"{message} are not expired"
logger.info(f"{message} are expired")

22 changes: 22 additions & 0 deletions ocs_ci/ocs/resources/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,28 @@ def get_noobaa_core_pod():
return noobaa_core_pod


def get_noobaa_db_pod():
"""
Get noobaa db pod obj
Returns:
Pod object: Noobaa db pod object
"""
if version.get_semantic_ocs_version_from_config() > version.VERSION_4_6:
nb_db = get_pods_having_label(
label=constants.NOOBAA_DB_LABEL_47_AND_ABOVE,
namespace=config.ENV_DATA["cluster_namespace"],
)
else:
nb_db = get_pods_having_label(
label=constants.NOOBAA_DB_LABEL_46_AND_UNDER,
namespace=config.ENV_DATA["cluster_namespace"],
)
nb_db_pod = Pod(**nb_db[0])
return nb_db_pod


def get_noobaa_endpoint_pods():
"""
Fetches noobaa endpoint pod details
Expand Down
27 changes: 26 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@
from ocs_ci.helpers.proxy import update_container_with_proxy_env
from ocs_ci.ocs import constants, defaults, fio_artefacts, node, ocp, platform_nodes
from ocs_ci.ocs.acm.acm import login_to_acm

from ocs_ci.ocs.bucket_utils import (
craft_s3_command,
put_bucket_policy,
change_expiration_query_interval,
)

from ocs_ci.ocs.dr.dr_workload import BusyBox, BusyBox_AppSet
from ocs_ci.ocs.exceptions import (
CommandFailed,
Expand Down Expand Up @@ -93,7 +96,7 @@
verify_data_integrity_for_multi_pvc_objs,
get_noobaa_pods,
get_pod_count,
wait_for_pods_by_label_count,
get_noobaa_core_pod, wait_for_pods_by_label_count,
)
from ocs_ci.ocs.resources.pvc import PVC, create_restore_pvc
from ocs_ci.ocs.version import get_ocs_version, get_ocp_version_dict, report_ocs_version
Expand Down Expand Up @@ -6910,3 +6913,25 @@ def factory(interval):
)

return factory


def change_noobaa_lifecycle_interval(request):
nb_core_pod = get_noobaa_core_pod()
env_var = "CONFIG_JS_LIFECYCLE_INTERVAL"

def factory(interval):
change_expiration_query_interval(new_interval=interval)

def finalizer():
params = f'[{{"op": "remove", "path": "/spec/template/spec/containers/0/env/name:{env_var}"}}]'
OCP(kind="statefulset", namespace=constants.OPENSHIFT_STORAGE_NAMESPACE).patch(
resource_name=constants.NOOBAA_CORE_STATEFULSET,
params=params,
format_type="json",
)
nb_core_pod.delete()
wait_for_pods_to_be_running(pod_names=[nb_core_pod.name], timeout=300)
log.info("Switched back to default lifecycle interval")

request.addfinalizer(finalizer)
return factory
6 changes: 6 additions & 0 deletions tests/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1292,3 +1292,9 @@ def factory(
return feature_setup_map

return factory

def multi_obc_setup_factory(request, bucket_factory, mcg_obj):

from tests.e2e.helpers import multi_obc_factory

return multi_obc_factory(bucket_factory, mcg_obj)
132 changes: 132 additions & 0 deletions tests/e2e/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import logging
import random
import copy

from ocs_ci.ocs import constants

logger = logging.getLogger(__name__)


def multi_obc_factory(bucket_factory, mcg_obj):
def get_all_combinations_map(providers, bucket_types):
all_combinations = dict()

for provider, provider_config in providers.items():
for bucket_type, type_config in bucket_types.items():
if provider == "pv" and bucket_type != "data":
provider = random.choice(["aws", "azure"])
provider_config = providers[provider]
bucketclass = copy.deepcopy(type_config)

if "backingstore_dict" in bucketclass.keys():
bucketclass["backingstore_dict"][provider] = [provider_config]
elif "namespace_policy_dict" in bucketclass.keys():
bucketclass["namespace_policy_dict"]["namespacestore_dict"][
provider
] = [provider_config]
all_combinations.update({f"{bucket_type}-{provider}": bucketclass})
return all_combinations

def create_obcs(num_obcs=50, type_of_bucket=None, expiration_rule=None):

cloud_providers = {
"aws": (1, "eu-central-1"),
"azure": (1, None),
"pv": (
1,
constants.MIN_PV_BACKINGSTORE_SIZE_IN_GB,
"ocs-storagecluster-ceph-rbd",
),
}

bucket_types = {
"data": {
"interface": "OC",
"backingstore_dict": {},
},
"namespace": {
"interface": "OC",
"namespace_policy_dict": {
"type": "Single",
"namespacestore_dict": {},
},
},
"cache": {
"interface": "OC",
"namespace_policy_dict": {
"type": "Cache",
"ttl": 300000,
"namespacestore_dict": {},
},
"placement_policy": {
"tiers": [
{"backingStores": [constants.DEFAULT_NOOBAA_BACKINGSTORE]}
]
},
},
}
to_remove = list()
if isinstance(type_of_bucket, list):
if set(type_of_bucket).issubset(set(list(bucket_types.keys()))):
for type in bucket_types.keys():
if type not in type_of_bucket:
to_remove.append(type)
else:
logger.error(
"Invalid bucket types, only possible types are: data, cache, namespace"
)
elif type_of_bucket is not None:
logger.error(
"Invalid argument type for 'type_of_bucket': It should be list type"
)

for i in range(len(to_remove)):
del bucket_types[to_remove[i]]

all_combination_of_obcs = get_all_combinations_map(
cloud_providers, bucket_types
)
buckets = list()
buckets_created = dict()
num_of_buckets_each = num_obcs // len(all_combination_of_obcs.keys())
buckets_left = num_obcs % len(all_combination_of_obcs.keys())
if num_of_buckets_each != 0:
for combo, combo_config in all_combination_of_obcs.items():
buckets.extend(
bucket_factory(
interface="OC",
amount=num_of_buckets_each,
bucketclass=combo_config,
)
)
buckets_created.update({combo: num_of_buckets_each})

for i in range(0, buckets_left):
buckets.extend(
bucket_factory(
interface="OC",
amount=1,
bucketclass=all_combination_of_obcs[
list(all_combination_of_obcs.keys())[i]
],
)
)
buckets_created.update(
{
list(all_combination_of_obcs.keys())[i]: (
buckets_created[list(all_combination_of_obcs.keys())[i]]
if len(buckets) >= len(all_combination_of_obcs.keys())
else 0
)
+ 1
}
)

for bucket in buckets:
mcg_obj.s3_client.put_bucket_lifecycle_configuration(
Bucket=bucket.name, LifecycleConfiguration=expiration_rule
)
logger.info("These are the buckets created:" f"{buckets_created}")
return buckets

return create_obcs
Loading

0 comments on commit 64a234c

Please sign in to comment.