From 0d5fb06b39e8244429be72f05e2066d24572dc2e Mon Sep 17 00:00:00 2001 From: Nikola Dipanov Date: Wed, 15 May 2013 15:47:31 +0200 Subject: DB migration to the new BDM data format This patch migrates the DB to the new data format. In addition it also utilizes routines introduced in the change I9370333059b8c9aaf92010470b8475a913d329b2 in a way that will allow us to transition into using the new data in Nova logic one step at a time. This is accomplished in a following manner in the DB/conductor layer, which is supposed to allow for subsequent changes to be as granular as possible: * Read operations - data is always read as is found in the DB - meaning in the new format, and transformed after every call. This will allow us to make granular changes in the API/Compute layers. * Data is converted inside the DB methods that do writes, and an additional 'legacy' flag is added (set to True by default). It is up to the calling method to make sure it supplies the DB layer with the format it is intending to write, to avoid guessing. An exception to the above is when using conductor due to rpcapi versioning, so this patch adds a 'legacy' flag to the block_device_mapping_get_all_by_instance conductor method and bumps the version of the API. This patch also fixes some of the block device fixtures in tests, when it was required to be aware of the new data structure (mostly when mocking DB methods that return the new data format). This patch is not supposed to provide any new functionality to Nova. blueprint: improve-block-device-handling Change-Id: If30afdb59d4c4268b97d3d10270df2cc729a0c4c --- nova/tests/api/ec2/test_cloud.py | 26 +++-- .../api/openstack/compute/test_server_actions.py | 3 +- nova/tests/api/openstack/compute/test_servers.py | 44 ++++++-- nova/tests/compute/test_compute.py | 28 +++-- nova/tests/conductor/test_conductor.py | 2 +- nova/tests/db/test_db_api.py | 62 ++++++----- nova/tests/db/test_migrations.py | 118 +++++++++++++++++++++ nova/tests/test_metadata.py | 12 ++- 8 files changed, 237 insertions(+), 58 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/ec2/test_cloud.py b/nova/tests/api/ec2/test_cloud.py index 22f9c2d81..8a10712cb 100644 --- a/nova/tests/api/ec2/test_cloud.py +++ b/nova/tests/api/ec2/test_cloud.py @@ -2119,9 +2119,10 @@ class CloudTestCase(test.TestCase): def fake_block_device_mapping_get_all_by_instance(context, inst_id): return [dict(id=1, + source_type='snapshot', + destination_type='volume', snapshot_id=snapshots[0], volume_id=volumes[0], - virtual_name=None, volume_size=1, device_name='sda1', delete_on_termination=False, @@ -2210,45 +2211,54 @@ class CloudTestCase(test.TestCase): @staticmethod def _fake_bdm_get(ctxt, id): return [{'volume_id': 87654321, + 'source_type': 'volume', + 'destination_type': 'volume', 'snapshot_id': None, 'no_device': None, - 'virtual_name': None, 'delete_on_termination': True, 'device_name': '/dev/sdh'}, {'volume_id': None, 'snapshot_id': 98765432, + 'source_type': 'snapshot', + 'destination_type': 'volume', 'no_device': None, - 'virtual_name': None, 'delete_on_termination': True, 'device_name': '/dev/sdi'}, {'volume_id': None, 'snapshot_id': None, 'no_device': True, - 'virtual_name': None, 'delete_on_termination': None, 'device_name': None}, {'volume_id': None, 'snapshot_id': None, 'no_device': None, - 'virtual_name': 'ephemeral0', + 'source_type': 'blank', + 'destination_type': 'local', + 'guest_format': None, 'delete_on_termination': None, 'device_name': '/dev/sdb'}, {'volume_id': None, 'snapshot_id': None, 'no_device': None, - 'virtual_name': 'swap', + 'source_type': 'blank', + 'destination_type': 'local', + 'guest_format': 'swap', 'delete_on_termination': None, 'device_name': '/dev/sdc'}, {'volume_id': None, 'snapshot_id': None, 'no_device': None, - 'virtual_name': 'ephemeral1', + 'source_type': 'blank', + 'destination_type': 'local', + 'guest_format': None, 'delete_on_termination': None, 'device_name': '/dev/sdd'}, {'volume_id': None, 'snapshot_id': None, 'no_device': None, - 'virtual_name': 'ephemeral2', + 'source_type': 'blank', + 'destination_type': 'local', + 'guest_format': None, 'delete_on_termination': None, 'device_name': '/dev/sd3'}, ] diff --git a/nova/tests/api/openstack/compute/test_server_actions.py b/nova/tests/api/openstack/compute/test_server_actions.py index 473d3a253..f1defe039 100644 --- a/nova/tests/api/openstack/compute/test_server_actions.py +++ b/nova/tests/api/openstack/compute/test_server_actions.py @@ -843,7 +843,8 @@ class ServerActionsControllerTest(test.TestCase): def fake_block_device_mapping_get_all_by_instance(context, inst_id): return [dict(volume_id=_fake_id('a'), - virtual_name=None, + source_type='snapshot', + destination_type='volume', volume_size=1, device_name='vda', snapshot_id=1, diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py index e11023308..97a1a5826 100644 --- a/nova/tests/api/openstack/compute/test_servers.py +++ b/nova/tests/api/openstack/compute/test_servers.py @@ -1807,6 +1807,7 @@ class ServersControllerCreateTest(test.TestCase): "fixed_ips": [], "task_state": "", "vm_state": "", + "root_device_name": inst.get('root_device_name', 'vda'), } self.instance_cache_by_id[instance['id']] = instance @@ -2411,7 +2412,7 @@ class ServersControllerCreateTest(test.TestCase): def test_create_instance_with_volumes_enabled(self): self.ext_mgr.extensions = {'os-volumes': 'fake'} - bdm = [{'device_name': 'foo'}] + bdm = [{'device_name': 'foo', 'volume_id': 'fake_vol'}] params = {'block_device_mapping': bdm} old_create = compute_api.API.create @@ -2419,7 +2420,11 @@ class ServersControllerCreateTest(test.TestCase): self.assertEqual(kwargs['block_device_mapping'], bdm) return old_create(*args, **kwargs) + def _validate_bdm(*args, **kwargs): + pass + self.stubs.Set(compute_api.API, 'create', create) + self.stubs.Set(compute_api.API, '_validate_bdm', _validate_bdm) self._test_create_extra(params) def test_create_instance_with_volumes_enabled_no_image(self): @@ -2471,6 +2476,9 @@ class ServersControllerCreateTest(test.TestCase): self.assertNotIn('imageRef', kwargs) return old_create(*args, **kwargs) + def _validate_bdm(*args, **kwargs): + pass + self.stubs.Set(compute_api.API, 'create', create) self.mox.ReplayAll() self._test_create_extra(params, no_image=True) @@ -2557,17 +2565,27 @@ class ServersControllerCreateTest(test.TestCase): def test_create_instance_with_bdm_delete_on_termination(self): self.ext_mgr.extensions = {'os-volumes': 'fake'} - bdm = [{'device_name': 'foo1', 'delete_on_termination': 1}, - {'device_name': 'foo2', 'delete_on_termination': True}, - {'device_name': 'foo3', 'delete_on_termination': 'invalid'}, - {'device_name': 'foo4', 'delete_on_termination': 0}, - {'device_name': 'foo5', 'delete_on_termination': False}] + bdm = [{'device_name': 'foo1', 'volume_id': 'fake_vol', + 'delete_on_termination': 1}, + {'device_name': 'foo2', 'volume_id': 'fake_vol', + 'delete_on_termination': True}, + {'device_name': 'foo3', 'volume_id': 'fake_vol', + 'delete_on_termination': 'invalid'}, + {'device_name': 'foo4', 'volume_id': 'fake_vol', + 'delete_on_termination': 0}, + {'device_name': 'foo5', 'volume_id': 'fake_vol', + 'delete_on_termination': False}] expected_bdm = [ - {'device_name': 'foo1', 'delete_on_termination': True}, - {'device_name': 'foo2', 'delete_on_termination': True}, - {'device_name': 'foo3', 'delete_on_termination': False}, - {'device_name': 'foo4', 'delete_on_termination': False}, - {'device_name': 'foo5', 'delete_on_termination': False}] + {'device_name': 'foo1', 'volume_id': 'fake_vol', + 'delete_on_termination': True}, + {'device_name': 'foo2', 'volume_id': 'fake_vol', + 'delete_on_termination': True}, + {'device_name': 'foo3', 'volume_id': 'fake_vol', + 'delete_on_termination': False}, + {'device_name': 'foo4', 'volume_id': 'fake_vol', + 'delete_on_termination': False}, + {'device_name': 'foo5', 'volume_id': 'fake_vol', + 'delete_on_termination': False}] params = {'block_device_mapping': bdm} old_create = compute_api.API.create @@ -2575,7 +2593,11 @@ class ServersControllerCreateTest(test.TestCase): self.assertEqual(expected_bdm, kwargs['block_device_mapping']) return old_create(*args, **kwargs) + def _validate_bdm(*args, **kwargs): + pass + self.stubs.Set(compute_api.API, 'create', create) + self.stubs.Set(compute_api.API, '_validate_bdm', _validate_bdm) self._test_create_extra(params) def test_create_instance_with_user_data_enabled(self): diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index c04f5cbe7..3e0fbe63e 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -31,6 +31,7 @@ import mox from oslo.config import cfg import nova +from nova import block_device from nova import compute from nova.compute import api as compute_api from nova.compute import flavors @@ -547,7 +548,8 @@ class ComputeVolumeTestCase(BaseTestCase): block_device_mapping = [{ 'id': 1, 'no_device': None, - 'virtual_name': None, + 'source_type': 'volume', + 'destination_type': 'volume', 'snapshot_id': None, 'volume_id': self.volume_id, 'device_name': 'vda', @@ -6145,6 +6147,8 @@ class ComputeAPITestCase(BaseTestCase): def fake_get_instance_bdms(*args, **kwargs): return [{'device_name': '/dev/vda', + 'source_type': 'volume', + 'destination_type': 'volume', 'volume_id': 'bf0b6b00-a20c-11e2-9e96-0800200c9a66'}] self.stubs.Set(self.compute_api, 'get_instance_bdms', @@ -7197,12 +7201,14 @@ class ComputeAPITestCase(BaseTestCase): self.context, instance_type, instance['uuid'], mappings) bdms = [self._parse_db_block_device_mapping(bdm_ref) - for bdm_ref in db.block_device_mapping_get_all_by_instance( - self.context, instance['uuid'])] + for bdm_ref in block_device.legacy_mapping( + db.block_device_mapping_get_all_by_instance( + self.context, instance['uuid']))] expected_result = [ {'virtual_name': 'swap', 'device_name': '/dev/sdb1', - 'volume_size': swap_size}, - {'virtual_name': 'ephemeral0', 'device_name': '/dev/sdc1'}, + 'volume_size': swap_size, 'delete_on_termination': True}, + {'virtual_name': 'ephemeral0', 'device_name': '/dev/sdc1', + 'delete_on_termination': True}, # NOTE(yamahata): ATM only ephemeral0 is supported. # they're ignored for now @@ -7217,21 +7223,23 @@ class ComputeAPITestCase(BaseTestCase): self.context, flavors.get_default_instance_type(), instance['uuid'], block_device_mapping) bdms = [self._parse_db_block_device_mapping(bdm_ref) - for bdm_ref in db.block_device_mapping_get_all_by_instance( - self.context, instance['uuid'])] + for bdm_ref in block_device.legacy_mapping( + db.block_device_mapping_get_all_by_instance( + self.context, instance['uuid']))] expected_result = [ {'snapshot_id': '00000000-aaaa-bbbb-cccc-000000000000', 'device_name': '/dev/sda1'}, {'virtual_name': 'swap', 'device_name': '/dev/sdb1', - 'volume_size': swap_size}, + 'volume_size': swap_size, 'delete_on_termination': True}, {'snapshot_id': '11111111-aaaa-bbbb-cccc-111111111111', 'device_name': '/dev/sdb2'}, {'snapshot_id': '22222222-aaaa-bbbb-cccc-222222222222', 'device_name': '/dev/sdb3'}, {'no_device': True, 'device_name': '/dev/sdb4'}, - {'virtual_name': 'ephemeral0', 'device_name': '/dev/sdc1'}, + {'virtual_name': 'ephemeral0', 'device_name': '/dev/sdc1', + 'delete_on_termination': True}, {'snapshot_id': '33333333-aaaa-bbbb-cccc-333333333333', 'device_name': '/dev/sdc2'}, {'snapshot_id': '44444444-aaaa-bbbb-cccc-444444444444', @@ -7419,6 +7427,8 @@ class ComputeAPITestCase(BaseTestCase): def fake_get_instance_bdms(*args, **kwargs): return [{'device_name': '/dev/vda', + 'source_type': 'volume', + 'destination_type': 'volume', 'volume_id': 'bf0b6b00-a20c-11e2-9e96-0800200c9a66'}] self.stubs.Set(self.compute_api, 'get_instance_bdms', diff --git a/nova/tests/conductor/test_conductor.py b/nova/tests/conductor/test_conductor.py index 8b397db02..e5abd1182 100644 --- a/nova/tests/conductor/test_conductor.py +++ b/nova/tests/conductor/test_conductor.py @@ -321,7 +321,7 @@ class _BaseTestCase(object): self.context, fake_inst['uuid']).AndReturn('fake-result') self.mox.ReplayAll() result = self.conductor.block_device_mapping_get_all_by_instance( - self.context, fake_inst) + self.context, fake_inst, legacy=False) self.assertEqual(result, 'fake-result') def test_instance_get_active_by_window_joined(self): diff --git a/nova/tests/db/test_db_api.py b/nova/tests/db/test_db_api.py index d3913117b..60811e65b 100644 --- a/nova/tests/db/test_db_api.py +++ b/nova/tests/db/test_db_api.py @@ -33,6 +33,7 @@ from sqlalchemy import MetaData from sqlalchemy.orm import query from sqlalchemy.sql.expression import select +from nova import block_device from nova.compute import vm_states from nova import context from nova import db @@ -4004,8 +4005,11 @@ class BlockDeviceMappingTestCase(test.TestCase): def _create_bdm(self, values): values.setdefault('instance_uuid', self.instance['uuid']) values.setdefault('device_name', 'fake_device') - db.block_device_mapping_create(self.ctxt, values) - uuid = values['instance_uuid'] + values.setdefault('source_type', 'volume') + values.setdefault('destination_type', 'volume') + block_dev = block_device.BlockDeviceDict(values) + db.block_device_mapping_create(self.ctxt, block_dev, legacy=False) + uuid = block_dev['instance_uuid'] bdms = db.block_device_mapping_get_all_by_instance(self.ctxt, uuid) @@ -4036,81 +4040,90 @@ class BlockDeviceMappingTestCase(test.TestCase): def test_block_device_mapping_update(self): bdm = self._create_bdm({}) db.block_device_mapping_update(self.ctxt, bdm['id'], - {'virtual_name': 'some_virt_name'}) + {'destination_type': 'moon'}, + legacy=False) uuid = bdm['instance_uuid'] bdm_real = db.block_device_mapping_get_all_by_instance(self.ctxt, uuid) - self.assertEqual(bdm_real[0]['virtual_name'], 'some_virt_name') + self.assertEqual(bdm_real[0]['destination_type'], 'moon') def test_block_device_mapping_update_or_create(self): values = { 'instance_uuid': self.instance['uuid'], 'device_name': 'fake_name', - 'virtual_name': 'some_virt_name' + 'source_type': 'volume', + 'destination_type': 'volume' } # check create - db.block_device_mapping_update_or_create(self.ctxt, values) + db.block_device_mapping_update_or_create(self.ctxt, values, + legacy=False) uuid = values['instance_uuid'] bdm_real = db.block_device_mapping_get_all_by_instance(self.ctxt, uuid) self.assertEqual(len(bdm_real), 1) self.assertEqual(bdm_real[0]['device_name'], 'fake_name') # check update - values['virtual_name'] = 'virtual_name' - db.block_device_mapping_update_or_create(self.ctxt, values) + values['destination_type'] = 'camelot' + db.block_device_mapping_update_or_create(self.ctxt, values, + legacy=False) bdm_real = db.block_device_mapping_get_all_by_instance(self.ctxt, uuid) self.assertEqual(len(bdm_real), 1) bdm_real = bdm_real[0] self.assertEqual(bdm_real['device_name'], 'fake_name') - self.assertEqual(bdm_real['virtual_name'], 'virtual_name') + self.assertEqual(bdm_real['destination_type'], 'camelot') def test_block_device_mapping_update_or_create_check_remove_virt(self): uuid = self.instance['uuid'] values = { 'instance_uuid': uuid, - 'virtual_name': 'ephemeral12' + 'source_type': 'blank', + 'guest_format': 'swap', } - # check that old bdm with same virtual_names are deleted on create + # check that old swap bdms are deleted on create val1 = dict(values) val1['device_name'] = 'device1' - db.block_device_mapping_create(self.ctxt, val1) + db.block_device_mapping_create(self.ctxt, val1, legacy=False) val2 = dict(values) val2['device_name'] = 'device2' - db.block_device_mapping_update_or_create(self.ctxt, val2) + db.block_device_mapping_update_or_create(self.ctxt, val2, legacy=False) bdm_real = db.block_device_mapping_get_all_by_instance(self.ctxt, uuid) self.assertEqual(len(bdm_real), 1) bdm_real = bdm_real[0] self.assertEqual(bdm_real['device_name'], 'device2') - self.assertEqual(bdm_real['virtual_name'], 'ephemeral12') + self.assertEqual(bdm_real['source_type'], 'blank') + self.assertEqual(bdm_real['guest_format'], 'swap') + db.block_device_mapping_destroy(self.ctxt, bdm_real['id']) - # check that old bdm with same virtual_names are deleted on update + # check that old ephemerals are deleted no matter what val3 = dict(values) val3['device_name'] = 'device3' - val3['virtual_name'] = 'some_name' - db.block_device_mapping_create(self.ctxt, val3) + val3['guest_format'] = None + val4 = dict(values) + val4['device_name'] = 'device4' + val4['guest_format'] = None + db.block_device_mapping_create(self.ctxt, val3, legacy=False) + db.block_device_mapping_create(self.ctxt, val4, legacy=False) bdm_real = db.block_device_mapping_get_all_by_instance(self.ctxt, uuid) self.assertEqual(len(bdm_real), 2) - val3['virtual_name'] = 'ephemeral12' - db.block_device_mapping_update_or_create(self.ctxt, val3) + val5 = dict(values) + val5['device_name'] = 'device5' + val5['guest_format'] = None + db.block_device_mapping_update_or_create(self.ctxt, val5, legacy=False) bdm_real = db.block_device_mapping_get_all_by_instance(self.ctxt, uuid) self.assertEqual(len(bdm_real), 1) bdm_real = bdm_real[0] - self.assertEqual(bdm_real['device_name'], 'device3') - self.assertEqual(bdm_real['virtual_name'], 'ephemeral12') + self.assertEqual(bdm_real['device_name'], 'device5') def test_block_device_mapping_get_all_by_instance(self): uuid1 = self.instance['uuid'] uuid2 = db.instance_create(self.ctxt, {})['uuid'] bmds_values = [{'instance_uuid': uuid1, - 'virtual_name': 'virtual_name', 'device_name': 'first'}, {'instance_uuid': uuid2, - 'virtual_name': 'virtual_name1', 'device_name': 'second'}, {'instance_uuid': uuid2, - 'virtual_name': 'virtual_name2', 'device_name': 'third'}] for bdm in bmds_values: @@ -4118,7 +4131,6 @@ class BlockDeviceMappingTestCase(test.TestCase): bmd = db.block_device_mapping_get_all_by_instance(self.ctxt, uuid1) self.assertEqual(len(bmd), 1) - self.assertEqual(bmd[0]['virtual_name'], 'virtual_name') self.assertEqual(bmd[0]['device_name'], 'first') bmd = db.block_device_mapping_get_all_by_instance(self.ctxt, uuid2) diff --git a/nova/tests/db/test_migrations.py b/nova/tests/db/test_migrations.py index 5bbf8d0c5..0e89cd521 100644 --- a/nova/tests/db/test_migrations.py +++ b/nova/tests/db/test_migrations.py @@ -1464,6 +1464,124 @@ class TestNovaMigrations(BaseMigrationTestCase, CommonTestsMixIn): def _post_downgrade_185(self, engine): self._unique_constraint_check_migrate_185(engine) + def _pre_upgrade_186(self, engine): + fake_instances = [ + dict(uuid='mig186_uuid-1', image_ref='fake_image_1', + root_device_name='/dev/vda'), + dict(uuid='mig186_uuid-2', image_ref='', + root_device_name='vda'), + dict(uuid='mig186_uuid-3', image_ref='fake_image_2', + root_device_name='/dev/vda'), + ] + + fake_bdms = [ + # Instance 1 - image, volume and swap + dict(instance_uuid='mig186_uuid-1', device_name='/dev/vdc', + volume_id='fake_volume_1'), + dict(instance_uuid='mig186_uuid-1', device_name='/dev/vdb', + virtual_name='swap'), + # Instance 2 - no image. snapshot and volume + dict(instance_uuid='mig186_uuid-2', device_name='/dev/vda', + snapshot_id='fake_snap_1', volume_id='fake_volume_2'), + dict(instance_uuid='mig186_uuid-2', device_name='/dev/vdc', + volume_id='fake_volume_3'), + # Instance 3 - ephemerals and swap + dict(instance_uuid='mig186_uuid-3', device_name='/dev/vdc', + virtual_name='ephemeral0'), + dict(instance_uuid='mig186_uuid-3', device_name='/dev/vdd', + virtual_name='ephemeral1'), + dict(instance_uuid='mig186_uuid-3', device_name='/dev/vdb', + virtual_name='swap'), + ] + + instances = db_utils.get_table(engine, 'instances') + block_device = db_utils.get_table(engine, 'block_device_mapping') + engine.execute(instances.insert(), fake_instances) + for fake_bdm in fake_bdms: + engine.execute(block_device.insert(), fake_bdm) + + return fake_instances, fake_bdms + + def _check_186(self, engine, data): + block_device = db_utils.get_table(engine, 'block_device_mapping') + + instance_qs = [] + + for instance in ('mig186_uuid-1', 'mig186_uuid-2', 'mig186_uuid-3'): + q = block_device.select().where( + block_device.c.instance_uuid == instance).order_by( + block_device.c.id.asc() + ) + instance_qs.append(q) + + bdm_1s, bdm_2s, bdm_3s = ( + [bdm for bdm in q.execute()] + for q in instance_qs + ) + + # Instance 1 + self.assertEqual(bdm_1s[0].source_type, 'volume') + self.assertEqual(bdm_1s[0].destination_type, 'volume') + self.assertEqual(bdm_1s[0].volume_id, 'fake_volume_1') + self.assertEqual(bdm_1s[0].device_type, 'disk') + self.assertEqual(bdm_1s[0].boot_index, -1) + self.assertEqual(bdm_1s[0].device_name, '/dev/vdc') + + self.assertEqual(bdm_1s[1].source_type, 'blank') + self.assertEqual(bdm_1s[1].guest_format, 'swap') + self.assertEqual(bdm_1s[1].destination_type, 'local') + self.assertEqual(bdm_1s[1].device_type, 'disk') + self.assertEqual(bdm_1s[1].boot_index, -1) + self.assertEqual(bdm_1s[1].device_name, '/dev/vdb') + + self.assertEqual(bdm_1s[2].source_type, 'image') + self.assertEqual(bdm_1s[2].destination_type, 'local') + self.assertEqual(bdm_1s[2].device_type, 'disk') + self.assertEqual(bdm_1s[2].image_id, 'fake_image_1') + self.assertEqual(bdm_1s[2].boot_index, 0) + + # Instance 2 + self.assertEqual(bdm_2s[0].source_type, 'snapshot') + self.assertEqual(bdm_2s[0].destination_type, 'volume') + self.assertEqual(bdm_2s[0].snapshot_id, 'fake_snap_1') + self.assertEqual(bdm_2s[0].volume_id, 'fake_volume_2') + self.assertEqual(bdm_2s[0].device_type, 'disk') + self.assertEqual(bdm_2s[0].boot_index, 0) + self.assertEqual(bdm_2s[0].device_name, '/dev/vda') + + self.assertEqual(bdm_2s[1].source_type, 'volume') + self.assertEqual(bdm_2s[1].destination_type, 'volume') + self.assertEqual(bdm_2s[1].volume_id, 'fake_volume_3') + self.assertEqual(bdm_2s[1].device_type, 'disk') + self.assertEqual(bdm_2s[1].boot_index, -1) + self.assertEqual(bdm_2s[1].device_name, '/dev/vdc') + + # Instance 3 + self.assertEqual(bdm_3s[0].source_type, 'blank') + self.assertEqual(bdm_3s[0].destination_type, 'local') + self.assertEqual(bdm_3s[0].device_type, 'disk') + self.assertEqual(bdm_3s[0].boot_index, -1) + self.assertEqual(bdm_3s[0].device_name, '/dev/vdc') + + self.assertEqual(bdm_3s[1].source_type, 'blank') + self.assertEqual(bdm_3s[1].destination_type, 'local') + self.assertEqual(bdm_3s[1].device_type, 'disk') + self.assertEqual(bdm_3s[1].boot_index, -1) + self.assertEqual(bdm_3s[1].device_name, '/dev/vdd') + + self.assertEqual(bdm_3s[2].source_type, 'blank') + self.assertEqual(bdm_3s[2].guest_format, 'swap') + self.assertEqual(bdm_3s[2].destination_type, 'local') + self.assertEqual(bdm_3s[2].device_type, 'disk') + self.assertEqual(bdm_3s[2].boot_index, -1) + self.assertEqual(bdm_3s[2].device_name, '/dev/vdb') + + self.assertEqual(bdm_3s[3].source_type, 'image') + self.assertEqual(bdm_3s[3].destination_type, 'local') + self.assertEqual(bdm_3s[3].device_type, 'disk') + self.assertEqual(bdm_3s[3].image_id, 'fake_image_2') + self.assertEqual(bdm_3s[3].boot_index, 0) + class TestBaremetalMigrations(BaseMigrationTestCase, CommonTestsMixIn): """Test sqlalchemy-migrate migrations.""" diff --git a/nova/tests/test_metadata.py b/nova/tests/test_metadata.py index 86d618930..6b84121c4 100644 --- a/nova/tests/test_metadata.py +++ b/nova/tests/test_metadata.py @@ -188,19 +188,24 @@ class MetadataTestCase(test.TestCase): return [{'volume_id': 87654321, 'snapshot_id': None, 'no_device': None, - 'virtual_name': None, + 'source_type': 'volume', + 'destination_type': 'volume', 'delete_on_termination': True, 'device_name': '/dev/sdh'}, {'volume_id': None, 'snapshot_id': None, 'no_device': None, - 'virtual_name': 'swap', + 'source_type': 'blank', + 'destination_type': 'local', + 'guest_format': 'swap', 'delete_on_termination': None, 'device_name': '/dev/sdc'}, {'volume_id': None, 'snapshot_id': None, 'no_device': None, - 'virtual_name': 'ephemeral0', + 'source_type': 'blank', + 'destination_type': 'local', + 'guest_format': None, 'delete_on_termination': None, 'device_name': '/dev/sdb'}] @@ -214,6 +219,7 @@ class MetadataTestCase(test.TestCase): 'ebs0': '/dev/sdh'} capi = conductor_api.LocalAPI() + self.assertEqual(base._format_instance_mapping(capi, ctxt, instance_ref0), block_device._DEFAULT_MAPPINGS) self.assertEqual(base._format_instance_mapping(capi, ctxt, -- cgit