Re: control_common_bundlesequence_end .. a bug??
"'Nick Anderson' via help-cfengine" <[email protected]> Tue, 9 Sep 2025 10:43:26 -0700 (PDT)
| Newsgroups | gmane.comp.sysutils.cfengine.general |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_117438_1783425540.1757439806478
Content-Type: multipart/alternative;
boundary="----=_Part_117439_418584605.1757439806478"
------=_Part_117439_418584605.1757439806478
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
PR here: https://github.com/cfengine/masterfiles/pull/3044
On Tuesday, September 9, 2025 at 12:28:38=E2=80=AFPM UTC-5 Nick Anderson wr=
ote:
> Hi, thanks for bringing it up.=20
>
> Indeed, I was able to reproduce the issue. And, I think you also correctl=
y=20
> spotted what is related to it.=20
>
>
> https://github.com/cfengine/masterfiles/blob/843a917db0e541d9a0c21a11e788=
6ddc30a2bec4/controls/def.cf#L285-L290=20
>
> "tbse" data =3D> mergedata( "def.control_common_bundlesequence_end" );
>
> "bundlesequence_end" slist =3D> getvalues( tbse );
>
>
> "tbse" data =3D> mergedata( "def.control_common_bundlesequence_classifica=
tion" );
>
> "bundlesequence_classification" slist =3D> getvalues( tbse );
>
> Here a *temporary* variable tbse is set twice, probably with the thought=
=20
> that it would be fully re-defined. But when=20
> def.control_common_bundlesequence_classification is not defined, then=20
> mergedata() returns nothing.=20
>
> For example here we see j2m doesn't get defined:=20
>
> bundle agent main{
> vars:
> "j1" data =3D> '["end_always"]';
>
> "j1m" data =3D> mergedata( "j1" );
>
> "j2m" data =3D> mergedata( "j2" );
>
>
> reports:
> "j1m: $(with)" with =3D> storejson( "j1m" );
> "j2m: $(with)" with =3D> storejson( "j2m" );
> }
>
>
> # cf-agent --no-lock --log-level info --show-evaluated-vars=3Dmain\\. --f=
ile ./example.cf
> R: j1m: [
> "end_always"
> ]
> R: j2m: $(with)
> Variable name Variable value =
Meta tags Comme=
nt
> default:main.j1 ["end_always"] =
source=3Dpromise
> default:main.j1m ["end_always"] =
source=3Dpromise
>
> To count the number of end_always in bundlesequence:=20
>
> cf-agent -KIf update.cf; cf-agent -Kv > out.log && grep "Using bundlesequ=
ence" out.log | awk '{print gsub("end_always", "&")}'
>
> Potential ways to address:=20
>
> We could make the temporary variables uniquely named:=20
>
>
> "tbse1" data =3D> mergedata( "def.control_common_bundlesequence_end" );
> "bundlesequence_end" slist =3D> getvalues( tbse1 );
> "tbse2" data =3D> mergedata( "def.control_common_bundlesequence_classific=
ation" );
> "bundlesequence_classification" slist =3D> getvalues( tbse2 );
>
> Define empty lists if control var not defined (as is the case when=20
> defining from Augments), override with values of data from Augments.=20
>
> We need to define an empty list or policy will error if it's not defined.=
=20
>
>
> "bundlesequence_end"
> slist =3D> { },
> if =3D> not( isvariable( "def.control_common_bundlesequence_end" ) );
> "bundlesequence_end" slist =3D> getvalues( mergedata( "def.control_common=
_bundlesequence_end" ) );
>
> "bundlesequence_classification"
> slist =3D> { },
> if =3D> not( isvariable( "def.control_common_bundlesequence_classificat=
ion" ) );
> "bundlesequence_classification" slist =3D> getvalues( mergedata( "def.con=
trol_common_bundlesequence_classification" ) );
>
> Nested functions doesn't work=20
>
>
> "bundlesequence_end" slist =3D> getvalues( mergedata( "def.control_common=
_bundlesequence_end" ) );
> "bundlesequence_classification" slist =3D> getvalues( mergedata( "def.con=
trol_common_bundlesequence_classification" ) );
>
> Because getvalues() on a variable that doesnt exist returns an *empty=20
> slist* but getvalues() on mergedata() that fails does not return an empty=
=20
> list.=20
>
> bundle agent main{
> vars:
> "l" slist =3D> getvalues( "does_not_exist" );
> "j" slist =3D> getvalues( mergedata( "does_not_exist" ) );}
>
>
> # cf-agent --no-lock --log-level info --show-evaluated-vars=3Dmain\\. --f=
ile ./example2.cf
> Variable name Variable value =
Meta tags Comme=
nt
> default:main.l =
source=3Dpromise
>
> I filed https://northerntech.atlassian.net/browse/CFE-4588=20
>
--=20
You received this message because you are subscribed to the Google Groups "=
help-cfengine" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/help-cfengi=
ne/11cb17ac-0d76-499d-ad2f-7f6ba5339c1dn%40googlegroups.com.
------=_Part_117439_418584605.1757439806478
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
PR here: https://github.com/cfengine/masterfiles/pull/3044<br /><br /><div =
class=3D"gmail_quote"><div dir=3D"auto" class=3D"gmail_attr">On Tuesday, Se=
ptember 9, 2025 at 12:28:38=E2=80=AFPM UTC-5 Nick Anderson wrote:<br/></div=
><blockquote class=3D"gmail_quote" style=3D"margin: 0 0 0 0.8ex; border-lef=
t: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><p>
Hi, thanks for bringing it up.
</p>
<p>
Indeed, I was able to reproduce the issue. And, I think you also correctly =
spotted what is related to it.
</p>
<p>
<a href=3D"https://github.com/cfengine/masterfiles/blob/843a917db0e541d9a0c=
21a11e7886ddc30a2bec4/controls/def.cf#L285-L290" target=3D"_blank" rel=3D"n=
ofollow" data-saferedirecturl=3D"https://www.google.com/url?hl=3Den&q=
=3Dhttps://github.com/cfengine/masterfiles/blob/843a917db0e541d9a0c21a11e78=
86ddc30a2bec4/controls/def.cf%23L285-L290&source=3Dgmail&ust=3D1757=
526193213000&usg=3DAOvVaw2LaUgq3kGLmhU7mAblAg68">https://github.com/cfe=
ngine/masterfiles/blob/843a917db0e541d9a0c21a11e7886ddc30a2bec4/controls/de=
f.cf#L285-L290</a>
</p>
<div>
<pre></pre></div><div><pre><span style=3D"color:#689d6a">"tbse"</=
span> <span style=3D"color:#d79921">data</span> =3D> mergedata<span styl=
e=3D"color:#689d6a">(</span> <span style=3D"color:#689d6a">"def.contro=
l_common_bundlesequence_end"</span> <span style=3D"color:#689d6a">)</s=
pan>;
</pre></div><div><pre><span style=3D"color:#689d6a">"bundlesequence_en=
d"</span> <span style=3D"color:#d79921">slist</span> =3D> getvalues=
<span style=3D"color:#689d6a">(</span> tbse <span style=3D"color:#689d6a">)=
</span>;
</pre></div><div><pre><span style=3D"color:#689d6a">"tbse"</span>=
<span style=3D"color:#d79921">data</span> =3D> mergedata<span style=3D"=
color:#689d6a">(</span> <span style=3D"color:#689d6a">"def.control_com=
mon_bundlesequence_classification"</span> <span style=3D"color:#689d6a=
">)</span>;
</pre></div><div><pre><span style=3D"color:#689d6a">"bundlesequence_cl=
assification"</span> <span style=3D"color:#d79921">slist</span> =3D>=
; getvalues<span style=3D"color:#689d6a">(</span> tbse <span style=3D"color=
:#689d6a">)</span>;
</pre>
</div>
<p>
Here a <i>temporary</i> variable <code>tbse</code> is set twice, probably w=
ith the thought that it would be fully re-defined. But when <code>def.contr=
ol_common_bundlesequence_classification</code> is not defined, then <code>m=
ergedata()</code> returns nothing.
</p>
<p>
For example here we see <code>j2m</code> doesn't get defined:
</p>
<div>
<pre><span style=3D"color:#a89984;font-weight:bold">bundle</span> <span sty=
le=3D"color:#458588;font-weight:bold">agent</span> <span style=3D"color:#45=
8588">main</span>
<span style=3D"color:#689d6a">{</span>
<span style=3D"color:#a89984;font-weight:bold">vars</span>:
<span style=3D"color:#689d6a">"j1"</span> <span style=3D"=
color:#d79921">data</span> =3D> <span style=3D"color:#689d6a">'[&quo=
t;end_always"]'</span>;
<span style=3D"color:#689d6a">"j1m"</span> <span style=3D=
"color:#d79921">data</span> =3D> mergedata<span style=3D"color:#d79921">=
(</span> <span style=3D"color:#689d6a">"j1"</span> <span style=3D=
"color:#d79921">)</span>;
<span style=3D"color:#689d6a">"j2m"</span> <span style=3D=
"color:#d79921">data</span> =3D> mergedata<span style=3D"color:#d79921">=
(</span> <span style=3D"color:#689d6a">"j2"</span> <span style=3D=
"color:#d79921">)</span>;
<span style=3D"color:#a89984;font-weight:bold">reports</span>:
<span style=3D"color:#689d6a">"j1m: $(with)"</span> with =
=3D> storejson<span style=3D"color:#d79921">(</span> <span style=3D"colo=
r:#689d6a">"j1m"</span> <span style=3D"color:#d79921">)</span>;
<span style=3D"color:#689d6a">"j2m: $(with)"</span> with =
=3D> storejson<span style=3D"color:#d79921">(</span> <span style=3D"colo=
r:#689d6a">"j2m"</span> <span style=3D"color:#d79921">)</span>;
<span style=3D"color:#689d6a">}</span>
</pre>
</div>
<pre>
# cf-agent --no-lock --log-level info --show-evaluated-vars=3Dmain\\. --fil=
e ./<a href=3D"http://example.cf" target=3D"_blank" rel=3D"nofollow" data-s=
aferedirecturl=3D"https://www.google.com/url?hl=3Den&q=3Dhttp://example=
.cf&source=3Dgmail&ust=3D1757526193213000&usg=3DAOvVaw21kNOaJju=
sMy9-zVFRfr2x">example.cf</a>
R: j1m: [
"end_always"
]
R: j2m: $(with)
Variable name Variable value =
Meta tags Comment
default:main.j1 ["end_always"] =
source=3Dpromise
default:main.j1m ["end_always"] =
source=3Dpromise
</pre>
<p>
To count the number of <code>end_always</code> in <code>bundlesequence</cod=
e>:
</p>
<div>
<pre>cf-agent -KIf <a href=3D"http://update.cf" target=3D"_blank" rel=3D"no=
follow" data-saferedirecturl=3D"https://www.google.com/url?hl=3Den&q=3D=
http://update.cf&source=3Dgmail&ust=3D1757526193213000&usg=3DAO=
vVaw3LNcivNetNjvjiMwn-Sz15">update.cf</a>; cf-agent -Kv > out.log &&=
amp; grep <span style=3D"color:#689d6a">"Using bundlesequence"</s=
pan> out.log | awk <span style=3D"color:#689d6a">'{print gsub("end=
_always", "&")}'</span>
</pre>
</div>
<p>
Potential ways to address:
</p>
<p>
We could make the temporary variables uniquely named:
</p>
<pre>
"tbse1" data =3D> mergedata( "def.control_common_bundlese=
quence_end" );
"bundlesequence_end" slist =3D> getvalues( tbse1 );
"tbse2" data =3D> mergedata( "def.control_common_bundlese=
quence_classification" );
"bundlesequence_classification" slist =3D> getvalues( tbse2 );
</pre>
<p>
Define empty lists if control var not defined (as is the case when defining=
from Augments), override with values of data from Augments.
</p>
<p>
We need to define an empty list or policy will error if it's not define=
d.
</p>
<pre>
"bundlesequence_end"
slist =3D> { },
if =3D> not( isvariable( "def.control_common_bundlesequence_end&q=
uot; ) );
"bundlesequence_end" slist =3D> getvalues( mergedata( "de=
f.control_common_bundlesequence_end" ) );
"bundlesequence_classification"
slist =3D> { },
if =3D> not( isvariable( "def.control_common_bundlesequence_class=
ification" ) );
"bundlesequence_classification" slist =3D> getvalues( mergedat=
a( "def.control_common_bundlesequence_classification" ) );
</pre>
<p>
Nested functions doesn't work
</p>
<pre>
"bundlesequence_end" slist =3D> getvalues( mergedata( "de=
f.control_common_bundlesequence_end" ) );
"bundlesequence_classification" slist =3D> getvalues( mergedat=
a( "def.control_common_bundlesequence_classification" ) );
</pre>
<p>
Because <code>getvalues()</code> on a variable that doesnt exist returns an=
<i>empty slist</i> but <code>getvalues()</code> on <code>mergedata()</code=
> that fails does not return an empty list.
</p>
<div>
<pre><span style=3D"color:#a89984;font-weight:bold">bundle</span> <span sty=
le=3D"color:#458588;font-weight:bold">agent</span> <span style=3D"color:#45=
8588">main</span>
<span style=3D"color:#689d6a">{</span>
<span style=3D"color:#a89984;font-weight:bold">vars</span>:
<span style=3D"color:#689d6a">"l"</span> <span style=3D"c=
olor:#d79921">slist</span> =3D> getvalues<span style=3D"color:#d79921">(=
</span> <span style=3D"color:#689d6a">"does_not_exist"</span> <s=
pan style=3D"color:#d79921">)</span>;
<span style=3D"color:#689d6a">"j"</span> <span style=3D"c=
olor:#d79921">slist</span> =3D> getvalues<span style=3D"color:#d79921">(=
</span> mergedata<span style=3D"color:#458588">(</span> <span style=3D"colo=
r:#689d6a">"does_not_exist"</span> <span style=3D"color:#458588">=
)</span> <span style=3D"color:#d79921">)</span>;
<span style=3D"color:#689d6a">}</span>
</pre>
</div>
<pre>
# cf-agent --no-lock --log-level info --show-evaluated-vars=3Dmain\\. --fil=
e ./<a href=3D"http://example2.cf" target=3D"_blank" rel=3D"nofollow" data-=
saferedirecturl=3D"https://www.google.com/url?hl=3Den&q=3Dhttp://exampl=
e2.cf&source=3Dgmail&ust=3D1757526193213000&usg=3DAOvVaw3czPgy1=
USAD9STf0GCcPiR">example2.cf</a>
Variable name Variable value =
Meta tags Comment
default:main.l =
source=3Dpromise
</pre>
<p>
I filed <a href=3D"https://northerntech.atlassian.net/browse/CFE-4588" tar=
get=3D"_blank" rel=3D"nofollow" data-saferedirecturl=3D"https://www.google.=
com/url?hl=3Den&q=3Dhttps://northerntech.atlassian.net/browse/CFE-4588&=
amp;source=3Dgmail&ust=3D1757526193213000&usg=3DAOvVaw29qle_ZGdCqyF=
bNgyrfG9i">https://northerntech.atlassian.net/browse/CFE-4588</a>
</p>
</blockquote></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;help-cfengine" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">help-=
[email protected]</a>.<br />
To view this discussion visit <a href=3D"https://groups.google.com/d/msgid/=
help-cfengine/11cb17ac-0d76-499d-ad2f-7f6ba5339c1dn%40googlegroups.com?utm_=
medium=3Demail&utm_source=3Dfooter">https://groups.google.com/d/msgid/help-=
cfengine/11cb17ac-0d76-499d-ad2f-7f6ba5339c1dn%40googlegroups.com</a>.<br /=
>
------=_Part_117439_418584605.1757439806478--
------=_Part_117438_1783425540.1757439806478--