diff --git a/control/grpc.py b/control/grpc.py index e58bd960..c02142f0 100644 --- a/control/grpc.py +++ b/control/grpc.py @@ -126,6 +126,10 @@ def _grpc_function_with_lock(self, func, request, context): return func(request, context) def execute_grpc_function(self, func, request, context): + """This functions handles both the RPC and OMAP locks. It first takes the OMAP lock and then calls a + help function which takes the RPC lock and call the GRPC function passes as a parameter. So, the GRPC + function runs with both the OMAP and RPC locks taken + """ return self.omap_lock.execute_omap_locking_function(self._grpc_function_with_lock, func, request, context) def create_bdev_safe(self, request, context=None): @@ -781,7 +785,7 @@ def get_subsystems(self, request, context): with self.rpc_lock: return self.get_subsystems_safe(request, context) - def get_spdk_nvmf_log_flags_and_level(self, request, context): + def get_spdk_nvmf_log_flags_and_level_safe(self, request, context): """Gets spdk nvmf log flags, log level and log print level""" self.logger.info(f"Received request to get SPDK nvmf log flags and level") try: @@ -803,7 +807,11 @@ def get_spdk_nvmf_log_flags_and_level(self, request, context): return pb2.spdk_nvmf_log_flags_and_level_info( flags_level=json.dumps(flags_log_level)) - def set_spdk_nvmf_logs(self, request, context): + def get_spdk_nvmf_log_flags_and_level(self, request, context): + with self.rpc_lock: + return self.get_spdk_nvmf_log_flags_and_level_safe(request, context) + + def set_spdk_nvmf_logs_safe(self, request, context): """Enables spdk nvmf logs""" self.logger.info(f"Received request to set SPDK nvmf logs") try: @@ -831,7 +839,11 @@ def set_spdk_nvmf_logs(self, request, context): return pb2.req_status(status=all(ret)) - def disable_spdk_nvmf_logs(self, request, context): + def set_spdk_nvmf_logs(self, request, context): + with self.rpc_lock: + return self.set_spdk_nvmf_logs_safe(request, context) + + def disable_spdk_nvmf_logs_safe(self, request, context): """Disables spdk nvmf logs""" self.logger.info(f"Received request to disable SPDK nvmf logs") try: @@ -848,4 +860,8 @@ def disable_spdk_nvmf_logs(self, request, context): context.set_details(f"{ex}") return pb2.req_status() - return pb2.req_status(status=all(ret)) \ No newline at end of file + return pb2.req_status(status=all(ret)) + + def disable_spdk_nvmf_logs(self, request, context): + with self.rpc_lock: + return self.disable_spdk_nvmf_logs_safe(request, context) diff --git a/tests/test_cli.py b/tests/test_cli.py index 45169b72..6ff3f1ec 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -190,3 +190,47 @@ def test_delete_subsystem_ana(self, caplog, gateway): cli(["delete_subsystem", "-n", subsystem]) assert "Failed to delete" not in caplog.text +class TestSDKLOg: + def test_log_flags(self, caplog, gateway): + caplog.clear() + cli(["get_spdk_nvmf_log_flags_and_level"]) + assert '"nvmf": false' in caplog.text + assert '"nvmf_tcp": false' in caplog.text + assert '"log_level": "NOTICE"' in caplog.text + assert '"log_print_level": "INFO"' in caplog.text + caplog.clear() + cli(["set_spdk_nvmf_logs", "-f"]) + assert "Set SPDK nvmf logs : True" in caplog.text + caplog.clear() + cli(["get_spdk_nvmf_log_flags_and_level"]) + assert '"nvmf": true' in caplog.text + assert '"nvmf_tcp": true' in caplog.text + assert '"log_level": "NOTICE"' in caplog.text + assert '"log_print_level": "INFO"' in caplog.text + caplog.clear() + cli(["set_spdk_nvmf_logs", "-f", "-l", "DEBUG"]) + assert "Set SPDK nvmf logs : True" in caplog.text + caplog.clear() + cli(["get_spdk_nvmf_log_flags_and_level"]) + assert '"nvmf": true' in caplog.text + assert '"nvmf_tcp": true' in caplog.text + assert '"log_level": "DEBUG"' in caplog.text + assert '"log_print_level": "INFO"' in caplog.text + caplog.clear() + cli(["set_spdk_nvmf_logs", "-f", "-p", "ERROR"]) + assert "Set SPDK nvmf logs : True" in caplog.text + caplog.clear() + cli(["get_spdk_nvmf_log_flags_and_level"]) + assert '"nvmf": true' in caplog.text + assert '"nvmf_tcp": true' in caplog.text + assert '"log_level": "DEBUG"' in caplog.text + assert '"log_print_level": "ERROR"' in caplog.text + caplog.clear() + cli(["disable_spdk_nvmf_logs"]) + assert "Disable SPDK nvmf logs: True" in caplog.text + caplog.clear() + cli(["get_spdk_nvmf_log_flags_and_level"]) + assert '"nvmf": false' in caplog.text + assert '"nvmf_tcp": false' in caplog.text + assert '"log_level": "NOTICE"' in caplog.text + assert '"log_print_level": "INFO"' in caplog.text