diff --git a/nova/test.py b/nova/test.py index 89bd0d7b3..529cce5cb 100644 --- a/nova/test.py +++ b/nova/test.py @@ -49,7 +49,6 @@ from nova import db from nova.network import manager as network_manager from nova.network.security_group import openstack_driver from nova.objects import base as objects_base -from nova.objects import flavor as flavor_obj from nova.tests import fixtures as nova_fixtures from nova.tests.unit import conf_fixture from nova.tests.unit import policy_fixture @@ -214,11 +213,7 @@ class TestCase(testtools.TestCase): if self.USES_DB: self.useFixture(nova_fixtures.Database()) self.useFixture(nova_fixtures.Database(database='api')) - # NOTE(danms): Flavors are encoded in our original migration - # which means we have no real option other than to migrate them - # onlineish every time we build a new database (for now). - ctxt = context.get_admin_context() - flavor_obj.migrate_flavors(ctxt, 100, hard_delete=True) + self.useFixture(nova_fixtures.DefaultFlavorsFixture()) elif not self.USES_DB_SELF: self.useFixture(nova_fixtures.DatabasePoisonFixture()) diff --git a/nova/tests/fixtures.py b/nova/tests/fixtures.py index ef2dc9115..58ef19eb9 100644 --- a/nova/tests/fixtures.py +++ b/nova/tests/fixtures.py @@ -28,9 +28,11 @@ from oslo_db.sqlalchemy import enginefacade from oslo_messaging import conffixture as messaging_conffixture import six +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 import rpc from nova import service @@ -297,6 +299,33 @@ class DatabaseAtVersion(fixtures.Fixture): self.addCleanup(self.cleanup) +class DefaultFlavorsFixture(fixtures.Fixture): + def setUp(self): + super(DefaultFlavorsFixture, self).setUp() + ctxt = context.get_admin_context() + defaults = {'rxtx_factor': 1.0, 'disabled': False, 'is_public': True, + 'ephemeral_gb': 0, 'swap': 0} + default_flavors = [ + objects.Flavor(context=ctxt, memory_mb=512, vcpus=1, + root_gb=1, flavorid='1', name='m1.tiny', + **defaults), + objects.Flavor(context=ctxt, memory_mb=2048, vcpus=1, + root_gb=20, flavorid='2', name='m1.small', + **defaults), + objects.Flavor(context=ctxt, memory_mb=4096, vcpus=2, + root_gb=40, flavorid='3', name='m1.medium', + **defaults), + objects.Flavor(context=ctxt, memory_mb=8192, vcpus=4, + root_gb=80, flavorid='4', name='m1.large', + **defaults), + objects.Flavor(context=ctxt, memory_mb=16384, vcpus=8, + root_gb=160, flavorid='5', name='m1.xlarge', + **defaults), + ] + for flavor in default_flavors: + flavor.create() + + class RPCFixture(fixtures.Fixture): def __init__(self, *exmods): super(RPCFixture, self).__init__()