common bundle and dynamic bundlesequence

48 views
Skip to first unread message

Mark

unread,
Dec 16, 2014, 4:38:36 AM12/16/14
to help-c...@googlegroups.com
v3.6.2

I'm trying to generate a dynamic bundlesequence using the global classes of a common bundle but something isn't right with the output. This is a simplified version of the real policy requiring 3 three passes of common.

bundle common classify
{
classes:
"c" expression => "b";
"b" expression => "a";
"a" expression => "any";
}

body common control
{
bundlesequence =>
{
"classify",
"get_bundles",
@(get_bundles.bundle_ind),
};
}


bundle agent get_bundles
{
vars:
a::
"bundle[report_a]" string => "file_a";
b::
"bundle[report_b]" string => "file_b";
c::
"bundle[report_c]" string => "file_c";
d::
"bundle[report_d]" string => "file_d";
any::
"bundle_ind" slist => getindices("bundle");
reports:
any::
"bundles: $(bundle_ind)";

}


bundle agent report_a
{
reports:
"a";
c::
"a: c is set";
}

bundle agent report_b
{
reports:
"b";
c::
"b: c is set";
}

bundle agent report_c
{
reports:
"c";
}

getindices returns report_a, report_b, report_c but the last bundle is not called.

If the class guards of get_bundles are changed to a.null:: and b.null:: (so not set) then getindicies returns report_c but I get a fatal error because the bundlesequence contains 'cf_null'

Is this an error on my part or that of cfengine?

Mark




This email is confidential.  If you have received this email in error please notify us immediately by return email and delete this email and any attachments.  
VIX accepts no liability for any damage caused by this email or any attachments due to viruses, interference, interception, corruption or unauthorised access.


Neil Watson

unread,
Dec 16, 2014, 8:38:23 AM12/16/14
to help-c...@googlegroups.com
On Tue, Dec 16, 2014 at 01:38:36AM -0800, Mark wrote:
bundle common classify
> {
> classes:
>
> "c" expression => "b";
> "b" expression => "a";
> "a" expression => "any";

Promises are evaluated in order. Reverse these to:

> "a" expression => "any";
> "b" expression => "a";
> "c" expression => "b";

Looking at the verbose output when running the original order I see that
the automatic look at the common bundle has but one run. The normal
three runs happens via the bundle sequence, but by then it's too late.
You can see class being set at that time.

--
Neil H Watson
Sr. Partner, Architecture and Infrastructure
CFEngine reporting: https://github.com/evolvethinking/delta_reporting
CFEngine policy: https://github.com/evolvethinking/evolve_cfengine_freelib
CFEngine and vim: https://github.com/neilhwatson/vim_cf3
CFEngine support: http://evolvethinking.com

Mark

unread,
Dec 17, 2014, 5:11:33 AM12/17/14
to help-c...@googlegroups.com, cfen...@watson-wilson.ca
Promises are evaluated in reverse order???? My example was contrived to replicate a more complex common I have with vars: and classes: requiring multiple passes. If I split the logic across multiple common bundles how can be sure the order of evaluation?

I've seen some discussion on whether common bundles should be included in the sequence or not and that the conclusion was that it doesn't make any difference. Taking my example removing 'classify' from the sequence give a different result.

Neil Watson

unread,
Dec 17, 2014, 8:24:36 AM12/17/14
to help-c...@googlegroups.com
We encourage putting common bundles is the bundlesequence as a best
practice.

What I provided was not reverse order. C depends on B, B depends on A,
and A is always true. So I stared with the A which begets B, which
begets C. That is the correct order, unless I misunderstand your
meaning.

Ted Zlatanov

unread,
Dec 17, 2014, 8:38:26 AM12/17/14
to help-c...@googlegroups.com
On Wed, 17 Dec 2014 08:23:27 -0500 Neil Watson <cfen...@watson-wilson.ca> wrote:

NW> We encourage putting common bundles is the bundlesequence as a best
NW> practice.

I think there is at least one case where it actually matters: reports
are printed if the common bundle is in the bundlesequence, but aren't if
it's not. This was changed in 3.6 I think. Example:

#+begin_src cfengine
body common control
{
bundlesequence => { common1 };
}

bundle common common1
{
reports:
"$(this.bundle): run";
}

bundle common common2
{
reports:
"$(this.bundle): run";
}
#+end_src

Output against master:

#+begin_src text
% cf-agent -KI -f ./test_common_bundlesequence.cf
R: common1: run
#+end_src

HTH
Ted

Mark

unread,
Dec 17, 2014, 11:10:01 AM12/17/14
to help-c...@googlegroups.com
Ted, thanks. That difference has already caught me out ;) I think including common bundles in the sequences removes any doubt as to when/if they are run - especially if they are separated into their own file.

Neil,
The order c,b,a was deliberate to force 3 passes to set all classes and then use them to form the array. My concern was why getindices slist contained the three bundle names but when referenced by the sequence only the first two were executed. It's as if the names used by the sequence are finalised before the reported slist.

Cfengine doesn't follow the normal procedural development rules I'm used to. Normal ordering and multiple passes go against the grain for me ;)
Reply all
Reply to author
Forward
0 new messages