summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa
diff options
context:
space:
mode:
authorRoss Burton <ross.burton@arm.com>2023-01-31 11:49:54 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-02-01 14:05:15 +0000
commitf6a1c8c3098d108da03a423cea16c378fc615e8c (patch)
tree95f1d438e46b78a7c9eddc08220ee9a25f5a180d /meta/lib/oeqa
parentd8ec2bbc77b48b1f163623eb3909387b3bc0d3e4 (diff)
downloadpoky-f6a1c8c3098d108da03a423cea16c378fc615e8c.tar.gz
oeqa/utils/httpserver: connect up the request logging
Call logger.info() in the log_message handler so that we get request logging, and hopefully even error messages. Create a child logger to be neat and compartmentalise the logging. Add a __main__ entrypoint so this class can be exercised outside of oeqa. Remove unused traceback import. (From OE-Core rev: 8fc939d942cec1662ca386b87c63f167bb10fd05) Signed-off-by: Ross Burton <ross.burton@arm.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa')
-rw-r--r--meta/lib/oeqa/utils/httpserver.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/meta/lib/oeqa/utils/httpserver.py b/meta/lib/oeqa/utils/httpserver.py
index 8ce1dd42f4..2aa172bf79 100644
--- a/meta/lib/oeqa/utils/httpserver.py
+++ b/meta/lib/oeqa/utils/httpserver.py
@@ -5,9 +5,9 @@
5# 5#
6 6
7import http.server 7import http.server
8import logging
8import multiprocessing 9import multiprocessing
9import os 10import os
10import traceback
11import signal 11import signal
12from socketserver import ThreadingMixIn 12from socketserver import ThreadingMixIn
13 13
@@ -15,20 +15,24 @@ class HTTPServer(ThreadingMixIn, http.server.HTTPServer):
15 15
16 def server_start(self, root_dir, logger): 16 def server_start(self, root_dir, logger):
17 os.chdir(root_dir) 17 os.chdir(root_dir)
18 self.logger = logger
18 self.serve_forever() 19 self.serve_forever()
19 20
20class HTTPRequestHandler(http.server.SimpleHTTPRequestHandler): 21class HTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
21 22
22 def log_message(self, format_str, *args): 23 def log_message(self, format_str, *args):
23 pass 24 self.server.logger.info(format_str, *args)
24 25
25class HTTPService(object): 26class HTTPService:
26 27
27 def __init__(self, root_dir, host='', port=0, logger=None): 28 def __init__(self, root_dir, host='', port=0, logger=None):
28 self.root_dir = root_dir 29 self.root_dir = root_dir
29 self.host = host 30 self.host = host
30 self.port = port 31 self.port = port
31 self.logger = logger 32 if logger:
33 self.logger = logger.getChild("HTTPService")
34 else:
35 self.logger = logging.getLogger("HTTPService")
32 36
33 def start(self): 37 def start(self):
34 if not os.path.exists(self.root_dir): 38 if not os.path.exists(self.root_dir):
@@ -49,7 +53,7 @@ class HTTPService(object):
49 signal.signal(signal.SIGTERM, orig) 53 signal.signal(signal.SIGTERM, orig)
50 54
51 if self.logger: 55 if self.logger:
52 self.logger.info("Started HTTPService on %s:%s" % (self.host, self.port)) 56 self.logger.info("Started HTTPService for %s on %s:%s" % (self.root_dir, self.host, self.port))
53 57
54 58
55 def stop(self): 59 def stop(self):
@@ -61,3 +65,10 @@ class HTTPService(object):
61 if self.logger: 65 if self.logger:
62 self.logger.info("Stopped HTTPService on %s:%s" % (self.host, self.port)) 66 self.logger.info("Stopped HTTPService on %s:%s" % (self.host, self.port))
63 67
68if __name__ == "__main__":
69 import sys, logging
70
71 logger = logging.getLogger(__name__)
72 logging.basicConfig(level=logging.DEBUG)
73 httpd = HTTPService(sys.argv[1], port=8888, logger=logger)
74 httpd.start()