Return None from get_swap() if input is not swap

If a non-swap parameter is passed to get_swap(), return None,
rather than returning the parameter itself.

Change-Id: Icfb0eb0e4d721522160d0b7a4fd9b98c1871a10a
Closes-bug: #1214406
This commit is contained in:
Ana Krivokapic 2014-09-18 16:37:46 +02:00
parent f4c780618c
commit 0efbcf4e16
2 changed files with 2 additions and 2 deletions

View File

@ -656,7 +656,7 @@ class TestDriverBlockDevice(test.NoDBTestCase):
self.assertEqual(swap[0], driver_block_device.get_swap(swap))
self.assertEqual(legacy_swap[0],
driver_block_device.get_swap(legacy_swap))
self.assertEqual(no_swap, driver_block_device.get_swap(no_swap))
self.assertIsNone(driver_block_device.get_swap(no_swap))
self.assertIsNone(driver_block_device.get_swap([]))
def test_is_implemented(self):

View File

@ -446,7 +446,7 @@ def get_swap(transformed_list):
if not all(isinstance(device, DriverSwapBlockDevice) or
'swap_size' in device
for device in transformed_list):
return transformed_list
return None
try:
return transformed_list.pop()
except IndexError: