Merge "Remove flavor seeding from the base migration"

This commit is contained in:
Jenkins 2016-04-06 17:55:45 +00:00 committed by Gerrit Code Review
commit b69296eb74
6 changed files with 81 additions and 56 deletions

View File

@ -85,33 +85,6 @@ def _create_shadow_tables(migrate_engine):
raise raise
def _populate_instance_types(instance_types_table):
default_inst_types = {
'm1.tiny': dict(mem=512, vcpus=1, root_gb=1, eph_gb=0, flavid=1),
'm1.small': dict(mem=2048, vcpus=1, root_gb=20, eph_gb=0, flavid=2),
'm1.medium': dict(mem=4096, vcpus=2, root_gb=40, eph_gb=0, flavid=3),
'm1.large': dict(mem=8192, vcpus=4, root_gb=80, eph_gb=0, flavid=4),
'm1.xlarge': dict(mem=16384, vcpus=8, root_gb=160, eph_gb=0, flavid=5)
}
try:
i = instance_types_table.insert()
for name, values in default_inst_types.items():
i.execute({'name': name, 'memory_mb': values["mem"],
'vcpus': values["vcpus"], 'deleted': 0,
'root_gb': values["root_gb"],
'ephemeral_gb': values["eph_gb"],
'rxtx_factor': 1,
'swap': 0,
'flavorid': values["flavid"],
'disabled': False,
'is_public': True})
except Exception:
LOG.info(repr(instance_types_table))
LOG.exception(_LE('Exception while seeding instance_types table'))
raise
# NOTE(dprince): we add these here so our schema contains dump tables # NOTE(dprince): we add these here so our schema contains dump tables
# which were added in migration 209 (in Havana). We can drop these in # which were added in migration 209 (in Havana). We can drop these in
# Icehouse: https://bugs.launchpad.net/nova/+bug/1266538 # Icehouse: https://bugs.launchpad.net/nova/+bug/1266538
@ -1574,7 +1547,4 @@ def upgrade(migrate_engine):
_create_shadow_tables(migrate_engine) _create_shadow_tables(migrate_engine)
# populate initial instance types
_populate_instance_types(instance_types)
_create_dump_tables(migrate_engine) _create_dump_tables(migrate_engine)

View File

@ -49,7 +49,6 @@ from nova import db
from nova.network import manager as network_manager from nova.network import manager as network_manager
from nova.network.security_group import openstack_driver from nova.network.security_group import openstack_driver
from nova.objects import base as objects_base 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 import fixtures as nova_fixtures
from nova.tests.unit import conf_fixture from nova.tests.unit import conf_fixture
from nova.tests.unit import policy_fixture from nova.tests.unit import policy_fixture
@ -214,11 +213,7 @@ class TestCase(testtools.TestCase):
if self.USES_DB: if self.USES_DB:
self.useFixture(nova_fixtures.Database()) self.useFixture(nova_fixtures.Database())
self.useFixture(nova_fixtures.Database(database='api')) self.useFixture(nova_fixtures.Database(database='api'))
# NOTE(danms): Flavors are encoded in our original migration self.useFixture(nova_fixtures.DefaultFlavorsFixture())
# 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)
elif not self.USES_DB_SELF: elif not self.USES_DB_SELF:
self.useFixture(nova_fixtures.DatabasePoisonFixture()) self.useFixture(nova_fixtures.DatabasePoisonFixture())

View File

@ -28,9 +28,11 @@ 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 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.objects import base as obj_base from nova.objects import base as obj_base
from nova import rpc from nova import rpc
from nova import service from nova import service
@ -297,6 +299,33 @@ class DatabaseAtVersion(fixtures.Fixture):
self.addCleanup(self.cleanup) 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): class RPCFixture(fixtures.Fixture):
def __init__(self, *exmods): def __init__(self, *exmods):
super(RPCFixture, self).__init__() super(RPCFixture, self).__init__()

View File

@ -114,10 +114,13 @@ class FlavorObjectTestCase(test.NoDBTestCase):
self._test_query(flavor) self._test_query(flavor)
def test_query_main(self): def test_query_main(self):
flavor = objects.Flavor.get_by_flavor_id(self.context, '3') self._create_main_flavor()
flavor = objects.Flavor.get_by_flavor_id(self.context, 'mainflavor')
self._test_query(flavor) self._test_query(flavor)
def _test_save(self, flavor): def test_save(self):
flavor = objects.Flavor(context=self.context, **fake_api_flavor)
flavor.create()
flavor.extra_specs['marty'] = 'mcfly' flavor.extra_specs['marty'] = 'mcfly'
flavor.extra_specs['foo'] = 'bart' flavor.extra_specs['foo'] = 'bart'
projects = list(flavor.projects) projects = list(flavor.projects)
@ -139,16 +142,6 @@ class FlavorObjectTestCase(test.NoDBTestCase):
self.assertEqual({'marty': 'mcfly'}, flavor2.extra_specs) self.assertEqual({'marty': 'mcfly'}, flavor2.extra_specs)
self.assertEqual(set(projects), set(flavor2.projects)) self.assertEqual(set(projects), set(flavor2.projects))
def test_save_api(self):
self._delete_main_flavors()
flavor = objects.Flavor(context=self.context, **fake_api_flavor)
flavor.create()
self._test_save(flavor)
def test_save_main(self):
flavor = objects.Flavor.get_by_flavor_id(self.context, '3')
self._test_save(flavor)
@staticmethod @staticmethod
@db_api.api_context_manager.reader @db_api.api_context_manager.reader
def _collect_flavor_residue_api(context, flavor): def _collect_flavor_residue_api(context, flavor):
@ -176,8 +169,16 @@ class FlavorObjectTestCase(test.NoDBTestCase):
self.assertEqual( self.assertEqual(
0, self._collect_flavor_residue_api(self.context, flavor)) 0, self._collect_flavor_residue_api(self.context, flavor))
def _create_main_flavor(self, **updates):
values = dict(fake_api_flavor, flavorid='mainflavor')
del values['projects']
del values['extra_specs']
values.update(updates)
return db_api.flavor_create(self.context, values)
def test_destroy_main(self): def test_destroy_main(self):
flavor = objects.Flavor.get_by_flavor_id(self.context, '3') self._create_main_flavor()
flavor = objects.Flavor.get_by_flavor_id(self.context, 'mainflavor')
self._test_destroy(flavor) self._test_destroy(flavor)
def test_destroy_missing_flavor_by_name(self): def test_destroy_missing_flavor_by_name(self):
@ -215,7 +216,9 @@ class FlavorObjectTestCase(test.NoDBTestCase):
self._test_get_all(1) self._test_get_all(1)
def test_get_all_with_marker_in_api(self): def test_get_all_with_marker_in_api(self):
db_flavors = db_api.flavor_get_all(self.context) db_flavors = [self._create_main_flavor(),
self._create_main_flavor(flavorid='mainflavor2',
name='m1.foo2')]
db_flavor_ids = [x['flavorid'] for x in db_flavors] db_flavor_ids = [x['flavorid'] for x in db_flavors]
flavor = ForcedFlavor(context=self.context, **fake_api_flavor) flavor = ForcedFlavor(context=self.context, **fake_api_flavor)
flavor.create() flavor.create()
@ -227,16 +230,19 @@ class FlavorObjectTestCase(test.NoDBTestCase):
self.assertEqual(['m1.zoo'] + db_flavor_ids[:2], result_flavorids) self.assertEqual(['m1.zoo'] + db_flavor_ids[:2], result_flavorids)
def test_get_all_with_marker_in_main(self): def test_get_all_with_marker_in_main(self):
db_flavors = db_api.flavor_get_all(self.context) db_flavors = [self._create_main_flavor(flavorid='mainflavor1',
name='main1'),
self._create_main_flavor(flavorid='mainflavor2',
name='main2')]
db_flavor_ids = [x['flavorid'] for x in db_flavors] db_flavor_ids = [x['flavorid'] for x in db_flavors]
flavor = ForcedFlavor(context=self.context, **fake_api_flavor) flavor = ForcedFlavor(context=self.context, **fake_api_flavor)
flavor.create() flavor.create()
fake_flavor2 = dict(fake_api_flavor, name='m1.zoo', flavorid='m1.zoo') fake_flavor2 = dict(fake_api_flavor, name='m1.zoo', flavorid='m1.zoo')
flavor = ForcedFlavor(context=self.context, **fake_flavor2) flavor = ForcedFlavor(context=self.context, **fake_flavor2)
flavor.create() flavor.create()
result = self._test_get_all(2, marker='3', limit=3) result = self._test_get_all(1, marker='mainflavor1', limit=3)
result_flavorids = [x.flavorid for x in result] result_flavorids = [x.flavorid for x in result]
self.assertEqual(db_flavor_ids[3:], result_flavorids) self.assertEqual(db_flavor_ids[1:], result_flavorids)
def test_get_all_with_marker_in_neither(self): def test_get_all_with_marker_in_neither(self):
flavor = ForcedFlavor(context=self.context, **fake_api_flavor) flavor = ForcedFlavor(context=self.context, **fake_api_flavor)
@ -248,6 +254,7 @@ class FlavorObjectTestCase(test.NoDBTestCase):
self._test_get_all, 2, marker='noflavoratall') self._test_get_all, 2, marker='noflavoratall')
def test_create_checks_main_flavors(self): def test_create_checks_main_flavors(self):
self._create_main_flavor()
flavor = objects.Flavor(context=self.context, **fake_api_flavor) flavor = objects.Flavor(context=self.context, **fake_api_flavor)
self.assertRaises(exception.ObjectActionError, flavor.create) self.assertRaises(exception.ObjectActionError, flavor.create)
self._delete_main_flavors() self._delete_main_flavors()

