From 68e008b21b463a261461a0f7bbfaa92f4e9a7e92 Mon Sep 17 00:00:00 2001 From: Feodor Tersin Date: Tue, 27 May 2014 00:00:07 +0400 Subject: [PATCH] Skip none value attributes for ec2 image bdm output. Fix crash in _format_block_device_mapping when there are None values for formatting attributes in the mapping. Change-Id: I0ebdb844d75cdf1580cc88e1ff40fc21aff96f21 Closes-Bug: #1323403 --- nova/api/ec2/cloud.py | 2 +- nova/tests/api/ec2/test_cloud.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 1b22d280b070..4f21c68581ef 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -175,7 +175,7 @@ def _format_block_device_mapping(bdm): ('deleteOnTermination', 'delete_on_termination')) ebs = {} for name, k in ebs_keys: - if k in bdm: + if bdm.get(k) is not None: if k == 'snapshot_id': ebs[name] = ec2utils.id_to_ec2_snap_id(bdm[k]) elif k == 'volume_id': diff --git a/nova/tests/api/ec2/test_cloud.py b/nova/tests/api/ec2/test_cloud.py index 7b802e850a54..76670b761288 100644 --- a/nova/tests/api/ec2/test_cloud.py +++ b/nova/tests/api/ec2/test_cloud.py @@ -1486,7 +1486,8 @@ class CloudTestCase(test.TestCase): mappings2 = [{'device': '/dev/sda1', 'virtual': 'root'}] block_device_mapping2 = [{'device_name': '/dev/sdb1', - 'snapshot_id': 'ccec42a2-c220-4806-b762-6b12fbb592e7'}] + 'snapshot_id': 'ccec42a2-c220-4806-b762-6b12fbb592e7', + 'volume_id': None}] image2 = { 'id': '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6', 'name': 'fake_name',