diff --git a/ocs_ci/helpers/helpers.py b/ocs_ci/helpers/helpers.py index d283d0bbaeb..ca3810fd6bd 100644 --- a/ocs_ci/helpers/helpers.py +++ b/ocs_ci/helpers/helpers.py @@ -4595,3 +4595,53 @@ def get_architecture_path(cli_type): elif system == "Darwin": # Mac path = os.path.join(path, "macosx", image_prefix) return path + + +def odf_cli_set_log_level(service, log_level, subsystem): + """ + Set the log level for a Ceph service. + Args: + service (str): The Ceph service name. + log_level (str): The log level to set. + subsystem (str): The subsystem for which to set the log level. + Returns: + str: The output of the command execution. + """ + from pathlib import Path + + if not Path(constants.CLI_TOOL_LOCAL_PATH).exists(): + retrieve_cli_binary(cli_type="odf") + + logger.info( + f"Setting ceph log level for {service} on {subsystem} to {log_level} using odf-cli tool." + ) + cmd = ( + f"{constants.CLI_TOOL_LOCAL_PATH} --kubeconfig {os.getenv('KUBECONFIG')} " + f" set ceph log-level {service} {subsystem} {log_level}" + ) + + logger.info(cmd) + return exec_cmd(cmd, use_shell=True) + + +def get_ceph_log_level(service, subsystem): + """ + Return CEPH log level value. + + Args: + service (_type_): _description_ + subsystem (_type_): _description_ + """ + + logger.info( + f"Fetching ceph log level for {service} on {subsystem} Using odf-cli tool." + ) + toolbox = pod.get_ceph_tools_pod() + ceph_cmd = f"ceph config get {service}" + + ceph_output = toolbox.exec_ceph_cmd(ceph_cmd) + + ceph_log_level = ceph_output.get(f"debug_{subsystem}", {}).get("value", None) + + memory_value, log_value = ceph_log_level.split("/") + return int(log_value) diff --git a/tests/functional/odf-cli/__init__.py b/tests/functional/odf-cli/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/functional/odf-cli/test_debug_verbocity_of_ceph_component.py b/tests/functional/odf-cli/test_debug_verbocity_of_ceph_component.py new file mode 100644 index 00000000000..048b81a18c5 --- /dev/null +++ b/tests/functional/odf-cli/test_debug_verbocity_of_ceph_component.py @@ -0,0 +1,48 @@ +import pytest +import logging + +from ocs_ci.helpers.helpers import odf_cli_set_log_level, get_ceph_log_level +from ocs_ci.framework.pytest_customization.marks import brown_squad +from ocs_ci.ocs.exceptions import CommandFailed +from ocs_ci.framework.testlib import tier1 + +log = logging.getLogger(__name__) + + +@brown_squad +@tier1 +class TestDebugVerbosityOfCephComponents: + @pytest.mark.polarion_id("OCS-5417") + @pytest.mark.parametrize( + argnames=["service", "subsystem"], + argvalues=[("osd", "crush"), ("mds", "crush"), ("mon", "crush")], + ) + def test_debug_verbosity_of_ceph_components(self, service, subsystem): + """ + Test setting the debug verbosity of Ceph components using ODF CLI. + Steps: + 1. Set log-level using ODF cli tool for services {mon, mds, osd } + 2. Verify log-level from the ceph toolbox pod + 3. Test Overriding log level with different value. + 4. Test Setting up log level to upper limit 99. + 5. Test Setting up log level to lower limit 0. + 6. Test Setting up log level beyond limit. + + """ + log_levels = (50, 99, 0, 100) + + for log_level in log_levels: + # Setting up and verifying the log level value with the odf CLI tool + log.info( + f"Setting log level to {log_level} for service: {service}, subsystem: {subsystem}" + ) + + if log_level > 99: + with pytest.raises(CommandFailed): + odf_cli_set_log_level(service, log_level, subsystem) + log.info("Log level beyond the limit was not set as expected.") + else: + assert odf_cli_set_log_level(service, log_level, subsystem) + assert log_level == get_ceph_log_level( + service, subsystem + ), f"Log level set by ODF CLI ({log_level}) does not match with the value reported by Ceph"