Skip to content

Commit

Permalink
test: factor out file server from upgrade test
Browse files Browse the repository at this point in the history
Signed-off-by: Joachim Wiberg <[email protected]>
  • Loading branch information
troglobit committed Nov 12, 2024
1 parent 6459523 commit 4f957ee
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
28 changes: 2 additions & 26 deletions test/case/ietf_system/upgrade/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand All @@ -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)}")
Expand Down
28 changes: 28 additions & 0 deletions test/infamy/file_server.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 4f957ee

Please sign in to comment.