get service unittests runnning again
This commit is contained in:
		@@ -68,6 +68,7 @@ class Service(object):
 | 
			
		||||
        self.periodic_interval = periodic_interval
 | 
			
		||||
        super(Service, self).__init__(*args, **kwargs)
 | 
			
		||||
        self.saved_args, self.saved_kwargs = args, kwargs
 | 
			
		||||
        self.timers = []
 | 
			
		||||
 | 
			
		||||
    def start(self):
 | 
			
		||||
        manager_class = utils.import_class(self.manager_class_name)
 | 
			
		||||
@@ -96,15 +97,17 @@ class Service(object):
 | 
			
		||||
                    topic='%s.%s' % (self.topic, self.host),
 | 
			
		||||
                    proxy=self)
 | 
			
		||||
 | 
			
		||||
            consumer_all.attach_to_eventlet()
 | 
			
		||||
            consumer_node.attach_to_eventlet()
 | 
			
		||||
            self.timers.append(consumer_all.attach_to_eventlet())
 | 
			
		||||
            self.timers.append(consumer_node.attach_to_eventlet())
 | 
			
		||||
            
 | 
			
		||||
            pulse = utils.LoopingCall(self.report_state)
 | 
			
		||||
            pulse.start(interval=self.report_interval, now=False)
 | 
			
		||||
            self.timers.append(pulse)
 | 
			
		||||
 | 
			
		||||
        if self.periodic_interval:
 | 
			
		||||
            pulse = utils.LoopingCall(self.periodic_tasks)
 | 
			
		||||
            pulse.start(interval=self.periodic_interval, now=False)
 | 
			
		||||
            periodic = utils.LoopingCall(self.periodic_tasks)
 | 
			
		||||
            periodic.start(interval=self.periodic_interval, now=False)
 | 
			
		||||
            self.timers.append(periodic)
 | 
			
		||||
 | 
			
		||||
    def _create_service_ref(self, context):
 | 
			
		||||
        service_ref = db.service_create(context,
 | 
			
		||||
@@ -156,11 +159,20 @@ class Service(object):
 | 
			
		||||
 | 
			
		||||
    def kill(self):
 | 
			
		||||
        """Destroy the service object in the datastore"""
 | 
			
		||||
        self.stop()
 | 
			
		||||
        try:
 | 
			
		||||
            db.service_destroy(context.get_admin_context(), self.service_id)
 | 
			
		||||
        except exception.NotFound:
 | 
			
		||||
            logging.warn("Service killed that has no database entry")
 | 
			
		||||
 | 
			
		||||
    def stop(self):
 | 
			
		||||
        for x in self.timers:
 | 
			
		||||
            try:
 | 
			
		||||
                x.stop()
 | 
			
		||||
            except Exception:
 | 
			
		||||
                pass
 | 
			
		||||
        self.timers = []
 | 
			
		||||
 | 
			
		||||
    def periodic_tasks(self):
 | 
			
		||||
        """Tasks to be run at a periodic interval"""
 | 
			
		||||
        self.manager.periodic_tasks(context.get_admin_context())
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,7 @@ Tests For Scheduler
 | 
			
		||||
from nova import context
 | 
			
		||||
from nova import db
 | 
			
		||||
from nova import flags
 | 
			
		||||
from nova import service
 | 
			
		||||
from nova import service_eventlet as service
 | 
			
		||||
from nova import test
 | 
			
		||||
from nova import rpc
 | 
			
		||||
from nova import utils
 | 
			
		||||
@@ -122,12 +122,12 @@ class SimpleDriverTestCase(test.TrialTestCase):
 | 
			
		||||
                                   'nova-compute',
 | 
			
		||||
                                   'compute',
 | 
			
		||||
                                   FLAGS.compute_manager)
 | 
			
		||||
        compute1.startService()
 | 
			
		||||
        compute1.start()
 | 
			
		||||
        compute2 = service.Service('host2',
 | 
			
		||||
                                   'nova-compute',
 | 
			
		||||
                                   'compute',
 | 
			
		||||
                                   FLAGS.compute_manager)
 | 
			
		||||
        compute2.startService()
 | 
			
		||||
        compute2.start()
 | 
			
		||||
        hosts = self.scheduler.driver.hosts_up(self.context, 'compute')
 | 
			
		||||
        self.assertEqual(len(hosts), 2)
 | 
			
		||||
        compute1.kill()
 | 
			
		||||
