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

All of Salt's loaders now accept loaded_base_name & Only functions defined on the modules being loaded will be added to the lazy loader #62189

Merged
merged 3 commits into from
Jun 29, 2022

Conversation

s0undt3ch
Copy link
Collaborator

@s0undt3ch s0undt3ch commented Jun 17, 2022

  • All of Salt's loaders now accept loaded_base_name as a keyword argument, allowing different namespacing the loaded modules.
  • Additionally, only functions defined on the modules being loaded will be added to the lazy loader, functions imported from other modules, unless they are properly namespaced, are not included.

Fixes #62186
Fixes #62190

@s0undt3ch s0undt3ch requested a review from a team as a code owner June 17, 2022 12:27
@s0undt3ch s0undt3ch requested review from waynew and removed request for a team June 17, 2022 12:27
@s0undt3ch s0undt3ch force-pushed the issues/62186-loaded-base-name branch from 123b47e to 0be65f0 Compare June 17, 2022 12:32
Ch3LL
Ch3LL previously approved these changes Jun 17, 2022
@s0undt3ch
Copy link
Collaborator Author

re-run full all

@saltstack saltstack deleted a comment from github-actions bot Jun 17, 2022
@s0undt3ch s0undt3ch force-pushed the issues/62186-loaded-base-name branch from 5e6bb1e to 94e39ea Compare June 17, 2022 19:07
@saltstack saltstack deleted a comment from github-actions bot Jun 17, 2022
@saltstack saltstack deleted a comment from github-actions bot Jun 17, 2022
Copy link
Contributor

@waynew waynew left a comment

Choose a reason for hiding this comment

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

Just a couple of questions here - The one yaml -> yamldumper is probably a blocker. I think the others are more just questions on my part. I'm not sure if there's a rush to get this in -- if so it's probably fine to merge before I get back & can re-review. Otherwise, I would like to bang on it a little more, just to make sure I really understand what the impact is for the LazyLoader 🤔 (I mean, I don't see anything else that's giving me cause for concern - just the fact that we're making the change for the Loader that affects all of salt)

@@ -263,8 +263,8 @@ def export_distributions(region=None, key=None, keyid=None, profile=None):
# as opposed to being called from execution or state modules
log.trace("Boto client error: {}", exc)

