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

Correctly update environment from the importing plan #2452

Merged
merged 1 commit into from
Dec 5, 2023

Conversation

thrix
Copy link
Collaborator

@thrix thrix commented Nov 3, 2023

The environment from the importing plan was ignored.

As agreed, let's make the environment a cached property and inherit
the importing plan environment automatically.

Resolves #2446

Pull Request Checklist

  • implement the feature
  • extend the test coverage

@thrix thrix requested review from kkaarreell, janhavlin, happz and psss and removed request for happz, lukaszachy, psss and janhavlin November 3, 2023 19:15
@thrix
Copy link
Collaborator Author

thrix commented Nov 3, 2023

@happz @psss can you check if this would be the obvious fix? then I can write some tests.

Maybe some unit tests would be nice?

@thrix thrix mentioned this pull request Nov 3, 2023
5 tasks
@LecrisUT
Copy link
Contributor

LecrisUT commented Nov 3, 2023

Weird thing is that this is being tested:

/importing-other-plan-and-modify-environment:
summary: Import plan and modify it with environment variable
environment:
VARIABLE: foobar
plan:
import:
url: https://github.com/teemtee/tmt
path: /tests/plan/import/modify-data
name: /plans/must-be-imported-and-modified

@thrix
Copy link
Collaborator Author

thrix commented Nov 6, 2023

Weird thing is that this is being tested:

/importing-other-plan-and-modify-environment:
summary: Import plan and modify it with environment variable
environment:
VARIABLE: foobar
plan:
import:
url: https://github.com/teemtee/tmt
path: /tests/plan/import/modify-data
name: /plans/must-be-imported-and-modified

Thank @LecrisUT looking into why it was not caught

@LecrisUT
Copy link
Contributor

LecrisUT commented Nov 6, 2023

Oh, I have an idea. Could it be that when environment is treated inside defining the plan/test is different from when it is used for execute, i.e. if it's used as replacing a variable in .fmf file vs when used in executing a .sh file?

@thrix thrix self-assigned this Nov 6, 2023
@thrix thrix added this to the 1.30 milestone Nov 6, 2023
@psss
Copy link
Collaborator

psss commented Nov 6, 2023

Could it be that when environment is treated inside defining the plan/test is different from when it is used for execute, i.e. if it's used as replacing a variable in .fmf file vs when used in executing a .sh file?

Yes, seems that the explicit node data expansion handles correctly the case when variable is in the config:

tmt/tmt/base.py

Lines 2345 to 2348 in 722563c

with tmt.utils.modify_environ(self.environment):
self._expand_node_data(node.data, {
key: ','.join(value)
for (key, value) in self._fmf_context.items()})

But its value does not get to the actual environment when an external script is executed.

@psss
Copy link
Collaborator

psss commented Nov 6, 2023

@happz @psss can you check if this would be the obvious fix?

The fix seems to be ok. Although, when reading the code I realized that in a76772f we've introduced double-updating the environment from the command line. This does not hurt but let's get that straight: I've filed #2461 to track this.

then I can write some tests.

Yes, please cover the scenario when the variable is used in an external script, not directly in the fmf file.

tmt/base.py Outdated Show resolved Hide resolved
@thrix thrix changed the title Correctly update imported plan environment Correctly update environment from the importing plan Nov 28, 2023
@thrix thrix requested review from psss and LecrisUT November 28, 2023 20:28
@thrix
Copy link
Collaborator Author

thrix commented Nov 28, 2023

@happz so I moved back from cached_property as mypy is not happy about it:

mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

tmt/steps/__init__.py:1519: error: Cannot determine type of "discover"  [has-type]
tmt/steps/__init__.py:1598: error: Cannot determine type of "provision"  [has-type]
tmt/steps/__init__.py:1684: error: Cannot determine type of "execute"  [has-type]
tmt/steps/__init__.py:1713: error: Cannot determine type of "provision"  [has-type]
tmt/steps/report/__init__.py:95: error: Cannot determine type of "execute"  [has-type]
tmt/steps/discover/__init__.py:199: error: Cannot determine type of "execute"  [has-type]
tmt/steps/discover/__init__.py:201: error: Cannot determine type of "execute"  [has-type]
tmt/steps/discover/__init__.py:233: error: Cannot determine type of "execute"  [has-type]
Found 8 errors in 3 files (checked 59 source files)

@thrix thrix requested a review from lukaszachy December 1, 2023 16:41
@thrix thrix requested a review from LecrisUT December 4, 2023 21:36
@thrix
Copy link
Collaborator Author

thrix commented Dec 4, 2023

@psss I am reading now your comment, I believe my test is enough, even though I am not sure why I added it to basic.sh, anyway, I do not mind it much to revisit this again.

Let me know if you want more proof it works as expected, I believe it does catch the problem, when I run it with old code, my test fails

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.

Yeah, looks good. Thanks for the fix. I just remembered we've agreed on the hacking session that we could use an environment property which could also cover the #2461 but let's handle that one separately.

@psss psss assigned psss and unassigned thrix Dec 5, 2023
@psss psss added command | import The import command command | plans tmt plans command area | environment Environment variables handling labels Dec 5, 2023
@LecrisUT
Copy link
Contributor

LecrisUT commented Dec 5, 2023

I've confirmed that the changes here work as intended

The environment from the importing plan was ignored.

Resolves teemtee#2446

Signed-off-by: Miroslav Vadkerti <[email protected]>
Co-authored-by: Petr Šplíchal <[email protected]>
@psss
Copy link
Collaborator

psss commented Dec 5, 2023

/packit test --identifier full

@psss psss merged commit 0b4f4a7 into teemtee:main Dec 5, 2023
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area | environment Environment variables handling command | import The import command command | plans tmt plans command
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Environment defined in plan is ignored when importing a plan
4 participants