Juan Hernandez has uploaded a new change for review.

Change subject: cli: Check existence of collection before adding
......................................................................

cli: Check existence of collection before adding

Currently when the user types a command that contains a wrong
subcollection name we try to find the corresponding subcollection
appending "s" to the name given by the user and using it to call the
"getattr" method on the object. This fails with an internal Python error
message. For example, if the user types the following command:

  # add snapshots --description 'My snap' --vm-identifier myvm

The resulting message is the following:

  unknown error: 'VM' object has no attribute 'snapshotss'

This happens because we are not checking with "hasattr" before calling
"getattr".

This patch changes the add action implementation so that it checks for
the existence of the subcollection before trying to get it. The result
will be just a more meaningful message:

  error: cannot create "snapshots" because snapshotss collection is
  not available or given arguments not valid.

This is the same behaviour that we currently have for top level
collections.

Change-Id: I435314037808b99fe947ceded6d75e3129fa78e6
Bug-Url: https://bugzilla.redhat.com/1043500
Signed-off-by: Juan Hernandez <[email protected]>
---
M src/ovirtcli/command/add.py
1 file changed, 2 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-cli refs/changes/57/23557/1

diff --git a/src/ovirtcli/command/add.py b/src/ovirtcli/command/add.py
index d018845..01d922f 100644
--- a/src/ovirtcli/command/add.py
+++ b/src/ovirtcli/command/add.py
@@ -141,8 +141,8 @@
         typs = self.get_singular_types(method='add', typ=args[0])
 
         if base:
-            collection = getattr(base, typ)
-
+            if hasattr(base, typ):
+                collection = getattr(base, typ)
         else:
             connection = self.check_connection()
             if hasattr(connection, typ):


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I435314037808b99fe947ceded6d75e3129fa78e6
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine-cli
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to