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.
ludwigschwardt
left a comment
There was a problem hiding this comment.
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.
Out of curiosity, why bytes and bytesarray?
There was a problem hiding this comment.
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.
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.
This is a candidate for raise_from.
| 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.
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.
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.
Maybe raise_from(..., None) here to suppress the double KeyError in the chain.
| @@ -1,5 +1,6 @@ | |||
| coverage | |||
| funcsigs | |||
| lxml==4.3.3 | |||
There was a problem hiding this comment.
Do you want this in requirements.txt as well, to be used on site?
There was a problem hiding this comment.
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
| """Could not access underlying storage medium (offline, auth failed, etc).""" | ||
|
|
||
|
|
||
| class NotSupported(ChunkStoreError): |
There was a problem hiding this comment.
This name is a bit vague... How about UnsupportedStoreFeature?
There was a problem hiding this comment.
Fair enough - changed
| 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.
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.
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.
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.
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.