Commit e820685c authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

ganeti.http: Remove ApacheLogfile class

We don't need it anymore and it wouldn't work as it is, anyway.

Reviewed-by: ultrotter
parent 05cc153f
......@@ -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:
def __init__(self, fd):
"""Constructor for ApacheLogfile class.
- 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
# RFC1413 identity (identd)
# Remote user
# Request time
# Message
format % args,
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.
- 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"
......@@ -30,54 +30,7 @@ import time
from ganeti import http
class HttpLogfileTests(unittest.TestCase):
"""Tests for ApacheLogfile class."""
class FakeRequest:
def address_string(self):
return self.FAKE_ADDRESS
def setUp(self):
self.tmpfile = tempfile.NamedTemporaryFile()
self.logfile = http.ApacheLogfile(self.tmpfile)
def tearDown(self):
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)
os.environ["TZ"] = timezone
result = self.logfile._FormatLogTime(seconds)
# Restore environment
if old_TZ is not None:
os.environ["TZ"] = old_TZ
elif "TZ" in os.environ:
del os.environ["TZ"]
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__':
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment