From 6f479a494e5f9270f6b4b7536d0bd16ad1b037f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20Gagne=CC=81?= Date: Mon, 2 Feb 2015 14:22:24 -0500 Subject: [PATCH] Don't create block device mappings in the API cell Otherwise 2 block_device_mapping entries will be created in the API cell: - the first one (created by the API cell) will have close to no information about the volume (device_name and volume_id are NULL) - the second one (bubbled up from the compute cell) will contain all the volume information The first entry confuses Nova when creating an image since it won't be able to find the associated volume (NULL) in Cinder. The compute cell should create it first and propagate it up to the API cell. Change-Id: I38edb953e73de6bc70a2e5950c68f457f83303e1 Closes-bug: #1417239 (cherry picked from commit 58633c4f085fc21be1e6439bb3d60d7492358d4a) --- nova/compute/cells_api.py | 7 +++++++ nova/tests/compute/test_compute_cells.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/nova/compute/cells_api.py b/nova/compute/cells_api.py index 72c7bde46e08..290d61f32b96 100644 --- a/nova/compute/cells_api.py +++ b/nova/compute/cells_api.py @@ -198,6 +198,13 @@ class ComputeCellsAPI(compute_api.API): """ return super(ComputeCellsAPI, self).create(*args, **kwargs) + def _update_block_device_mapping(self, *args, **kwargs): + """Don't create block device mappings in the API cell. + + The child cell will create it and propagate it up to the parent cell. + """ + pass + def update(self, context, instance, **kwargs): """Update an instance.""" cell_name = instance['cell_name'] diff --git a/nova/tests/compute/test_compute_cells.py b/nova/tests/compute/test_compute_cells.py index fdca06c973bd..57029e8629a8 100644 --- a/nova/tests/compute/test_compute_cells.py +++ b/nova/tests/compute/test_compute_cells.py @@ -21,6 +21,7 @@ import inspect import mock from oslo.config import cfg +from nova import block_device from nova.cells import manager from nova.compute import api as compute_api from nova.compute import cells_api as compute_cells_api @@ -178,6 +179,19 @@ class CellsComputeAPITestCase(test_compute.ComputeAPITestCase): self.assertEqual(migrations, response) + def test_update_block_device_mapping(self): + instance_type = {'swap': 1, 'ephemeral_gb': 1} + instance = self._create_fake_instance_obj() + bdms = [block_device.BlockDeviceDict({'source_type': 'image', + 'destination_type': 'local', + 'image_id': 'fake-image', + 'boot_index': 0})] + self.compute_api._update_block_device_mapping( + instance_type, instance.uuid, bdms) + bdms = db.block_device_mapping_get_all_by_instance( + self.context, instance['uuid']) + self.assertEqual(0, len(bdms)) + @mock.patch('nova.cells.messaging._TargetedMessage') def test_rebuild_sig(self, mock_msg): # TODO(belliott) Cells could benefit from better testing to ensure API