From fac36f67d51c4288e1218a31293b74c688af2c77 Mon Sep 17 00:00:00 2001 From: Yin Congmin Date: Wed, 10 May 2023 17:35:40 +0800 Subject: [PATCH] control/cli: add ip requirement for listener discovert controller need a specific ip/port. fixes: https://github.com/ceph/ceph-nvmeof/issues/87 Signed-off-by: Yin Congmin --- README.md | 4 ++-- control/cli.py | 8 ++++---- control/grpc.py | 34 ++++------------------------------ mk/demo.mk | 2 +- tests/test_cli.py | 8 +++----- 5 files changed, 14 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index ff1e554ef..49cde242d 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ DOCKER_BUILDKIT=1 docker-compose run --rm ceph-nvmeof-cli --server-address ceph- Creating nvmeof_ceph-nvmeof-cli_run ... done INFO:__main__:Added namespace 1 to nqn.2016-06.io.spdk:cnode1: True -DOCKER_BUILDKIT=1 docker-compose run --rm ceph-nvmeof-cli --server-address ceph-nvmeof --server-port 5500 create_listener --subnqn nqn.2016-06.io.spdk:cnode1 -s 4420 +DOCKER_BUILDKIT=1 docker-compose run --rm ceph-nvmeof-cli --server-address ceph-nvmeof --server-port 5500 create_listener --subnqn nqn.2016-06.io.spdk:cnode1 -g gateway_name -a gateway_addr -s 4420 Creating nvmeof_ceph-nvmeof-cli_run ... done INFO:__main__:Created nqn.2016-06.io.spdk:cnode1 listener: True @@ -153,7 +153,7 @@ The same configuration can also be manually run: 1. Create a listener so that NVMe initiators can connect to: ```bash - nvmeof-cli create_listener ---subnqn nqn.2016-06.io.spdk:cnode1 -s 4420 + nvmeof-cli create_listener ---subnqn nqn.2016-06.io.spdk:cnode1 -g gateway_name -a gateway_addr -s 4420 ``` 1. Define which hosts can connect: diff --git a/control/cli.py b/control/cli.py index 4115a09eb..477d37a14 100644 --- a/control/cli.py +++ b/control/cli.py @@ -267,10 +267,10 @@ def remove_host(self, args): @cli.cmd([ argument("-n", "--subnqn", help="Subsystem NQN", required=True), - argument("-g", "--gateway-name", help="Gateway name", default=""), + argument("-g", "--gateway-name", help="Gateway name", required=True), argument("-t", "--trtype", help="Transport type", default="TCP"), argument("-f", "--adrfam", help="Address family", default="ipv4"), - argument("-a", "--traddr", help="NVMe host IP", default=""), + argument("-a", "--traddr", help="NVMe host IP", required=True), argument("-s", "--trsvcid", help="Port number", required=True), ]) def create_listener(self, args): @@ -288,10 +288,10 @@ def create_listener(self, args): @cli.cmd([ argument("-n", "--subnqn", help="Subsystem NQN", required=True), - argument("-g", "--gateway-name", help="Gateway name", default=""), + argument("-g", "--gateway-name", help="Gateway name", required=True), argument("-t", "--trtype", help="Transport type", default="TCP"), argument("-f", "--adrfam", help="Address family", default="ipv4"), - argument("-a", "--traddr", help="NVMe host IP", default=""), + argument("-a", "--traddr", help="NVMe host IP", required=True), argument("-s", "--trsvcid", help="Port number", required=True), ]) def delete_listener(self, args): diff --git a/control/grpc.py b/control/grpc.py index 08561d791..36cf27489 100644 --- a/control/grpc.py +++ b/control/grpc.py @@ -333,25 +333,12 @@ def create_listener(self, request, context=None): f" {request.trtype} listener for {request.nqn} at" f" {request.traddr}:{request.trsvcid}.") try: - if (request.gateway_name and not request.traddr) or \ - (not request.gateway_name and request.traddr): - raise Exception( - "both gateway_name and traddr or neither must be specified") - - if not request.gateway_name or \ - request.gateway_name == self.gateway_name: - if not request.traddr: - traddr = self.config.get("gateway", "addr") - if not traddr: - raise Exception("gateway.addr option is not set") - else: - traddr = request.traddr - + if request.gateway_name == self.gateway_name: ret = rpc_nvmf.nvmf_subsystem_add_listener( self.spdk_rpc_client, nqn=request.nqn, trtype=request.trtype, - traddr=traddr, + traddr=request.traddr, trsvcid=request.trsvcid, adrfam=request.adrfam, ) @@ -387,25 +374,12 @@ def delete_listener(self, request, context=None): f" {request.trtype} listener for {request.nqn} at" f" {request.traddr}:{request.trsvcid}.") try: - if (request.gateway_name and not request.traddr) or \ - (not request.gateway_name and request.traddr): - raise Exception( - "both gateway_name and traddr or neither must be specified") - - if not request.gateway_name or \ - request.gateway_name == self.gateway_name: - if not request.traddr: - traddr = self.config.get("gateway", "addr") - if not traddr: - raise Exception("gateway.addr option is not set") - else: - traddr = request.traddr - + if request.gateway_name == self.gateway_name: ret = rpc_nvmf.nvmf_subsystem_remove_listener( self.spdk_rpc_client, nqn=request.nqn, trtype=request.trtype, - traddr=traddr, + traddr=request.traddr, trsvcid=request.trsvcid, adrfam=request.adrfam, ) diff --git a/mk/demo.mk b/mk/demo.mk index d9fcf86c9..9851234f7 100644 --- a/mk/demo.mk +++ b/mk/demo.mk @@ -10,7 +10,7 @@ demo: rbd ## Expose RBD_IMAGE_NAME as NVMe-oF target $(NVMEOF_CLI) create_bdev --pool $(RBD_POOL) --image $(RBD_IMAGE_NAME) --bdev $(BDEV_NAME) $(NVMEOF_CLI) create_subsystem --subnqn $(NQN) --serial $(SERIAL) $(NVMEOF_CLI) add_namespace --subnqn $(NQN) --bdev $(BDEV_NAME) - $(NVMEOF_CLI) create_listener --subnqn $(NQN) --trsvcid $(NVMEOF_IO_PORT) + $(NVMEOF_CLI) create_listener --subnqn $(NQN) --gateway-name $(HOSTNAME) --traddr $(NVMEOF_IP_ADDRESS) --trsvcid $(NVMEOF_IO_PORT) $(NVMEOF_CLI) add_host --subnqn $(NQN) --host "*" .PHONY: demo rbd diff --git a/tests/test_cli.py b/tests/test_cli.py index 6a9588b95..b39febe41 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -12,7 +12,7 @@ trtype = "TCP" gateway_name = socket.gethostname() addr = "127.0.0.1" -listener_list = [["-g", gateway_name, "-a", addr, "-s", "5001"], ["-s", "5002"]] +listener = ["-g", gateway_name, "-a", addr, "-s", "5001"] config = "ceph-nvmeof.conf" @@ -40,8 +40,7 @@ def test_add_host(self, caplog, host): cli(["-c", config, "add_host", "-n", subsystem, "-t", host]) assert "Failed to add" not in caplog.text - @pytest.mark.parametrize("listener", listener_list) - def test_create_listener(self, caplog, listener): + def test_create_listener(self, caplog): cli(["-c", config, "create_listener", "-n", subsystem] + listener) assert "Failed to create" not in caplog.text @@ -52,8 +51,7 @@ def test_remove_host(self, caplog, host): cli(["-c", config, "remove_host", "-n", subsystem, "-t", host]) assert "Failed to remove" not in caplog.text - @pytest.mark.parametrize("listener", listener_list) - def test_delete_listener(self, caplog, listener): + def test_delete_listener(self, caplog): cli(["-c", config, "delete_listener", "-n", subsystem] + listener) assert "Failed to delete" not in caplog.text