summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgordon chung <gord@live.ca>2015-12-01 23:44:47 -0500
committergordon chung <gord@live.ca>2015-12-02 08:19:26 -0500
commit6f1de9ca0471e3a6e079f89ad03adf39e8ea97d0 (patch)
tree3713a06613250b8604d4ddf16c480f2dbc5a46de
parentb6a74b729c0d00fd9374046832ee7cef3a9a0528 (diff)
downloadpycadf-6f1de9ca0471e3a6e079f89ad03adf39e8ea97d0.tar.gz
relax id validation2.0.1
we want uuid, unfortunately most of openstack is a mess so we can't have nice things. this patch makes it so we continue to allow basically anything that is a string but we warn that they should stop this. Change-Id: I2a89aed143c22b9a3e2261d5473af93c1cad67cd Closes-Bug: #1521844
-rw-r--r--pycadf/identifier.py12
-rw-r--r--pycadf/tests/test_cadf_spec.py11
2 files changed, 18 insertions, 5 deletions
diff --git a/pycadf/identifier.py b/pycadf/identifier.py
index cb60627..c032bd2 100644
--- a/pycadf/identifier.py
+++ b/pycadf/identifier.py
@@ -13,9 +13,11 @@
# the License.
import hashlib
import uuid
+import warnings
from debtcollector import removals
from oslo_config import cfg
+import six
CONF = cfg.CONF
opts = [
@@ -54,7 +56,9 @@ def is_valid(value):
return True
try:
uuid.UUID(value)
- except ValueError:
- return False
- else:
- return True
+ except (ValueError, TypeError):
+ if not isinstance(value, six.string_types) or not value:
+ return False
+ warnings.warn('Invalid uuid. To ensure interoperability, identifiers'
+ 'should be a valid uuid.')
+ return True
diff --git a/pycadf/tests/test_cadf_spec.py b/pycadf/tests/test_cadf_spec.py
index a5a4dde..6223060 100644
--- a/pycadf/tests/test_cadf_spec.py
+++ b/pycadf/tests/test_cadf_spec.py
@@ -15,6 +15,8 @@
import time
import uuid
+import mock
+
from pycadf import attachment
from pycadf import cadftype
from pycadf import credential
@@ -35,9 +37,16 @@ from pycadf import timestamp
class TestCADFSpec(base.TestCase):
- def test_identifier_empty(self):
+ @mock.patch('pycadf.identifier.warnings.warn')
+ def test_identifier(self, warning_mock):
+ # empty string
self.assertFalse(identifier.is_valid(''))
+ # generated uuid
self.assertTrue(identifier.is_valid(identifier.generate_uuid()))
+ self.assertFalse(warning_mock.called)
+ # any string
+ self.assertTrue(identifier.is_valid('blah'))
+ self.assertTrue(warning_mock.called)
def test_endpoint(self):
endp = endpoint.Endpoint(url='http://192.168.0.1',