From 426d394b77584bb0f9be89e4a11df937448a5087 Mon Sep 17 00:00:00 2001 From: Andrew Laski Date: Fri, 8 Aug 2014 12:59:24 -0400 Subject: [PATCH] Prepend /dev/ to root_device_name in get_next_device_name Because the API docs for booting an instance from a volume have shown to use 'vda' for a long time, and it has worked, there may be instances with root_device_name = 'vda'. These instances will fail a check in get_next_device_name when attempting to attach another volume, making that impossible. Another patch fixes new block_device_mappings by prepending /dev/ when the root_device_name is populated, but this will allow incorrectly populated instances to attach volumes. Change-Id: I709a195c7e3f559315a2c307de62cbae8b72ac46 Partial-Bug: #1337821 --- nova/compute/utils.py | 3 ++- nova/tests/compute/test_compute_utils.py | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/nova/compute/utils.py b/nova/compute/utils.py index 775698c482f0..aa455e37fc50 100644 --- a/nova/compute/utils.py +++ b/nova/compute/utils.py @@ -148,7 +148,8 @@ def get_next_device_name(instance, device_name_list, root_device_name = block_device.DEFAULT_ROOT_DEV_NAME try: - prefix = block_device.match_device(root_device_name)[0] + prefix = block_device.match_device( + block_device.prepend_dev(root_device_name))[0] except (TypeError, AttributeError, ValueError): raise exception.InvalidDevicePath(path=root_device_name) diff --git a/nova/tests/compute/test_compute_utils.py b/nova/tests/compute/test_compute_utils.py index a9d13b00bb70..4b945fcaac69 100644 --- a/nova/tests/compute/test_compute_utils.py +++ b/nova/tests/compute/test_compute_utils.py @@ -168,11 +168,6 @@ class ComputeValidateDeviceTestCase(test.TestCase): device = self._validate_device('/dev/xvdc') self.assertEqual(device, '/dev/vdc') - def test_invalid_bdms(self): - self.instance['root_device_name'] = "baddata" - self.assertRaises(exception.InvalidDevicePath, - self._validate_device) - def test_invalid_device_prefix(self): self.assertRaises(exception.InvalidDevicePath, self._validate_device, '/baddata/vdc') @@ -236,6 +231,11 @@ class ComputeValidateDeviceTestCase(test.TestCase): device = self._validate_device() self.assertEqual(device, '/dev/xvdd') + def test_no_dev_root_device_name_get_next_name(self): + self.instance['root_device_name'] = 'vda' + device = self._validate_device() + self.assertEqual('/dev/vdc', device) + class DefaultDeviceNamesForInstanceTestCase(test.NoDBTestCase):