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

[4.18] MCG Bucket Notifications - add advanced tests, improvements and fixes #11260

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion ocs_ci/ocs/bucket_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2688,7 +2688,7 @@ def delete_object_tags(
"""
logger.info(f"Deleting tags of objects in bucket {bucket}")
for object_key in object_keys:
object_key = f"prefix/{object_key}" if prefix else object_key
object_key = f"{prefix}/{object_key}" if prefix else object_key
io_pod.exec_cmd_on_pod(
craft_s3_command(
f"delete-object-tagging --bucket {bucket} --key {object_key}",
Expand Down
27 changes: 12 additions & 15 deletions ocs_ci/ocs/resources/bucket_notifications_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
)
from ocs_ci.ocs import constants
from ocs_ci.ocs.amq import AMQ
from ocs_ci.ocs.cluster import CephCluster
from ocs_ci.ocs.exceptions import CommandFailed
from ocs_ci.ocs.ocp import OCP
from ocs_ci.ocs.resources.mcg import MCG
from ocs_ci.ocs.resources.pod import (
Pod,
get_noobaa_pods,
get_pods_having_label,
wait_for_pods_to_be_running,
)
Expand Down Expand Up @@ -230,13 +229,14 @@ def create_kafka_conn_secret(self, topic):
self.conn_secrets.append(secret_ocp_obj)
return secret_ocp_obj, conn_file_name

def add_notif_conn_to_noobaa_cr(self, secret):
def add_notif_conn_to_noobaa_cr(self, secret, wait=True):
"""
Add a connection secret to list of bucket notifications
connections in the NooBaa CR.

Args:
secret(ocs_ci.ocs.ocp.OCP): OCP instance of the secret to add
wait(bool): Whether to wait for the NooBaa resources to be ready
"""
conn_data = {
"name": secret.resource_name,
Expand All @@ -249,17 +249,12 @@ def add_notif_conn_to_noobaa_cr(self, secret):
params=json.dumps(add_op),
format_type="json",
)
if wait:
MCG.wait_for_ready_status()

nb_pods = [pod.name for pod in get_noobaa_pods()]
wait_for_pods_to_be_running(
namespace=self.namespace,
pod_names=nb_pods,
timeout=60,
sleep=10,
)
CephCluster().wait_for_noobaa_health_ok()

def put_bucket_notification(self, awscli_pod, mcg_obj, bucket, events, conn_file):
def put_bucket_notification(
self, awscli_pod, mcg_obj, bucket, events, conn_file, wait=True
):
"""
Configure bucket notifications on a bucket using the AWS CLI

Expand All @@ -269,6 +264,7 @@ def put_bucket_notification(self, awscli_pod, mcg_obj, bucket, events, conn_file
bucket(str): Name of the bucket
events(list): List of events to trigger notifications
conn_file(str): Name of the file that NooBaa uses to connect to Kafka
wait(bool): Whether to wait for the notification to propagate
"""
rand_id = create_unique_resource_name(
resource_description="notif", resource_type="id"
Expand All @@ -288,8 +284,9 @@ def put_bucket_notification(self, awscli_pod, mcg_obj, bucket, events, conn_file
api=True,
)
)
logger.info("Waiting for put-bucket-notification to propogate")
sleep(60)
if wait:
logger.info("Waiting for put-bucket-notification to propagate")
sleep(60)

def get_bucket_notification(self, awscli_pod, mcg_obj, bucket):
"""
Expand Down
50 changes: 46 additions & 4 deletions ocs_ci/ocs/resources/mcg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import tempfile
from time import sleep
import time

import boto3
from botocore.client import ClientError
Expand All @@ -27,8 +28,10 @@
)
from ocs_ci.ocs.ocp import OCP
from ocs_ci.ocs.resources.pod import (
get_noobaa_pods,
get_pods_having_label,
Pod,
wait_for_pods_to_be_running,
)
from ocs_ci.utility import templating, version
from ocs_ci.utility.retry import retry
Expand Down Expand Up @@ -934,13 +937,20 @@ def exec_mcg_cmd(
return result

@property
def status(self):
"""
Expose the status check of NooBaa as a property
"""
return self._status()

@staticmethod
@retry(
exception_to_check=(CommandFailed, KeyError, subprocess.TimeoutExpired),
tries=10,
delay=6,
backoff=1,
)
def status(self):
def _status():
"""
Verify the status of NooBaa, and its default backing store and bucket class

Expand All @@ -949,13 +959,14 @@ def status(self):

"""
# Get noobaa status
get_noobaa = OCP(kind="noobaa", namespace=self.namespace).get(
namespace = config.ENV_DATA["cluster_namespace"]
get_noobaa = OCP(kind="noobaa", namespace=namespace).get(
resource_name=NOOBAA_RESOURCE_NAME
)
get_default_bs = OCP(kind="backingstore", namespace=self.namespace).get(
get_default_bs = OCP(kind="backingstore", namespace=namespace).get(
resource_name=DEFAULT_NOOBAA_BACKINGSTORE
)
get_default_bc = OCP(kind="bucketclass", namespace=self.namespace).get(
get_default_bc = OCP(kind="bucketclass", namespace=namespace).get(
resource_name=DEFAULT_NOOBAA_BUCKETCLASS
)
return (
Expand All @@ -965,6 +976,37 @@ def status(self):
== STATUS_READY
)

@staticmethod
def wait_for_ready_status(timeout=600):
"""
Wait for NooBaa's resources to reach the 'Ready' status

Args:
timeout (int): Number of seconds to wait for the status

Raises:
TimeoutExpiredError: If the status is not reached within the timeout
"""
starttime = time.time()
nb_pods = [pod.name for pod in get_noobaa_pods()]
wait_for_pods_to_be_running(
namespace=config.ENV_DATA["cluster_namespace"],
pod_names=nb_pods,
timeout=timeout,
sleep=10,
)
timeout = int(timeout - (time.time() - starttime))
try:
for mcg_status_ready in TimeoutSampler(
timeout=timeout, sleep=30, func=MCG._status
):
if mcg_status_ready:
return
except TimeoutExpiredError as e:
raise TimeoutExpiredError(
e, f"NooBaa health is not OK after {timeout} seconds"
)

def get_mcg_cli_version(self):
"""
Get the MCG CLI version by parsing the output of the `mcg-cli version` command.
Expand Down
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7657,6 +7657,15 @@ def add_env_vars_to_noobaa_core_class(request, mcg_obj_session):
return add_env_vars_to_noobaa_core_fixture(request, mcg_obj_session)


@pytest.fixture(scope="function")
def add_env_vars_to_noobaa_core(request, mcg_obj_session):
"""
Function-scoped fixture for adding env vars to the noobaa-core sts

"""
return add_env_vars_to_noobaa_core_fixture(request, mcg_obj_session)


def add_env_vars_to_noobaa_core_fixture(request, mcg_obj_session):
"""
Add env vars to the noobaa-core sts
Expand Down
Loading