← Back to Pull requests

Add a CLI command for listing namespace locations counts #1775

Merged
gbregman merged 3 files (258 lines) on Feb 12, 2026 17:22 UTC
View on GitHub
gbregman gbregman commented on Feb 12, 2026 13:26 UTC
Author

Fixes: #1763

Diff: 258 lines (+253 / -5) across 3 files Reviewer: leonidc Review duration: 236m
All Vouch review confidence checks passed
Residual risk 0.05 = Change Risk (0.45) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 258 lines diff across 3 files
0.45
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.89 · 5 substantive comment(s)
0.89
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
89%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.332
Empty Description empty_description
0.060
Real PR Conversation Timeline
15 items
Copilot Copilot commented on code on Feb 12, 2026 13:32 UTC
Code Review
control/cli.py:1
@@ -2679,6 +2744,8 @@ def ns_list(self, args, show_hosts=False):
                                  f"{namespaces_info.subsystem_nqn} which is different than the "
                                  f"requested subsystem {args.subsystem}")
                         return errno.ENODEV
+                if show_ns_locations and namespaces_info.namespaces:

The condition only calls ns_location_list when namespaces is non-empty. When show_ns_locations is True but the namespace list is empty, the function falls through to the regular namespace listing logic and displays "No namespaces in..." messages. This creates inconsistent behavior. Consider removing the namespaces_info.namespaces check to always call ns_location_list when show_ns_locations is True, allowing that function to handle the empty case consistently.

                if show_ns_locations:

Copilot Copilot commented on code on Feb 12, 2026 13:32 UTC
Code Review
control/cli.py:1
@@ -2648,13 +2648,78 @@ def get_size_in_bytes(self, sz):
         int_size *= multiply
         return int_size
 
-    def ns_list(self, args, show_hosts=False):
+    def ns_location_list(self, args, ns_info):
+        """List namespace distribution per site locations"""
+
+        out_func, _, warn_func = self.get_output_functions(args)
+        ns_locations_count = {}
+        if ns_info.namespaces:
+            for ns in ns_info.namespaces:
+                nqn = ns.ns_subsystem_nqn
+                if not nqn:
+                    warn_func("Found a namespace without a subsystem")
+                    nqn = "<n/a>"
+                lb = ns.load_balancing_group
+                if not lb:
+                    lb = 0
+                loc = ns.location
+                if not loc:
+                    loc = "<default>"
+                if nqn not in ns_locations_count:
+                    ns_locations_count[nqn] = {}
+                if lb not in ns_locations_count[nqn]:
+                    ns_locations_count[nqn][lb] = {}
+                if loc not in ns_locations_count[nqn][lb]:
+                    ns_locations_count[nqn][lb][loc] = 0
+                ns_locations_count[nqn][lb][loc] += 1
+
+        loc_list = []
+        for nqn in sorted(ns_locations_count.keys()):
+            first_nqn = True
+            for lb in sorted(ns_locations_count[nqn].keys()):
+                for loc in sorted(ns_locations_count[nqn][lb].keys()):
+                    nqnstr = nqn if first_nqn else ""
+                    first_nqn = False
+                    lbstr = str(lb) if lb else "<n/a>"

The load balancing group is set to 0 if it's falsy at line 2664, which means the condition if lb at line 2683 will always be True (since lb is either the original non-zero value or 0). This makes the else branch with "<n/a>" unreachable. Consider either removing the default assignment at line 2664 and keeping the check at 2683, or removing the conditional at 2683 and always converting to string since 0 is a valid load balancing group value.

copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Feb 12, 2026 13:32 UTC
Reviewer

Pull request overview

This pull request adds a new CLI command namespace list_locations that displays the distribution of namespaces by site location, grouped by subsystem and load balancing group. This addresses issue #1763 by providing administrators with visibility into how namespaces are distributed across different geographic locations.

