diff options
| -rw-r--r-- | nova/service.py | 11 | ||||
| -rw-r--r-- | nova/tests/service_unittest.py | 26 |
2 files changed, 26 insertions, 11 deletions
diff --git a/nova/service.py b/nova/service.py index fc188be34..d7471f4c6 100644 --- a/nova/service.py +++ b/nova/service.py @@ -85,9 +85,6 @@ class Service(object, service.Service): manager, defaults to FLAGS.<topic>_manager report_interval, defaults to FLAGS.report_interval """ - if not report_interval: - report_interval = FLAGS.report_interval - if not host: host = FLAGS.host if not binary: @@ -96,16 +93,18 @@ class Service(object, service.Service): topic = binary.rpartition("nova-")[2] if not manager: manager = FLAGS.get('%s_manager' % topic, None) + if not report_interval: + report_interval = FLAGS.report_interval logging.warn("Starting %s node", topic) - service_obj = cls(FLAGS.host, binary, topic, manager) + service_obj = cls(host, binary, topic, manager) conn = rpc.Connection.instance() consumer_all = rpc.AdapterConsumer( connection=conn, - topic='%s' % topic, + topic=topic, proxy=service_obj) consumer_node = rpc.AdapterConsumer( connection=conn, - topic='%s.%s' % (topic, FLAGS.host), + topic='%s.%s' % (topic, host), proxy=service_obj) pulse = task.LoopingCall(service_obj.report_state) diff --git a/nova/tests/service_unittest.py b/nova/tests/service_unittest.py index 274e74b5b..590d760b9 100644 --- a/nova/tests/service_unittest.py +++ b/nova/tests/service_unittest.py @@ -47,34 +47,50 @@ class ServiceTestCase(test.BaseTestCase): self.mox.StubOutWithMock(service, 'db') def test_create(self): + host='foo' + binary='nova-fake' + topic='fake' self.mox.StubOutWithMock(rpc, 'AdapterConsumer', use_mock_anything=True) self.mox.StubOutWithMock( service.task, 'LoopingCall', use_mock_anything=True) rpc.AdapterConsumer(connection=mox.IgnoreArg(), - topic='fake', + topic=topic, proxy=mox.IsA(service.Service)).AndReturn( rpc.AdapterConsumer) rpc.AdapterConsumer(connection=mox.IgnoreArg(), - topic='fake.%s' % FLAGS.host, + topic='%s.%s' % (topic, host), proxy=mox.IsA(service.Service)).AndReturn( rpc.AdapterConsumer) # Stub out looping call a bit needlessly since we don't have an easy # way to cancel it (yet) when the tests finishes - service.task.LoopingCall( - mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg()).AndReturn( + service.task.LoopingCall(mox.IgnoreArg()).AndReturn( service.task.LoopingCall) service.task.LoopingCall.start(interval=mox.IgnoreArg(), now=mox.IgnoreArg()) rpc.AdapterConsumer.attach_to_twisted() rpc.AdapterConsumer.attach_to_twisted() + service_create = {'host': host, + 'binary': binary, + 'topic': topic, + 'report_count': 0} + service_ref = {'host': host, + 'binary': binary, + 'report_count': 0, + 'id': 1} + + service.db.service_get_by_args(None, + host, + binary).AndRaise(exception.NotFound()) + service.db.service_create(None, + service_create).AndReturn(service_ref['id']) self.mox.ReplayAll() - app = service.Service.create(bin_name='nova-fake') + app = service.Service.create(host=host, binary=binary) self.assert_(app) # We're testing sort of weird behavior in how report_state decides |
