From 2af896ceccc6fa947bbdb8b06442439db1c6dc1f Mon Sep 17 00:00:00 2001 From: Devananda van der Veen Date: Thu, 17 Jan 2013 09:09:32 -0800 Subject: PXE driver should not accept empty kernel UUID. Baremetal PXE driver was aborting only if the kernel and ramdisk specified in image metadata were None, but not if they were another non-true value, such as "". Now, exception is raised if they are any non-true value. Fix bug 1100589. Change-Id: I9783a14cc242e1b9db04d797c61d54b06d52c680 --- nova/tests/baremetal/test_pxe.py | 18 ++++++++++++++++++ nova/virt/baremetal/pxe.py | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/nova/tests/baremetal/test_pxe.py b/nova/tests/baremetal/test_pxe.py index 45c9ede43..02d1a26e6 100644 --- a/nova/tests/baremetal/test_pxe.py +++ b/nova/tests/baremetal/test_pxe.py @@ -254,6 +254,13 @@ class PXEClassMethodsTestCase(BareMetalPXETestCase): pxe.get_tftp_image_info, self.instance) + # Test that other non-true values also raise an exception + CONF.baremetal.deploy_kernel = "" + CONF.baremetal.deploy_ramdisk = "" + self.assertRaises(exception.NovaException, + pxe.get_tftp_image_info, + self.instance) + # Even if the instance includes kernel_id and ramdisk_id, # we still need deploy_kernel_id and deploy_ramdisk_id. # If those aren't present in instance[], and not specified in @@ -295,6 +302,17 @@ class PXEClassMethodsTestCase(BareMetalPXETestCase): self.assertEqual(res['deploy_kernel'][0], 'eeee') self.assertEqual(res['deploy_ramdisk'][0], 'ffff') + # However, if invalid values are passed on the image extra_specs, + # this should still raise an exception. + extra_specs = { + 'deploy_kernel_id': '', + 'deploy_ramdisk_id': '', + } + self.instance['extra_specs'] = extra_specs + self.assertRaises(exception.NovaException, + pxe.get_tftp_image_info, + self.instance) + class PXEPrivateMethodsTestCase(BareMetalPXETestCase): diff --git a/nova/virt/baremetal/pxe.py b/nova/virt/baremetal/pxe.py index b94ac9032..cc3790a8f 100644 --- a/nova/virt/baremetal/pxe.py +++ b/nova/virt/baremetal/pxe.py @@ -219,7 +219,7 @@ def get_tftp_image_info(instance): missing_labels = [] for label in image_info.keys(): (uuid, path) = image_info[label] - if uuid is None: + if not uuid: missing_labels.append(label) else: image_info[label][1] = os.path.join(CONF.baremetal.tftp_root, -- cgit