From 2a518543fd5a3e6437f9b297dd24d20d0e5e3aab Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Fri, 29 Jan 2010 13:14:51 +0100 Subject: [PATCH] Handle errors better for wrong nic_count in export This fixes an old 'FIXME' entry. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- lib/cmdlib.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 52744bd9e..cceb7d756 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -6391,8 +6391,12 @@ class LUCreateInstance(LogicalUnit): self.src_images = disk_images old_name = export_info.get(constants.INISECT_INS, 'name') - # FIXME: int() here could throw a ValueError on broken exports - exp_nic_count = int(export_info.get(constants.INISECT_INS, 'nic_count')) + try: + exp_nic_count = export_info.getint(constants.INISECT_INS, 'nic_count') + except (TypeError, ValueError), err: + raise errors.OpPrereqError("Invalid export file, nic_count is not" + " an integer: %s" % str(err), + errors.ECODE_STATE) if self.op.instance_name == old_name: for idx, nic in enumerate(self.nics): if nic.mac == constants.VALUE_AUTO and exp_nic_count >= idx: -- GitLab