Re: [Freeipa-devel] [PATCH 0053] fix crash when installer with no positional arguments handles invalid options

2015-08-06 Thread Martin Babinsky

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

Re: [Freeipa-devel] [PATCH 0053] fix crash when installer with no positional arguments handles invalid options

2015-08-06 Thread Jan Cholasta

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

--
Jan Cholasta

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


[Freeipa-devel] [PATCH 0053] fix crash when installer with no positional arguments handles invalid options

2015-08-06 Thread Martin Babinsky
This bug was discovered when writing tests for functionality introduced 
in my PATCH 0051.


This patch should apply on top of PATCH 0051.

--
Martin^3 Babinsky
From 7b281ba47e4fec7da7eab4a861a7cbaceb2bd859 Mon Sep 17 00:00:00 2001
From: Martin Babinsky 
Date: Thu, 6 Aug 2015 14:19:52 +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 Attribute error was raised due to incorrect error handling with
no positional arguments.
---
 ipapython/install/cli.py | 51 +---
 1 file changed, 31 insertions(+), 20 deletions(-)

diff --git a/ipapython/install/cli.py b/ipapython/install/cli.py
index 98297aa3d3361dbaa08529340e69e034fb04a4f8..242eb40550e92d41cc6ad31bffbd84bb3d332000 100644
--- a/ipapython/install/cli.py
+++ b/ipapython/install/cli.py
@@ -31,48 +31,59 @@ def install_tool(configurable_class, command_name, log_file_name,
 configurable_class=configurable_class,
 command_name=command_name,
 log_file_name=uninstall_log_file_name,
-positional_arguments=uninstall_positional_arguments,
 usage=uninstall_usage,
 debug_option=debug_option,
 )
+if uninstall_positional_arguments is not None:
+uninstall_kwargs.update(
+dict(positional_arguments=uninstall_positional_arguments)
+)
 else:
 uninstall_kwargs = None
 
+kwargs = dict(
+configurable_class=configurable_class,
+command_name=command_name,
+log_file_name=log_file_name,
+usage=usage,
+debug_option=debug_option,
+uninstall_kwargs=uninstall_kwargs,
+)
+
+if positional_arguments is not None:
+kwargs.update(dict(positional_arguments=positional_arguments))
+
 return type(
 'install_tool({0})'.format(configurable_class.__name__),
 (InstallTool,),
-dict(
-configurable_class=configurable_class,
-command_name=command_name,
-log_file_name=log_file_name,
-positional_arguments=positional_arguments,
-usage=usage,
-debug_option=debug_option,
-uninstall_kwargs=uninstall_kwargs,
-)
+kwargs
 )
 
 
 def uninstall_tool(configurable_class, command_name, log_file_name,
positional_arguments=None, usage=None, debug_option=False):
+kwargs = dict(
+configurable_class=configurable_class,
+command_name=command_name,
+log_file_name=log_file_name,
+usage=usage,
+debug_option=debug_option,
+)
+
+if positional_arguments is not None:
+kwargs.update(dict(positional_arguments=positional_arguments))
+
 return type(
 'uninstall_tool({0})'.format(configurable_class.__name__),
 (UninstallTool,),
-dict(
-configurable_class=configurable_class,
-command_name=command_name,
-log_file_name=log_file_name,
-positional_arguments=positional_arguments,
-usage=usage,
-debug_option=debug_option,
-)
+kwargs
 )
 
 
 class ConfigureTool(admintool.AdminTool):
 configurable_class = None
 debug_option = False
-positional_arguments = None
+positional_arguments = ()
 cfgr = None
 
 @staticmethod
@@ -311,7 +322,7 @@ class ConfigureTool(admintool.AdminTool):
 knob_cls = getattr(transformed_cls, e.name)
 try:
 index = self.positional_arguments.index(e.name)
-except IndexError:
+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