From 0b4422b6ac9064d094356c2490b061ec3b0987a3 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Thu, 7 Apr 2016 07:18:53 -0700 Subject: [PATCH] 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 --- nova/tests/fixtures.py | 14 ++++++++++++++ nova/tests/unit/test_fixtures.py | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/nova/tests/fixtures.py b/nova/tests/fixtures.py index 58ef19eb9324..1cff0e596a87 100644 --- a/nova/tests/fixtures.py +++ b/nova/tests/fixtures.py @@ -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 diff --git a/nova/tests/unit/test_fixtures.py b/nova/tests/unit/test_fixtures.py index 9bf4a0a469a2..4011621d12cc 100644 --- a/nova/tests/unit/test_fixtures.py +++ b/nova/tests/unit/test_fixtures.py @@ -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)