From 061fcc1159bef439bef26a5f44067c794f7c28c5 Mon Sep 17 00:00:00 2001 From: Yuriy Zveryanskyy Date: Mon, 16 Sep 2013 16:16:00 +0300 Subject: [PATCH] Improve parameters validate in PXE driver Verification that 'root_gb' and 'swap_mb' from 'driver_info' converts to integer. Change-Id: I938cc61c6eb06d4d8c5f610d1d57d8fe602164c4 --- ironic/drivers/modules/pxe.py | 9 +++++++++ ironic/tests/drivers/test_pxe.py | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/ironic/drivers/modules/pxe.py b/ironic/drivers/modules/pxe.py index 5f65992a6b..b0194c1868 100644 --- a/ironic/drivers/modules/pxe.py +++ b/ironic/drivers/modules/pxe.py @@ -112,6 +112,15 @@ def _parse_driver_info(node): #TODO(ghe): Should we get rid of swap partition? d_info['swap_mb'] = info.get('swap_mb', 1) d_info['key_data'] = info.get('key_data', None) + + for param in ('root_gb', 'swap_mb'): + try: + int(d_info[param]) + except ValueError: + raise exception.InvalidParameterValue(_( + "Can not validate PXE bootloader. Invalid " + "parameter %s") % param) + return d_info diff --git a/ironic/tests/drivers/test_pxe.py b/ironic/tests/drivers/test_pxe.py index e45599f842..43d03f6339 100644 --- a/ironic/tests/drivers/test_pxe.py +++ b/ironic/tests/drivers/test_pxe.py @@ -128,6 +128,15 @@ class PXEValidateParametersTestCase(base.TestCase): node) self.mox.VerifyAll() + def test__parse_driver_info_invalid_root_gb(self): + tmp_dict = dict(INFO_DICT) + tmp_dict['root_gb'] = 'foobar' + info = {'pxe': tmp_dict} + node = self._create_test_node(driver_info=info) + self.assertRaises(exception.InvalidParameterValue, + pxe._parse_driver_info, + node) + def test__get_pxe_mac_path(self): mac = '00:11:22:33:44:55:66' self.assertEqual(pxe._get_pxe_mac_path(mac),