Skip to content

Commit d293976

Browse files
authored
Merge pull request #880 from leonidc/limit_manual_ns_change_lb
To refuse change load balancing group of the namespace if ana-group owner is another gw
2 parents dca6f83 + 27e0972 commit d293976

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

control/cephutils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import rbd
1313
import rados
1414
import time
15+
import json
1516
from .utils import GatewayLogger
1617

1718
class CephUtils:
@@ -31,6 +32,23 @@ def execute_ceph_monitor_command(self, cmd):
3132
rply = cluster.mon_command(cmd, b'')
3233
self.logger.debug(f"Monitor reply: {rply}")
3334
return rply
35+
def get_gw_id_owner_ana_group(self, pool, group, anagrp):
36+
str = '{' + f'"prefix":"nvme-gw show", "pool":"{pool}", "group":"{group}"' + '}'
37+
self.logger.debug(f"nvme-show string: {str}")
38+
rply = self.execute_ceph_monitor_command(str)
39+
self.logger.debug(f"reply \"{rply}\"")
40+
conv_str = rply[1].decode()
41+
data = json.loads(conv_str)
42+
43+
# Find the gw-id that contains "2: ACTIVE" in "ana states"
44+
gw_id = None
45+
comp_str = f"{anagrp}: ACTIVE"
46+
for gateway in data["Created Gateways:"]:
47+
if comp_str in gateway["ana states"]:
48+
gw_id = gateway["gw-id"]
49+
self.logger.debug(f"found gw owner of anagrp {anagrp}: gw {gw_id}")
50+
break
51+
return gw_id
3452

3553
def get_number_created_gateways(self, pool, group):
3654
now = time.time()

control/grpc.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,13 @@ def namespace_change_load_balancing_group_safe(self, request, context):
12251225
errmsg = f"{change_lb_group_failure_prefix}: Can't find entry for namespace {request.nsid} in {request.subsystem_nqn}"
12261226
self.logger.error(errmsg)
12271227
return pb2.req_status(status=errno.ENOENT, error_message=errmsg)
1228+
anagrp = ns_entry["anagrpid"]
1229+
gw_id = self.ceph_utils.get_gw_id_owner_ana_group(self.gateway_pool, self.gateway_group, anagrp)
1230+
self.logger.debug(f"ANA group of ns#{request.nsid} - {anagrp} is owned by gateway {gw_id}, self.name is {self.gateway_name}")
1231+
if self.gateway_name != gw_id:
1232+
errmsg = f"ANA group of ns#{request.nsid} - {anagrp} is owned by gateway {gw_id} so try this command from it, this gateway name is {self.gateway_name}"
1233+
self.logger.error(errmsg)
1234+
return pb2.req_status(status=errno.ENODEV, error_message=errmsg)
12281235

12291236
try:
12301237
ret = rpc_nvmf.nvmf_subsystem_set_ns_ana_group(

tests/ha/ns_lb_change.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,9 @@ make exec SVC=bdevperf OPTS=-T CMD="$bdevperf -v -t $timeout -s $BDEVPERF_SOCKET
6060

6161
(
6262
sleep 8;
63-
6463
lb_group=1;
65-
docker compose run -T --rm nvmeof-cli --server-address $ip --server-port 5500 namespace change_load_balancing_group -n nqn.2016-06.io.spdk:cnode1 --nsid 1 --load-balancing-group $lb_group ;
66-
6764

65+
docker compose run -T --rm nvmeof-cli --server-address $ip --server-port 5500 namespace change_load_balancing_group -n nqn.2016-06.io.spdk:cnode1 --nsid 1 --load-balancing-group $lb_group;
6866
priv_res1=$(calc_written_bytes_in_sec $ip) ;
6967

7068
echo "ℹ️ written bytes through $ip $priv_res1 ";
@@ -77,14 +75,16 @@ echo "ℹ️ written bytes through $ip2 $priv_res2 ";
7775
for i in $(seq 6); do
7876
if [ $lb_group -eq 1 ]; then
7977
lb_group=2
78+
IP=$ip
8079
else
8180
lb_group=1
81+
IP=$ip2
8282
fi;
8383

8484
echo "ℹ️ ℹ️ Change lb group of ns 1 to $lb_group :" ;
85-
docker compose run -T --rm nvmeof-cli --server-address $ip --server-port 5500 namespace change_load_balancing_group -n nqn.2016-06.io.spdk:cnode1 --nsid 1 --load-balancing-group $lb_group ;
85+
docker compose run -T --rm nvmeof-cli --server-address $IP --server-port 5500 namespace change_load_balancing_group -n nqn.2016-06.io.spdk:cnode1 --nsid 1 --load-balancing-group $lb_group;
8686
sleep 4;
87-
87+
8888
res1=$(calc_written_bytes_in_sec $ip) ;
8989

9090
echo "ℹ️ written bytes through $ip ?: $res1";

tests/test_cli_change_lb.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,13 @@ def create_namespaces(caplog, ns_count, subsys):
109109

110110
def change_one_namespace_lb_group(caplog, subsys, nsid_to_change, new_group):
111111
caplog.clear()
112-
cli(["--server-port", "5501", "namespace", "change_load_balancing_group", "--subsystem", subsys, "--nsid", nsid_to_change, "--load-balancing-group", new_group])
113-
time.sleep(10)
112+
cli(["--server-port", "5502", "namespace", "change_load_balancing_group", "--subsystem", subsys, "--nsid", nsid_to_change, "--load-balancing-group", new_group])
113+
time.sleep(8)
114+
if "so try this command from it" in caplog.text:
115+
caplog.clear()
116+
cli(["--server-port", "5501", "namespace", "change_load_balancing_group", "--subsystem", subsys, "--nsid", nsid_to_change, "--load-balancing-group", new_group])
117+
time.sleep(8)
118+
114119
assert f"Changing load balancing group of namespace {nsid_to_change} in {subsys} to {new_group}: Successful" in caplog.text
115120
assert f"Received request to change load balancing group for namespace with NSID {nsid_to_change} in {subsys} to {new_group}, context: <grpc._server" in caplog.text
116121
assert f"Received request to delete namespace" not in caplog.text

0 commit comments

Comments
 (0)