Changes:

  • Added ns_location_list() function to aggregate and display namespace counts per location

  • Modified ns_list() function to support a show_ns_locations parameter for routing to location list view

  • Changed namespace location display from "<N/A>" to "<default>" for consistency with new location semantics
  • Reviewed changes

    Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

    | File | Description |
    | ---- | ----------- |
    | control/cli.py | Added new ns_location_list() function, modified ns_list() to support location listing mode, added CLI action definition for list_locations, and updated location display to use "<default>" instead of "<N/A>" |
    | tests/test_cli_list_ns_locations.py | Added comprehensive test coverage with two-gateway setup testing location distribution across subsystems and load balancing groups |
    | .github/workflows/build-container.yml | Added new test to CI/CD pipeline test matrix |

    ---

    💡 <a href="/ceph/ceph-nvmeof/new/devel/.github/instructions?filename=*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.

    gbregman gbregman commented on code on Feb 12, 2026 13:54 UTC
    Code Review
    control/cli.py:1
    @@ -2679,6 +2744,8 @@ def ns_list(self, args, show_hosts=False):
                                      f"{namespaces_info.subsystem_nqn} which is different than the "
                                      f"requested subsystem {args.subsystem}")
                             return errno.ENODEV
    +                if show_ns_locations and namespaces_info.namespaces:

    changed

    gbregman gbregman commented on code on Feb 12, 2026 13:57 UTC
    Code Review
    control/cli.py:1
    @@ -2648,13 +2648,78 @@ def get_size_in_bytes(self, sz):
             int_size *= multiply
             return int_size
     
    -    def ns_list(self, args, show_hosts=False):
    +    def ns_location_list(self, args, ns_info):
    +        """List namespace distribution per site locations"""
    +
    +        out_func, _, warn_func = self.get_output_functions(args)
    +        ns_locations_count = {}
    +        if ns_info.namespaces:
    +            for ns in ns_info.namespaces:
    +                nqn = ns.ns_subsystem_nqn
    +                if not nqn:
    +                    warn_func("Found a namespace without a subsystem")
    +                    nqn = "<n/a>"
    +                lb = ns.load_balancing_group
    +                if not lb:
    +                    lb = 0
    +                loc = ns.location
    +                if not loc:
    +                    loc = "<default>"
    +                if nqn not in ns_locations_count:
    +                    ns_locations_count[nqn] = {}
    +                if lb not in ns_locations_count[nqn]:
    +                    ns_locations_count[nqn][lb] = {}
    +                if loc not in ns_locations_count[nqn][lb]:
    +                    ns_locations_count[nqn][lb][loc] = 0
    +                ns_locations_count[nqn][lb][loc] += 1
    +
    +        loc_list = []
    +        for nqn in sorted(ns_locations_count.keys()):
    +            first_nqn = True
    +            for lb in sorted(ns_locations_count[nqn].keys()):
    +                for loc in sorted(ns_locations_count[nqn][lb].keys()):
    +                    nqnstr = nqn if first_nqn else ""
    +                    first_nqn = False
    +                    lbstr = str(lb) if lb else "<n/a>"

    This is wrong. When lb is 0 we'll get the "<n/a>" string.

    Copilot Copilot commented on code on Feb 12, 2026 14:04 UTC
    Code Review
    tests/test_cli_list_ns_locations.py:1
    @@ -0,0 +1,172 @@
    +import pytest
    +from control.server import GatewayServer
    +from control.cli import main as cli
    +from control.cephutils import CephUtils
    +import grpc
    +from control.proto import gateway_pb2_grpc as pb2_grpc
    +import copy
    +import os
    +import time
    +import re
    +
    +image = "mytestdevimage1"
    +image2 = "mytestdevimage2"
    +image3 = "mytestdevimage3"
    +image4 = "mytestdevimage4"
    +image5 = "mytestdevimage5"
    +pool = "rbd"
    +subsystem = "nqn.2016-06.io.spdk:cnode1"
    +subsystem2 = "nqn.2016-06.io.spdk:cnode2"
    +group_name = "GROUPNAME"
    +location = "USA"
    +location2 = "France"
    +
    +
    +@pytest.fixture(scope="module")
    +def two_gateways(config):
    +    """Sets up and tears down two gateways"""
    +
    +    global location, location2
    +    nameA = "GatewayAA"
    +    nameB = "GatewayBB"
    +    sockA = f"spdk_{nameA}.sock"
    +    sockB = f"spdk_{nameB}.sock"
    +    addr = config.get("gateway", "addr")
    +    config.config["gateway"]["group"] = group_name
    +    config.config["gateway-logs"]["log_level"] = "debug"
    +    configA = copy.deepcopy(config)
    +    configB = copy.deepcopy(config)
    +    configA.config["gateway"]["name"] = nameA
    +    configA.config["gateway"]["override_hostname"] = nameA
    +    configA.config["spdk"]["rpc_socket_name"] = sockA
    +    if os.cpu_count() >= 4:
    +        configA.config["spdk"]["tgt_cmd_extra_args"] = "--lcores (0-1)"
    +    else:
    +        configA.config["spdk"]["tgt_cmd_extra_args"] = "--disable-cpumask-locks"
    +    portA = configA.getint("gateway", "port")
    +    configB.config["gateway"]["name"] = nameB
    +    configB.config["gateway"]["override_hostname"] = nameB
    +    configB.config["spdk"]["rpc_socket_name"] = sockB
    +    portB = portA + 2
    +    discPortB = configB.getint("discovery", "port") + 1
    +    configB.config["gateway"]["port"] = str(portB)
    +    configB.config["discovery"]["port"] = str(discPortB)
    +    if os.cpu_count() >= 4:
    +        configB.config["spdk"]["tgt_cmd_extra_args"] = "--lcores (2-3)"
    +    else:
    +        configB.config["spdk"]["tgt_cmd_extra_args"] = "--disable-cpumask-locks"
    +
    +    ceph_utils = CephUtils(config)
    +    with (GatewayServer(configA) as gatewayA, GatewayServer(configB) as gatewayB):
    +
    +        # Start gateway
    +        gatewayA.gw_logger_object.set_log_level("debug")
    +        gatewayB.gw_logger_object.set_log_level("debug")
    +        ceph_utils.execute_ceph_monitor_command(
    +            "{" + f'"prefix":"nvme-gw create", "id": "{nameA}", "pool": "{pool}", '
    +            f'"group": "{group_name}"' + "}"
    +        )
    +        ceph_utils.execute_ceph_monitor_command(
    +            "{" + f'"prefix":"nvme-gw create", "id": "{nameB}", "pool": "{pool}", '
    +            f'"group": "{group_name}"' + "}"
    +        )
    +        rc = ceph_utils.execute_ceph_monitor_command(
    +            "{" + f'"prefix":"nvme-gw set-location", "id": "{nameA}", "pool": "{pool}", '
    +            f'"group": "{group_name}", "location": "{location}"' + "}"
    +        )
    +        if rc[0]:
    +            location = ""
    +            location2 = ""
    +            print("set-location is not implemented in Ceph, will use default")
    +        else:
    +            rc = ceph_utils.execute_ceph_monitor_command(
    +                "{" + f'"prefix":"nvme-gw set-location", "id": "{nameB}", "pool": "{pool}", '
    +                f'"group": "{group_name}", "location": "{location2}"' + "}"
    +            )
    +            assert rc[0] == 0
    +
    +        assert (location and location2) or (not location and not location2)
    +
    +        gatewayA.serve()
    +        gatewayB.serve()
    +
    +        # Bind the client and Gateway
    +        channel = grpc.insecure_channel(f"{addr}:{portA}")
    +        pb2_grpc.GatewayStub(channel)
    +        channel = grpc.insecure_channel(f"{addr}:{portB}")
    +        pb2_grpc.GatewayStub(channel)
    +        yield gatewayA.gateway_rpc, gatewayB.gateway_rpc
    +
    +        # Stop gateway
    +        gatewayA.server.stop(grace=1)
    +        gatewayB.server.stop(grace=1)
    +        gatewayA.gateway_rpc.gateway_state.delete_state()
    +        gatewayB.gateway_rpc.gateway_state.delete_state()
    +
    +
    +@pytest.fixture(scope="module", autouse=True)
    +def create_resources(two_gateways):
    +    _, gwB = two_gateways
    +    rc = cli(["subsystem", "add", "--subsystem", subsystem, "--no-group-append"])
    +    assert rc == 0
    +    rc = cli(["subsystem", "add", "--subsystem", subsystem2, "--no-group-append"])
    +    assert rc == 0
    +    rc = cli(["namespace", "add", "--subsystem", subsystem, "--rbd-pool", pool,
    +              "--rbd-image", image, "--size", "16MB", "--load-balancing-group", "1",
    +              "--rbd-create-image", "--location", location])
    +    assert rc == 0
    +    rc = cli(["namespace", "add", "--subsystem", subsystem, "--rbd-pool", pool,
    +              "--rbd-image", image2, "--size", "16MB", "--load-balancing-group", "1",
    +              "--rbd-create-image", "--location", location])
    +    assert rc == 0
    +    rc = cli(["namespace", "add", "--subsystem", subsystem, "--rbd-pool", pool,
    +              "--rbd-image", image3, "--size", "16MB", "--load-balancing-group", "1",
    +              "--rbd-create-image", "--location", location])
    +    assert rc == 0
    +    rc = cli(["namespace", "add", "--subsystem", subsystem2, "--rbd-pool", pool,
    +              "--rbd-image", image4, "--size", "16MB", "--load-balancing-group", "1",
    +              "--rbd-create-image", "--location", location])
    +    assert rc == 0
    +    time.sleep(20)
    +    rc = cli(["--server-port", gwB.config.config["gateway"]["port"],
    +              "namespace", "add", "--subsystem", subsystem2,
    +              "--rbd-pool", pool, "--rbd-image", image5, "--size", "16MB",
    +              "--rbd-create-image", "--location", location2, "--load-balancing-group", "2"])
    +    assert rc == 0
    +    time.sleep(20)
    +
    +
    +def find_in_caplog(lookfor, captext) -> bool:
    +    regex = re.compile(lookfor, re.MULTILINE)
    +    if re.search(regex, captext) is not None:
    +        return True
    +    return False
    +
    +
    +def test_list_namespace_locations_one_subsystem(caplog, two_gateways):
    +    caplog.clear()
    +    cli(["--format", "plain", "namespace", "list_locations", "--subsystem", subsystem2])
    +    if location and location2:
    +        assert find_in_caplog(rf"^\s*{re.escape(subsystem2)}\s*1\s*{re.escape(location)}\s*1\s*$",
    +                              caplog.text)
    +        assert find_in_caplog(rf"^\s*2\s*{re.escape(location2)}\s*1\s*$", caplog.text)

    Several of these assert lines are likely to exceed the repo’s flake8 max-line-length = 100 limit (E501), which will fail make verify. Consider factoring the regex into a local variable, or splitting the pattern string across multiple shorter concatenated literals to keep each physical line <= 100 chars.

    Copilot Copilot commented on code on Feb 12, 2026 14:04 UTC
    Code Review
    tests/test_cli_list_ns_locations.py:1
    @@ -0,0 +1,172 @@
    +import pytest
    +from control.server import GatewayServer
    +from control.cli import main as cli
    +from control.cephutils import CephUtils
    +import grpc
    +from control.proto import gateway_pb2_grpc as pb2_grpc
    +import copy
    +import os
    +import time
    +import re
    +
    +image = "mytestdevimage1"
    +image2 = "mytestdevimage2"
    +image3 = "mytestdevimage3"
    +image4 = "mytestdevimage4"
    +image5 = "mytestdevimage5"
    +pool = "rbd"
    +subsystem = "nqn.2016-06.io.spdk:cnode1"
    +subsystem2 = "nqn.2016-06.io.spdk:cnode2"
    +group_name = "GROUPNAME"
    +location = "USA"
    +location2 = "France"
    +
    +
    +@pytest.fixture(scope="module")
    +def two_gateways(config):
    +    """Sets up and tears down two gateways"""
    +
    +    global location, location2
    +    nameA = "GatewayAA"
    +    nameB = "GatewayBB"
    +    sockA = f"spdk_{nameA}.sock"
    +    sockB = f"spdk_{nameB}.sock"
    +    addr = config.get("gateway", "addr")
    +    config.config["gateway"]["group"] = group_name
    +    config.config["gateway-logs"]["log_level"] = "debug"
    +    configA = copy.deepcopy(config)
    +    configB = copy.deepcopy(config)
    +    configA.config["gateway"]["name"] = nameA
    +    configA.config["gateway"]["override_hostname"] = nameA
    +    configA.config["spdk"]["rpc_socket_name"] = sockA
    +    if os.cpu_count() >= 4:
    +        configA.config["spdk"]["tgt_cmd_extra_args"] = "--lcores (0-1)"
    +    else:
    +        configA.config["spdk"]["tgt_cmd_extra_args"] = "--disable-cpumask-locks"
    +    portA = configA.getint("gateway", "port")
    +    configB.config["gateway"]["name"] = nameB
    +    configB.config["gateway"]["override_hostname"] = nameB
    +    configB.config["spdk"]["rpc_socket_name"] = sockB
    +    portB = portA + 2
    +    discPortB = configB.getint("discovery", "port") + 1
    +    configB.config["gateway"]["port"] = str(portB)
    +    configB.config["discovery"]["port"] = str(discPortB)
    +    if os.cpu_count() >= 4:
    +        configB.config["spdk"]["tgt_cmd_extra_args"] = "--lcores (2-3)"
    +    else:
    +        configB.config["spdk"]["tgt_cmd_extra_args"] = "--disable-cpumask-locks"
    +
    +    ceph_utils = CephUtils(config)
    +    with (GatewayServer(configA) as gatewayA, GatewayServer(configB) as gatewayB):
    +
    +        # Start gateway
    +        gatewayA.gw_logger_object.set_log_level("debug")
    +        gatewayB.gw_logger_object.set_log_level("debug")
    +        ceph_utils.execute_ceph_monitor_command(
    +            "{" + f'"prefix":"nvme-gw create", "id": "{nameA}", "pool": "{pool}", '
    +            f'"group": "{group_name}"' + "}"
    +        )
    +        ceph_utils.execute_ceph_monitor_command(
    +            "{" + f'"prefix":"nvme-gw create", "id": "{nameB}", "pool": "{pool}", '
    +            f'"group": "{group_name}"' + "}"
    +        )
    +        rc = ceph_utils.execute_ceph_monitor_command(
    +            "{" + f'"prefix":"nvme-gw set-location", "id": "{nameA}", "pool": "{pool}", '
    +            f'"group": "{group_name}", "location": "{location}"' + "}"
    +        )
    +        if rc[0]:
    +            location = ""
    +            location2 = ""
    +            print("set-location is not implemented in Ceph, will use default")
    +        else:
    +            rc = ceph_utils.execute_ceph_monitor_command(
    +                "{" + f'"prefix":"nvme-gw set-location", "id": "{nameB}", "pool": "{pool}", '
    +                f'"group": "{group_name}", "location": "{location2}"' + "}"
    +            )
    +            assert rc[0] == 0
    +
    +        assert (location and location2) or (not location and not location2)
    +
    +        gatewayA.serve()
    +        gatewayB.serve()
    +
    +        # Bind the client and Gateway
    +        channel = grpc.insecure_channel(f"{addr}:{portA}")
    +        pb2_grpc.GatewayStub(channel)
    +        channel = grpc.insecure_channel(f"{addr}:{portB}")
    +        pb2_grpc.GatewayStub(channel)
    +        yield gatewayA.gateway_rpc, gatewayB.gateway_rpc
    +
    +        # Stop gateway
    +        gatewayA.server.stop(grace=1)
    +        gatewayB.server.stop(grace=1)
    +        gatewayA.gateway_rpc.gateway_state.delete_state()
    +        gatewayB.gateway_rpc.gateway_state.delete_state()
    +
    +
    +@pytest.fixture(scope="module", autouse=True)
    +def create_resources(two_gateways):
    +    _, gwB = two_gateways
    +    rc = cli(["subsystem", "add", "--subsystem", subsystem, "--no-group-append"])
    +    assert rc == 0
    +    rc = cli(["subsystem", "add", "--subsystem", subsystem2, "--no-group-append"])
    +    assert rc == 0
    +    rc = cli(["namespace", "add", "--subsystem", subsystem, "--rbd-pool", pool,
    +              "--rbd-image", image, "--size", "16MB", "--load-balancing-group", "1",
    +              "--rbd-create-image", "--location", location])
    +    assert rc == 0
    +    rc = cli(["namespace", "add", "--subsystem", subsystem, "--rbd-pool", pool,
    +              "--rbd-image", image2, "--size", "16MB", "--load-balancing-group", "1",
    +              "--rbd-create-image", "--location", location])
    +    assert rc == 0
    +    rc = cli(["namespace", "add", "--subsystem", subsystem, "--rbd-pool", pool,
    +              "--rbd-image", image3, "--size", "16MB", "--load-balancing-group", "1",
    +              "--rbd-create-image", "--location", location])
    +    assert rc == 0
    +    rc = cli(["namespace", "add", "--subsystem", subsystem2, "--rbd-pool", pool,
    +              "--rbd-image", image4, "--size", "16MB", "--load-balancing-group", "1",
    +              "--rbd-create-image", "--location", location])
    +    assert rc == 0
    +    time.sleep(20)
    +    rc = cli(["--server-port", gwB.config.config["gateway"]["port"],
    +              "namespace", "add", "--subsystem", subsystem2,
    +              "--rbd-pool", pool, "--rbd-image", image5, "--size", "16MB",
    +              "--rbd-create-image", "--location", location2, "--load-balancing-group", "2"])
    +    assert rc == 0
    +    time.sleep(20)
    +
    +
    +def find_in_caplog(lookfor, captext) -> bool:
    +    regex = re.compile(lookfor, re.MULTILINE)
    +    if re.search(regex, captext) is not None:
    +        return True
    +    return False
    +
    +
    +def test_list_namespace_locations_one_subsystem(caplog, two_gateways):
    +    caplog.clear()
    +    cli(["--format", "plain", "namespace", "list_locations", "--subsystem", subsystem2])
    +    if location and location2:
    +        assert find_in_caplog(rf"^\s*{re.escape(subsystem2)}\s*1\s*{re.escape(location)}\s*1\s*$",
    +                              caplog.text)
    +        assert find_in_caplog(rf"^\s*2\s*{re.escape(location2)}\s*1\s*$", caplog.text)
    +    else:
    +        assert find_in_caplog(rf"^\s*{re.escape(subsystem2)}\s*1\s*<default>\s*1\s*$",
    +                              caplog.text)
    +        assert find_in_caplog(r"^\s*2\s*<default>\s*1\s*$", caplog.text)
    +    assert subsystem not in caplog.text
    +
    +
    +def test_list_namespace_locations_all_subsystems(caplog, two_gateways):
    +    caplog.clear()
    +    cli(["--format", "plain", "namespace", "list_locations"])
    +    if location and location2:
    +        assert find_in_caplog(rf"^\s*{re.escape(subsystem)}\s*1\s*{re.escape(location)}\s*3\s*$",
    +                              caplog.text)
    +        assert find_in_caplog(rf"^\s*{re.escape(subsystem2)}\s*1\s*{re.escape(location)}\s*1\s*$",
    +                              caplog.text)
    +        assert find_in_caplog(rf"^\s*2\s*{re.escape(location2)}\s*1\s*$", caplog.text)
    +    else:
    +        assert find_in_caplog(rf"^\s*{re.escape(subsystem)}\s*1\s*<default>\s*3\s*$", caplog.text)
    +        assert find_in_caplog(rf"^\s*{re.escape(subsystem2)}\s*1\s*<default>\s*1\s*$", caplog.text)

    These assertions appear to have very long lines (especially the regex patterns) and may violate the project’s flake8 100-character line limit. Please wrap/split these into shorter physical lines to avoid E501 failures in CI.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Feb 12, 2026 14:04 UTC
    Reviewer

    Pull request overview

    Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

    ---

    💡 <a href="/ceph/ceph-nvmeof/new/devel/.github/instructions?filename=*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.

    gbregman gbregman commented on code on Feb 12, 2026 14:07 UTC
    Code Review
    tests/test_cli_list_ns_locations.py:1
    @@ -0,0 +1,172 @@
    +import pytest
    +from control.server import GatewayServer
    +from control.cli import main as cli
    +from control.cephutils import CephUtils
    +import grpc
    +from control.proto import gateway_pb2_grpc as pb2_grpc
    +import copy
    +import os
    +import time
    +import re
    +
    +image = "mytestdevimage1"
    +image2 = "mytestdevimage2"
    +image3 = "mytestdevimage3"
    +image4 = "mytestdevimage4"
    +image5 = "mytestdevimage5"
    +pool = "rbd"
    +subsystem = "nqn.2016-06.io.spdk:cnode1"
    +subsystem2 = "nqn.2016-06.io.spdk:cnode2"
    +group_name = "GROUPNAME"
    +location = "USA"
    +location2 = "France"
    +
    +
    +@pytest.fixture(scope="module")
    +def two_gateways(config):
    +    """Sets up and tears down two gateways"""
    +
    +    global location, location2
    +    nameA = "GatewayAA"
    +    nameB = "GatewayBB"
    +    sockA = f"spdk_{nameA}.sock"
    +    sockB = f"spdk_{nameB}.sock"
    +    addr = config.get("gateway", "addr")
    +    config.config["gateway"]["group"] = group_name
    +    config.config["gateway-logs"]["log_level"] = "debug"
    +    configA = copy.deepcopy(config)
    +    configB = copy.deepcopy(config)
    +    configA.config["gateway"]["name"] = nameA
    +    configA.config["gateway"]["override_hostname"] = nameA
    +    configA.config["spdk"]["rpc_socket_name"] = sockA
    +    if os.cpu_count() >= 4:
    +        configA.config["spdk"]["tgt_cmd_extra_args"] = "--lcores (0-1)"
    +    else:
    +        configA.config["spdk"]["tgt_cmd_extra_args"] = "--disable-cpumask-locks"
    +    portA = configA.getint("gateway", "port")
    +    configB.config["gateway"]["name"] = nameB
    +    configB.config["gateway"]["override_hostname"] = nameB
    +    configB.config["spdk"]["rpc_socket_name"] = sockB
    +    portB = portA + 2
    +    discPortB = configB.getint("discovery", "port") + 1
    +    configB.config["gateway"]["port"] = str(portB)
    +    configB.config["discovery"]["port"] = str(discPortB)
    +    if os.cpu_count() >= 4:
    +        configB.config["spdk"]["tgt_cmd_extra_args"] = "--lcores (2-3)"
    +    else:
    +        configB.config["spdk"]["tgt_cmd_extra_args"] = "--disable-cpumask-locks"
    +
    +    ceph_utils = CephUtils(config)
    +    with (GatewayServer(configA) as gatewayA, GatewayServer(configB) as gatewayB):
    +
    +        # Start gateway
    +        gatewayA.gw_logger_object.set_log_level("debug")
    +        gatewayB.gw_logger_object.set_log_level("debug")
    +        ceph_utils.execute_ceph_monitor_command(
    +            "{" + f'"prefix":"nvme-gw create", "id": "{nameA}", "pool": "{pool}", '
    +            f'"group": "{group_name}"' + "}"
    +        )
    +        ceph_utils.execute_ceph_monitor_command(
    +            "{" + f'"prefix":"nvme-gw create", "id": "{nameB}", "pool": "{pool}", '
    +            f'"group": "{group_name}"' + "}"
    +        )
    +        rc = ceph_utils.execute_ceph_monitor_command(
    +            "{" + f'"prefix":"nvme-gw set-location", "id": "{nameA}", "pool": "{pool}", '
    +            f'"group": "{group_name}", "location": "{location}"' + "}"
    +        )
    +        if rc[0]:
    +            location = ""
    +            location2 = ""
    +            print("set-location is not implemented in Ceph, will use default")
    +        else:
    +            rc = ceph_utils.execute_ceph_monitor_command(
    +                "{" + f'"prefix":"nvme-gw set-location", "id": "{nameB}", "pool": "{pool}", '
    +                f'"group": "{group_name}", "location": "{location2}"' + "}"
    +            )
    +            assert rc[0] == 0
    +
    +        assert (location and location2) or (not location and not location2)
    +
    +        gatewayA.serve()
    +        gatewayB.serve()
    +
    +        # Bind the client and Gateway
    +        channel = grpc.insecure_channel(f"{addr}:{portA}")
    +        pb2_grpc.GatewayStub(channel)
    +        channel = grpc.insecure_channel(f"{addr}:{portB}")
    +        pb2_grpc.GatewayStub(channel)
    +        yield gatewayA.gateway_rpc, gatewayB.gateway_rpc
    +
    +        # Stop gateway
    +        gatewayA.server.stop(grace=1)
    +        gatewayB.server.stop(grace=1)
    +        gatewayA.gateway_rpc.gateway_state.delete_state()
    +        gatewayB.gateway_rpc.gateway_state.delete_state()
    +
    +
    +@pytest.fixture(scope="module", autouse=True)
    +def create_resources(two_gateways):
    +    _, gwB = two_gateways
    +    rc = cli(["subsystem", "add", "--subsystem", subsystem, "--no-group-append"])
    +    assert rc == 0
    +    rc = cli(["subsystem", "add", "--subsystem", subsystem2, "--no-group-append"])
    +    assert rc == 0
    +    rc = cli(["namespace", "add", "--subsystem", subsystem, "--rbd-pool", pool,
    +              "--rbd-image", image, "--size", "16MB", "--load-balancing-group", "1",
    +              "--rbd-create-image", "--location", location])
    +    assert rc == 0
    +    rc = cli(["namespace", "add", "--subsystem", subsystem, "--rbd-pool", pool,
    +              "--rbd-image", image2, "--size", "16MB", "--load-balancing-group", "1",
    +              "--rbd-create-image", "--location", location])
    +    assert rc == 0
    +    rc = cli(["namespace", "add", "--subsystem", subsystem, "--rbd-pool", pool,
    +              "--rbd-image", image3, "--size", "16MB", "--load-balancing-group", "1",
    +              "--rbd-create-image", "--location", location])
    +    assert rc == 0
    +    rc = cli(["namespace", "add", "--subsystem", subsystem2, "--rbd-pool", pool,
    +              "--rbd-image", image4, "--size", "16MB", "--load-balancing-group", "1",
    +              "--rbd-create-image", "--location", location])
    +    assert rc == 0
    +    time.sleep(20)
    +    rc = cli(["--server-port", gwB.config.config["gateway"]["port"],
    +              "namespace", "add", "--subsystem", subsystem2,
    +              "--rbd-pool", pool, "--rbd-image", image5, "--size", "16MB",
    +              "--rbd-create-image", "--location", location2, "--load-balancing-group", "2"])
    +    assert rc == 0
    +    time.sleep(20)
    +
    +
    +def find_in_caplog(lookfor, captext) -> bool:
    +    regex = re.compile(lookfor, re.MULTILINE)
    +    if re.search(regex, captext) is not None:
    +        return True
    +    return False
    +
    +
    +def test_list_namespace_locations_one_subsystem(caplog, two_gateways):
    +    caplog.clear()
    +    cli(["--format", "plain", "namespace", "list_locations", "--subsystem", subsystem2])
    +    if location and location2:
    +        assert find_in_caplog(rf"^\s*{re.escape(subsystem2)}\s*1\s*{re.escape(location)}\s*1\s*$",
    +                              caplog.text)
    +        assert find_in_caplog(rf"^\s*2\s*{re.escape(location2)}\s*1\s*$", caplog.text)

    This is OK. All the lines are shorter than 100 characters

    gbregman gbregman commented on code on Feb 12, 2026 14:08 UTC
    Code Review
    tests/test_cli_list_ns_locations.py:1
    @@ -0,0 +1,172 @@
    +import pytest
    +from control.server import GatewayServer
    +from control.cli import main as cli
    +from control.cephutils import CephUtils
    +import grpc
    +from control.proto import gateway_pb2_grpc as pb2_grpc
    +import copy
    +import os
    +import time
    +import re
    +
    +image = "mytestdevimage1"
    +image2 = "mytestdevimage2"
    +image3 = "mytestdevimage3"
    +image4 = "mytestdevimage4"
    +image5 = "mytestdevimage5"
    +pool = "rbd"
    +subsystem = "nqn.2016-06.io.spdk:cnode1"
    +subsystem2 = "nqn.2016-06.io.spdk:cnode2"
    +group_name = "GROUPNAME"
    +location = "USA"
    +location2 = "France"
    +
    +
    +@pytest.fixture(scope="module")
    +def two_gateways(config):
    +    """Sets up and tears down two gateways"""
    +
    +    global location, location2
    +    nameA = "GatewayAA"
    +    nameB = "GatewayBB"
    +    sockA = f"spdk_{nameA}.sock"
    +    sockB = f"spdk_{nameB}.sock"
    +    addr = config.get("gateway", "addr")
    +    config.config["gateway"]["group"] = group_name
    +    config.config["gateway-logs"]["log_level"] = "debug"
    +    configA = copy.deepcopy(config)
    +    configB = copy.deepcopy(config)
    +    configA.config["gateway"]["name"] = nameA
    +    configA.config["gateway"]["override_hostname"] = nameA
    +    configA.config["spdk"]["rpc_socket_name"] = sockA
    +    if os.cpu_count() >= 4:
    +        configA.config["spdk"]["tgt_cmd_extra_args"] = "--lcores (0-1)"
    +    else:
    +        configA.config["spdk"]["tgt_cmd_extra_args"] = "--disable-cpumask-locks"
    +    portA = configA.getint("gateway", "port")
    +    configB.config["gateway"]["name"] = nameB
    +    configB.config["gateway"]["override_hostname"] = nameB
    +    configB.config["spdk"]["rpc_socket_name"] = sockB
    +    portB = portA + 2
    +    discPortB = configB.getint("discovery", "port") + 1
    +    configB.config["gateway"]["port"] = str(portB)
    +    configB.config["discovery"]["port"] = str(discPortB)
    +    if os.cpu_count() >= 4:
    +        configB.config["spdk"]["tgt_cmd_extra_args"] = "--lcores (2-3)"
    +    else:
    +        configB.config["spdk"]["tgt_cmd_extra_args"] = "--disable-cpumask-locks"
    +
    +    ceph_utils = CephUtils(config)
    +    with (GatewayServer(configA) as gatewayA, GatewayServer(configB) as gatewayB):
    +
    +        # Start gateway
    +        gatewayA.gw_logger_object.set_log_level("debug")
    +        gatewayB.gw_logger_object.set_log_level("debug")
    +        ceph_utils.execute_ceph_monitor_command(
    +            "{" + f'"prefix":"nvme-gw create", "id": "{nameA}", "pool": "{pool}", '
    +            f'"group": "{group_name}"' + "}"
    +        )
    +        ceph_utils.execute_ceph_monitor_command(
    +            "{" + f'"prefix":"nvme-gw create", "id": "{nameB}", "pool": "{pool}", '
    +            f'"group": "{group_name}"' + "}"
    +        )
    +        rc = ceph_utils.execute_ceph_monitor_command(
    +            "{" + f'"prefix":"nvme-gw set-location", "id": "{nameA}", "pool": "{pool}", '
    +            f'"group": "{group_name}", "location": "{location}"' + "}"
    +        )
    +        if rc[0]:
    +            location = ""
    +            location2 = ""
    +            print("set-location is not implemented in Ceph, will use default")
    +        else:
    +            rc = ceph_utils.execute_ceph_monitor_command(
    +                "{" + f'"prefix":"nvme-gw set-location", "id": "{nameB}", "pool": "{pool}", '
    +                f'"group": "{group_name}", "location": "{location2}"' + "}"
    +            )
    +            assert rc[0] == 0
    +
    +        assert (location and location2) or (not location and not location2)
    +
    +        gatewayA.serve()
    +        gatewayB.serve()
    +
    +        # Bind the client and Gateway
    +        channel = grpc.insecure_channel(f"{addr}:{portA}")
    +        pb2_grpc.GatewayStub(channel)
    +        channel = grpc.insecure_channel(f"{addr}:{portB}")
    +        pb2_grpc.GatewayStub(channel)
    +        yield gatewayA.gateway_rpc, gatewayB.gateway_rpc
    +
    +        # Stop gateway
    +        gatewayA.server.stop(grace=1)
    +        gatewayB.server.stop(grace=1)
    +        gatewayA.gateway_rpc.gateway_state.delete_state()
    +        gatewayB.gateway_rpc.gateway_state.delete_state()
    +
    +
    +@pytest.fixture(scope="module", autouse=True)
    +def create_resources(two_gateways):
    +    _, gwB = two_gateways
    +    rc = cli(["subsystem", "add", "--subsystem", subsystem, "--no-group-append"])
    +    assert rc == 0
    +    rc = cli(["subsystem", "add", "--subsystem", subsystem2, "--no-group-append"])
    +    assert rc == 0
    +    rc = cli(["namespace", "add", "--subsystem", subsystem, "--rbd-pool", pool,
    +              "--rbd-image", image, "--size", "16MB", "--load-balancing-group", "1",
    +              "--rbd-create-image", "--location", location])
    +    assert rc == 0
    +    rc = cli(["namespace", "add", "--subsystem", subsystem, "--rbd-pool", pool,
    +              "--rbd-image", image2, "--size", "16MB", "--load-balancing-group", "1",
    +              "--rbd-create-image", "--location", location])
    +    assert rc == 0
    +    rc = cli(["namespace", "add", "--subsystem", subsystem, "--rbd-pool", pool,
    +              "--rbd-image", image3, "--size", "16MB", "--load-balancing-group", "1",
    +              "--rbd-create-image", "--location", location])
    +    assert rc == 0
    +    rc = cli(["namespace", "add", "--subsystem", subsystem2, "--rbd-pool", pool,
    +              "--rbd-image", image4, "--size", "16MB", "--load-balancing-group", "1",
    +              "--rbd-create-image", "--location", location])
    +    assert rc == 0
    +    time.sleep(20)
    +    rc = cli(["--server-port", gwB.config.config["gateway"]["port"],
    +              "namespace", "add", "--subsystem", subsystem2,
    +              "--rbd-pool", pool, "--rbd-image", image5, "--size", "16MB",
    +              "--rbd-create-image", "--location", location2, "--load-balancing-group", "2"])
    +    assert rc == 0
    +    time.sleep(20)
    +
    +
    +def find_in_caplog(lookfor, captext) -> bool:
    +    regex = re.compile(lookfor, re.MULTILINE)
    +    if re.search(regex, captext) is not None:
    +        return True
    +    return False
    +
    +
    +def test_list_namespace_locations_one_subsystem(caplog, two_gateways):
    +    caplog.clear()
    +    cli(["--format", "plain", "namespace", "list_locations", "--subsystem", subsystem2])
    +    if location and location2:
    +        assert find_in_caplog(rf"^\s*{re.escape(subsystem2)}\s*1\s*{re.escape(location)}\s*1\s*$",
    +                              caplog.text)
    +        assert find_in_caplog(rf"^\s*2\s*{re.escape(location2)}\s*1\s*$", caplog.text)
    +    else:
    +        assert find_in_caplog(rf"^\s*{re.escape(subsystem2)}\s*1\s*<default>\s*1\s*$",
    +                              caplog.text)
    +        assert find_in_caplog(r"^\s*2\s*<default>\s*1\s*$", caplog.text)
    +    assert subsystem not in caplog.text
    +
    +
    +def test_list_namespace_locations_all_subsystems(caplog, two_gateways):
    +    caplog.clear()
    +    cli(["--format", "plain", "namespace", "list_locations"])
    +    if location and location2:
    +        assert find_in_caplog(rf"^\s*{re.escape(subsystem)}\s*1\s*{re.escape(location)}\s*3\s*$",
    +                              caplog.text)
    +        assert find_in_caplog(rf"^\s*{re.escape(subsystem2)}\s*1\s*{re.escape(location)}\s*1\s*$",
    +                              caplog.text)
    +        assert find_in_caplog(rf"^\s*2\s*{re.escape(location2)}\s*1\s*$", caplog.text)
    +    else:
    +        assert find_in_caplog(rf"^\s*{re.escape(subsystem)}\s*1\s*<default>\s*3\s*$", caplog.text)
    +        assert find_in_caplog(rf"^\s*{re.escape(subsystem2)}\s*1\s*<default>\s*1\s*$", caplog.text)

    All the lines are shorter than 100 characters.

    leonidc leonidc commented on code on Feb 12, 2026 14:53 UTC
    Code Review
    control/cli.py:1
    @@ -2648,13 +2648,78 @@ def get_size_in_bytes(self, sz):
             int_size *= multiply
             return int_size
     
    -    def ns_list(self, args, show_hosts=False):
    +    def ns_location_list(self, args, ns_info):
    +        """List namespace distribution per site locations"""
    +
    +        out_func, _, warn_func = self.get_output_functions(args)
    +        ns_locations_count = {}
    +        if ns_info.namespaces:
    +            for ns in ns_info.namespaces:
    +                nqn = ns.ns_subsystem_nqn
    +                if not nqn:
    +                    warn_func("Found a namespace without a subsystem")
    +                    nqn = "<n/a>"

    it can happen ?

    gbregman gbregman commented on code on Feb 12, 2026 15:10 UTC
    Code Review
    control/cli.py:1
    @@ -2648,13 +2648,78 @@ def get_size_in_bytes(self, sz):
             int_size *= multiply
             return int_size
     
    -    def ns_list(self, args, show_hosts=False):
    +    def ns_location_list(self, args, ns_info):
    +        """List namespace distribution per site locations"""
    +
    +        out_func, _, warn_func = self.get_output_functions(args)
    +        ns_locations_count = {}
    +        if ns_info.namespaces:
    +            for ns in ns_info.namespaces:
    +                nqn = ns.ns_subsystem_nqn
    +                if not nqn:
    +                    warn_func("Found a namespace without a subsystem")
    +                    nqn = "<n/a>"

    It shouldn't happen unless there is some bug in the gateway. I just prefer to write the code so it wouldn't crash even if there is a bug elsewhere.

    gbregman gbregman commented on code on Feb 12, 2026 15:17 UTC
    Code Review
    control/cli.py:1
    @@ -2648,13 +2648,78 @@ def get_size_in_bytes(self, sz):
             int_size *= multiply
             return int_size
     
    -    def ns_list(self, args, show_hosts=False):
    +    def ns_location_list(self, args, ns_info):
    +        """List namespace distribution per site locations"""
    +
    +        out_func, _, warn_func = self.get_output_functions(args)
    +        ns_locations_count = {}
    +        if ns_info.namespaces:
    +            for ns in ns_info.namespaces:
    +                nqn = ns.ns_subsystem_nqn
    +                if not nqn:
    +                    warn_func("Found a namespace without a subsystem")
    +                    nqn = "<n/a>"

    I just abort with an error message in such a case as this means we have a bug somewhere.

    leonidc leonidc approved these changes on Feb 12, 2026 17:22 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    gbregman gbregman
    Labels
    risk: low confidence: 90.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.2% (MEDIUM) · Higher = larger blast radius
    45.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 90.0% · Lower = rushed or shallow review
    90.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.5% · Safe to merge
    4.5%