On 08/06/2015 02:35 PM, Jan Cholasta wrote:
Hi,

Dne 6.8.2015 v 14:29 Martin Babinsky napsal(a):
This bug was discovered when writing tests for functionality introduced
in my PATCH 0051.

This patch should apply on top of PATCH 0051.

This whole patch can be reduced to:

          except core.KnobValueError as e:
              knob_cls = getattr(transformed_cls, e.name)
              try:
-                index = self.positional_arguments.index(e.name)
-            except IndexError:
+                if self.positional_arguments:
+                    index = self.positional_arguments.index(e.name)
+                else:
+                    raise ValueError
+            except ValueError:
                  cli_name = knob_cls.cli_name or e.name.replace('_', '-')
                  desc = "option --{0}".format(cli_name)
              else:

Honza

Right. I have rewritten the patch in your way.

--
Martin^3 Babinsky
From f854921ca3bc4ef73a8a4c5565036911041ce594 Mon Sep 17 00:00:00 2001
From: Martin Babinsky <mbabi...@redhat.com>
Date: Thu, 6 Aug 2015 14:43:32 +0200
Subject: [PATCH] fix crash when installer with no positional arguments handles
 invalid options

when ipa-server-install received an option value which did not pass knob
validator an AttributeError was raised due to incorrect error handling with
no positional arguments.
---
 ipapython/install/cli.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/ipapython/install/cli.py b/ipapython/install/cli.py
index 98297aa3d3361dbaa08529340e69e034fb04a4f8..4a0fbdbd82fdbef78dbe96c008e2c90a9d839833 100644
--- a/ipapython/install/cli.py
+++ b/ipapython/install/cli.py
@@ -310,8 +310,11 @@ class ConfigureTool(admintool.AdminTool):
         except core.KnobValueError as e:
             knob_cls = getattr(transformed_cls, e.name)
             try:
-                index = self.positional_arguments.index(e.name)
-            except IndexError:
+                if self.positional_arguments:
+                    index = self.positional_arguments.index(e.name)
+                else:
+                    raise ValueError
+            except ValueError:
                 cli_name = knob_cls.cli_name or e.name.replace('_', '-')
                 desc = "option --{0}".format(cli_name)
             else:
-- 
2.4.3

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to