Skip to content

Commit

Permalink
grpc: structured subsystems_info
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Indenbaum <[email protected]>
  • Loading branch information
Alexander Indenbaum committed Nov 16, 2023
1 parent a26d301 commit bdd6ab4
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 12 deletions.
11 changes: 7 additions & 4 deletions control/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import sys

from functools import wraps
from google.protobuf import json_format

from .proto import gateway_pb2_grpc as pb2_grpc
from .proto import gateway_pb2 as pb2
Expand Down Expand Up @@ -338,10 +339,12 @@ def delete_listener(self, args):
def get_subsystems(self, args):
"""Gets subsystems."""
req = pb2.get_subsystems_req()
ret = self.stub.get_subsystems(req)
subsystems = json.loads(ret.subsystems)
formatted_subsystems = json.dumps(subsystems, indent=4)
self.logger.info(f"Get subsystems:\n{formatted_subsystems}")

subsystems = json_format.MessageToJson(
self.stub.get_subsystems(req),
indent=4,
preserving_proto_field_name=True)
self.logger.info(f"Get subsystems:\n{subsystems}")

@cli.cmd()
def get_spdk_nvmf_log_flags_and_level(self, args):
Expand Down
13 changes: 12 additions & 1 deletion control/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ def get_subsystems_safe(self, request, context):
"""Gets subsystems."""

self.logger.info(f"Received request to get subsystems, context: {context}")
subsystems = []
try:
ret = rpc_nvmf.nvmf_get_subsystems(self.spdk_rpc_client)
self.logger.info(f"get_subsystems: {ret}")
Expand All @@ -800,7 +801,17 @@ def get_subsystems_safe(self, request, context):
context.set_details(f"{ex}")
return pb2.subsystems_info()

return pb2.subsystems_info(subsystems=json.dumps(ret))
for s in ret:
try:
# Parse the JSON dictionary into the protobuf message
subsystem = pb2.subsystem()
json_format.Parse(json.dumps(s), subsystem)
subsystems.append(subsystem)
except Exception:
self.logger.exception(f"{s=} parse error: ")
raise

return pb2.subsystems_info(subsystems=subsystems)

def get_subsystems(self, request, context):
with self.rpc_lock:
Expand Down
43 changes: 38 additions & 5 deletions control/proto/gateway.proto
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ message delete_subsystem_req {
message add_namespace_req {
string subsystem_nqn = 1;
string bdev_name = 2;
optional int32 nsid = 3;
optional uint32 nsid = 3;
optional int32 anagrpid = 4;
}

message remove_namespace_req {
string subsystem_nqn = 1;
int32 nsid = 2;
uint32 nsid = 2;
}

message add_host_req {
Expand Down Expand Up @@ -156,15 +156,48 @@ message req_status {
}

message nsid_status {
int32 nsid = 1;
uint32 nsid = 1;
bool status = 2;
}

message subsystems_info {
string subsystems = 1;
repeated subsystem subsystems = 1;
}

message subsystem {
string nqn = 1;
string subtype = 2;
repeated listen_address listen_addresses = 3;
repeated host hosts = 4;
bool allow_any_host = 5;
optional string serial_number = 6;
optional string model_number = 7;
optional uint32 max_namespaces = 8;
optional uint32 min_cntlid = 9;
optional uint32 max_cntlid = 10;
repeated namespace namespaces = 11;
}

message listen_address {
string transport = 1;
string trtype = 2;
string adrfam = 3;
string traddr = 4;
string trsvcid = 5;
}

message host {
string nqn = 1;
}

message namespace {
uint32 nsid = 1;
string name = 2;
optional string bdev_name = 3;
optional string nguid = 4;
optional string uuid = 5;
}

message spdk_nvmf_log_flags_and_level_info {
string flags_level =1;
}

5 changes: 3 additions & 2 deletions tests/test_multi_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import grpc
import json
import time
from google.protobuf import json_format
from control.server import GatewayServer
from control.proto import gateway_pb2 as pb2
from control.proto import gateway_pb2_grpc as pb2_grpc
Expand Down Expand Up @@ -95,8 +96,8 @@ def test_multi_gateway_coordination(config, image, conn):
# Watch/Notify
if update_notify:
time.sleep(1)
watchB = stubB.get_subsystems(get_subsystems_req)
listB = json.loads(watchB.subsystems)
listB = json.loads(json_format.MessageToJson(
stubB.get_subsystems(get_subsystems_req)))
assert len(listB) == num_subsystems
assert listB[num_subsystems-1]["nqn"] == nqn
assert listB[num_subsystems-1]["serial_number"] == serial
Expand Down

0 comments on commit bdd6ab4

Please sign in to comment.