aboutsummaryrefslogtreecommitdiffstats
path: root/.ci/utils/httpd.py
diff options
context:
space:
mode:
authorSteven Koo <steven.koo@ni.com>2022-06-20 10:47:18 -0500
committerskooNI <60897865+skooNI@users.noreply.github.com>2022-07-20 15:57:20 -0500
commit770711c40a482d1e87d75393dd3fe95d75efa379 (patch)
tree87e877dffdc4740c47904caa1118fa267b89f0c5 /.ci/utils/httpd.py
parenta3ca7796b75ab17df4980e76749dfaa3cf6ea110 (diff)
downloaduhd-770711c40a482d1e87d75393dd3fe95d75efa379.tar.gz
uhd-770711c40a482d1e87d75393dd3fe95d75efa379.tar.bz2
uhd-770711c40a482d1e87d75393dd3fe95d75efa379.zip
ci: add devtest e320 support
This commit adds devtest support for e320 via tftp. The e320 has a hardware incompatibility with sdmuxes that we use for the n3xx devices, which makes them unreliable. Instead this loads a small Linux OS into the e320 system memory and reimages the sd card from there. Signed-off-by: Steven Koo <steven.koo@ni.com>
Diffstat (limited to '.ci/utils/httpd.py')
-rw-r--r--.ci/utils/httpd.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/.ci/utils/httpd.py b/.ci/utils/httpd.py
new file mode 100644
index 000000000..53741566e
--- /dev/null
+++ b/.ci/utils/httpd.py
@@ -0,0 +1,63 @@
+import http.server
+import time
+import os
+import pyroute2
+import socket
+import socketserver
+import threading
+from functools import partial
+from pathlib import Path
+
+class ThreadingHTTPServer(socketserver.ThreadingMixIn, http.server.HTTPServer):
+ pass
+
+class HTTPServer:
+ def __init__(self, path, remote_ip):
+ self.path = path
+ self.port = None
+ self.old_path = None
+ self.httpd = None
+
+ with pyroute2.IPRoute() as ipr:
+ r = ipr.route('get', dst=remote_ip)
+ for attr in r[0]['attrs']:
+ if attr[0] == 'RTA_PREFSRC':
+ self.ip = attr[1]
+ with socket.socket() as s:
+ s.bind(('', 0))
+ self.port = s.getsockname()[1]
+
+ def get_url(self, filename):
+ path = Path(self.path) / filename
+ assert path.exists()
+ return f"http://{self.ip}:{self.port}/{filename}"
+
+ def __enter__(self):
+ def start_server():
+ Handler = http.server.SimpleHTTPRequestHandler
+ self.httpd = ThreadingHTTPServer(("", self.port), Handler)
+ self.httpd.serve_forever()
+
+ # Kind of annoying, but to work with older pythons where
+ # SimpleHTTPRequestHandler doesn't take a directory parameter but only
+ # serves the current directory:
+ self.old_path = os.getcwd()
+ os.chdir(self.path)
+
+ self.thread = threading.Thread(target=start_server)
+ self.thread.start()
+ return self
+
+ def __exit__(self, type, value, exc):
+ if self.httpd is not None:
+ self.httpd.shutdown()
+ self.httpd.server_close()
+ if self.old_path is not None:
+ os.chdir(self.old_path)
+
+if __name__ == '__main__':
+ with HTTPServer("/tmp", "127.0.0.1") as server:
+ print("server ip", server.ip)
+ print("server port", server.port)
+ time.sleep(300)
+