Merge lp:~soren/nova/logdir into lp:~hudson-openstack/nova/trunk

Proposed by Soren Hansen
Status: Merged
Approved by: Soren Hansen
Approved revision: 674
Merged at revision: 681
Proposed branch: lp:~soren/nova/logdir
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 104 lines (+40/-4)
4 files modified
nova/flags.py (+2/-0)
nova/log.py (+17/-2)
nova/tests/test_log.py (+21/-0)
nova/twistd.py (+0/-2)
To merge this branch: bzr merge lp:~soren/nova/logdir
Reviewer Review Type Date Requested Status
Jay Pipes (community) Approve
Devin Carlen (community) Approve
Review via email: mp+49722@code.launchpad.net

Commit message

Add back --logdir=DIR option. If set, a logfile named after the binary (e.g. nova-api.log) will be kept in DIR.

Description of the change

Resurrect the logdir option.

With The Big Eventlet Merge™, the logdir option went missing. I've
cried myself to sleep ever since.

Setting this option will create a logfile in the named directory
with a filename based on the binary's name. E.g. "nova-api --logdir=/var/log/nova"
will will create logfile /var/log/nova/nova-api.log.

To post a comment you must log in.
Revision history for this message
Devin Carlen (devcamcar) wrote :

lgtm

review: Approve
Revision history for this message
Jay Pipes (jaypipes) wrote :

Hi!

35 + if FLAGS.logfile or FLAGS.logdir:
36 + if FLAGS.logfile:
37 + logfile = FLAGS.logfile
38 + else:
39 + binary = os.path.basename(inspect.stack()[-1][1])
40 + logpath = '%s.log' % (os.path.join(FLAGS.logdir, binary),)
41 + logfile = FileHandler(logpath)

Looks like line 37 abve should be:

logpath = FLAGS.logfile

Otherwise line 41 will fail with a NameError is logfile is passed and logpath isn't defined.

Cheers,
jay

review: Needs Fixing
Revision history for this message
Soren Hansen (soren) wrote :

Good catch, Jay. I've fixed that, refactored it somewhat, and added unit tests. This will never happen again :)

Revision history for this message
Jay Pipes (jaypipes) wrote :

test cases, ftw.

review: Approve
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :
Download full text (21.2 KiB)

The attempt to merge lp:~soren/nova/logdir into lp:nova failed. Below is the output from the failed tests.

AdminAPITest
    test_admin_disabled ok
    test_admin_enabled ok
APITest
    test_exceptions_are_converted_to_faults ok
Test
    test_authorize_token ok
    test_authorize_user ok
    test_bad_token ok
    test_bad_user ok
    test_no_user ok
    test_token_expiry ok
TestLimiter
    test_authorize_token ok
TestFaults
    test_fault_parts ok
    test_raise ok
    test_retry_header ok
FlavorsTest
    test_get_flavor_by_id ok
    test_get_flavor_list ok
GlanceImageServiceTest
    test_create ok
    test_create_and_show_non_existing_image ok
    test_delete ok
    test_update ok
ImageControllerWithGlanceServiceTest
    test_get_image_details ok
    test_get_image_index ok
LocalImageServiceTest
    test_create ok
    test_create_and_show_non_existing_image ok
    test_delete ok
    test_update ok
LimiterTest
    test_minute ok
    test_one_per_period ok
    test_second ok
    test_users_get_separate_buckets ok
    test_we_can_go_indefinitely_if_we_spread_out_requests ok
WSGIAppProxyTest
    test_200 ok
    test_403 ok
    test_failure ok
WSGIAppTest
    test_escaping ok
    test_good_urls ok
    test_invalid_methods ok
    test_invalid_urls ok
    test_response_to_delays ok
ServersTest
    test_create_backup_schedules ok
    test_create_instance ok
    test_delete_backup_schedules ok
    test_delete_server_instance ok
    test_get_all_server_details ok
    test_get_se...

Revision history for this message
Jay Pipes (jaypipes) wrote :

lgtm.

review: Approve
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :
Download full text (23.3 KiB)

The attempt to merge lp:~soren/nova/logdir into lp:nova failed. Below is the output from the failed tests.

AdminAPITest
    test_admin_disabled ok
    test_admin_enabled ok
APITest
    test_exceptions_are_converted_to_faults ok
Test
    test_authorize_token ok
    test_authorize_user ok
    test_bad_token ok
    test_bad_user ok
    test_no_user ok
    test_token_expiry ok
TestLimiter
    test_authorize_token ok
TestFaults
    test_fault_parts ok
    test_raise ok
    test_retry_header ok
FlavorsTest
    test_get_flavor_by_id ok
    test_get_flavor_list ok
GlanceImageServiceTest
    test_create ok
    test_create_and_show_non_existing_image ok
    test_delete ok
    test_update ok
ImageControllerWithGlanceServiceTest
    test_get_image_details ok
    test_get_image_index ok
LocalImageServiceTest
    test_create ok
    test_create_and_show_non_existing_image ok
    test_delete ok
    test_update ok
LimiterTest
    test_minute ok
    test_one_per_period ok
    test_second ok
    test_users_get_separate_buckets ok
    test_we_can_go_indefinitely_if_we_spread_out_requests ok
