Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

sratcliffe
Copy link
Contributor

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.

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.
Copy link
Contributor

@ludwigschwardt ludwigschwardt left a 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')))
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

try:
xml_doc = etree.fromstring(bytes(bytearray(xml_string, encoding='utf-8')))
except etree.XMLSyntaxError as e:
raise ValueError(e)
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

try:
return validators[validator_name].validate(string_to_validate)
except KeyError:
raise KeyError("Specified validator {} doesn't map to an installed"
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@@ -38,6 +38,11 @@ class StoreUnavailable(OSError, ChunkStoreError):
"""Could not access underlying storage medium (offline, auth failed, etc)."""


class NotSupported(ChunkStoreError):
Copy link
Contributor

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?

Copy link
Contributor Author

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.")
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants