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

ENT-4681: Test proper scoping of classes defined from non-default namespace #3689

Merged
merged 1 commit into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

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
nickanderson committed Jun 20, 2019
commit 2d17459229a7167120a114982eec46e85f47e3bd
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"; }
Copy link
Contributor

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?

Copy link
Member Author

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 the test namespace but bundle agent test is in the default namespace.

Copy link
Member Author

Choose a reason for hiding this comment

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

Please fix the typos. Also, is there a ticket for this issue?

ACK, and yes, ENT-4681 is the related ticket

Copy link
Contributor

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! 😉

Copy link
Member

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.

Copy link
Member Author

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

This directive can be given multiple times within any file, outside of body and bundle definitions.

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";
}
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";
}
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";
}
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";
}