WSGIAppProxyTest
    test_200 ok
    test_403 ok
    test_failure ok
WSGIAppTest
    test_escaping ok
    test_good_urls ok
    test_invalid_methods ok
    test_invalid_urls ok
    test_response_to_delays ok
ServersTest
    test_create_backup_schedules ok
    test_create_instance ok
    test_delete_backup_schedules ok
    test_delete_server_instance ok
    test_get_all_server_details ok
    test_get_se...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'nova/flags.py'
--- nova/flags.py 2011-02-10 19:40:21 +0000
+++ nova/flags.py 2011-02-16 09:49:27 +0000
@@ -282,6 +282,8 @@
282282
283DEFINE_string('state_path', os.path.join(os.path.dirname(__file__), '../'),283DEFINE_string('state_path', os.path.join(os.path.dirname(__file__), '../'),
284 "Top-level directory for maintaining nova's state")284 "Top-level directory for maintaining nova's state")
285DEFINE_string('logdir', None, 'output to a per-service log file in named '
286 'directory')
285287
286DEFINE_string('sql_connection',288DEFINE_string('sql_connection',
287 'sqlite:///$state_path/nova.sqlite',289 'sqlite:///$state_path/nova.sqlite',
288290
=== modified file 'nova/log.py'
--- nova/log.py 2011-01-28 17:46:46 +0000
+++ nova/log.py 2011-02-16 09:49:27 +0000
@@ -28,9 +28,11 @@
2828
2929
30import cStringIO30import cStringIO
31import inspect
31import json32import json
32import logging33import logging
33import logging.handlers34import logging.handlers
35import os
34import sys36import sys
35import traceback37import traceback
3638
@@ -111,6 +113,18 @@
111 return context113 return context
112114
113115
116def _get_binary_name():
117 return os.path.basename(inspect.stack()[-1][1])
118
119
120def get_log_file_path(binary=None):
121 if FLAGS.logfile:
122 return FLAGS.logfile
123 if FLAGS.logdir:
124 binary = binary or _get_binary_name()
125 return '%s.log' % (os.path.join(FLAGS.logdir, binary),)
126
127
114def basicConfig():128def basicConfig():
115 logging.basicConfig()129 logging.basicConfig()
116 for handler in logging.root.handlers:130 for handler in logging.root.handlers:
@@ -123,8 +137,9 @@
123 syslog = SysLogHandler(address='/dev/log')137 syslog = SysLogHandler(address='/dev/log')
124 syslog.setFormatter(_formatter)138 syslog.setFormatter(_formatter)
125 logging.root.addHandler(syslog)139 logging.root.addHandler(syslog)
126 if FLAGS.logfile:140 logpath = get_log_file_path()
127 logfile = FileHandler(FLAGS.logfile)141 if logpath:
142 logfile = FileHandler(logpath)
128 logfile.setFormatter(_formatter)143 logfile.setFormatter(_formatter)
129 logging.root.addHandler(logfile)144 logging.root.addHandler(logfile)
130145
131146
=== modified file 'nova/tests/test_log.py'
--- nova/tests/test_log.py 2011-01-14 19:00:47 +0000
+++ nova/tests/test_log.py 2011-02-16 09:49:27 +0000
@@ -46,6 +46,27 @@
46 self.assert_(True) # didn't raise exception46 self.assert_(True) # didn't raise exception
4747
4848
49class LogHandlerTestCase(test.TestCase):
50 def test_log_path_logdir(self):
51 self.flags(logdir='/some/path')
52 self.assertEquals(log.get_log_file_path(binary='foo-bar'),
53 '/some/path/foo-bar.log')
54
55 def test_log_path_logfile(self):
56 self.flags(logfile='/some/path/foo-bar.log')
57 self.assertEquals(log.get_log_file_path(binary='foo-bar'),
58 '/some/path/foo-bar.log')
59
60 def test_log_path_none(self):
61 self.assertTrue(log.get_log_file_path(binary='foo-bar') is None)
62
63 def test_log_path_logfile_overrides_logdir(self):
64 self.flags(logdir='/some/other/path',
65 logfile='/some/path/foo-bar.log')
66 self.assertEquals(log.get_log_file_path(binary='foo-bar'),
67 '/some/path/foo-bar.log')
68
69
49class NovaFormatterTestCase(test.TestCase):70class NovaFormatterTestCase(test.TestCase):
50 def setUp(self):71 def setUp(self):
51 super(NovaFormatterTestCase, self).setUp()72 super(NovaFormatterTestCase, self).setUp()
5273
=== modified file 'nova/twistd.py'
--- nova/twistd.py 2011-01-20 17:52:02 +0000
+++ nova/twistd.py 2011-02-16 09:49:27 +0000
@@ -43,8 +43,6 @@
4343
4444
45FLAGS = flags.FLAGS45FLAGS = flags.FLAGS
46flags.DEFINE_string('logdir', None, 'directory to keep log files in '
47 '(will be prepended to $logfile)')
4846
4947
50class TwistdServerOptions(ServerOptions):48class TwistdServerOptions(ServerOptions):