Skip to content

Commit

Permalink
rebase the code to use newly added system test entry criteria fixtures
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 17caf48 commit 5848d35
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 354 deletions.
46 changes: 11 additions & 35 deletions ocs_ci/ocs/bucket_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import os
import shlex
from uuid import uuid4
from datetime import date

import boto3
from botocore.handlers import disable_signing
Expand Down Expand Up @@ -1929,37 +1928,6 @@ def upload_bulk_buckets(s3_obj, buckets, amount=1, object_key="obj-key-0", prefi
s3_put_object(s3_obj, bucket.name, f"{prefix}/{object_key}-{i}", 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):

"""
Expand All @@ -1975,9 +1943,6 @@ def expire_objects_in_bucket(bucket_name, new_expire_interval=None):
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 @@ -2035,3 +2000,14 @@ 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")


def s3_put_bucket_lifecycle_config(mcg_obj, buckets, rule):
"""
This method applies lifecycle configuration for a bucket
"""
for bucket in buckets:
mcg_obj.s3_client.put_bucket_lifecycle_configuration(
Bucket=bucket.name, LifecycleConfiguration=rule
)
logger.info("Applied lifecyle rule on all the buckets")
25 changes: 1 addition & 24 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
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
Expand Down Expand Up @@ -96,7 +95,7 @@
verify_data_integrity_for_multi_pvc_objs,
get_noobaa_pods,
get_pod_count,
get_noobaa_core_pod, wait_for_pods_by_label_count,
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 @@ -6913,25 +6912,3 @@ 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
Loading

0 comments on commit 5848d35

Please sign in to comment.