View File

@ -192,7 +192,7 @@ class TestDatabaseFixture(testtools.TestCase):
conn = engine.connect() conn = engine.connect()
result = conn.execute("select * from instance_types") result = conn.execute("select * from instance_types")
rows = result.fetchall() rows = result.fetchall()
self.assertEqual(5, len(rows), "Rows %s" % rows) self.assertEqual(0, len(rows), "Rows %s" % rows)
# insert a 6th instance type, column 5 below is an int id # insert a 6th instance type, column 5 below is an int id
# which has a constraint on it, so if new standard instance # which has a constraint on it, so if new standard instance
@ -202,7 +202,7 @@ class TestDatabaseFixture(testtools.TestCase):
", 1.0, 40, 0, 0, 1, 0)") ", 1.0, 40, 0, 0, 1, 0)")
result = conn.execute("select * from instance_types") result = conn.execute("select * from instance_types")
rows = result.fetchall() rows = result.fetchall()
self.assertEqual(6, len(rows), "Rows %s" % rows) self.assertEqual(1, len(rows), "Rows %s" % rows)
# reset by invoking the fixture again # reset by invoking the fixture again
# #
@ -213,7 +213,7 @@ class TestDatabaseFixture(testtools.TestCase):
conn = engine.connect() conn = engine.connect()
result = conn.execute("select * from instance_types") result = conn.execute("select * from instance_types")
rows = result.fetchall() rows = result.fetchall()
self.assertEqual(5, len(rows), "Rows %s" % rows) self.assertEqual(0, len(rows), "Rows %s" % rows)
def test_api_fixture_reset(self): def test_api_fixture_reset(self):
# This sets up reasonable db connection strings # This sets up reasonable db connection strings
@ -311,6 +311,25 @@ class TestDatabaseAtVersionFixture(testtools.TestCase):
self.useFixture(fixtures.DatabaseAtVersion(318)) self.useFixture(fixtures.DatabaseAtVersion(318))
class TestDefaultFlavorsFixture(testtools.TestCase):
def test_flavors(self):
self.useFixture(conf_fixture.ConfFixture())
self.useFixture(fixtures.Database())
self.useFixture(fixtures.Database(database='api'))
engine = session.get_api_engine()
conn = engine.connect()
result = conn.execute("select * from flavors")
rows = result.fetchall()
self.assertEqual(0, len(rows), "Rows %s" % rows)
self.useFixture(fixtures.DefaultFlavorsFixture())
result = conn.execute("select * from flavors")
rows = result.fetchall()
self.assertEqual(5, len(rows), "Rows %s" % rows)
class TestIndirectionAPIFixture(testtools.TestCase): class TestIndirectionAPIFixture(testtools.TestCase):
def test_indirection_api(self): def test_indirection_api(self):
# Should initially be None # Should initially be None

View File

@ -0,0 +1,5 @@
---
other:
- The default flavors that nova has previously had are no longer
created as part of the first database migration. New deployments
will need to create appropriate flavors before first use.