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

Proposed by Soren Hansen
Status: Merged
Approved by: Jay Pipes
Approved revision: 320
Merged at revision: 322
Proposed branch: lp:~soren/nova/lp654452
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 114 lines (+22/-3)
3 files modified
nova/service.py (+9/-3)
nova/tests/scheduler_unittest.py (+10/-0)
nova/tests/service_unittest.py (+3/-0)
To merge this branch: bzr merge lp:~soren/nova/lp654452
Reviewer Review Type Date Requested Status
Jay Pipes (community) Approve
Eric Day (community) Approve
Review via email: mp+37442@code.launchpad.net

Description of the change

Move manager_class instantiation and db.service_* calls out of nova.service.Service.__init__ into a new nova.service.Service.startService method which gets called by twisted. This delays opening db connections (and thus sqlite file creation) until after privileges have been shed by twisted.

To post a comment you must log in.
Revision history for this message
Eric Day (eday) wrote :

lgtm

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

Add a # pylint: disable-msg C0103 because twisted.application.service.Service requires the method be called startService...

lp:~soren/nova/lp654452 updated
320. By Soren Hansen

Add pylint thingamajig for startService (name defined by Twisted).

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/service.py'
2--- nova/service.py 2010-10-01 01:13:45 +0000
3+++ nova/service.py 2010-10-04 19:05:53 +0000
4@@ -52,11 +52,17 @@
5 self.host = host
6 self.binary = binary
7 self.topic = topic
8- manager_class = utils.import_class(manager)
9- self.manager = manager_class(host=host, *args, **kwargs)
10+ self.manager_class_name = manager
11+ super(Service, self).__init__(*args, **kwargs)
12+ self.saved_args, self.saved_kwargs = args, kwargs
13+
14+
15+ def startService(self): # pylint: disable-msg C0103
16+ manager_class = utils.import_class(self.manager_class_name)
17+ self.manager = manager_class(host=self.host, *self.saved_args,
18+ **self.saved_kwargs)
19 self.manager.init_host()
20 self.model_disconnected = False
21- super(Service, self).__init__(*args, **kwargs)
22 try:
23 service_ref = db.service_get_by_args(None,
24 self.host,
25
26=== modified file 'nova/tests/scheduler_unittest.py'
27--- nova/tests/scheduler_unittest.py 2010-09-12 02:40:38 +0000
28+++ nova/tests/scheduler_unittest.py 2010-10-04 19:05:53 +0000
29@@ -117,10 +117,12 @@
30 'nova-compute',
31 'compute',
32 FLAGS.compute_manager)
33+ compute1.startService()
34 compute2 = service.Service('host2',
35 'nova-compute',
36 'compute',
37 FLAGS.compute_manager)
38+ compute2.startService()
39 hosts = self.scheduler.driver.hosts_up(self.context, 'compute')
40 self.assertEqual(len(hosts), 2)
41 compute1.kill()
42@@ -132,10 +134,12 @@
43 'nova-compute',
44 'compute',
45 FLAGS.compute_manager)
46+ compute1.startService()
47 compute2 = service.Service('host2',
48 'nova-compute',
49 'compute',
50 FLAGS.compute_manager)
51+ compute2.startService()
52 instance_id1 = self._create_instance()
53 compute1.run_instance(self.context, instance_id1)
54 instance_id2 = self._create_instance()
55@@ -153,10 +157,12 @@
56 'nova-compute',
57 'compute',
58 FLAGS.compute_manager)
59+ compute1.startService()
60 compute2 = service.Service('host2',
61 'nova-compute',
62 'compute',
63 FLAGS.compute_manager)
64+ compute2.startService()
65 instance_ids1 = []
66 instance_ids2 = []
67 for index in xrange(FLAGS.max_cores):
68@@ -184,10 +190,12 @@
69 'nova-volume',
70 'volume',
71 FLAGS.volume_manager)
72+ volume1.startService()
73 volume2 = service.Service('host2',
74 'nova-volume',
75 'volume',
76 FLAGS.volume_manager)
77+ volume2.startService()
78 volume_id1 = self._create_volume()
79 volume1.create_volume(self.context, volume_id1)
80 volume_id2 = self._create_volume()
81@@ -205,10 +213,12 @@
82 'nova-volume',
83 'volume',
84 FLAGS.volume_manager)
85+ volume1.startService()
86 volume2 = service.Service('host2',
87 'nova-volume',
88 'volume',
89 FLAGS.volume_manager)
90+ volume2.startService()
91 volume_ids1 = []
92 volume_ids2 = []
93 for index in xrange(FLAGS.max_gigabytes):
94
95=== modified file 'nova/tests/service_unittest.py'
96--- nova/tests/service_unittest.py 2010-09-12 23:02:22 +0000
97+++ nova/tests/service_unittest.py 2010-10-04 19:05:53 +0000
98@@ -22,6 +22,8 @@
99
100 import mox
101
102+from twisted.application.app import startApplication
103+
104 from nova import exception
105 from nova import flags
106 from nova import rpc
107@@ -96,6 +98,7 @@
108 self.mox.ReplayAll()
109
110 app = service.Service.create(host=host, binary=binary)
111+ startApplication(app, False)
112 self.assert_(app)
113
114 # We're testing sort of weird behavior in how report_state decides