Skip to content

Commit

Permalink
Tweak pytests
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Indenbaum <[email protected]>
  • Loading branch information
Alexander Indenbaum committed Mar 3, 2024
1 parent 4a16b1b commit b2cb9d6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from control.proto import gateway_pb2 as pb2
from control.proto import gateway_pb2_grpc as pb2_grpc
import os
import subprocess

image = "mytestdevimage"
image2 = "mytestdevimage2"
Expand Down Expand Up @@ -37,6 +38,25 @@
listener_list_wrong_gw = [["-g", "WRONG", "-a", addr, "-s", "5015", "-f", "ipv4"]]
config = "ceph-nvmeof.conf"

def create_nvme_gateway(name):
# Formulate the command
command = [
"docker-compose",
"exec",
"-T",
"ceph",
"ceph",
"nvme-gw",
"create",
name,
"rbd",
""
]

# Execute the command
subprocess.run(command, check=True)
print(f"NVMe gateway {name} created successfully.")

@pytest.fixture(scope="module")
def gateway(config):
"""Sets up and tears down Gateway"""
Expand All @@ -47,6 +67,7 @@ def gateway(config):
with GatewayServer(config) as gateway:

# Start gateway
create_nvme_gateway(gateway.name)
gateway.serve()

# Bind the client and Gateway
Expand Down
2 changes: 2 additions & 0 deletions tests/test_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def check_resource_by_index(i, caplog):
def test_create_get_subsys(caplog, config):
with GatewayServer(config) as gateway:
gateway.serve()
gateway.set_group_id(0)

for i in range(created_resource_count):
create_resource_by_index(i)
Expand Down Expand Up @@ -67,6 +68,7 @@ def test_create_get_subsys(caplog, config):
# restart the gateway here
with GatewayServer(config) as gateway:
gateway.serve()
gateway.set_group_id(0)

for i in range(subsys_list_count):
cli(["--format", "plain", "subsystem", "list"])
Expand Down
1 change: 1 addition & 0 deletions tests/test_log_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def gateway(config, request):

# Start gateway
gateway.serve()
gateway.set_group_id(0)

# Bind the client and Gateway
channel = grpc.insecure_channel(f"{addr}:{port}")
Expand Down
2 changes: 2 additions & 0 deletions tests/test_old_omap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
def test_old_omap(caplog, config):
with GatewayServer(config) as gateway:
gateway.serve()
gateway.set_group_id(0)
gateway.gateway_rpc.gateway_state.omap._add_key("bdev_dummy", "dummy")

caplog.clear()
with GatewayServer(config) as gateway:
with pytest.raises(Exception) as ex:
gateway.serve()
gateway.set_group_id(0)
assert f"Old OMAP file format, still contains bdevs, please remove file and try again" in str(ex.value)
4 changes: 4 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ def test_spdk_exception(self):
with self.assertRaises(SystemExit) as cm:
with GatewayServer(config_spdk_exception) as gateway:
gateway.serve()
gateway.set_group_id(0)
self.validate_exception(cm.exception)

def test_spdk_abort(self):
"""Tests spdk sub process dumps core on during normal shutdown."""
with GatewayServer(copy.deepcopy(self.config)) as gateway:
gateway.serve()
gateway.set_group_id(0)
time.sleep(10)
# exited context, spdk process should be aborted here by __exit__()
time.sleep(10) # let it dump
Expand All @@ -65,7 +67,9 @@ def test_spdk_multi_gateway_exception(self):
GatewayServer(configB) as gatewayB,
):
gatewayA.serve()
gatewayA.set_group_id(0)
gatewayB.serve()
gatewayB.set_group_id(1)
self.validate_exception(cm.exception)

if __name__ == '__main__':
Expand Down

0 comments on commit b2cb9d6

Please sign in to comment.