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 test for step data update with CLI options #1939

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

happz
Copy link
Collaborator

@happz happz commented Mar 23, 2023

This functionality has been inside BasePlugin, and today a bug was reported with its handling of flag-like options. Therefore, this patch:

  • extracts the code into a standalone function, complementing the rest of normalization code,
  • fixes the bug,
  • fixes a few more issues discovered, mostly readability,
  • adds a pile of comment WRT various related issues, and
  • adds a unit test.

@happz happz force-pushed the normalize-options-properly branch from f0c5216 to 6e18c3c Compare March 23, 2023 13:57
@psss psss added this to the 1.22 milestone Mar 23, 2023
@happz happz added bug Something isn't working code | cli Changes related to the command line interface labels Mar 23, 2023
@thrix thrix requested review from thrix and janhavlin April 3, 2023 14:28
@thrix thrix self-assigned this Apr 3, 2023
tmt/utils.py Show resolved Hide resolved
tmt/utils.py Outdated Show resolved Hide resolved
@happz happz force-pushed the normalize-options-properly branch from 6e18c3c to 00107c3 Compare April 3, 2023 14:47
@psss psss requested a review from thrix April 11, 2023 08:34
Copy link
Collaborator

@thrix thrix left a comment

Choose a reason for hiding this comment

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

LGTM, test failed on some network glitch, restarted

Copy link
Collaborator

@psss psss left a comment

Choose a reason for hiding this comment

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

The default handling does not seem to be ok.

# `self.data`, or it has been replaced with whatever came from an
# fmf node.
if value == container._default(keyname):
continue
Copy link
Collaborator

Choose a reason for hiding this comment

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

This does not seem to be right: When the fmf config contains a non-default value we are not able to override it from the command line by the default one. Confirmed with this plan:

provision:
    how: container
    image: fedora:36
execute:
    how: tmt
    script: tmt --help

Trying to overide with fedora does not work:

> tmt run -av provision -h container -i fedora
/var/tmp/tmt/run-153
Found 1 plan.

/plans/example
    discover
        how: shell
        summary: 1 test selected
            /script-00
    provision
        how: container
        image: fedora:36
        name: tmt-153-IAAErkjE
        full name: default-0
        distro: Fedora Linux 36 (Container Image)
        kernel: 6.1.18-200.fc37.x86_64
        summary: 1 guest provisioned

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All of this is just wrong... It's all guessing, and it's a big smoking pile of corner cases. Let me find out what exactly breaks when this particular check is dropped, I bet there's something just waiting to bite us :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Summary from the call: We need to find a reliable way how to detect if a flag option was provided on the command line or not (versus set as the default). Moving to the next release because of the regression (unable to override non-default config value with default value provided on the command line).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, it's the boolean value of these defaults. TL;DR, there's no way for code to tell whether -i was used on the command line, or whether the fedora string comes from the default value. For the code, these two look the same: -h container vs -h container -i fedora, both would present fedora as the value of the --image CLI option. Now, in the first case, we do not want to overwrite fmf source, in the second we do want to. How to tell the difference?

As briefly discussed, there is a couple of options, none trivial or immediately available. I'd try to look into introducing a callback that would notify us when an option was actually encountered on a command line, and we'd then simply use the value no matter what it ould be. Postponing this PR to avoid bigger harm.

bar: List[str] = field(option='--bar', default_factory=list, multiple=True)
baz: str = 'undefined'
qux: List[str] = field(option='--qux', default_factory=list, multiple=True)
corge: bool = field(option='--corge / --no-corge', default=True, multiple=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is multiple=True valid for a flag?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, depends, could be. --foo --no-foo --foo might look pointless, but maybe there's a use for it. It is definitely a copy & paste issue rather than intention.

@psss psss modified the milestones: 1.22, 1.23 Apr 11, 2023
@happz happz force-pushed the normalize-options-properly branch from 00107c3 to 667f238 Compare April 11, 2023 13:20
happz added 3 commits April 17, 2023 09:35
This functionality has been inside `BasePlugin`, and today a bug was
reported with its handling of flag-like options. Therefore, this patch:

* extracts the code into a standalone function, complementing the rest
of normalization code,
* fixes the bug,
* fixes a few more issues discovered, mostly readability,
* adds a pile of comment WRT various related issues, and
* adds a unit test.
@happz happz force-pushed the normalize-options-properly branch from 667f238 to 68a650d Compare April 17, 2023 07:36
@psss psss modified the milestones: 1.23, 1.24 Apr 25, 2023
@happz happz marked this pull request as draft May 11, 2023 15:28
@happz happz removed this from the 1.24 milestone May 26, 2023
@psss
Copy link
Collaborator

psss commented Nov 21, 2023

Any plans with this one, @happz?

@happz happz requested a review from thrix July 2, 2024 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working code | cli Changes related to the command line interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants