From 4821e8456a226fdd207ff66bb4c4cb6a21ea8b60 Mon Sep 17 00:00:00 2001 From: Mahesh Shetty Date: Wed, 26 Jun 2024 11:42:40 +0530 Subject: [PATCH] Test noobaa db activitylogs table for unnecessary logs when in default log level (#9720) Signed-off-by: Mahesh Shetty --- .../object/mcg/test_write_to_bucket.py | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tests/functional/object/mcg/test_write_to_bucket.py b/tests/functional/object/mcg/test_write_to_bucket.py index b97309fd92b..1ac12950b0e 100644 --- a/tests/functional/object/mcg/test_write_to_bucket.py +++ b/tests/functional/object/mcg/test_write_to_bucket.py @@ -1,5 +1,6 @@ import logging import os +import time import zipfile from concurrent.futures import ThreadPoolExecutor from zipfile import ZipFile @@ -20,6 +21,7 @@ acceptance, performance, ) +from ocs_ci.utility.utils import exec_nb_db_query from ocs_ci.ocs import constants from ocs_ci.ocs.bucket_utils import ( sync_object_directory, @@ -27,7 +29,10 @@ craft_s3_command, s3_put_object, s3_head_object, + rm_object_recursive, + write_random_test_objects_to_bucket, ) + from ocs_ci.framework.pytest_customization.marks import ( skipif_managed_service, bugzilla, @@ -456,3 +461,63 @@ def test_content_encoding_with_write( logger.info( "Put object operation is preserving ContentEncoding as a object metadata" ) + + @tier2 + @bugzilla("2259189") + @bugzilla("2264480") + @pytest.mark.polarion_id("OCS-5773") + def test_nb_db_activity_logs_on_io( + self, + bucket_factory, + awscli_pod_session, + mcg_obj, + change_the_noobaa_log_level, + test_directory_setup, + ): + + """ + This test checks if the activity logs are being logged + in the activitylogs table for every object upload and + deletion when noobaa log is set to default. As no activity + logs are expected for creation/deletion at defualt log level. + + """ + logger.info("Making sure noobaa log is at default_level...") + change_the_noobaa_log_level(level="default_level") + + bucket = bucket_factory()[0] + logger.info("successfully created bucket") + + obj_uploaded = write_random_test_objects_to_bucket( + awscli_pod_session, + bucket.name, + test_directory_setup.origin_dir, + amount=1, + mcg_obj=mcg_obj, + )[0] + logger.info(f"uploaded object {obj_uploaded} to the bucket") + + rm_object_recursive(awscli_pod_session, bucket.name, mcg_obj) + logger.info("deleted all the objects from the bucket") + + tries = 0 + while tries <= 10: + logger.info("Checking the logs for 10 minutes if any ") + nb_activitylogs = [ + line + for line in exec_nb_db_query("SELECT data FROM activitylogs;") + if obj_uploaded in line + ] + logger.info("successfully fetched noobaa db activitylogs data") + + assert "obj.uploaded" not in str( + nb_activitylogs + ), "Object upload event is being logged in activitylogs table" + assert "obj.deleted" not in str( + nb_activitylogs + ), "Object deletion event is being logged in activitylogs table" + logger.info( + "No object upload/deletion info is being updated in the activitylogs table" + ) + time.sleep(60) + tries += 1