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

Implement a user configuration #84

Open
psss opened this issue Jan 16, 2020 · 9 comments · May be fixed by #3339
Open

Implement a user configuration #84

psss opened this issue Jan 16, 2020 · 9 comments · May be fixed by #3339
Assignees
Labels
area | config User configuration
Milestone

Comments

@psss
Copy link
Collaborator

psss commented Jan 16, 2020

Seems we'll soon need a way how to store user configuration data. For example tmt test export --nitrate might need a url to the test case management system.

Brainstorming first ideas here: What about storing data under $HOME/.config/tmt in the form of an fmf tree? For the above-mentioned example we could have something like this:

/test/convert/nitrate:
    url: https://nitrate.example.com/

This would work naturaly / consistently with how the rest of data is handled in tmt.

@psss
Copy link
Collaborator Author

psss commented Mar 23, 2020

Config story has been already described in detail for user and system scenarios covering L2 metadata.

@psss
Copy link
Collaborator Author

psss commented Jun 29, 2021

Proposing for 2.0 as discussed on today's hacking session.

@psss psss added this to the 2.0 milestone Jun 29, 2021
@psss
Copy link
Collaborator Author

psss commented Jun 29, 2021

This is blocking #813.

@RHEmployee
Copy link
Collaborator

Is this still free? It can be nice to play around and try to implement:
#38

@psss
Copy link
Collaborator Author

psss commented Jan 11, 2022

Yes, this is free. I expect the configuration format will need some discussion though.

@psss psss removed the enhancement label Sep 17, 2024
@psss psss removed this from the 2.0 milestone Sep 25, 2024
@therazix therazix self-assigned this Sep 25, 2024
@psss psss added this to the 1.38 milestone Sep 26, 2024
@psss
Copy link
Collaborator Author

psss commented Oct 23, 2024

@therazix, regarding the implementation I would recommend to start with simplifying the following code:

tmt/tmt/utils/jira.py

Lines 85 to 124 in e485608

# Check for the 'link' config section, exit if config missing
try:
config_tree = tmt.utils.Config().fmf_tree
link_config = cast(Optional[fmf.Tree], config_tree.find('/link'))
except tmt.utils.MetadataError:
return None
if not link_config:
return None
# Check the list of configured issues trackers
issue_trackers: Any = link_config.data.get('issue-tracker')
if not issue_trackers:
raise tmt.utils.GeneralError(
"No 'issue-tracker' section found in the 'link' config.")
if not isinstance(issue_trackers, list):
raise tmt.utils.GeneralError(
"The 'issue-tracker' section should be a 'list'.")
# Find Jira instance matching the issue url
issue_tracker: Any
for issue_tracker in issue_trackers:
if not isinstance(issue_tracker, dict):
raise tmt.utils.GeneralError(
"Issue tracker config should be a 'dict'.")
# Tracker type must match
issue_tracker_type: Any = issue_tracker.get("type")
if not isinstance(issue_tracker_type, str) or issue_tracker_type != "jira":
continue
# Issue url must match
jira_server_url: Any = issue_tracker.get("url")
if not isinstance(jira_server_url, str):
raise tmt.utils.GeneralError(
"Issue tracker 'url' should be a string.")
if issue_url.startswith(jira_server_url):
return JiraInstance(cast(IssueTracker, issue_tracker), logger=logger)

Instead of the complex checking of the types and values, the code above should probably just do something like:

issue_trackers = tmt.utils.Config().get("/link/issue-trackers")

or maybe even something like this?

issue_trackers = tmt.utils.Config().link.issue-trackers

The rest would be handled by the Config class. @happz might also have some hints about how the implementation could look like.

@happz
Copy link
Collaborator

happz commented Oct 23, 2024

@LecrisUT Cc ^^ would you have any tips WRT implementation of "containers with configuration"? In the light of current code in tmt.utils, the moved one in tmt.container, and possibly the future with attrs & co., how can we make configuration easier to use for developers, with guarantees of types and stuff like that?

It would be the best if we could, cheaply and easily, if possible, land on a state where the user would be notified if /link/issue-trackes is not a list of expected structures, and where the developer wouldn't need to worry about whether isinstance(/link/issue-trackers, list) and so on. Right now, with fmf id and raw config, we need to use the validation layer and then have _RawFoo typed dicts that get converted into actual data classes we define. Something more dynamic, but with the same guarantees and visibility for linters and IDEs would be very nice to have.

Configuration is very similar to any other fmf tmt consumes - we can definitely use what we have now, and improve everything later, but, maybe we could use the configuration as a prototyping ground for the better state of the future.

@LecrisUT
Copy link
Contributor

If I read this correctly the goal is for the user configurations to override the contents of the fmf file effectively? There is an ambiguity of how to order the preference between:

  • default value (no field in the project's fmf)
  • user config fmf
  • project's fmf field specified

Maybe if we put some more restrictions that the user config can only affect leaf configurations the intent could be clearer. But then it can get quite weird figuring out which user config applies to the fmf tree of which project. Or are the fmf fields defined in the user configuration completely orthogonal, in which case what would the path signify? Are only a few fields or containers meant to be linked with configurations, maybe the class definition can be changed to a decorator instead of inheritance?

About the container part, it would depend on the part above, but generally I was thinking that the containers are just the datastructures and basically as close to a json-schema as possible. The reading of the source: fmf tree, click arguments or configuration could be completely separate from this. How to unify the definitions within the field would be a bit more tricky because that one is getting quite dense in the amount of arguments that are being passed, if only you could decorate those 😮‍💨. Well there is a way I guess that attrs is using by wrapping dummy functions 1, but that would get verbose quite quickly.

Footnotes

  1. https://www.attrs.org/en/stable/examples.html#defaults

@thrix thrix modified the milestones: 1.38, 1.39 Oct 25, 2024
@psss
Copy link
Collaborator Author

psss commented Oct 29, 2024

If I read this correctly the goal is for the user configurations to override the contents of the fmf file effectively? There is an ambiguity of how to order the preference between...

I see, the original story describing/brainstorming the possible features can be confusing. I think we would like to start small first. Without handling user versus system configuration and without interaction with test or plan metadata.

We have the following tangible use case for the tmt link command: An fmf node /link saved under the ~/.config/tmt tree intended for storing supported issue trackers. The config can look like this:

issue-tracker:
  - type: jira
    url: https://issues.redhat.com
    tmt-web-url: http://tmt.testing-farm.io/
    token: <secret>

This is in no way related to affecting default values of tests or plans. It's a config to be used solely by the tmt link command. So, as the first step, here we would like to validate that it has the expected format and store the values in easily accessible objects.

@therazix therazix linked a pull request Nov 2, 2024 that will close this issue
8 tasks
@psss psss added the area | config User configuration label Nov 21, 2024
@psss psss modified the milestones: 1.39, 1.40 Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area | config User configuration
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants