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

Initial implementation of pydantic validation for site adapters #231

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

Conversation

giffels
Copy link
Member

@giffels giffels commented Feb 28, 2022

This pull request enables pydantic input validation for the configuration of the site adapters used in TARDIS. In addition, it enables support for OpenStack application credentials.

  • Implement the general concept on how to invoke pydantic input validation on site adapters.

    • Each site adapter class implements its AdapterConfigurationModel
    • In the constructor of each site adapter class self._configuration_validation_model is point to AdapterConfigurationModel
    • When accessing the configuration using self.configuration, the validation is invoked in the SiteAdapter interface implementation of the configuration property.
  • Add configuration model for

    • OpenStack adapter
    • CloudStack adapter
    • HTCondor adapter
    • Slurm adapter
    • Moab adapter
    • Kubernetes adapter
    • Fake adapter
  • Add support for OpenStack application credentials

@codecov-commenter
Copy link

codecov-commenter commented Feb 28, 2022

Codecov Report

Base: 98.85% // Head: 98.91% // Increases project coverage by +0.06% 🎉

Coverage data is based on head (ddc952e) compared to base (459f3de).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #231      +/-   ##
==========================================
+ Coverage   98.85%   98.91%   +0.06%     
==========================================
  Files          55       55              
  Lines        2262     2387     +125     
==========================================
+ Hits         2236     2361     +125     
  Misses         26       26              
Impacted Files Coverage Δ
tardis/adapters/sites/cloudstack.py 100.00% <100.00%> (ø)
tardis/adapters/sites/fakesite.py 100.00% <100.00%> (ø)
tardis/adapters/sites/htcondor.py 100.00% <100.00%> (ø)
tardis/adapters/sites/kubernetes.py 100.00% <100.00%> (ø)
tardis/adapters/sites/moab.py 100.00% <100.00%> (ø)
tardis/adapters/sites/openstack.py 100.00% <100.00%> (ø)
tardis/adapters/sites/slurm.py 100.00% <100.00%> (ø)
tardis/interfaces/siteadapter.py 100.00% <100.00%> (ø)
tardis/utilities/attributedict.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@giffels giffels force-pushed the enable-pydantic-validation-site-adapter branch from 4cc1d9d to 856a6e7 Compare February 28, 2022 20:21
@giffels giffels force-pushed the enable-pydantic-validation-site-adapter branch from 5116617 to 1f6c452 Compare March 8, 2022 08:19
@giffels giffels force-pushed the enable-pydantic-validation-site-adapter branch from 1f6c452 to 772eac9 Compare March 15, 2022 11:30
@giffels giffels force-pushed the enable-pydantic-validation-site-adapter branch from 772eac9 to ddd77b9 Compare April 19, 2022 13:21
@giffels giffels force-pushed the enable-pydantic-validation-site-adapter branch from ddd77b9 to 09aea26 Compare May 6, 2022 14:26
@giffels giffels force-pushed the enable-pydantic-validation-site-adapter branch from bfca82f to 2285f1f Compare May 17, 2022 09:52
@giffels giffels force-pushed the enable-pydantic-validation-site-adapter branch from 2285f1f to 3a8ee41 Compare May 25, 2022 12:51
@giffels giffels force-pushed the enable-pydantic-validation-site-adapter branch from 3a8ee41 to 7dd3ba6 Compare June 24, 2022 09:00
@giffels giffels force-pushed the enable-pydantic-validation-site-adapter branch 2 times, most recently from cf3cf65 to 6df1eb1 Compare July 14, 2022 09:06
@giffels giffels requested a review from maxfischer2781 July 15, 2022 08:22
@giffels giffels marked this pull request as ready for review July 15, 2022 14:57
@giffels giffels requested review from a team and mschnepf and removed request for a team July 15, 2022 14:57
@giffels giffels force-pushed the enable-pydantic-validation-site-adapter branch from df1fbd4 to d17dbb3 Compare July 18, 2022 09:54
@giffels giffels force-pushed the enable-pydantic-validation-site-adapter branch from d17dbb3 to eca3399 Compare July 28, 2022 09:49
Copy link
Member

@mschnepf mschnepf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one question two times. Otherwise it looks good. Thanks a lot. :-)

tardis/adapters/sites/moab.py Outdated Show resolved Hide resolved
tardis/adapters/sites/slurm.py Outdated Show resolved Hide resolved
@giffels giffels requested a review from mschnepf July 29, 2022 15:25
mschnepf
mschnepf previously approved these changes Aug 2, 2022
Copy link
Member

@mschnepf mschnepf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. 👍

@giffels giffels force-pushed the enable-pydantic-validation-site-adapter branch from 3b7b992 to c9ab342 Compare August 30, 2022 08:30
Copy link
Member

@maxfischer2781 maxfischer2781 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good, nice to see so much manual config-reading gone or accumulated. I've dropped a few comments, but keep in mind I haven't worked with Pydantic extensively – it might be that they just won't work.

self._executor = getattr(self.configuration, "executor", ShellExecutor())
bulk_size = getattr(self.configuration, "bulk_size", 100)
bulk_delay = getattr(self.configuration, "bulk_delay", 1.0)
self._configuration_validation_model = HTCondorAdapterConfigurationModel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understood things, you can (and actually intended to) set these as class attributes. This would make it clearer that the attribute really does not depend on instance data and it's not just a typo.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Thanks for the hint.


import logging

logger = logging.getLogger("cobald.runtime.tardis.adapters.sites.openstack")


class OpenStackAdapterConfigurationModel(SiteAdapterBaseModel):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether this works in practice, but it looks like what you actually want is a Union where one part is only the application_credential and the other part is only the user+pwd+... part (both including auth_url).

So basically one class ApplicationConfigurationModel(SiteAdapterBaseModel): ..., one class UserConfigurationModel(SiteAdapterBaseModel): ... and then using Union[ApplicationConfigurationModel, UserConfigurationModel]. That could get rid of the manual either-or-exclusive test code. Probably a good idea to use a shorter naming scheme if you give this a try... 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I will check pydantic documentation and give it try.

tardis/interfaces/siteadapter.py Outdated Show resolved Hide resolved
tardis/interfaces/siteadapter.py Outdated Show resolved Hide resolved
tardis/interfaces/siteadapter.py Outdated Show resolved Hide resolved
"""
Property to access the configuration_validation model of a site adapter
implementation and ensuring that all sub-classes of the SiteAdapter have
a _configuration_validation_model class variable.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description and usage seem to confuse class and instance attributes. From the description and usage it seems you wanted class attributes, the assignments indicate instance attributes and the error mixes both. Based on the semantics I would guess you actually want class attributes.

Can you adjust this to be consistent? I think it needs to be addressed just here and when assigning the models to the classes/instances.

tardis/utilities/attributedict.py Outdated Show resolved Hide resolved
@giffels giffels force-pushed the enable-pydantic-validation-site-adapter branch from 10461fc to 65ad254 Compare September 27, 2022 07:50
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.

4 participants