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
=== modified file 'nova/service.py'
--- nova/service.py 2010-10-01 01:13:45 +0000
+++ nova/service.py 2010-10-04 19:05:53 +0000
@@ -52,11 +52,17 @@
52 self.host = host52 self.host = host
53 self.binary = binary53 self.binary = binary
54 self.topic = topic54 self.topic = topic
55 manager_class = utils.import_class(manager)55 self.manager_class_name = manager
56 self.manager = manager_class(host=host, *args, **kwargs)56 super(Service, self).__init__(*args, **kwargs)
57 self.saved_args, self.saved_kwargs = args, kwargs
58
59
60 def startService(self): # pylint: disable-msg C0103
61 manager_class = utils.import_class(self.manager_class_name)
62 self.manager = manager_class(host=self.host, *self.saved_args,
63 **self.saved_kwargs)
57 self.manager.init_host()64 self.manager.init_host()
58 self.model_disconnected = False65 self.model_disconnected = False
59 super(Service, self).__init__(*args, **kwargs)
60 try:66 try:
61 service_ref = db.service_get_by_args(None,67 service_ref = db.service_get_by_args(None,
62 self.host,68 self.host,
6369
=== modified file 'nova/tests/scheduler_unittest.py'
--- nova/tests/scheduler_unittest.py 2010-09-12 02:40:38 +0000
+++ nova/tests/scheduler_unittest.py 2010-10-04 19:05:53 +0000
@@ -117,10 +117,12 @@
117 'nova-compute',117 'nova-compute',
118 'compute',118 'compute',
119 FLAGS.compute_manager)119 FLAGS.compute_manager)
120 compute1.startService()
120 compute2 = service.Service('host2',121 compute2 = service.Service('host2',
121 'nova-compute',122 'nova-compute',
122 'compute',123 'compute',
123 FLAGS.compute_manager)124 FLAGS.compute_manager)
125 compute2.startService()
124 hosts = self.scheduler.driver.hosts_up(self.context, 'compute')126 hosts = self.scheduler.driver.hosts_up(self.context, 'compute')
125 self.assertEqual(len(hosts), 2)127 self.assertEqual(len(hosts), 2)
126 compute1.kill()128 compute1.kill()
@@ -132,10 +134,12 @@
132 'nova-compute',134 'nova-compute',
133 'compute',135 'compute',
134 FLAGS.compute_manager)136 FLAGS.compute_manager)
137 compute1.startService()
135 compute2 = service.Service('host2',138 compute2 = service.Service('host2',
136 'nova-compute',139 'nova-compute',
137 'compute',140 'compute',
138 FLAGS.compute_manager)141 FLAGS.compute_manager)
142 compute2.startService()
139 instance_id1 = self._create_instance()143 instance_id1 = self._create_instance()
140 compute1.run_instance(self.context, instance_id1)144 compute1.run_instance(self.context, instance_id1)
141 instance_id2 = self._create_instance()145 instance_id2 = self._create_instance()
@@ -153,10 +157,12 @@
153 'nova-compute',157 'nova-compute',
154 'compute',158 'compute',
155 FLAGS.compute_manager)159 FLAGS.compute_manager)
160 compute1.startService()
156 compute2 = service.Service('host2',161 compute2 = service.Service('host2',
157 'nova-compute',162 'nova-compute',
158 'compute',163 'compute',
159 FLAGS.compute_manager)164 FLAGS.compute_manager)
165 compute2.startService()
160 instance_ids1 = []166 instance_ids1 = []
161 instance_ids2 = []167 instance_ids2 = []
162 for index in xrange(FLAGS.max_cores):168 for index in xrange(FLAGS.max_cores):
@@ -184,10 +190,12 @@
184 'nova-volume',190 'nova-volume',
185 'volume',191 'volume',
186 FLAGS.volume_manager)192 FLAGS.volume_manager)
193 volume1.startService()
187 volume2 = service.Service('host2',194 volume2 = service.Service('host2',
188 'nova-volume',195 'nova-volume',
189 'volume',196 'volume',
190 FLAGS.volume_manager)197 FLAGS.volume_manager)
198 volume2.startService()
191 volume_id1 = self._create_volume()199 volume_id1 = self._create_volume()
192 volume1.create_volume(self.context, volume_id1)200 volume1.create_volume(self.context, volume_id1)
193 volume_id2 = self._create_volume()201 volume_id2 = self._create_volume()
@@ -205,10 +213,12 @@
205 'nova-volume',213 'nova-volume',
206 'volume',214 'volume',
207 FLAGS.volume_manager)215 FLAGS.volume_manager)
216 volume1.startService()
208 volume2 = service.Service('host2',217 volume2 = service.Service('host2',
209 'nova-volume',218 'nova-volume',
210 'volume',219 'volume',
211 FLAGS.volume_manager)220 FLAGS.volume_manager)
221 volume2.startService()
212 volume_ids1 = []222 volume_ids1 = []
213 volume_ids2 = []223 volume_ids2 = []
214 for index in xrange(FLAGS.max_gigabytes):224 for index in xrange(FLAGS.max_gigabytes):
215225
=== modified file 'nova/tests/service_unittest.py'
--- nova/tests/service_unittest.py 2010-09-12 23:02:22 +0000
+++ nova/tests/service_unittest.py 2010-10-04 19:05:53 +0000
@@ -22,6 +22,8 @@
2222
23import mox23import mox
2424
25from twisted.application.app import startApplication
26
25from nova import exception27from nova import exception
26from nova import flags28from nova import flags
27from nova import rpc29from nova import rpc
@@ -96,6 +98,7 @@
96 self.mox.ReplayAll()98 self.mox.ReplayAll()
9799
98 app = service.Service.create(host=host, binary=binary)100 app = service.Service.create(host=host, binary=binary)
101 startApplication(app, False)
99 self.assert_(app)102 self.assert_(app)
100103
101 # We're testing sort of weird behavior in how report_state decides104 # We're testing sort of weird behavior in how report_state decides