diff options
| author | Isaku Yamahata <yamahata@valinux.co.jp> | 2011-09-17 17:50:41 +0000 |
|---|---|---|
| committer | Tarmac <> | 2011-09-17 17:50:41 +0000 |
| commit | 830a85815cc6b53395a91efb93466692dc33fc83 (patch) | |
| tree | f617030c61446d59faf6ccb14fe5a76fa324c583 | |
| parent | 0dc06712aa06a60a582938770a9555b9df90fa22 (diff) | |
| parent | 24db80baa4a5125ba32250b7aa495b58465cfdf5 (diff) | |
| download | nova-830a85815cc6b53395a91efb93466692dc33fc83.tar.gz nova-830a85815cc6b53395a91efb93466692dc33fc83.tar.xz nova-830a85815cc6b53395a91efb93466692dc33fc83.zip | |
When swap is specified as block device mapping, its size becomes 0 wrongly.
This patch make it set to correct size according to instance_type.
| -rw-r--r-- | nova/compute/api.py | 37 | ||||
| -rw-r--r-- | nova/tests/test_compute.py | 14 |
2 files changed, 28 insertions, 23 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py index 95ea13f61..d8657d403 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -287,18 +287,24 @@ class API(base.Base): return (num_instances, base_options, image) @staticmethod - def _ephemeral_size(instance_type, ephemeral_name): - num = block_device.ephemeral_num(ephemeral_name) + def _volume_size(instance_type, virtual_name): + size = 0 + if virtual_name == 'swap': + size = instance_type.get('swap', 0) + elif block_device.is_ephemeral(virtual_name): + num = block_device.ephemeral_num(virtual_name) - # TODO(yamahata): ephemeralN where N > 0 - # Only ephemeral0 is allowed for now because InstanceTypes - # table only allows single local disk, local_gb. - # In order to enhance it, we need to add a new columns to - # instance_types table. - if num > 0: - return 0 + # TODO(yamahata): ephemeralN where N > 0 + # Only ephemeral0 is allowed for now because InstanceTypes + # table only allows single local disk, local_gb. + # In order to enhance it, we need to add a new columns to + # instance_types table. + if num > 0: + return 0 - return instance_type.get('local_gb') + size = instance_type.get('local_gb') + + return size def _update_image_block_device_mapping(self, elevated_context, instance_type, instance_id, @@ -319,12 +325,7 @@ class API(base.Base): if not block_device.is_swap_or_ephemeral(virtual_name): continue - size = 0 - if virtual_name == 'swap': - size = instance_type.get('swap', 0) - elif block_device.is_ephemeral(virtual_name): - size = self._ephemeral_size(instance_type, virtual_name) - + size = self._volume_size(instance_type, virtual_name) if size == 0: continue @@ -354,8 +355,8 @@ class API(base.Base): virtual_name = bdm.get('virtual_name') if (virtual_name is not None and - block_device.is_ephemeral(virtual_name)): - size = self._ephemeral_size(instance_type, virtual_name) + block_device.is_swap_or_ephemeral(virtual_name)): + size = self._volume_size(instance_type, virtual_name) if size == 0: continue values['volume_size'] = size diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 4d463572b..d600c9f15 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -1563,12 +1563,16 @@ class ComputeTestCase(test.TestCase): db.block_device_mapping_destroy(self.context, bdm['id']) self.compute.terminate_instance(self.context, instance_id) - def test_ephemeral_size(self): + def test_volume_size(self): local_size = 2 - inst_type = {'local_gb': local_size} - self.assertEqual(self.compute_api._ephemeral_size(inst_type, + swap_size = 3 + inst_type = {'local_gb': local_size, 'swap': swap_size} + self.assertEqual(self.compute_api._volume_size(inst_type, 'ephemeral0'), local_size) - self.assertEqual(self.compute_api._ephemeral_size(inst_type, - 'ephemeral1'), + self.assertEqual(self.compute_api._volume_size(inst_type, + 'ephemeral1'), 0) + self.assertEqual(self.compute_api._volume_size(inst_type, + 'swap'), + swap_size) |
