diff --git a/test/case/ietf_system/upgrade/test.py b/test/case/ietf_system/upgrade/test.py index 1e05d4d1..24d45737 100755 --- a/test/case/ietf_system/upgrade/test.py +++ b/test/case/ietf_system/upgrade/test.py @@ -4,16 +4,11 @@ Verify it is possible to upgrade. """ -import concurrent.futures -import functools -import http.server import os -import socket import time - import netifaces - import infamy +import infamy.file_server as srv SRVPORT = 8008 @@ -27,25 +22,6 @@ "package" ) -class FileServer(http.server.HTTPServer): - class RequestHandler(http.server.SimpleHTTPRequestHandler): - def log_message(*args, **kwargs): - pass - - address_family = socket.AF_INET6 - - def __init__(self, server_address, directory): - rh = functools.partial(FileServer.RequestHandler, directory=directory) - self.__tp = concurrent.futures.ThreadPoolExecutor(max_workers=1) - super().__init__(server_address, rh) - - def __enter__(self): - self.__tp.submit(self.serve_forever) - - def __exit__(self, _, __, ___): - self.shutdown() - self.__tp.shutdown() - with infamy.Test() as test: with test.step("Set up topology and attach to target DUT"): env = infamy.Env() @@ -66,7 +42,7 @@ def __exit__(self, _, __, ___): hip = netifaces.ifaddresses(hport)[netifaces.AF_INET6][0]["addr"] hip = hip.replace(f"%{hport}", f"%{tport}") - with FileServer(("::", SRVPORT), BUNDLEDIR): + with srv.FileServer(("::", SRVPORT), BUNDLEDIR): with test.step("Start installation of selected package"): print(f"Installing {os.path.basename(env.args.package)}") diff --git a/test/infamy/file_server.py b/test/infamy/file_server.py new file mode 100644 index 00000000..68de4d9c --- /dev/null +++ b/test/infamy/file_server.py @@ -0,0 +1,28 @@ +""" +Basic file server over HTTP +""" +import concurrent.futures +import functools +import http.server +import socket + + +class FileServer(http.server.HTTPServer): + """Open web server on (address, port) serving files from directory""" + class RequestHandler(http.server.SimpleHTTPRequestHandler): + def log_message(self, *args, **kwargs): + pass + + address_family = socket.AF_INET6 + + def __init__(self, server_address, directory): + rh = functools.partial(FileServer.RequestHandler, directory=directory) + self.__tp = concurrent.futures.ThreadPoolExecutor(max_workers=1) + super().__init__(server_address, rh) + + def __enter__(self): + self.__tp.submit(self.serve_forever) + + def __exit__(self, _, __, ___): + self.shutdown() + self.__tp.shutdown()