summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorNikola Dipanov <ndipanov@redhat.com>2013-05-15 16:00:05 +0200
committerChris Behrens <cbehrens@codestud.com>2013-06-10 23:10:39 +0000
commit41eb083d228f159e8d4e566148db5994ad49143c (patch)
tree41f8828730de39290c2b03f5fe1e08e691580caa /nova/tests
parent0d5fb06b39e8244429be72f05e2066d24572dc2e (diff)
Create an image BDM for every instance
This patch makes every boot create a block device mapping if the instance was started with an image. These block devices are not used anywhere at the moment but will be used in the future as part of a more flexible block device API. This patch also makes sure they are deleted once the instance is deleted as well. Change-Id: Ia89d531be71c460f1f82fcfce34b270639a23061 blueprint: improve-block-device-handling
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/compute/test_compute.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py
index 3e0fbe63e..4dea52dfb 100644
--- a/nova/tests/compute/test_compute.py
+++ b/nova/tests/compute/test_compute.py
@@ -7263,6 +7263,56 @@ class ComputeAPITestCase(BaseTestCase):
instance = db.instance_get_by_uuid(self.context, instance['uuid'])
self.compute.terminate_instance(self.context, instance)
+ def test_populate_instance_for_bdm(self):
+ # Test that the image bdm is created
+ instance_type = {'swap': 1}
+ instance = self._create_fake_instance(
+ {'root_device_name': 'vda'}
+ )
+ image = {'uuid': FAKE_IMAGE_REF}
+ fake_bdms = [{'device_name': '/dev/vda',
+ 'snapshot_id': '33333333-aaaa-bbbb-cccc-333333333333',
+ 'delete_on_termination': False}]
+
+ # Has an image but no bdms
+ self.compute_api._populate_instance_for_bdm(self.context,
+ instance,
+ instance_type,
+ image, [])
+ bdms = db.block_device_mapping_get_all_by_instance(
+ self.context, instance['uuid'])
+ self.assertEqual(len(bdms), 1)
+ self.assertEqual(bdms[0]['image_id'], FAKE_IMAGE_REF)
+ for bdm in bdms:
+ db.block_device_mapping_destroy(self.context, bdm['id'])
+
+ # Has an image and is volume backed - legacy style
+ self.compute_api._populate_instance_for_bdm(self.context,
+ instance,
+ instance_type,
+ image, fake_bdms)
+ bdms = db.block_device_mapping_get_all_by_instance(
+ self.context, instance['uuid'])
+ self.assertEqual(len(bdms), 1)
+ self.assertEqual(bdms[0]['snapshot_id'],
+ '33333333-aaaa-bbbb-cccc-333333333333')
+ for bdm in bdms:
+ db.block_device_mapping_destroy(self.context, bdm['id'])
+
+ # Is volume backed and has no image
+ instance['image_ref'] = ''
+ self.compute_api._populate_instance_for_bdm(self.context,
+ instance,
+ instance_type,
+ image, fake_bdms)
+ bdms = db.block_device_mapping_get_all_by_instance(
+ self.context, instance['uuid'])
+ self.assertEqual(len(bdms), 1)
+ self.assertEqual(bdms[0]['snapshot_id'],
+ '33333333-aaaa-bbbb-cccc-333333333333')
+ for bdm in bdms:
+ db.block_device_mapping_destroy(self.context, bdm['id'])
+
def test_volume_size(self):
ephemeral_size = 2
swap_size = 3