From 316e1f1bb51799ef8810237ef23ededdbda18e22 Mon Sep 17 00:00:00 2001 From: Yulia Persky Date: Fri, 13 Dec 2024 18:23:17 +0200 Subject: [PATCH 1/4] adding a new test file for mcg cli functions with bucket list command verification Signed-off-by: Yulia Persky --- tests/functional/object/mcg/test_mcg_cli.py | 77 +++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tests/functional/object/mcg/test_mcg_cli.py diff --git a/tests/functional/object/mcg/test_mcg_cli.py b/tests/functional/object/mcg/test_mcg_cli.py new file mode 100644 index 00000000000..fc8e04a5d74 --- /dev/null +++ b/tests/functional/object/mcg/test_mcg_cli.py @@ -0,0 +1,77 @@ +import logging +import re + +import botocore +import pytest + +from ocs_ci.framework.pytest_customization.marks import ( + tier2, + acceptance, + performance, + skipif_mcg_only, + runs_on_provider, + red_squad, + mcg, +) +from ocs_ci.ocs.bucket_utils import sync_object_directory +from ocs_ci.ocs.constants import DEFAULT_STORAGECLASS_RBD, AWSCLI_TEST_OBJ_DIR +from ocs_ci.ocs.exceptions import CommandFailed +from ocs_ci.ocs.resources.objectbucket import BUCKET_MAP +from ocs_ci.ocs.resources.pod import get_pod_logs, get_operator_pods +from ocs_ci.framework.testlib import MCGTest +from ocs_ci.framework.pytest_customization.marks import skipif_managed_service + +logger = logging.getLogger(__name__) + + +@mcg +@red_squad +@tier2 +class TestMcgCli(MCGTest): + """ + Tests for mcg cli commands validation + """ + + def test_bucket_list_command( + self, + mcg_obj, + bucket_factory, + ): + """ + Test proper output of MCG CLI bucket list command. + The method does the following: + 1) runs this command to count the number of existing buckets + 2) creates number of buckets + 3) runs bucket list command again a + 4) verifies that the number of current buckets equals the number of previously existing and the added ones + + """ + bucket_lst_res = mcg_obj.exec_mcg_cmd("bucket list").stdout.split("\n") + bucket_names = [name.strip() for name in bucket_lst_res if name][ + 1: + ] # get rid of empty strings and the title + default_bucket_name = "first.bucket" + existing_buckets_num = len(bucket_names) + assert bucket_names[0] == default_bucket_name, ( + f"First bucket name is {bucket_names[0]}, " + f" expected {default_bucket_name}." + ) + logger.info(f"{existing_buckets_num} bucket(s) exist") + + count = 3 + logger.info(f"Creating {count} buckets") + buckets = bucket_factory(count) + created_bucket_names = (b.name for b in buckets) + logger.info("Buckets " + ", ".join(created_bucket_names) + " created") + + bucket_lst_res = mcg_obj.exec_mcg_cmd("bucket list").stdout.split("\n") + bucket_names = [name.strip() for name in bucket_lst_res if name][ + 1: + ] # get rid of empty strings and the title + current_buckets_num = len(bucket_names) + assert current_buckets_num == existing_buckets_num + count, ( + f"'bucket list' command shows" + f" {current_buckets_num} buckets" + f" expected {existing_buckets_num + count}." + ) + logger.info("'bucket list' command finished successfully") From b494faac4f5546072bfaa64091a51f94424078c1 Mon Sep 17 00:00:00 2001 From: Yulia Persky Date: Fri, 13 Dec 2024 18:32:39 +0200 Subject: [PATCH 2/4] Fix flake8 errors Signed-off-by: Yulia Persky --- tests/functional/object/mcg/test_mcg_cli.py | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/tests/functional/object/mcg/test_mcg_cli.py b/tests/functional/object/mcg/test_mcg_cli.py index fc8e04a5d74..5afffac62e0 100644 --- a/tests/functional/object/mcg/test_mcg_cli.py +++ b/tests/functional/object/mcg/test_mcg_cli.py @@ -1,25 +1,11 @@ import logging -import re - -import botocore -import pytest from ocs_ci.framework.pytest_customization.marks import ( tier2, - acceptance, - performance, - skipif_mcg_only, - runs_on_provider, red_squad, mcg, ) -from ocs_ci.ocs.bucket_utils import sync_object_directory -from ocs_ci.ocs.constants import DEFAULT_STORAGECLASS_RBD, AWSCLI_TEST_OBJ_DIR -from ocs_ci.ocs.exceptions import CommandFailed -from ocs_ci.ocs.resources.objectbucket import BUCKET_MAP -from ocs_ci.ocs.resources.pod import get_pod_logs, get_operator_pods from ocs_ci.framework.testlib import MCGTest -from ocs_ci.framework.pytest_customization.marks import skipif_managed_service logger = logging.getLogger(__name__) @@ -42,7 +28,7 @@ def test_bucket_list_command( The method does the following: 1) runs this command to count the number of existing buckets 2) creates number of buckets - 3) runs bucket list command again a + 3) runs bucket list command again 4) verifies that the number of current buckets equals the number of previously existing and the added ones """ From 5e3a67f300c53e88bec9bd7817400f2d2ba4f43a Mon Sep 17 00:00:00 2001 From: Yulia Persky Date: Wed, 18 Dec 2024 02:16:31 +0200 Subject: [PATCH 3/4] making buckets count an argument Signed-off-by: Yulia Persky --- tests/functional/object/mcg/test_mcg_cli.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/functional/object/mcg/test_mcg_cli.py b/tests/functional/object/mcg/test_mcg_cli.py index 5afffac62e0..cd00d87cfae 100644 --- a/tests/functional/object/mcg/test_mcg_cli.py +++ b/tests/functional/object/mcg/test_mcg_cli.py @@ -1,3 +1,5 @@ +import pytest + import logging from ocs_ci.framework.pytest_customization.marks import ( @@ -18,8 +20,15 @@ class TestMcgCli(MCGTest): Tests for mcg cli commands validation """ + @pytest.mark.parametrize( + argnames="count", + argvalues=[ + pytest.param(3), + ], + ) def test_bucket_list_command( self, + count, mcg_obj, bucket_factory, ): @@ -31,6 +40,9 @@ def test_bucket_list_command( 3) runs bucket list command again 4) verifies that the number of current buckets equals the number of previously existing and the added ones + Args: + count (int): number of buckets to create + """ bucket_lst_res = mcg_obj.exec_mcg_cmd("bucket list").stdout.split("\n") bucket_names = [name.strip() for name in bucket_lst_res if name][ @@ -44,7 +56,6 @@ def test_bucket_list_command( ) logger.info(f"{existing_buckets_num} bucket(s) exist") - count = 3 logger.info(f"Creating {count} buckets") buckets = bucket_factory(count) created_bucket_names = (b.name for b in buckets) From a270b74f2fe03cdd64492b49e3799cf4979f59da Mon Sep 17 00:00:00 2001 From: Yulia Persky Date: Tue, 24 Dec 2024 17:19:27 +0200 Subject: [PATCH 4/4] fixing review comment Signed-off-by: Yulia Persky --- tests/functional/object/mcg/test_mcg_cli.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/functional/object/mcg/test_mcg_cli.py b/tests/functional/object/mcg/test_mcg_cli.py index cd00d87cfae..412fb47df4e 100644 --- a/tests/functional/object/mcg/test_mcg_cli.py +++ b/tests/functional/object/mcg/test_mcg_cli.py @@ -48,12 +48,7 @@ def test_bucket_list_command( bucket_names = [name.strip() for name in bucket_lst_res if name][ 1: ] # get rid of empty strings and the title - default_bucket_name = "first.bucket" existing_buckets_num = len(bucket_names) - assert bucket_names[0] == default_bucket_name, ( - f"First bucket name is {bucket_names[0]}, " - f" expected {default_bucket_name}." - ) logger.info(f"{existing_buckets_num} bucket(s) exist") logger.info(f"Creating {count} buckets")