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 0197bfa commit ace3d18
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def gateway(config):
with GatewayServer(config) as gateway:

# Start gateway
gateway.set_group_id(0)
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 @@ -31,6 +31,7 @@ def check_resource_by_index(i, caplog):
@pytest.mark.filterwarnings("error::pytest.PytestUnhandledThreadExceptionWarning")
def test_create_get_subsys(caplog, config):
with GatewayServer(config) as gateway:
gateway.set_group_id(0)
gateway.serve()

for i in range(created_resource_count):
Expand Down Expand Up @@ -66,6 +67,7 @@ def test_create_get_subsys(caplog, config):

# restart the gateway here
with GatewayServer(config) as gateway:
gateway.set_group_id(0)
gateway.serve()

for i in range(subsys_list_count):
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 @@ -47,6 +47,7 @@ def gateway(config, request):
with GatewayServer(config) as gateway:

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

# Bind the client and Gateway
Expand Down
8 changes: 3 additions & 5 deletions tests/test_multi_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@ def conn(config):
configA.config["gateway"]["name"] = "GatewayA"
configA.config["gateway"]["group"] = "Group1"
configA.config["gateway"]["state_update_notify"] = str(update_notify)
configA.config["gateway"]["min_controller_id"] = "1"
configA.config["gateway"]["max_controller_id"] = "20000"
configA.config["gateway"]["enable_spdk_discovery_controller"] = "True"
configA.config["spdk"]["rpc_socket_name"] = "spdk_GatewayA.sock"
configB = copy.deepcopy(configA)
addr = configA.get("gateway", "addr")
portA = configA.getint("gateway", "port")
portB = portA + 1
portB = portA + 2
configB.config["gateway"]["name"] = "GatewayB"
configB.config["gateway"]["port"] = str(portB)
configA.config["gateway"]["min_controller_id"] = "20001"
configA.config["gateway"]["max_controller_id"] = "40000"
configB.config["gateway"]["state_update_interval_sec"] = str(
update_interval_sec)
configB.config["spdk"]["rpc_socket_name"] = "spdk_GatewayB.sock"
Expand All @@ -41,10 +37,12 @@ def conn(config):
GatewayServer(configA) as gatewayA,
GatewayServer(configB) as gatewayB,
):
gatewayA.set_group_id(0)
gatewayA.serve()
# Delete existing OMAP state
gatewayA.gateway_rpc.gateway_state.delete_state()
# Create new
gatewayB.set_group_id(1)
gatewayB.serve()

# Bind the client and Gateways A & B
Expand Down
8 changes: 3 additions & 5 deletions tests/test_namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,14 @@ def conn(config):
configA.config["gateway"]["name"] = "GatewayA"
configA.config["gateway"]["group"] = "Group1"
configA.config["gateway"]["state_update_notify"] = str(update_notify)
configA.config["gateway"]["min_controller_id"] = "1"
configA.config["gateway"]["max_controller_id"] = "20000"
configA.config["gateway"]["enable_spdk_discovery_controller"] = "True"
configA.config["spdk"]["rpc_socket_name"] = "spdk_GatewayA.sock"
configB = copy.deepcopy(configA)
addr = configA.get("gateway", "addr")
portA = configA.getint("gateway", "port")
portB = portA + 1
portB = portA + 2
configB.config["gateway"]["name"] = "GatewayB"
configB.config["gateway"]["port"] = str(portB)
configA.config["gateway"]["min_controller_id"] = "20001"
configA.config["gateway"]["max_controller_id"] = "40000"
configB.config["gateway"]["state_update_interval_sec"] = str(
update_interval_sec)
configB.config["spdk"]["rpc_socket_name"] = "spdk_GatewayB.sock"
Expand All @@ -48,10 +44,12 @@ def conn(config):
GatewayServer(configA) as gatewayA,
GatewayServer(configB) as gatewayB,
):
gatewayA.set_group_id(0)
gatewayA.serve()
# Delete existing OMAP state
gatewayA.gateway_rpc.gateway_state.delete_state()
# Create new
gatewayB.set_group_id(1)
gatewayB.serve()

# Bind the client and Gateways A & B
Expand Down
5 changes: 4 additions & 1 deletion tests/test_nsid.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def setup_config(config, gw1_name, gw2_name, gw_group, update_notify, update_int
configB = copy.deepcopy(configA)
portA = configA.getint("gateway", "port")
configA.config["gateway"]["port"] = str(portA)
portB = portA + 1
portB = portA + 2
configB.config["gateway"]["name"] = gw2_name
configB.config["gateway"]["port"] = str(portB)
configB.config["spdk"]["rpc_socket_name"] = sock2_name
Expand All @@ -39,10 +39,12 @@ def setup_config(config, gw1_name, gw2_name, gw_group, update_notify, update_int
return configA, configB

def start_servers(gatewayA, gatewayB, addr, portA, portB):
gatewayA.set_group_id(0)
gatewayA.serve()
# Delete existing OMAP state
gatewayA.gateway_rpc.gateway_state.delete_state()
# Create new
gatewayB.set_group_id(1)
gatewayB.serve()
gatewayB.gateway_rpc.gateway_state.delete_state()

Expand Down Expand Up @@ -142,6 +144,7 @@ def test_multi_gateway_namespace_ids(config, image, caplog):
assert False
gatewayB.__exit__(None, None, None)
gatewayB = GatewayServer(configB)
gatewayB.set_group_id(1)
gatewayB.serve()
channelB = grpc.insecure_channel(f"{addr}:{portB}")
stubB = pb2_grpc.GatewayStub(channelB)
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 @@ -5,11 +5,13 @@

def test_old_omap(caplog, config):
with GatewayServer(config) as gateway:
gateway.set_group_id(0)
gateway.serve()
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.set_group_id(0)
gateway.serve()
assert f"Old OMAP file format, still contains bdevs, please remove file and try again" in str(ex.value)
2 changes: 2 additions & 0 deletions tests/test_omap_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ def setup_config(config, gw1_name, gw2_name, gw_group, update_notify ,update_int
return configA, configB

def start_servers(gatewayA, gatewayB, addr, portA, portB):
gatewayA.set_group_id(0)
gatewayA.serve()
# Delete existing OMAP state
gatewayA.gateway_rpc.gateway_state.delete_state()
# Create new
gatewayB.set_group_id(1)
gatewayB.serve()
gatewayB.gateway_rpc.gateway_state.delete_state()

Expand Down
4 changes: 4 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ def test_spdk_exception(self):

with self.assertRaises(SystemExit) as cm:
with GatewayServer(config_spdk_exception) as gateway:
gateway.set_group_id(0)
gateway.serve()
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.set_group_id(0)
gateway.serve()
time.sleep(10)
# exited context, spdk process should be aborted here by __exit__()
Expand All @@ -64,7 +66,9 @@ def test_spdk_multi_gateway_exception(self):
GatewayServer(configA) as gatewayA,
GatewayServer(configB) as gatewayB,
):
gatewayA.set_group_id(0)
gatewayA.serve()
gatewayB.set_group_id(1)
gatewayB.serve()
self.validate_exception(cm.exception)

Expand Down

0 comments on commit ace3d18

Please sign in to comment.