@@ -139,12 +139,12 @@ class SimpleDriverTestCase(test.TrialTestCase):
 | 
			
		||||
                                   'nova-compute',
 | 
			
		||||
                                   'compute',
 | 
			
		||||
                                   FLAGS.compute_manager)
 | 
			
		||||
        compute1.startService()
 | 
			
		||||
        compute1.start()
 | 
			
		||||
        compute2 = service.Service('host2',
 | 
			
		||||
                                   'nova-compute',
 | 
			
		||||
                                   'compute',
 | 
			
		||||
                                   FLAGS.compute_manager)
 | 
			
		||||
        compute2.startService()
 | 
			
		||||
        compute2.start()
 | 
			
		||||
        instance_id1 = self._create_instance()
 | 
			
		||||
        compute1.run_instance(self.context, instance_id1)
 | 
			
		||||
        instance_id2 = self._create_instance()
 | 
			
		||||
@@ -162,12 +162,12 @@ class SimpleDriverTestCase(test.TrialTestCase):
 | 
			
		||||
                                   'nova-compute',
 | 
			
		||||
                                   'compute',
 | 
			
		||||
                                   FLAGS.compute_manager)
 | 
			
		||||
        compute1.startService()
 | 
			
		||||
        compute1.start()
 | 
			
		||||
        compute2 = service.Service('host2',
 | 
			
		||||
                                   'nova-compute',
 | 
			
		||||
                                   'compute',
 | 
			
		||||
                                   FLAGS.compute_manager)
 | 
			
		||||
        compute2.startService()
 | 
			
		||||
        compute2.start()
 | 
			
		||||
        instance_ids1 = []
 | 
			
		||||
        instance_ids2 = []
 | 
			
		||||
        for index in xrange(FLAGS.max_cores):
 | 
			
		||||
@@ -195,12 +195,12 @@ class SimpleDriverTestCase(test.TrialTestCase):
 | 
			
		||||
                                   'nova-volume',
 | 
			
		||||
                                   'volume',
 | 
			
		||||
                                   FLAGS.volume_manager)
 | 
			
		||||
        volume1.startService()
 | 
			
		||||
        volume1.start()
 | 
			
		||||
        volume2 = service.Service('host2',
 | 
			
		||||
                                   'nova-volume',
 | 
			
		||||
                                   'volume',
 | 
			
		||||
                                   FLAGS.volume_manager)
 | 
			
		||||
        volume2.startService()
 | 
			
		||||
        volume2.start()
 | 
			
		||||
        volume_id1 = self._create_volume()
 | 
			
		||||
        volume1.create_volume(self.context, volume_id1)
 | 
			
		||||
        volume_id2 = self._create_volume()
 | 
			
		||||
@@ -218,12 +218,12 @@ class SimpleDriverTestCase(test.TrialTestCase):
 | 
			
		||||
                                   'nova-volume',
 | 
			
		||||
                                   'volume',
 | 
			
		||||
                                   FLAGS.volume_manager)
 | 
			
		||||
        volume1.startService()
 | 
			
		||||
        volume1.start()
 | 
			
		||||
        volume2 = service.Service('host2',
 | 
			
		||||
                                   'nova-volume',
 | 
			
		||||
                                   'volume',
 | 
			
		||||
                                   FLAGS.volume_manager)
 | 
			
		||||
        volume2.startService()
 | 
			
		||||
        volume2.start()
 | 
			
		||||
        volume_ids1 = []
 | 
			
		||||
        volume_ids2 = []
 | 
			
		||||
        for index in xrange(FLAGS.max_gigabytes):
 | 
			
		||||
 
 | 
			
		||||