dumper = __utils__["yaml.get_dumper"]("IndentedSafeOrderedDumper")
return __utils__["yaml.dump"](
dumper = __utils__["yamldumper.get_dumper"]("IndentedSafeOrderedDumper")
Copy link
Contributor

Choose a reason for hiding this comment

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

question do all these need to be changed?


✦2 ❯ ag '"yaml\.' salt
salt/modules/boto_iam.py
1682:    return __utils__["yaml.safe_dump"](results, default_flow_style=False, indent=2)
1728:    return __utils__["yaml.safe_dump"](results, default_flow_style=False, indent=2)

I'm assuming that this only applies for __utils__ and not __serializers__ - I just went and found a couple of those, specifically in salt/states/file.py - it looks for serialzer_name in serializers where yaml.serialize is what's called, which doesn't look like the yamldumper 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The yamldumper only applies to the utils dunder.
They were never using our yamldumper utils module, they were using the actual yaml package.

@@ -30,7 +30,7 @@ def configure_loader_modules(setup_vars):
whitelist=[
"boto3",
"dictdiffer",
"yaml",
"yamldumper",
Copy link
Contributor

Choose a reason for hiding this comment

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

question if I do git checkout salt/master -- salt/loader/lazy.py then this doesn't fail 🤔 It only fails if I leave lazy as-is and change this back. Why is that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because now the loader, correctly, only adds functions defined in the module, not functions imported into the module, unless these are namespaced into the module scope.

@@ -30,7 +30,7 @@ def configure_loader_modules(setup_vars):
whitelist=[
"boto3",
"dictdiffer",
"yaml",
"yamldumper",
Copy link
Contributor

Choose a reason for hiding this comment

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

question if I do git checkout salt/master -- salt/loader/lazy.py then this doesn't fail 🤔 It only fails if I leave lazy as-is and change this back. Why is that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same answer.

@s0undt3ch
Copy link
Collaborator Author

Just a couple of questions here - The one yaml -> yamldumper is probably a blocker. I think the others are more just questions on my part. I'm not sure if there's a rush to get this in -- if so it's probably fine to merge before I get back & can re-review. Otherwise, I would like to bang on it a little more, just to make sure I really understand what the impact is for the LazyLoader 🤔 (I mean, I don't see anything else that's giving me cause for concern - just the fact that we're making the change for the Loader that affects all of salt)

The rush is to get it into 3005.
Until we freeze, I'm good to leave this open for further review.

@s0undt3ch
Copy link
Collaborator Author

To complement, the lazy loader, prior to these changes loaded every function or partial it could get its hands on, namely due to the loader doing a dir(<module>).

This is the wrong behavior because the loader should only care about functions defined on the module being loaded.

If we did from json import dumps into any module which was loaded by the loader, then, dumps would be available on the dunder.

On some rare occasions, that is the intended behavior, and thats why the namespace_function function was created.

@s0undt3ch
Copy link
Collaborator Author

However, we were failing to enforce these constraints.

@s0undt3ch
Copy link
Collaborator Author

This is why we should never allowed __utils__ to be a thing.
The __utils__['yaml.*'] worked because of these imports.

Which goes against how the LazyLoader was intended to work.
It relied on a side effect of not applying the original intended constraints.

@s0undt3ch
Copy link
Collaborator Author

Fixes saltstack#62186

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
Fixes saltstack#62190

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
@s0undt3ch s0undt3ch force-pushed the issues/62186-loaded-base-name branch from 94e39ea to 41102c9 Compare June 18, 2022 06:07
@github-actions
Copy link

Hi! I'm your friendly PR bot!

You might be wondering what I'm doing commenting here on your PR.

Yes, as a matter of fact, I am...

I'm just here to help us improve the documentation. I can't respond to
questions or anything, but what I can do, I do well!

Okay... so what do you do?

I detect modules that are missing docstrings or "CLI Example" on existing docstrings!
When I was created we had a lot of these. The documentation for these
modules need some love and attention to make Salt better for our users.

So what does that have to do with my PR?

I noticed that in this PR there are some files changed that have some of these
issues. So I'm leaving this comment to let you know your options.

Okay, what are they?

Well, my favorite, is that since you were making changes here I'm hoping that
you would be the most familiar with this module and be able to add some other
examples or fix any of the reported issues.

If I can, then what?

Well, you can either add them to this PR or add them to another PR. Either way is fine!

Well... what if I can't, or don't want to?

That's also fine! We appreciate all contributions to the Salt Project. If you
can't add those other examples, either because you're too busy, or unfamiliar,
or you just aren't interested, we still appreciate the contributions that
you've made already.

Whatever approach you decide to take, just drop a comment here letting us know!

Detected Issues (click me)
Check Known Missing Docstrings...........................................Failed
- hook id: invoke
- duration: 1.06s
- exit code: 1

/home/runner/.cache/pre-commit/repoavddhtkl/py_env-python3/lib/python3.9/site-packages/_distutils_hack/init.py:30: UserWarning: Setuptools is replacing distutils.
warnings.warn("Setuptools is replacing distutils.")
The function 'delete_alarm' on 'salt/modules/boto_cloudwatch.py' does not have a 'CLI Example:' in its docstring
Found 1 errors


Thanks again!

@s0undt3ch s0undt3ch force-pushed the issues/62186-loaded-base-name branch from 41102c9 to 6a7e599 Compare June 18, 2022 06:52
@s0undt3ch
Copy link
Collaborator Author

The __utils__ relies on so much of the bad behavior that I decided to leave it as it was until we completely get rid of __utils__.
Too many things would break.

…funcs in ``__utils__``

!@#$%@!#@$%!$@#$T

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
@s0undt3ch s0undt3ch force-pushed the issues/62186-loaded-base-name branch from 6a7e599 to ab42a89 Compare June 18, 2022 07:07
@s0undt3ch s0undt3ch requested review from waynew and Ch3LL June 21, 2022 09:32
Copy link
Contributor

@twangboy twangboy left a comment

Choose a reason for hiding this comment

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

Shouldn't we add some documentation about the loaded_base_name option in the salt/loader/__init__.py file? We mention it in the changelog, but I think it should be documented in the __init__.py where that is being added as an additional option.

@s0undt3ch
Copy link
Collaborator Author

Shouldn't we add some documentation about the loaded_base_name option in the salt/loader/__init__.py file? We mention it in the changelog, but I think it should be documented in the __init__.py where that is being added as an additional option.

Can I do it on a follow up PR if @waynew approves this one? I'll do it right after merge.

@s0undt3ch s0undt3ch added the Phosphorus v3005.0 Release code name and version label Jun 23, 2022
@s0undt3ch s0undt3ch added this to the Phosphorus v3005.0 milestone Jun 23, 2022
@Ch3LL Ch3LL merged commit 29d66ec into saltstack:master Jun 29, 2022
@Ch3LL
Copy link
Contributor

Ch3LL commented Jun 29, 2022

@waynew when you get time to re-review this, Pedro will do a follow up PR if you see any more issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Phosphorus v3005.0 Release code name and version
Projects
None yet
4 participants