Merge "Add AllServicesCurrent fixture"

This commit is contained in:
Jenkins 2016-04-12 21:57:09 +00:00 committed by Gerrit Code Review
commit 9ab9d81d76
2 changed files with 34 additions and 0 deletions

View File

@ -28,12 +28,14 @@ from oslo_db.sqlalchemy import enginefacade
from oslo_messaging import conffixture as messaging_conffixture
import six
from nova.compute import rpcapi as compute_rpcapi
from nova import context
from nova.db import migration
from nova.db.sqlalchemy import api as session
from nova import exception
from nova import objects
from nova.objects import base as obj_base
from nova.objects import service as service_obj
from nova import rpc
from nova import service
from nova.tests.functional.api import client
@ -651,3 +653,15 @@ class ForbidNewLegacyNotificationFixture(fixtures.Fixture):
self.notifier.fatal = False
self.notifier.allowed_legacy_notification_event_types.remove(
'_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

View File

@ -24,9 +24,11 @@ from oslo_log import log as logging
from oslo_utils import uuidutils
import testtools
from nova.compute import rpcapi as compute_rpcapi
from nova.db.sqlalchemy import api as session
from nova import exception
from nova.objects import base as obj_base
from nova.objects import service as service_obj
from nova.tests import fixtures
from nova.tests.unit import conf_fixture
from nova import utils
@ -432,3 +434,21 @@ class TestStableObjectJsonFixture(testtools.TestCase):
with fixtures.StableObjectJsonFixture():
self.assertEqual(['a', 'z'],
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)