@@ -22,14 +22,11 @@ Unit Tests for remote procedure calls using queue
 | 
			
		||||
 | 
			
		||||
import mox
 | 
			
		||||
 | 
			
		||||
from twisted.application.app import startApplication
 | 
			
		||||
from twisted.internet import defer
 | 
			
		||||
 | 
			
		||||
from nova import exception
 | 
			
		||||
from nova import flags
 | 
			
		||||
from nova import rpc
 | 
			
		||||
from nova import test
 | 
			
		||||
from nova import service
 | 
			
		||||
from nova import service_eventlet as service
 | 
			
		||||
from nova import manager
 | 
			
		||||
 | 
			
		||||
FLAGS = flags.FLAGS
 | 
			
		||||
@@ -63,7 +60,7 @@ class ServiceManagerTestCase(test.TrialTestCase):
 | 
			
		||||
                               'test',
 | 
			
		||||
                               'test',
 | 
			
		||||
                               'nova.tests.service_unittest.FakeManager')
 | 
			
		||||
        serv.startService()
 | 
			
		||||
        serv.start()
 | 
			
		||||
        self.assertEqual(serv.test_method(), 'manager')
 | 
			
		||||
 | 
			
		||||
    def test_override_manager_method(self):
 | 
			
		||||
@@ -71,7 +68,7 @@ class ServiceManagerTestCase(test.TrialTestCase):
 | 
			
		||||
                               'test',
 | 
			
		||||
                               'test',
 | 
			
		||||
                               'nova.tests.service_unittest.FakeManager')
 | 
			
		||||
        serv.startService()
 | 
			
		||||
        serv.start()
 | 
			
		||||
        self.assertEqual(serv.test_method(), 'service')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -94,8 +91,8 @@ class ServiceTestCase(test.TrialTestCase):
 | 
			
		||||
        self.mox.StubOutWithMock(rpc,
 | 
			
		||||
                                 'AdapterConsumer',
 | 
			
		||||
                                 use_mock_anything=True)
 | 
			
		||||
        self.mox.StubOutWithMock(
 | 
			
		||||
                service.task, 'LoopingCall', use_mock_anything=True)
 | 
			
		||||
        #self.mox.StubOutWithMock(
 | 
			
		||||
        #        service.task, 'LoopingCall', use_mock_anything=True)
 | 
			
		||||
        rpc.AdapterConsumer(connection=mox.IgnoreArg(),
 | 
			
		||||
                            topic=topic,
 | 
			
		||||
                            proxy=mox.IsA(service.Service)).AndReturn(
 | 
			
		||||
@@ -106,19 +103,19 @@ class ServiceTestCase(test.TrialTestCase):
 | 
			
		||||
                            proxy=mox.IsA(service.Service)).AndReturn(
 | 
			
		||||
                                    rpc.AdapterConsumer)
 | 
			
		||||
 | 
			
		||||
        rpc.AdapterConsumer.attach_to_twisted()
 | 
			
		||||
        rpc.AdapterConsumer.attach_to_twisted()
 | 
			
		||||
        rpc.AdapterConsumer.attach_to_eventlet()
 | 
			
		||||
        rpc.AdapterConsumer.attach_to_eventlet()
 | 
			
		||||
 | 
			
		||||
        # 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()).AndReturn(
 | 
			
		||||
                        service.task.LoopingCall)
 | 
			
		||||
        service.task.LoopingCall.start(interval=mox.IgnoreArg(),
 | 
			
		||||
                                       now=mox.IgnoreArg())
 | 
			
		||||
        service.task.LoopingCall(mox.IgnoreArg()).AndReturn(
 | 
			
		||||
                        service.task.LoopingCall)
 | 
			
		||||
        service.task.LoopingCall.start(interval=mox.IgnoreArg(),
 | 
			
		||||
                                       now=mox.IgnoreArg())
 | 
			
		||||
        #service.task.LoopingCall(mox.IgnoreArg()).AndReturn(
 | 
			
		||||
        #                service.task.LoopingCall)
 | 
			
		||||
        #service.task.LoopingCall.start(interval=mox.IgnoreArg(),
 | 
			
		||||
        #                               now=mox.IgnoreArg())
 | 
			
		||||
        #service.task.LoopingCall(mox.IgnoreArg()).AndReturn(
 | 
			
		||||
        #                service.task.LoopingCall)
 | 
			
		||||
        #service.task.LoopingCall.start(interval=mox.IgnoreArg(),
 | 
			
		||||
        #                               now=mox.IgnoreArg())
 | 
			
		||||
 | 
			
		||||
        service_create = {'host': host,
 | 
			
		||||
                          'binary': binary,
 | 
			
		||||
@@ -136,7 +133,8 @@ class ServiceTestCase(test.TrialTestCase):
 | 
			
		||||
                                  service_create).AndReturn(service_ref)
 | 
			
		||||
        self.mox.ReplayAll()
 | 
			
		||||
        
 | 
			
		||||
        startApplication(app, False)
 | 
			
		||||
        app.start()
 | 
			
		||||
        app.stop()
 | 
			
		||||
        self.assert_(app)
 | 
			
		||||
 | 
			
		||||
    # We're testing sort of weird behavior in how report_state decides
 | 
			
		||||
