Merge lp:~vishvananda/nova/fix_service_unittest into lp:~hudson-openstack/nova/trunk

Proposed by Vish Ishaya
Status: Merged
Approved by: Devin Carlen
Approved revision: 384
Merged at revision: 385
Proposed branch: lp:~vishvananda/nova/fix_service_unittest
Merge into: lp:~hudson-openstack/nova/trunk
Prerequisite: lp:~gundlach/nova/tornado-excision
Diff against target: 221 lines (+105/-94)
1 file modified
nova/tests/service_unittest.py (+105/-94)
To merge this branch: bzr merge lp:~vishvananda/nova/fix_service_unittest
Reviewer Review Type Date Requested Status
Devin Carlen (community) Approve
Michael Gundlach (community) Approve
Review via email: mp+39386@code.launchpad.net

Commit message

Fixes service unit tests after tornado excision.

Description of the change

Fixes the service unit tests after tornado excision.

To post a comment you must log in.
Revision history for this message
Michael Gundlach (gundlach) wrote :

Assuming the unit tests pass, lgtm! If you like my code that you merged in, feel free to set status to approved.

review: Approve
Revision history for this message
Devin Carlen (devcamcar) wrote :

looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/tests/service_unittest.py'
2--- nova/tests/service_unittest.py 2010-10-26 16:29:40 +0000
3+++ nova/tests/service_unittest.py 2010-10-26 16:29:40 +0000
4@@ -23,8 +23,8 @@
5 import mox
6
7 from twisted.application.app import startApplication
8+from twisted.internet import defer
9
10-from nova import context
11 from nova import exception
12 from nova import flags
13 from nova import rpc
14@@ -81,7 +81,6 @@
15 def setUp(self):
16 super(ServiceTestCase, self).setUp()
17 self.mox.StubOutWithMock(service, 'db')
18- self.context = context.get_admin_context()
19
20 def test_create(self):
21 host = 'foo'
22@@ -140,95 +139,107 @@
23 startApplication(app, False)
24 self.assert_(app)
25
26-# TODO(gundlach): These tests were "passing" when this class inherited from
27-# BaseTestCase. In reality, they were failing, but BaseTestCase was
28-# swallowing the error. Now that we inherit from TrialTestCase, these tests
29-# are failing, and need to get fixed.
30-# # We're testing sort of weird behavior in how report_state decides
31-# # whether it is disconnected, it looks for a variable on itself called
32-# # 'model_disconnected' and report_state doesn't really do much so this
33-# # these are mostly just for coverage
34-# def test_report_state(self):
35-# host = 'foo'
36-# binary = 'bar'
37-# service_ref = {'host': host,
38-# 'binary': binary,
39-# 'report_count': 0,
40-# 'id': 1}
41-# service.db.__getattr__('report_state')
42-# service.db.service_get_by_args(self.context,
43-# host,
44-# binary).AndReturn(service_ref)
45-# service.db.service_update(self.context, service_ref['id'],
46-# mox.ContainsKeyValue('report_count', 1))
47-#
48-# self.mox.ReplayAll()
49-# s = service.Service()
50-# rv = yield s.report_state(host, binary)
51-#
52-# def test_report_state_no_service(self):
53-# host = 'foo'
54-# binary = 'bar'
55-# service_create = {'host': host,
56-# 'binary': binary,
57-# 'report_count': 0}
58-# service_ref = {'host': host,
59-# 'binary': binary,
60-# 'report_count': 0,
61-# 'id': 1}
62-#
63-# service.db.__getattr__('report_state')
64-# service.db.service_get_by_args(self.context,
65-# host,
66-# binary).AndRaise(exception.NotFound())
67-# service.db.service_create(self.context,
68-# service_create).AndReturn(service_ref)
69-# service.db.service_get(self.context,
70-# service_ref['id']).AndReturn(service_ref)
71-# service.db.service_update(self.context, service_ref['id'],
72-# mox.ContainsKeyValue('report_count', 1))
73-#
74-# self.mox.ReplayAll()
75-# s = service.Service()
76-# rv = yield s.report_state(host, binary)
77-#
78-# def test_report_state_newly_disconnected(self):
79-# host = 'foo'
80-# binary = 'bar'
81-# service_ref = {'host': host,
82-# 'binary': binary,
83-# 'report_count': 0,
84-# 'id': 1}
85-#
86-# service.db.__getattr__('report_state')
87-# service.db.service_get_by_args(self.context,
88-# host,
89-# binary).AndRaise(Exception())
90-#
91-# self.mox.ReplayAll()
92-# s = service.Service()
93-# rv = yield s.report_state(host, binary)
94-#
95-# self.assert_(s.model_disconnected)
96-#
97-# def test_report_state_newly_connected(self):
98-# host = 'foo'
99-# binary = 'bar'
100-# service_ref = {'host': host,
101-# 'binary': binary,
102-# 'report_count': 0,
103-# 'id': 1}
104-#
105-# service.db.__getattr__('report_state')
106-# service.db.service_get_by_args(self.context,
107-# host,
108-# binary).AndReturn(service_ref)
109-# service.db.service_update(self.context, service_ref['id'],
110-# mox.ContainsKeyValue('report_count', 1))
111-#
112-# self.mox.ReplayAll()
113-# s = service.Service()
114-# s.model_disconnected = True
115-# rv = yield s.report_state(host, binary)
116-#
117-# self.assert_(not s.model_disconnected)
118+ # We're testing sort of weird behavior in how report_state decides
119+ # whether it is disconnected, it looks for a variable on itself called
120+ # 'model_disconnected' and report_state doesn't really do much so this
121+ # these are mostly just for coverage
122+ @defer.inlineCallbacks
123+ def test_report_state_no_service(self):
124+ host = 'foo'
125+ binary = 'bar'
126+ topic = 'test'
127+ service_create = {'host': host,
128+ 'binary': binary,
129+ 'topic': topic,
130+ 'report_count': 0}
131+ service_ref = {'host': host,
132+ 'binary': binary,
133+ 'topic': topic,
134+ 'report_count': 0,
135+ 'id': 1}
136+
137+ service.db.service_get_by_args(mox.IgnoreArg(),
138+ host,
139+ binary).AndRaise(exception.NotFound())
140+ service.db.service_create(mox.IgnoreArg(),
141+ service_create).AndReturn(service_ref)
142+ service.db.service_get(mox.IgnoreArg(),
143+ service_ref['id']).AndReturn(service_ref)
144+ service.db.service_update(mox.IgnoreArg(), service_ref['id'],
145+ mox.ContainsKeyValue('report_count', 1))
146+
147+ self.mox.ReplayAll()
148+ serv = service.Service(host,
149+ binary,
150+ topic,
151+ 'nova.tests.service_unittest.FakeManager')
152+ serv.startService()
153+ yield serv.report_state()
154+
155+ @defer.inlineCallbacks
156+ def test_report_state_newly_disconnected(self):
157+ host = 'foo'
158+ binary = 'bar'
159+ topic = 'test'
160+ service_create = {'host': host,
161+ 'binary': binary,
162+ 'topic': topic,
163+ 'report_count': 0}
164+ service_ref = {'host': host,
165+ 'binary': binary,
166+ 'topic': topic,
167+ 'report_count': 0,
168+ 'id': 1}
169+
170+ service.db.service_get_by_args(mox.IgnoreArg(),
171+ host,
172+ binary).AndRaise(exception.NotFound())
173+ service.db.service_create(mox.IgnoreArg(),
174+ service_create).AndReturn(service_ref)
175+ service.db.service_get(mox.IgnoreArg(),
176+ mox.IgnoreArg()).AndRaise(Exception())
177+
178+ self.mox.ReplayAll()
179+ serv = service.Service(host,
180+ binary,
181+ topic,
182+ 'nova.tests.service_unittest.FakeManager')
183+ serv.startService()
184+ yield serv.report_state()
185+ self.assert_(serv.model_disconnected)
186+
187+ @defer.inlineCallbacks
188+ def test_report_state_newly_connected(self):
189+ host = 'foo'
190+ binary = 'bar'
191+ topic = 'test'
192+ service_create = {'host': host,
193+ 'binary': binary,
194+ 'topic': topic,
195+ 'report_count': 0}
196+ service_ref = {'host': host,
197+ 'binary': binary,
198+ 'topic': topic,
199+ 'report_count': 0,
200+ 'id': 1}
201+
202+ service.db.service_get_by_args(mox.IgnoreArg(),
203+ host,
204+ binary).AndRaise(exception.NotFound())
205+ service.db.service_create(mox.IgnoreArg(),
206+ service_create).AndReturn(service_ref)
207+ service.db.service_get(mox.IgnoreArg(),
208+ service_ref['id']).AndReturn(service_ref)
209+ service.db.service_update(mox.IgnoreArg(), service_ref['id'],
210+ mox.ContainsKeyValue('report_count', 1))
211+
212+ self.mox.ReplayAll()
213+ serv = service.Service(host,
214+ binary,
215+ topic,
216+ 'nova.tests.service_unittest.FakeManager')
217+ serv.startService()
218+ serv.model_disconnected = True
219+ yield serv.report_state()
220+
221+ self.assert_(not serv.model_disconnected)