Change in vdsm[master]: tool: Fix error message for non-existing module

nsoffer at redhat.com nsoffer at redhat.com
Thu Aug 21 03:25:20 UTC 2014


Nir Soffer has uploaded a new change for review.

Change subject: tool: Fix error message for non-existing module
......................................................................

tool: Fix error message for non-existing module

When user specify non existing module (e.g. foo)using the --module
option, he would get this confusing error:

    UsageError: error: argument --module: invalid choice: foo (choose from ['foo'])

While the availabe modules are certificates, libvirt, and sanlock.

Now the error display the available modules, sorted, and formatted in a
user friendly way, instead of as Python list:

    UsageError: error: argument --module: invalid choice: foo
    (available: certificates, libvirt, sanlock)

The relevant test use now real names, so errors look like real errors,
which help to format them properly.

Change-Id: Ib794b4cb0dcedbbd5b5bb4bb4396860e5edd8710
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M lib/vdsm/tool/configurator.py
M tests/toolTests.py
2 files changed, 6 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/42/31742/1

diff --git a/lib/vdsm/tool/configurator.py b/lib/vdsm/tool/configurator.py
index 7f4dc1a..6130d56 100644
--- a/lib/vdsm/tool/configurator.py
+++ b/lib/vdsm/tool/configurator.py
@@ -180,9 +180,10 @@
         try:
             requiredNames = _getConfigurers()[next_].getRequires()
         except KeyError:
+            available = ', '.join(sorted(_getConfigurers()))
             raise UsageError(
-                "error: argument --module: "
-                "invalid choice: %s (choose from %s)\n" % (next_, modulesNames)
+                "error: argument --module: invalid choice: %s\n"
+                "(available: %s)\n" % (next_, available)
             )
 
         for requiredName in requiredNames:
diff --git a/tests/toolTests.py b/tests/toolTests.py
index b41ae50..88e249f 100644
--- a/tests/toolTests.py
+++ b/tests/toolTests.py
@@ -146,7 +146,8 @@
         configurator,
         '_getConfigurers',
         lambda:  {
-            'a': MockModuleConfigurator('a', set()),
+            'libvirt': MockModuleConfigurator('libvirt', set()),
+            'sanlock': MockModuleConfigurator('sanlock', set()),
         }
     )
     def testNonExistentModule(self):
@@ -155,7 +156,7 @@
             UsageError,
             configurator._parse_args,
             'validate-config',
-            '--module=b'
+            '--module=multipath'
         )
 
 


-- 
To view, visit http://gerrit.ovirt.org/31742
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib794b4cb0dcedbbd5b5bb4bb4396860e5edd8710
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer at redhat.com>


More information about the vdsm-patches mailing list