@@ -172,7 +170,7 @@ class ServiceTestCase(test.TrialTestCase):
 | 
			
		||||
                               binary,
 | 
			
		||||
                               topic,
 | 
			
		||||
                               'nova.tests.service_unittest.FakeManager')
 | 
			
		||||
        serv.startService()
 | 
			
		||||
        serv.start()
 | 
			
		||||
        serv.report_state()
 | 
			
		||||
 | 
			
		||||
    def test_report_state_newly_disconnected(self):
 | 
			
		||||
@@ -202,7 +200,7 @@ class ServiceTestCase(test.TrialTestCase):
 | 
			
		||||
                               binary,
 | 
			
		||||
                               topic,
 | 
			
		||||
                               'nova.tests.service_unittest.FakeManager')
 | 
			
		||||
        serv.startService()
 | 
			
		||||
        serv.start()
 | 
			
		||||
        serv.report_state()
 | 
			
		||||
        self.assert_(serv.model_disconnected)
 | 
			
		||||
 | 
			
		||||
@@ -235,7 +233,7 @@ class ServiceTestCase(test.TrialTestCase):
 | 
			
		||||
                               binary,
 | 
			
		||||
                               topic,
 | 
			
		||||
                               'nova.tests.service_unittest.FakeManager')
 | 
			
		||||
        serv.startService()
 | 
			
		||||
        serv.start()
 | 
			
		||||
        serv.model_disconnected = True
 | 
			
		||||
        serv.report_state()
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -48,7 +48,6 @@ import sys
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
from twisted.scripts import trial as trial_script
 | 
			
		||||
import unittest
 | 
			
		||||
 | 
			
		||||
from nova import flags
 | 
			
		||||
from nova import twistd
 | 
			
		||||
@@ -62,11 +61,10 @@ from nova.tests.flags_unittest import *
 | 
			
		||||
from nova.tests.misc_unittest import *
 | 
			
		||||
from nova.tests.network_unittest import *
 | 
			
		||||
#from nova.tests.objectstore_unittest import *
 | 
			
		||||
#from nova.tests.process_unittest import *
 | 
			
		||||
from nova.tests.quota_unittest import *
 | 
			
		||||
from nova.tests.rpc_unittest import *
 | 
			
		||||
from nova.tests.scheduler_unittest import *
 | 
			
		||||
#from nova.tests.service_unittest import *
 | 
			
		||||
from nova.tests.service_unittest import *
 | 
			
		||||
from nova.tests.twistd_unittest import *
 | 
			
		||||
from nova.tests.validator_unittest import *
 | 
			
		||||
from nova.tests.virt_unittest import *
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user