Skip to content

Commit

Permalink
test monitor client abort
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Indenbaum <[email protected]>
  • Loading branch information
Alexander Indenbaum authored and baum committed Oct 21, 2024
1 parent 567ab1e commit ed1a7c4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion control/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def __enter__(self):

def __exit__(self, exc_type, exc_value, traceback):
"""Cleans up SPDK and server instances."""
if exc_type is not None and exc_type is not SystemExit:
if exc_type is not None:
self.logger.exception("GatewayServer exception occurred:")
else:
self.logger.info("GatewayServer is terminating gracefully...")
Expand Down
50 changes: 47 additions & 3 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,40 @@
import pytest
import time
import re
import signal
import os
import unittest
from control.server import GatewayServer

class TestServer(unittest.TestCase):
# Location of core files in test env.
core_dir="/tmp/coredump"

@pytest.fixture(autouse=True)
def _config(self, config):
self.config = config

def validate_exception(self, e):
pattern = r'Gateway subprocess terminated pid=(\d+) exit_code=(\d+)'
pattern = r'Gateway subprocess terminated pid=(\d+) exit_code=(-?\d+)'
m = re.match(pattern, e.code)
assert(m)
pid = int(m.group(1))
code = int(m.group(2))
assert(pid > 0)
assert(code == 1)
assert(code)

def remove_core_files(self, directory_path):
# List all files starting with "core." in the core directory
files = [
f for f in os.listdir(directory_path)
if os.path.isfile(os.path.join(directory_path, f)) and f.startswith("core.")
]

# Remove each matching file
for f in files:
file_path = os.path.join(directory_path, f)
os.remove(file_path)
print(f"Removed: {file_path}")

def assert_no_core_files(self, directory_path):
assert(os.path.exists(directory_path) and os.path.isdir(directory_path))
Expand Down Expand Up @@ -46,7 +63,34 @@ def test_no_coredumps_on_gracefull_shutdown(self):
time.sleep(10)
# exited context, sub processes should terminate gracefully
time.sleep(10) # let it dump
self.assert_no_core_files("/tmp/coredump")
self.assert_no_core_files(self.core_dir)

def test_monc_exit(self):
"""Tests monitor client sub process abort."""
config_monc_abort = copy.deepcopy(self.config)
signals = [ signal.SIGABRT, signal.SIGTERM, signal.SIGKILL ]

for sig in signals:
with self.assertRaises(SystemExit) as cm:
with GatewayServer(config_monc_abort) as gateway:
gateway.set_group_id(0)
gateway.serve()

# Give the gateway some time to start
time.sleep(2)

# Send SIGABRT (abort signal) to the monitor client process
assert(gateway.monitor_client_process)
gateway.monitor_client_process.send_signal(signal.SIGABRT)

# Block on running keep alive ping
gateway.keep_alive()

# Assert error exit code
self.validate_exception(cm.exception)

# Clean up monc core
self.remove_core_files(self.core_dir)

def test_spdk_multi_gateway_exception(self):
"""Tests spdk sub process exiting with error, in multi gateway configuration."""
Expand Down

0 comments on commit ed1a7c4

Please sign in to comment.