Method to filter non-root block device mappings

Adding a generator that would provide a non-root block device
mappings, when it's optional variable exclude_root_mapping is
set to true. Otherwise, all mappings will be returned.

The method will be used to handle LXC volumes, as it's root FS
should be handled differently.

Change-Id: I879916021c3b61f19dd69ff11838dbbac19f72d1
Related-Bug: #1269990
This commit is contained in:
Vladik Romanovsky
2014-06-13 10:11:08 -04:00
parent 90cf9f6542
commit 099aad2c3f
2 changed files with 19 additions and 0 deletions

View File

@@ -422,6 +422,14 @@ def get_root_bdm(bdms):
return None
def get_bdms_to_connect(bdms, exclude_root_mapping=False):
"""Will return non-root mappings, when exclude_root_mapping is true.
Otherwise all mappings will be returned.
"""
return (bdm for bdm in bdms if bdm.get('boot_index', -1) != 0 or
not exclude_root_mapping)
def mappings_prepend_dev(mappings):
"""Prepend '/dev/' to 'device' entry of swap/ephemeral virtual type."""
for m in mappings:

View File

@@ -230,6 +230,17 @@ class BlockDeviceTestCase(test.NoDBTestCase):
block_device.validate_and_default_volume_size,
bdm)
def test_get_bdms_to_connect(self):
root_bdm = {'device_name': 'vda', 'boot_index': 0}
bdms = [root_bdm,
{'device_name': 'vdb', 'boot_index': 1},
{'device_name': 'vdc', 'boot_index': -1},
{'device_name': 'vde', 'boot_index': None},
{'device_name': 'vdd'}]
self.assertNotIn(root_bdm, block_device.get_bdms_to_connect(bdms,
exclude_root_mapping=True))
self.assertIn(root_bdm, block_device.get_bdms_to_connect(bdms))
class TestBlockDeviceDict(test.NoDBTestCase):
def setUp(self):