-
Notifications
You must be signed in to change notification settings - Fork 188
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
ENT-4681: Test proper scoping of classes defined from non-default namespace #3689
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Test proper scoping of classes defined from non-default namespace
Ticket: ENT-4681 Changelog: none
- Loading branch information
commit 2d17459229a7167120a114982eec46e85f47e3bd
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
tests/acceptance/00_basics/04_bundles/agent-bundle-class-bundle-scope-default-perspective.cf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/var/cfengine/bin/cf-agent -f- | ||
body common control | ||
{ | ||
inputs => { "../../default.cf.sub" }; | ||
bundlesequence => { | ||
default("$(this.promise_filename)") }; | ||
version => "1.0"; | ||
} | ||
body file control { namespace => "test"; } | ||
bundle agent example | ||
{ | ||
classes: | ||
"TRIGGERED" | ||
expression => "any", | ||
scope => "bundle"; # Bundle scoped classes are NOT visible from other bundles | ||
} | ||
body file control { namespace => "default"; } | ||
bundle agent test | ||
{ | ||
meta: | ||
"description" -> {"ENT-4681" } | ||
string => "Test that bundle scoped classes defined from namespaced | ||
agent bundles are properly scoped. Specifically from the default | ||
namespace."; | ||
|
||
"test_soft_fail" | ||
string => "any", | ||
meta => { "ENT-4681" }; | ||
|
||
methods: | ||
"test:example"; | ||
} | ||
bundle agent check | ||
{ | ||
classes: | ||
# Expectation, default:TRIGGERED is NOT defined | ||
"default_TRIGGERED_OK" | ||
expression => "!default:TRIGGERED"; | ||
|
||
# Expectation, test:TRIGGERED is NOT defined (not visable since it's a bundle scoped class) | ||
"namespaced_TRIGGERED_OK" | ||
expression => "!test:TRIGGERED"; | ||
|
||
# Expectation, TRIGGERED is NOT defined, we are now in the default namespace, the TRIGGERED class was defined in the test namespace with a bundle scope | ||
"TRIGGERED_OK" | ||
expression => "!TRIGGERED"; | ||
|
||
|
||
"pass" and => { | ||
"default_TRIGGERED_OK", | ||
"namespaced_TRIGGERED_OK", | ||
"TRIGGERED_OK", | ||
}; | ||
reports: | ||
pass:: | ||
"Pass $(this.promise_filename)"; | ||
!pass:: | ||
"FAIL $(this.promise_filename)"; | ||
!default_TRIGGERED_OK:: | ||
"Expected 'default:TRIGGERED' to not be seen as defined, but expression '!default:TRIGGERED' resulted in true"; | ||
!namespaced_TRIGGERED_OK:: | ||
"Expected 'test:TRIGGERED' to NOT be seen as defined, but expression '!test:TRIGGERED' resulted in false"; | ||
!TRIGGERED_OK:: | ||
"Expected 'TRIGGERED' to NOT be seen as defined, but expression 'TRIGGERED' resulted in true even without specify the test namespace"; | ||
|
||
} | ||
bundle agent __main__ | ||
{ | ||
|
||
methods: | ||
"test:example"; | ||
"check"; | ||
} |
80 changes: 80 additions & 0 deletions
80
.../acceptance/00_basics/04_bundles/agent-bundle-class-bundle-scope-namespace-perspective.cf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/var/cfengine/bin/cf-agent -f- | ||
body common control | ||
{ | ||
inputs => { "../../default.cf.sub" }; | ||
bundlesequence => { | ||
default("$(this.promise_filename)") }; | ||
version => "1.0"; | ||
} | ||
body file control { namespace => "test"; } | ||
bundle agent example | ||
{ | ||
classes: | ||
"TRIGGERED" | ||
expression => "any", | ||
scope => "bundle"; # Namespace scoped classes are visible from other bundles | ||
} | ||
bundle agent check | ||
{ | ||
classes: | ||
# Expectation, default:TRIGGERED is NOT defined | ||
"default_TRIGGERED_OK" | ||
expression => "!default:TRIGGERED"; | ||
|
||
# Expectation, test:TRIGGERED is NOT defined (not visable since it's a bundle scoped class) | ||
"namespaced_TRIGGERED_OK" | ||
expression => "!test:TRIGGERED"; | ||
|
||
# Expectation, TRIGGERED is NOT defined, we are now in the test namespace where the TRIGGERED class was defined, but it was bundle scoped, so not visable from another bundle | ||
"TRIGGERED_OK" | ||
expression => "!TRIGGERED"; | ||
|
||
|
||
"pass" and => { | ||
"default_TRIGGERED_OK", | ||
"namespaced_TRIGGERED_OK", | ||
"TRIGGERED_OK", | ||
}; | ||
reports: | ||
pass:: | ||
"Pass $(this.promise_filename)"; | ||
!pass:: | ||
"FAIL $(this.promise_filename)"; | ||
!default_TRIGGERED_OK:: | ||
"Expected 'default:TRIGGERED' to not be seen as defined, but expression '!default:TRIGGERED' resulted in true"; | ||
!namespaced_TRIGGERED_OK:: | ||
"Expected 'test:TRIGGERED' to NOT be seen as defined, but expression '!test:TRIGGERED' resulted in false"; | ||
!TRIGGERED_OK:: | ||
"Expected 'TRIGGERED' to NOT be seen as defined, but expression '!TRIGGERED' resulted in false"; | ||
|
||
} | ||
body file control { namespace => "default"; } | ||
bundle agent test | ||
{ | ||
meta: | ||
"description" -> {"ENT-4681" } | ||
|
||
string => "Test that bundle scoped classes defined from namespaced | ||
agent bundles are properly scoped. Specifically from the perspective of | ||
the non-default namespace itself."; | ||
|
||
|
||
"test_soft_fail" | ||
string => "any", | ||
meta => { "ENT-4681" }; | ||
|
||
methods: | ||
"test:example"; | ||
} | ||
bundle agent check | ||
{ | ||
methods: | ||
"test:check"; | ||
} | ||
bundle agent __main__ | ||
{ | ||
|
||
methods: | ||
"test"; | ||
"check"; | ||
} |
83 changes: 83 additions & 0 deletions
83
tests/acceptance/00_basics/04_bundles/agent-bundle-namespaced-class-default-perspective.cf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/var/cfengine/bin/cf-agent -f- | ||
body common control | ||
{ | ||
inputs => { "../../default.cf.sub" }; | ||
bundlesequence => { | ||
default("$(this.promise_filename)") }; | ||
version => "1.0"; | ||
} | ||
body file control { namespace => "test"; } | ||
bundle agent example | ||
{ | ||
classes: | ||
"TRIGGERED" | ||
expression => "any", | ||
scope => "namespace"; # Namespace scoped classes are visible from other bundles | ||
|
||
reports: | ||
TRIGGERED:: | ||
"TRIGGERED is defined within $(this.namespace).$(this.bundle)"; | ||
|
||
default:TRIGGERED:: | ||
"default:TRIGGERED is defined within $(this.namespace).$(this.bundle)"; | ||
|
||
test:TRIGGERED:: | ||
"$(this.namespace):TRIGGERED is defined within $(this.namespace).$(this.bundle)"; | ||
} | ||
body file control { namespace => "default"; } | ||
bundle agent test | ||
{ | ||
meta: | ||
"description" -> {"ENT-4681" } | ||
string => "Test that namespace scoped classes defined from namespaced | ||
agent bundles are properly scoped. Specifically from the default | ||
namespace."; | ||
|
||
"test_soft_fail" | ||
string => "any", | ||
meta => { "ENT-4681" }; | ||
|
||
methods: | ||
"test:example"; | ||
} | ||
bundle agent check | ||
{ | ||
classes: | ||
# Expectation, default:TRIGGERED is NOT defined | ||
"default_TRIGGERED_OK" | ||
expression => "!default:TRIGGERED"; | ||
|
||
# Expectation, test:TRIGGERED is defined (visable since it's a namespace scoped class) | ||
"namespaced_TRIGGERED_OK" | ||
expression => "test:TRIGGERED"; | ||
|
||
# Expectation, TRIGGERED is NOT defined, we are now in the default namespace, the TRIGGERED class was defined in the test namespace and should not be seen without explicitly using it's namespace | ||
"TRIGGERED_OK" | ||
expression => "!TRIGGERED"; | ||
|
||
|
||
"pass" and => { | ||
"default_TRIGGERED_OK", | ||
"namespaced_TRIGGERED_OK", | ||
"TRIGGERED_OK", | ||
}; | ||
reports: | ||
pass:: | ||
"Pass $(this.promise_filename)"; | ||
!pass:: | ||
"FAIL $(this.promise_filename)"; | ||
!default_TRIGGERED_OK:: | ||
"Expected 'default:TRIGGERED' to not be seen as defined, but expression '!default:TRIGGERED' resulted in true"; | ||
!namespaced_TRIGGERED_OK:: | ||
"Expected 'test:TRIGGERED' to be seen as defined, but expression 'test:TRIGGERED' resulted in false"; | ||
!TRIGGERED_OK:: | ||
"Expected 'TRIGGERED' to NOT be seen as defined, but expression 'TRIGGERED' resulted in true even without specify the test namespace"; | ||
|
||
} | ||
bundle agent __main__ | ||
{ | ||
|
||
methods: | ||
"test:example"; | ||
"check"; | ||
} |
80 changes: 80 additions & 0 deletions
80
tests/acceptance/00_basics/04_bundles/agent-bundle-namespaced-class-namespace-perspective.cf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/var/cfengine/bin/cf-agent -f- | ||
body common control | ||
{ | ||
inputs => { "../../default.cf.sub" }; | ||
bundlesequence => { | ||
default("$(this.promise_filename)") }; | ||
version => "1.0"; | ||
} | ||
body file control { namespace => "test"; } | ||
bundle agent example | ||
{ | ||
classes: | ||
"TRIGGERED" | ||
expression => "any", | ||
scope => "namespace"; # Namespace scoped classes are visible from other bundles | ||
} | ||
bundle agent check | ||
{ | ||
classes: | ||
# Expectation, default:TRIGGERED is NOT defined | ||
"default_TRIGGERED_OK" | ||
expression => "!default:TRIGGERED"; | ||
|
||
# Expectation, test:TRIGGERED is defined (visable since it's a namespace scoped class) | ||
"namespaced_TRIGGERED_OK" | ||
expression => "test:TRIGGERED"; | ||
|
||
# Expectation, TRIGGERED is defined, we are now in the test namespace where the TRIGGERED class was defined. We should be able to reference classes defined in our current namespace without being explicit | ||
"TRIGGERED_OK" | ||
expression => "TRIGGERED"; | ||
|
||
|
||
"pass" and => { | ||
"default_TRIGGERED_OK", | ||
"namespaced_TRIGGERED_OK", | ||
"TRIGGERED_OK", | ||
}; | ||
reports: | ||
pass:: | ||
"Pass $(this.promise_filename)"; | ||
!pass:: | ||
"FAIL $(this.promise_filename)"; | ||
!default_TRIGGERED_OK:: | ||
"Expected 'default:TRIGGERED' to not be seen as defined, but expression '!default:TRIGGERED' resulted in true"; | ||
!namespaced_TRIGGERED_OK:: | ||
"Expected 'test:TRIGGERED' to be seen as defined, but expression 'test:TRIGGERED' resulted in false"; | ||
!TRIGGERED_OK:: | ||
"Expected 'TRIGGERED' to be seen as defined, but expression 'TRIGGERED' resulted in false"; | ||
|
||
} | ||
body file control { namespace => "default"; } | ||
bundle agent test | ||
{ | ||
meta: | ||
"description" -> {"ENT-4681" } | ||
|
||
string => "Test that namespace scoped classes defined from namespaced | ||
agent bundles are properly scoped. Specifically from the perspective of | ||
the non-default namespace itself."; | ||
|
||
|
||
"test_soft_fail" | ||
string => "any", | ||
meta => { "ENT-4681" }; | ||
|
||
methods: | ||
"test:example"; | ||
} | ||
bundle agent check | ||
{ | ||
methods: | ||
"test:check"; | ||
} | ||
bundle agent __main__ | ||
{ | ||
|
||
methods: | ||
"test"; | ||
"check"; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this double
body file control
supposed to do? And what makes you think it should be like that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first one set the namespace to test, the second one returned the namespace to default. So
bundle agent example
is in thetest
namespace butbundle agent test
is in the default namespace.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK, and yes, ENT-4681 is the related ticket
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am quite surprised that the double
body file control
just works like this, sequentially. That looks almost like a crime! 😉There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @vpodzime this looks insane to me. The ordering of bodies and bundles within a file shouldn't matter, at all. Also a
body file control
is the control body for the file no? It should be for the whole file. I would expect the last body to overwrite the attributes of the first one, or an error.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but this is how it was designed.
https://docs.cfengine.com/docs/3.12/reference-components-file_control_promises.html