diff --git a/lib/http.py b/lib/http.py index 9cdc564acf42b2eafe276cd62c292f10352a9d8e..ab5349b3f99cd3da6d8171b7e0ab623ae6e7d287 100644 --- a/lib/http.py +++ b/lib/http.py @@ -150,61 +150,6 @@ class HTTPVersionNotSupported(HTTPException): code = 505 -class ApacheLogfile: - """Utility class to write HTTP server log files. - - The written format is the "Common Log Format" as defined by Apache: - http://httpd.apache.org/docs/2.2/mod/mod_log_config.html#examples - - """ - def __init__(self, fd): - """Constructor for ApacheLogfile class. - - Args: - - fd: Open file object - - """ - self._fd = fd - - def LogRequest(self, request, format, *args): - self._fd.write("%s %s %s [%s] %s\n" % ( - # Remote host address - request.address_string(), - - # RFC1413 identity (identd) - "-", - - # Remote user - "-", - - # Request time - self._FormatCurrentTime(), - - # Message - format % args, - )) - self._fd.flush() - - def _FormatCurrentTime(self): - """Formats current time in Common Log Format. - - """ - return self._FormatLogTime(time.time()) - - def _FormatLogTime(self, seconds): - """Formats time for Common Log Format. - - All timestamps are logged in the UTC timezone. - - Args: - - seconds: Time in seconds since the epoch - - """ - (_, month, _, _, _, _, _, _, _) = tm = time.gmtime(seconds) - format = "%d/" + MONTHNAME[month] + "/%Y:%H:%M:%S +0000" - return time.strftime(format, tm) - - class HTTPJsonConverter: CONTENT_TYPE = "application/json" diff --git a/test/ganeti.http_unittest.py b/test/ganeti.http_unittest.py index e5f787f9a78a8db37eac14fa7f4e81df17eed182..c10c0000e4b7c40051f94bb2109877a2998c9ca0 100755 --- a/test/ganeti.http_unittest.py +++ b/test/ganeti.http_unittest.py @@ -30,54 +30,7 @@ import time from ganeti import http -class HttpLogfileTests(unittest.TestCase): - """Tests for ApacheLogfile class.""" - - class FakeRequest: - FAKE_ADDRESS = "1.2.3.4" - - def address_string(self): - return self.FAKE_ADDRESS - - def setUp(self): - self.tmpfile = tempfile.NamedTemporaryFile() - self.logfile = http.ApacheLogfile(self.tmpfile) - - def tearDown(self): - self.tmpfile.close() - - def testFormatLogTime(self): - self._TestInTimezone(1208646123.0, "Europe/London", - "19/Apr/2008:23:02:03 +0000") - self._TestInTimezone(1208646123, "Europe/Zurich", - "19/Apr/2008:23:02:03 +0000") - self._TestInTimezone(1208646123, "Australia/Sydney", - "19/Apr/2008:23:02:03 +0000") - - def _TestInTimezone(self, seconds, timezone, expected): - """Tests HttpLogfile._FormatLogTime with a specific timezone - - """ - # Preserve environment - old_TZ = os.environ.get("TZ", None) - try: - os.environ["TZ"] = timezone - time.tzset() - result = self.logfile._FormatLogTime(seconds) - finally: - # Restore environment - if old_TZ is not None: - os.environ["TZ"] = old_TZ - elif "TZ" in os.environ: - del os.environ["TZ"] - time.tzset() - - self.assertEqual(result, expected) - - - def testLogRequest(self): - request = self.FakeRequest() - self.logfile.LogRequest(request, "This is only a %s", "test") +# TODO: Write unittests if __name__ == '__main__':