Change in vdsm[master]: vdsm/storage/misc.py: ensure uuid input is str or unicode fo...

danken at redhat.com danken at redhat.com
Tue Apr 24 06:43:45 UTC 2012


Dan Kenigsberg has submitted this change and it was merged.

Change subject: vdsm/storage/misc.py: ensure uuid input is str or unicode for regex
......................................................................


vdsm/storage/misc.py: ensure uuid input is str or unicode for regex

When abusing the createVolume() method by passing numeric values
as UUIDs, the validation regex needs a string to process and
throws an exception when it isn't:

Traceback (most recent call last):
  File "/usr/share/vdsm/storage/task.py", line 861, in _run
    return fn(*args, **kargs)
  File "/usr/share/vdsm/logUtils.py", line 38, in wrapper
    res = f(*args, **kwargs)
  File "/usr/share/vdsm/storage/hsm.py", line 1206, in createVolume
    misc.validateUUID(imgUUID, 'imgUUID')
  File "/usr/share/vdsm/storage/misc.py", line 525, in validateUUID
    m = UUID_REGEX.match(uuid)
TypeError: expected string or buffer

And on the client side, I get a less than useful error:

Traceback (most recent call last):
  File "create_a_vm.py", line 98, in <module>
    BLANK_UUID, BLANK_UUID))
  File "create_a_vm.py", line 19, in vdsOK
    raise Exception(str(d))
Exception: {'status': {'message': "Error creating a new volume: ('sdUUID=99d43d50-5946-4451-8e12-9d85cb426e19, spUUID=150e55ab-e68c-411c-af30-587071905216, imgUUID=4194304, size=4, volFormat=2, preallocate=rootfs, diskType=7bdf7b4b-4909-41ce-a9c0-9bc06ba045fe, volUUID=00000000-0000-0000-0000-000000000000, desc=00000000-0000-0000-0000-000000000000, srcImgUUID=00000000-0000-0000-0000-000000000000, srcVolUUID=00000000-0000-0000-0000-000000000000',)", 'code': 205}}

We can test that the input is str or unicode before attempting to regex
if it's something else, raise an exception.

Now, I get:

Traceback (most recent call last):
  File "create_a_vm.py", line 98, in <module>
    BLANK_UUID, BLANK_UUID))
  File "create_a_vm.py", line 19, in vdsOK
    raise Exception(str(d))
Exception: {'status': {'message': "Invalid parameter: 'imgUUID=4194304'", 'code': 1000}}

Which explains to me my error quite well.

V2 -> V3:
    - change check to use isinstance(s, basestring) per Dan Kenigsberg
V1 -> V2:
    - Fix case where we pass in a string, but it's not a UUID as
      Reported by Dan Kenigsberg <danken at redhat.com>

Change-Id: If16466e88a50d3af03ae7830d4d8148ebf69d0d9
Signed-off-by: Ryan Harper <ryanh at us.ibm.com>
---
M vdsm/storage/misc.py
1 file changed, 6 insertions(+), 4 deletions(-)

Approvals:
  Dan Kenigsberg: Verified; Looks good to me, approved


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

Gerrit-MessageType: merged
Gerrit-Change-Id: If16466e88a50d3af03ae7830d4d8148ebf69d0d9
Gerrit-PatchSet: 4
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ryan Harper <ryanh at us.ibm.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Eduardo <ewarszaw at redhat.com>
Gerrit-Reviewer: Igor Lvovsky <ilvovsky at redhat.com>
Gerrit-Reviewer: Lei Li <lilei at linux.vnet.ibm.com>
Gerrit-Reviewer: Ryan Harper <ryanh at us.ibm.com>


More information about the vdsm-patches mailing list