]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
add dbg cmda2 wip-tomer-debug-cmd-centos9-only
authorTomer Haskalovitch <tomer.haska@ibm.com>
Tue, 25 Nov 2025 09:44:27 +0000 (11:44 +0200)
committerTomer Haskalovitch <tomer.haska@ibm.com>
Wed, 26 Nov 2025 22:32:43 +0000 (00:32 +0200)
src/pybind/mgr/dashboard/services/nvmeof_cli.py

index 6cb8d361f5d4ca82ce66f5741710b5b8969a24bb..d4788f60ed4fb092578a98cdd7af7e4446c69bf4 100644 (file)
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 import errno
 import json
+import traceback
 from abc import ABC, abstractmethod
 from enum import Enum
 from typing import Annotated, Any, Dict, List, NamedTuple, Optional, Type, \
@@ -13,10 +14,14 @@ from prettytable import PrettyTable
 
 from ..model.nvmeof import CliFieldTransformer, CliFlags, CliHeader
 from ..rest_client import RequestException
+from ..exceptions import DashboardException
 from .nvmeof_conf import ManagedByOrchestratorException, \
-    NvmeofGatewayAlreadyExists, NvmeofGatewaysConfig
-
+    NvmeofGatewayAlreadyExists, NvmeofGatewaysConfig, is_mtls_enabled
 
+try:
+    from .proto import gateway_pb2 as pb2  # type: ignore
+    from .proto import gateway_pb2_grpc as pb2_grpc  # type: ignore
+    
 @CLIReadCommand('dashboard nvmeof-gateway-list')
 def list_nvmeof_gateways(_):
     '''
@@ -63,6 +68,59 @@ UNITS = {
     if not (prefix == '' and suffix == 'iB')
 }
 
+@CLIReadCommand('dashboard nvmeof-dbg')
+def list_nvmeof_gateways(_):
+    try:
+        res = NvmeofGatewaysConfig.get_service_info()
+        if res is None:
+            raise DashboardException("Gateway group does not exists")
+        service_name, gateway_addr = res
+    except TypeError as e:
+        raise DashboardException(
+            f'Unable to retrieve the gateway info: {e}'
+        )
+                
+    client_key = NvmeofGatewaysConfig.get_client_key(service_name)
+    client_cert = NvmeofGatewaysConfig.get_client_cert(service_name)
+    server_cert = NvmeofGatewaysConfig.get_server_cert(service_name)
+    mtls_enabled = is_mtls_enabled(service_name)
+    
+    channel_err = None
+    credentials = None
+    channel = None
+    stub = None
+    gw_info_msg = None
+    msg_dict = None
+    try:
+        credentials = grpc.ssl_channel_credentials(
+                        root_certificates=server_cert,
+                        private_key=client_key,
+                        certificate_chain=client_cert,
+                    )
+        channel = grpc.secure_channel(gateway_addr, credentials)
+
+        stub = pb2_grpc.GatewayStub(channel)
+        gw_info_msg = stub.get_gateway_info(NVMeoFClient.pb2.get_gateway_info_req())
+        msg_dict = MessageToDict(gw_info_msg, including_default_value_fields=True,
+                                         preserving_proto_field_name=True)  # type: ignore
+    except Exception as e:
+        channel_err = traceback.format_exc()
+    
+    resp = {
+        "gw_addr": gateway_addr,
+        "client_key": client_key,
+        "client_cert": client_cert,
+        "server_cert": server_cert,
+        "gw_config": NvmeofGatewaysConfig.get_gateways_config(),
+        
+        "channel_err": channel_err,
+        "channel_flag": bool(channel),
+        "stub_flag": bool(stub),
+        "gw_info_msg_flag": bool(gw_info_msg),
+        "msg_dict": msg_dict,
+        
+    }
+    return 0, json.dumps(resp), ''
 
 def convert_to_bytes(size: Union[int, str], default_unit=None):
     if isinstance(size, int):