Closed Abuelodelanada closed 2 years ago
The method was updated:
def is_valid_uuid(self, uuid):
"""Validate the supplied UUID against the Juju Model UUID pattern."""
# TODO:
# Harness is harcoding an UUID that is v1 not v4: f2c1b2a6-e006-11eb-ba80-0242ac130004
# See: https://github.com/canonical/operator/issues/779
#
# >>> uuid.UUID("f2c1b2a6-e006-11eb-ba80-0242ac130004").version
# 1
#
# we changed the validation of the 3ed UUID block: 4[a-f0-9]{3} -> [a-f0-9]{4}
# See: https://github.com/canonical/operator/blob/main/ops/testing.py#L1094
#
# Juju in fact generates a UUID v4: https://github.com/juju/utils/blob/master/uuid.go#L62
# but does not validate it is actually v4:
# See:
# - https://github.com/juju/utils/blob/master/uuid.go#L22
# - https://github.com/juju/schema/blob/master/strings.go#L79
#
# Once Harness fixes this, we should remove this comment and refactor the regex or
# the entire method using the uuid module to validate UUIDs
regex = re.compile(
"^[a-f0-9]{8}-?[a-f0-9]{4}-?[a-f0-9]{4}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}$"
)
return bool(regex.match(uuid))
The fix in the Operator framework was merged in this PR
I would like to work on this issue
Hi @grequa
We are happy that you want to work on this issue!
Let me know if you need any guidance. You can chat with us in this Mattermost channel
how exactly do I run tests for this?
You need to install tox
and the run tox -e unit
for unit tests.
In this file you can see all the tasks you can run with tox
Today the
is_valid_uuid
method inJujuTopology
class, utilises a regex to validate UUID v4:An old friend told me many years ago:
Jokes aside, regular expressions are powerful but complex to read sometimes.
We can avoid regex in this case by using the python
uuid
module. The result is much easy to read and maintain.