Skip to content

Commit

Permalink
Merge pull request #316 from gbregman/devel
Browse files Browse the repository at this point in the history
Add RPC locks to new SPDK log CLI commands and add them to CLI test
  • Loading branch information
gbregman authored Nov 12, 2023
2 parents 10ab62d + 7cb3cdc commit 41a88dc
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
24 changes: 20 additions & 4 deletions control/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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))
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)
44 changes: 44 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 41a88dc

Please sign in to comment.