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

Return error message when no fmf root found in ansible prepare #3212

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

falconizmi
Copy link
Collaborator

@falconizmi falconizmi commented Sep 12, 2024

Pull Request Checklist

  • implement the feature

@falconizmi falconizmi self-assigned this Sep 12, 2024
@falconizmi falconizmi added the code | trivial A simple patch - a couple of lines, an easy-to-understand change, a typo fix. label Sep 12, 2024
@falconizmi falconizmi added this to the 1.37 milestone Sep 12, 2024
playbook_root = self.step.plan.fmf_root
except TypeError:
raise PrepareError(
"No fmf root found. Directory is not initialized with `tmt init`")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems needlessly complicated :)

if not self.step.plan.fmf_root:
    raise PrepareError("No fmf root found. Directory is not initialized with `tmt init`")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I already tried to do it like that but its not working, because fmf_root is not value but a getter, its failing before it can go to inside the if statement.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see. But that's very interesting information: it fails because the getter, declared as -> Path, runs return Path(self.node.root), and we realized an fmf node may not always be present. So what you do is scratching the surface, your change will turn "give me fmf root" into an exception in one place only, while everything else trying to access fmf root will be left unsanitized. We should go deeper :)

So, it feels like this check & exception should be raised by fmf_root itself, to prevent anyone from accessing fmf_root without a punishment. I'm not sure how exactly the exception raised now by getter looks like, could you share it? Or feel free to design the test right away.

BTW there's enough blame for more pieces of code, e.g. all these classes, Core, Test, Plan, Story - they take fmf node as an input parameter: how can they take an fmf node when we agreed that without an fmf node, there is no fmf tree and therefore no fmf nodes representing plans and tests?? How can we ever get to run a playbook, as directed by a prepare step of a plan when there is no fmf root and therefore no plans to recognize?? So there is more to review, basically, all constructs based on fmf are now suspicious when they can get constructed without an fmf root and get as far as to run a playbook :) I would start by checking whether we could put the check & exception into fmf_root for now, but eventually, we might check how can we even have Plan instance running playbooks when we have no fmf root to start with, and push this check to trigger way sooner.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is the new change enough for now? I tested it and it returns me the exception message
~/.local/bin/tmt run -vvv prepare --how ansible --playbook packages.yml provision --how virtual (in directory without tmt init)

Copy link
Collaborator

Choose a reason for hiding this comment

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

, we might check how can we even have Plan instance running playbooks when we have no fmf root to start with, and push this check to trigger way sooner.

But we (technically) do allow to specify the plan via CLI, right? IMO in that case fmf root doesn't need to exist.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we should have something like self.anchor_path that would provide this particular path

Yeah, that sounds good.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If I understand correctly, instead of having property fmt_root and its getter in base.py, we will have anchor_path property and its getter (that would try to return fmf_root and if it fails, it would return Path.cwd() ) and I would change only those which used fmf_root getter from base.py and the rest of fmf_root usage we would keep them as they are?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wouldn't say instead, sometimes it might be good to know what's fmf root. I'd say it's rather an addition, anchor_path would perform this self.fmf_root or Path.cwd() dance, and it should be used instead of fmf_root at places where fmf_root is used today, yes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So in fmf_root getter instead of returning exception, it would return None

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, that's what I would do. If objects like Plan can exist without an fmf root, then it shouldn't be a sin to access Plan.fmf_root, instead an "undefined" value like None should be returned.

@falconizmi falconizmi removed the code | trivial A simple patch - a couple of lines, an easy-to-understand change, a typo fix. label Sep 17, 2024
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