-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include lifecycle policy tests #239
base: master
Are you sure you want to change the base?
Conversation
We can't test expiry directly, firstly because minio doesn't support lifecycle polices, and secondly because the minimum expiry time is 1 day. This basically just test the infrastructure and that the schema for the policy is created correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still need to understand the use case a bit better...
if `xml_string` cannot be parsed into a valid XML document | ||
""" | ||
try: | ||
xml_doc = etree.fromstring(bytes(bytearray(xml_string, encoding='utf-8'))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, why bytes
and bytesarray
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python2.7 doesn't allow encoding types in bytes, but does in bytearray. Kludge to keep 2/3 compatible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be something in future.utils
to force things one way or another.
But also, why encode at all? lxml.etree.fromstring seems perfectly happy to take Unicode.
katdal/schemas/__init__.py
Outdated
try: | ||
xml_doc = etree.fromstring(bytes(bytearray(xml_string, encoding='utf-8'))) | ||
except etree.XMLSyntaxError as e: | ||
raise ValueError(e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a candidate for raise_from
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
raise ValueError(e) | ||
if not self.validator.validate(xml_doc): | ||
log = self.validator.error_log | ||
raise etree.DocumentInvalid(log.last_error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are converting etree.XMLSyntaxError
to ValueError
but leaving etree.DocumentInvalid
as is... This seems a bit inconsistent. Will the end user typically be expected to catch invalid document exceptions? If that's the case, I'd probably also transmogrify it for the user's convenience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simply because the XMLSyntaxError is quite messy. I also wanted to easily catch the difference between an XML syntax error and an invalid document. If I didn't use DocumentInvalid, then ValueError would be the sensible standard exception but wouldn't allow this differentiation.
katdal/schemas/__init__.py
Outdated
try: | ||
return validators[validator_name].validate(string_to_validate) | ||
except KeyError: | ||
raise KeyError("Specified validator {} doesn't map to an installed" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe raise_from(..., None)
here to suppress the double KeyError
in the chain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -1,5 +1,6 @@ | |||
coverage | |||
funcsigs | |||
lxml==4.3.3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want this in requirements.txt
as well, to be used on site?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope - the import checking handles this being missing for production systems and lets you know that validation wont be used if it is missing.
katdal/chunkstore.py
Outdated
@@ -38,6 +38,11 @@ class StoreUnavailable(OSError, ChunkStoreError): | |||
"""Could not access underlying storage medium (offline, auth failed, etc).""" | |||
|
|||
|
|||
class NotSupported(ChunkStoreError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name is a bit vague... How about UnsupportedStoreFeature
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough - changed
@@ -467,6 +483,10 @@ def create_array(self, array_name): | |||
|
|||
if self.expiry_days > 0: | |||
xml_payload = _BASE_LIFECYCLE_POLICY.format(self.expiry_days) | |||
if self.validate_xml_policies: | |||
if not schemas.has_lxml: | |||
raise ImportError("XML schema validation requires lxml to be installed.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to link to the original error via raise_from
. See e.g. the RDB reader handling in katsdptelstate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I agree - I prefer the very unambiguous nature of just telling the user that you need lxml if you want to use validators.
@@ -467,6 +483,10 @@ def create_array(self, array_name): | |||
|
|||
if self.expiry_days > 0: | |||
xml_payload = _BASE_LIFECYCLE_POLICY.format(self.expiry_days) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So xml_payload
is always _BASE_LIFECYCLE_POLICY
? When would it not validate - a bad value for expiry_days
? It seems like a lot of effort to solve future problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The grand scheme is that you will sometimes want to override the base for very user specific things - like managing storage migration say. I can see us ending up with quite a number of policies as future versions of CEPH support more elaborate management via lifecycle policies.
We can't test expiry directly, firstly because minio doesn't support lifecycle polices, and secondly because the minimum expiry time is 1 day.
This basically just test the infrastructure and that the schema for the policy is created correctly.