Add AllServicesCurrent fixture
This adds a fixture that simulates a fully up-to-date system where all services are current. This is the vast majority of what we test for our unit tests, of course. Change-Id: I209cd0d986304b2d913f2cf49b5ba54dcc872c18
This commit is contained in:
parent
52b9b1408a
commit
0b4422b6ac
@ -28,12 +28,14 @@ from oslo_db.sqlalchemy import enginefacade
|
|||||||
from oslo_messaging import conffixture as messaging_conffixture
|
from oslo_messaging import conffixture as messaging_conffixture
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
from nova.compute import rpcapi as compute_rpcapi
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova.db import migration
|
from nova.db import migration
|
||||||
from nova.db.sqlalchemy import api as session
|
from nova.db.sqlalchemy import api as session
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import objects
|
from nova import objects
|
||||||
from nova.objects import base as obj_base
|
from nova.objects import base as obj_base
|
||||||
|
from nova.objects import service as service_obj
|
||||||
from nova import rpc
|
from nova import rpc
|
||||||
from nova import service
|
from nova import service
|
||||||
from nova.tests.functional.api import client
|
from nova.tests.functional.api import client
|
||||||
@ -651,3 +653,15 @@ class ForbidNewLegacyNotificationFixture(fixtures.Fixture):
|
|||||||
self.notifier.fatal = False
|
self.notifier.fatal = False
|
||||||
self.notifier.allowed_legacy_notification_event_types.remove(
|
self.notifier.allowed_legacy_notification_event_types.remove(
|
||||||
'_decorated_function')
|
'_decorated_function')
|
||||||
|
|
||||||
|
|
||||||
|
class AllServicesCurrent(fixtures.Fixture):
|
||||||
|
def setUp(self):
|
||||||
|
super(AllServicesCurrent, self).setUp()
|
||||||
|
self.useFixture(fixtures.MonkeyPatch(
|
||||||
|
'nova.objects.Service.get_minimum_version_multi',
|
||||||
|
self._fake_minimum))
|
||||||
|
compute_rpcapi.LAST_VERSION = None
|
||||||
|
|
||||||
|
def _fake_minimum(self, *args, **kwargs):
|
||||||
|
return service_obj.SERVICE_VERSION
|
||||||
|
@ -24,9 +24,11 @@ from oslo_log import log as logging
|
|||||||
from oslo_utils import uuidutils
|
from oslo_utils import uuidutils
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
|
from nova.compute import rpcapi as compute_rpcapi
|
||||||
from nova.db.sqlalchemy import api as session
|
from nova.db.sqlalchemy import api as session
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova.objects import base as obj_base
|
from nova.objects import base as obj_base
|
||||||
|
from nova.objects import service as service_obj
|
||||||
from nova.tests import fixtures
|
from nova.tests import fixtures
|
||||||
from nova.tests.unit import conf_fixture
|
from nova.tests.unit import conf_fixture
|
||||||
from nova import utils
|
from nova import utils
|
||||||
@ -432,3 +434,21 @@ class TestStableObjectJsonFixture(testtools.TestCase):
|
|||||||
with fixtures.StableObjectJsonFixture():
|
with fixtures.StableObjectJsonFixture():
|
||||||
self.assertEqual(['a', 'z'],
|
self.assertEqual(['a', 'z'],
|
||||||
obj.obj_to_primitive()['nova_object.changes'])
|
obj.obj_to_primitive()['nova_object.changes'])
|
||||||
|
|
||||||
|
|
||||||
|
class TestAllServicesCurrentFixture(testtools.TestCase):
|
||||||
|
@mock.patch('nova.objects.Service._db_service_get_minimum_version')
|
||||||
|
def test_services_current(self, mock_db):
|
||||||
|
mock_db.return_value = {'nova-compute': 123}
|
||||||
|
self.assertEqual(123, service_obj.Service.get_minimum_version(
|
||||||
|
None, 'nova-compute'))
|
||||||
|
mock_db.assert_called_once_with(None, ['nova-compute'],
|
||||||
|
use_slave=False)
|
||||||
|
mock_db.reset_mock()
|
||||||
|
compute_rpcapi.LAST_VERSION = 123
|
||||||
|
self.useFixture(fixtures.AllServicesCurrent())
|
||||||
|
self.assertIsNone(compute_rpcapi.LAST_VERSION)
|
||||||
|
self.assertEqual(service_obj.SERVICE_VERSION,
|
||||||
|
service_obj.Service.get_minimum_version(
|
||||||
|
None, 'nova-compute'))
|
||||||
|
self.assertFalse(mock_db.called)
|
||||||
|
Loading…
Reference in New Issue
Block a user