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

Add new API for loading config by content set label #44

Closed
wants to merge 7 commits into from

Conversation

negillett
Copy link
Member

@negillett negillett commented Aug 16, 2019

Previously, a file name was needed in order to load a specific
configuration file. Now one may provide a content set label instead.

Fixes #42

Previously, a file name was needed in order to load a specific
configuration file. Now one may provide a content set label instead.
ubiconfig/_impl/loaders/gitlab.py Outdated Show resolved Hide resolved
Removed storing of raised errors and replaced their subsequent calls
with a new ConfigNotFound exception.
Copy link
Member

@rohanpm rohanpm left a comment

Choose a reason for hiding this comment

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

Assuming that load_from_cs_label is intended as new public API:

  • It ought to have a doc string
  • The same API should be available for any kind of loader - right now you've fragmented the API such that this new method is only available for the gitlab loader. So, for example, you can't use it on a local copy of config files.
  • This has added a new silent requirement that files are named with a certain scheme (filename matching up with content set name), yet this isn't documented anywhere and nor is it enforced by any check on the repo. It's also a redundant requirement as all the config files contain the content set labels within themselves. So this is now forcing two pieces of data to be maintained in sync with each other.

Regarding that last point - as I commented on the related JIRA issue, I really think we should not do that unless there is some strong reason to (e.g. is it going to solve a performance issue which otherwise has no reasonable solution).

The way I'd actually suggest implementing it is to:

  • implement this on the shared Loader class
  • make it work by calling load_all(recursive=True) and filtering the result

In other words, there is an implementation on the base class which loads all the config, then filters to just the requested content set(s).

Specific Loader implementations could potentially override it for a faster implementation, e.g. if loading each config file is expected to be slow. Ideally, that would be done without introducing some new requirement on the naming of files.

Where it previously attempted to compute the file name for loading, the
new API will now load all config files and return only the one in which
the label was found, as file names may be inconsistent.
@negillett negillett requested a review from rohanpm August 20, 2019 19:36
Copy link
Contributor

@JayZ12138 JayZ12138 left a comment

Choose a reason for hiding this comment

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

Also, could you bump the version in setup.py and add what you did to CHANGELOD.md?

ubiconfig/_impl/loaders/local.py Show resolved Hide resolved
@negillett
Copy link
Member Author

Also, could you bump the version in setup.py and add what you did to CHANGELOD.md?

Aren't these items for a release?

@JayZ12138
Copy link
Contributor

Also, could you bump the version in setup.py and add what you did to CHANGELOD.md?

Aren't these items for a release?

Nope.
When you add a new API, you always bump the version in setup.py, though it won't be released by you immediately.
Also, you should add your change to CHANGELOG.md under the 'unreleased' section.

@negillett
Copy link
Member Author

Also, could you bump the version in setup.py and add what you did to CHANGELOD.md?

Aren't these items for a release?

Nope.
When you add a new API, you always bump the version in setup.py, though it won't be released by you immediately.
Also, you should add your change to CHANGELOG.md under the 'unreleased' section.

Okay. I don't think we're proceeding with this issue #42 but I'll keep that in mind.

@@ -9,6 +9,12 @@ def test_no_load():
Loader().load('something.yaml')


def test_no_load_by_cs_label():
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is passing because we are calling load_by_cs_label from Loader in base class, which calls load_all, from base class too, and that's the method that is raising the NotImplementedError. So the test is asserting that we cannot call load_by_cs_label from base class. Can you update the doc string?

@@ -51,6 +50,10 @@ def load_all(self, recursive=False):

return ubi_configs

def load_by_cs_label(self, cs_label):
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be removed, as we are using the implementation from Loader.

@@ -44,6 +44,10 @@ def load_all(self, recursive=False):

return ubi_configs

def load_by_cs_label(self, cs_label):
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as the one for GitLab, can be removed.

Copy link
Contributor

@danrodrig danrodrig left a comment

Choose a reason for hiding this comment

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

The load_by_cs_label method on Gitlab and Local class can be removed. And the test_no_load_by_cs_label doc string should be updated, as commented in the code. Also, load_by_cs_label doc string.

def load_by_cs_label(self, cs_label):
"""
Load all the config files from repo and return one containing config for
the provided content set label.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should expose the implementation of the method here. Rather, would be better to comment only on the outcome. It returns an ubiconfig matching the input or output content set label. Raises if there is no config for that label.

@negillett negillett closed this Aug 26, 2019
@negillett negillett deleted the 7374 branch August 26, 2019 13:30
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.

Support for getting config by content set label
5 participants