fix completely broken ServiceTestCase
This commit is contained in:
@@ -23,8 +23,8 @@ Unit Tests for remote procedure calls using queue
|
|||||||
import mox
|
import mox
|
||||||
|
|
||||||
from twisted.application.app import startApplication
|
from twisted.application.app import startApplication
|
||||||
|
from twisted.internet import defer
|
||||||
|
|
||||||
from nova import context
|
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import rpc
|
from nova import rpc
|
||||||
@@ -48,7 +48,7 @@ class ExtendedService(service.Service):
|
|||||||
return 'service'
|
return 'service'
|
||||||
|
|
||||||
|
|
||||||
class ServiceManagerTestCase(test.BaseTestCase):
|
class ServiceManagerTestCase(test.TrialTestCase):
|
||||||
"""Test cases for Services"""
|
"""Test cases for Services"""
|
||||||
|
|
||||||
def test_attribute_error_for_no_manager(self):
|
def test_attribute_error_for_no_manager(self):
|
||||||
@@ -75,13 +75,12 @@ class ServiceManagerTestCase(test.BaseTestCase):
|
|||||||
self.assertEqual(serv.test_method(), 'service')
|
self.assertEqual(serv.test_method(), 'service')
|
||||||
|
|
||||||
|
|
||||||
class ServiceTestCase(test.BaseTestCase):
|
class ServiceTestCase(test.TrialTestCase):
|
||||||
"""Test cases for Services"""
|
"""Test cases for Services"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(ServiceTestCase, self).setUp()
|
super(ServiceTestCase, self).setUp()
|
||||||
self.mox.StubOutWithMock(service, 'db')
|
self.mox.StubOutWithMock(service, 'db')
|
||||||
self.context = context.get_admin_context()
|
|
||||||
|
|
||||||
def test_create(self):
|
def test_create(self):
|
||||||
host = 'foo'
|
host = 'foo'
|
||||||
@@ -144,87 +143,103 @@ class ServiceTestCase(test.BaseTestCase):
|
|||||||
# whether it is disconnected, it looks for a variable on itself called
|
# whether it is disconnected, it looks for a variable on itself called
|
||||||
# 'model_disconnected' and report_state doesn't really do much so this
|
# 'model_disconnected' and report_state doesn't really do much so this
|
||||||
# these are mostly just for coverage
|
# these are mostly just for coverage
|
||||||
def test_report_state(self):
|
@defer.inlineCallbacks
|
||||||
host = 'foo'
|
|
||||||
binary = 'bar'
|
|
||||||
service_ref = {'host': host,
|
|
||||||
'binary': binary,
|
|
||||||
'report_count': 0,
|
|
||||||
'id': 1}
|
|
||||||
service.db.__getattr__('report_state')
|
|
||||||
service.db.service_get_by_args(self.context,
|
|
||||||
host,
|
|
||||||
binary).AndReturn(service_ref)
|
|
||||||
service.db.service_update(self.context, service_ref['id'],
|
|
||||||
mox.ContainsKeyValue('report_count', 1))
|
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
|
||||||
s = service.Service()
|
|
||||||
rv = yield s.report_state(host, binary)
|
|
||||||
|
|
||||||
def test_report_state_no_service(self):
|
def test_report_state_no_service(self):
|
||||||
host = 'foo'
|
host = 'foo'
|
||||||
binary = 'bar'
|
binary = 'bar'
|
||||||
|
topic = 'test'
|
||||||
service_create = {'host': host,
|
service_create = {'host': host,
|
||||||
'binary': binary,
|
'binary': binary,
|
||||||
|
'topic': topic,
|
||||||
'report_count': 0}
|
'report_count': 0}
|
||||||
service_ref = {'host': host,
|
service_ref = {'host': host,
|
||||||
'binary': binary,
|
'binary': binary,
|
||||||
'report_count': 0,
|
'topic': topic,
|
||||||
'id': 1}
|
'report_count': 0,
|
||||||
|
'id': 1}
|
||||||
|
|
||||||
service.db.__getattr__('report_state')
|
service.db.service_get_by_args(mox.IgnoreArg(),
|
||||||
service.db.service_get_by_args(self.context,
|
|
||||||
host,
|
host,
|
||||||
binary).AndRaise(exception.NotFound())
|
binary).AndRaise(exception.NotFound())
|
||||||
service.db.service_create(self.context,
|
service.db.service_create(mox.IgnoreArg(),
|
||||||
service_create).AndReturn(service_ref)
|
service_create).AndReturn(service_ref)
|
||||||
service.db.service_get(self.context,
|
service.db.service_get(mox.IgnoreArg(),
|
||||||
service_ref['id']).AndReturn(service_ref)
|
service_ref['id']).AndReturn(service_ref)
|
||||||
service.db.service_update(self.context, service_ref['id'],
|
service.db.service_update(mox.IgnoreArg(), service_ref['id'],
|
||||||
mox.ContainsKeyValue('report_count', 1))
|
mox.ContainsKeyValue('report_count', 1))
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
s = service.Service()
|
serv = service.Service(host,
|
||||||
rv = yield s.report_state(host, binary)
|
binary,
|
||||||
|
topic,
|
||||||
|
'nova.tests.service_unittest.FakeManager')
|
||||||
|
serv.startService()
|
||||||
|
yield serv.report_state()
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
def test_report_state_newly_disconnected(self):
|
def test_report_state_newly_disconnected(self):
|
||||||
host = 'foo'
|
host = 'foo'
|
||||||
binary = 'bar'
|
binary = 'bar'
|
||||||
|
topic = 'test'
|
||||||
|
service_create = {'host': host,
|
||||||
|
'binary': binary,
|
||||||
|
'topic': topic,
|
||||||
|
'report_count': 0}
|
||||||
service_ref = {'host': host,
|
service_ref = {'host': host,
|
||||||
'binary': binary,
|
'binary': binary,
|
||||||
'report_count': 0,
|
'topic': topic,
|
||||||
'id': 1}
|
'report_count': 0,
|
||||||
|
'id': 1}
|
||||||
|
|
||||||
service.db.__getattr__('report_state')
|
service.db.service_get_by_args(mox.IgnoreArg(),
|
||||||
service.db.service_get_by_args(self.context,
|
host,
|
||||||
host,
|
binary).AndRaise(exception.NotFound())
|
||||||
binary).AndRaise(Exception())
|
service.db.service_create(mox.IgnoreArg(),
|
||||||
|
service_create).AndReturn(service_ref)
|
||||||
|
service.db.service_get(mox.IgnoreArg(),
|
||||||
|
mox.IgnoreArg()).AndRaise(Exception())
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
s = service.Service()
|
serv = service.Service(host,
|
||||||
rv = yield s.report_state(host, binary)
|
binary,
|
||||||
|
topic,
|
||||||
self.assert_(s.model_disconnected)
|
'nova.tests.service_unittest.FakeManager')
|
||||||
|
serv.startService()
|
||||||
|
yield serv.report_state()
|
||||||
|
self.assert_(serv.model_disconnected)
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
def test_report_state_newly_connected(self):
|
def test_report_state_newly_connected(self):
|
||||||
host = 'foo'
|
host = 'foo'
|
||||||
binary = 'bar'
|
binary = 'bar'
|
||||||
|
topic = 'test'
|
||||||
|
service_create = {'host': host,
|
||||||
|
'binary': binary,
|
||||||
|
'topic': topic,
|
||||||
|
'report_count': 0}
|
||||||
service_ref = {'host': host,
|
service_ref = {'host': host,
|
||||||
'binary': binary,
|
'binary': binary,
|
||||||
'report_count': 0,
|
'topic': topic,
|
||||||
'id': 1}
|
'report_count': 0,
|
||||||
|
'id': 1}
|
||||||
|
|
||||||
service.db.__getattr__('report_state')
|
service.db.service_get_by_args(mox.IgnoreArg(),
|
||||||
service.db.service_get_by_args(self.context,
|
host,
|
||||||
host,
|
binary).AndRaise(exception.NotFound())
|
||||||
binary).AndReturn(service_ref)
|
service.db.service_create(mox.IgnoreArg(),
|
||||||
service.db.service_update(self.context, service_ref['id'],
|
service_create).AndReturn(service_ref)
|
||||||
|
service.db.service_get(mox.IgnoreArg(),
|
||||||
|
service_ref['id']).AndReturn(service_ref)
|
||||||
|
service.db.service_update(mox.IgnoreArg(), service_ref['id'],
|
||||||
mox.ContainsKeyValue('report_count', 1))
|
mox.ContainsKeyValue('report_count', 1))
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
s = service.Service()
|
serv = service.Service(host,
|
||||||
s.model_disconnected = True
|
binary,
|
||||||
rv = yield s.report_state(host, binary)
|
topic,
|
||||||
|
'nova.tests.service_unittest.FakeManager')
|
||||||
|
serv.startService()
|
||||||
|
serv.model_disconnected = True
|
||||||
|
yield serv.report_state()
|
||||||
|
|
||||||
self.assert_(not s.model_disconnected)
|
self.assert_(not serv.model_disconnected)
|
||||||
|
|||||||
Reference in New Issue
Block a user