Improve parameters validate in PXE driver

Verification that 'root_gb' and 'swap_mb'
from 'driver_info' converts to integer.

Change-Id: I938cc61c6eb06d4d8c5f610d1d57d8fe602164c4
This commit is contained in:
Yuriy Zveryanskyy 2013-09-16 16:16:00 +03:00
parent d5d42ad655
commit 061fcc1159
2 changed files with 18 additions and 0 deletions

View File

@ -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

View File

@ -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),