Re: control_common_bundlesequence_end .. a bug??

"'Nick Anderson' via help-cfengine" <[email protected]> Wed, 10 Sep 2025 10:47:14 -0700 (PDT)
Newsgroups gmane.comp.sysutils.cfengine.general
Message-ID <[email protected]>
------=_Part_107328_1471506313.1757526434530
Content-Type: multipart/alternative; 
	boundary="----=_Part_107329_1462458281.1757526434530"

------=_Part_107329_1462458281.1757526434530
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

This was merged and backported.
https://northerntech.atlassian.net/browse/CFE-4588

On Tuesday, September 9, 2025 at 12:43:26=E2=80=AFPM UTC-5 Nick Anderson wr=
ote:

> 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 =
wrote:
>
>> Hi, thanks for bringing it up.=20
>>
>> Indeed, I was able to reproduce the issue. And, I think you also=20
>> correctly spotted what is related to it.=20
>>
>>
>> https://github.com/cfengine/masterfiles/blob/843a917db0e541d9a0c21a11e78=
86ddc30a2bec4/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_classific=
ation" );
>>
>> "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\\. --=
file ./example.cf
>> R: j1m: [
>>   "end_always"
>> ]
>> R: j2m: $(with)
>> Variable name                            Variable value                 =
                              Meta tags                                Comm=
ent
>> 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 bundleseq=
uence" 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_classifi=
cation" );
>> "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_commo=
n_bundlesequence_end" ) );
>>
>> "bundlesequence_classification"
>>   slist =3D> { },
>>   if =3D> not( isvariable( "def.control_common_bundlesequence_classifica=
tion" ) );
>> "bundlesequence_classification" slist =3D> getvalues( mergedata( "def.co=
ntrol_common_bundlesequence_classification" ) );
>>
>> Nested functions doesn't work=20
>>
>>
>> "bundlesequence_end" slist =3D> getvalues( mergedata( "def.control_commo=
n_bundlesequence_end" ) );
>> "bundlesequence_classification" slist =3D> getvalues( mergedata( "def.co=
ntrol_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=20
>> empty 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\\. --=
file ./example2.cf
>> Variable name                            Variable value                 =
                              Meta tags                                Comm=
ent
>> 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/85c72bb6-9d9c-4977-b13d-ed81aef4d7b0n%40googlegroups.com.

------=_Part_107329_1462458281.1757526434530
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div>This was merged and backported.</div><div>https://northerntech.atlassi=
an.net/browse/CFE-4588</div><br /><div class=3D"gmail_quote"><div dir=3D"au=
to" class=3D"gmail_attr">On Tuesday, September 9, 2025 at 12:43:26=E2=80=AF=
PM UTC-5 Nick Anderson wrote:<br/></div><blockquote class=3D"gmail_quote" s=
tyle=3D"margin: 0 0 0 0.8ex; border-left: 1px solid rgb(204, 204, 204); pad=
ding-left: 1ex;">PR here: <a href=3D"https://github.com/cfengine/masterfile=
s/pull/3044" target=3D"_blank" rel=3D"nofollow" data-saferedirecturl=3D"htt=
ps://www.google.com/url?hl=3Den&amp;q=3Dhttps://github.com/cfengine/masterf=
iles/pull/3044&amp;source=3Dgmail&amp;ust=3D1757612822497000&amp;usg=3DAOvV=
aw1jF3idAVZp-4mpGf0s0QOb">https://github.com/cfengine/masterfiles/pull/3044=
</a><br><br><div class=3D"gmail_quote"><div dir=3D"auto" class=3D"gmail_att=
r">On Tuesday, September 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-left: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" rel=3D"nofollow" target=3D=
"_blank" data-saferedirecturl=3D"https://www.google.com/url?hl=3Den&amp;q=
=3Dhttps://github.com/cfengine/masterfiles/blob/843a917db0e541d9a0c21a11e78=
86ddc30a2bec4/controls/def.cf%23L285-L290&amp;source=3Dgmail&amp;ust=3D1757=
612822498000&amp;usg=3DAOvVaw1Qyl9p51y2J3EHr-LajmIN">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">&quot;tbse&quot;</=
span> <span style=3D"color:#d79921">data</span> =3D&gt; mergedata<span styl=
e=3D"color:#689d6a">(</span> <span style=3D"color:#689d6a">&quot;def.contro=
l_common_bundlesequence_end&quot;</span> <span style=3D"color:#689d6a">)</s=
pan>;
</pre></div><div><pre><span style=3D"color:#689d6a">&quot;bundlesequence_en=
d&quot;</span> <span style=3D"color:#d79921">slist</span> =3D&gt; getvalues=
<span style=3D"color:#689d6a">(</span> tbse <span style=3D"color:#689d6a">)=
</span>;

</pre></div><div><pre><span style=3D"color:#689d6a">&quot;tbse&quot;</span>=
 <span style=3D"color:#d79921">data</span> =3D&gt; mergedata<span style=3D"=
color:#689d6a">(</span> <span style=3D"color:#689d6a">&quot;def.control_com=
mon_bundlesequence_classification&quot;</span> <span style=3D"color:#689d6a=
">)</span>;
</pre></div><div><pre><span style=3D"color:#689d6a">&quot;bundlesequence_cl=
assification&quot;</span> <span style=3D"color:#d79921">slist</span> =3D&gt=
; 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&#39;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">&quot;j1&quot;</span> <span style=3D"=
color:#d79921">data</span> =3D&gt; <span style=3D"color:#689d6a">&#39;[&quo=
t;end_always&quot;]&#39;</span>;

        <span style=3D"color:#689d6a">&quot;j1m&quot;</span> <span style=3D=
"color:#d79921">data</span> =3D&gt; mergedata<span style=3D"color:#d79921">=
(</span> <span style=3D"color:#689d6a">&quot;j1&quot;</span> <span style=3D=
"color:#d79921">)</span>;

        <span style=3D"color:#689d6a">&quot;j2m&quot;</span> <span style=3D=
"color:#d79921">data</span> =3D&gt; mergedata<span style=3D"color:#d79921">=
(</span> <span style=3D"color:#689d6a">&quot;j2&quot;</span> <span style=3D=
"color:#d79921">)</span>;


      <span style=3D"color:#a89984;font-weight:bold">reports</span>:
        <span style=3D"color:#689d6a">&quot;j1m: $(with)&quot;</span> with =
=3D&gt; storejson<span style=3D"color:#d79921">(</span> <span style=3D"colo=
r:#689d6a">&quot;j1m&quot;</span> <span style=3D"color:#d79921">)</span>;
        <span style=3D"color:#689d6a">&quot;j2m: $(with)&quot;</span> with =
=3D&gt; storejson<span style=3D"color:#d79921">(</span> <span style=3D"colo=
r:#689d6a">&quot;j2m&quot;</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" rel=3D"nofollow" target=3D"_blank" data-s=
aferedirecturl=3D"https://www.google.com/url?hl=3Den&amp;q=3Dhttp://example=
.cf&amp;source=3Dgmail&amp;ust=3D1757612822498000&amp;usg=3DAOvVaw3sHAUEEA7=
p7B_DONdItR8p">example.cf</a>
R: j1m: [
  &quot;end_always&quot;
]
R: j2m: $(with)
Variable name                            Variable value                    =
                           Meta tags                                Comment
default:main.j1                          [&quot;end_always&quot;]          =
                                     source=3Dpromise
default:main.j1m                         [&quot;end_always&quot;]          =
                                     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" rel=3D"nofollow" target=3D"=
_blank" data-saferedirecturl=3D"https://www.google.com/url?hl=3Den&amp;q=3D=
http://update.cf&amp;source=3Dgmail&amp;ust=3D1757612822498000&amp;usg=3DAO=
vVaw3onJ7hMRx6XIwYdL9naOVI">update.cf</a>; cf-agent -Kv &gt; out.log &amp;&=
amp; grep <span style=3D"color:#689d6a">&quot;Using bundlesequence&quot;</s=
pan> out.log | awk <span style=3D"color:#689d6a">&#39;{print gsub(&quot;end=
_always&quot;, &quot;&amp;&quot;)}&#39;</span>
</pre>
</div>

<p>
Potential ways to address:
</p>

<p>
We could make the temporary variables uniquely named:
</p>

<pre>
&quot;tbse1&quot; data =3D&gt; mergedata( &quot;def.control_common_bundlese=
quence_end&quot; );
&quot;bundlesequence_end&quot; slist =3D&gt; getvalues( tbse1 );
&quot;tbse2&quot; data =3D&gt; mergedata( &quot;def.control_common_bundlese=
quence_classification&quot; );
&quot;bundlesequence_classification&quot; slist =3D&gt; 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&#39;s not define=
d.
</p>

<pre>
&quot;bundlesequence_end&quot;
  slist =3D&gt; { },
  if =3D&gt; not( isvariable( &quot;def.control_common_bundlesequence_end&q=
uot; ) );
&quot;bundlesequence_end&quot; slist =3D&gt; getvalues( mergedata( &quot;de=
f.control_common_bundlesequence_end&quot; ) );

&quot;bundlesequence_classification&quot;
  slist =3D&gt; { },
  if =3D&gt; not( isvariable( &quot;def.control_common_bundlesequence_class=
ification&quot; ) );
&quot;bundlesequence_classification&quot; slist =3D&gt; getvalues( mergedat=
a( &quot;def.control_common_bundlesequence_classification&quot; ) );
</pre>

<p>
Nested functions doesn&#39;t work
</p>

<pre>
&quot;bundlesequence_end&quot; slist =3D&gt; getvalues( mergedata( &quot;de=
f.control_common_bundlesequence_end&quot; ) );
&quot;bundlesequence_classification&quot; slist =3D&gt; getvalues( mergedat=
a( &quot;def.control_common_bundlesequence_classification&quot; ) );
</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">&quot;l&quot;</span> <span style=3D"c=
olor:#d79921">slist</span> =3D&gt; getvalues<span style=3D"color:#d79921">(=
</span> <span style=3D"color:#689d6a">&quot;does_not_exist&quot;</span>  <s=
pan style=3D"color:#d79921">)</span>;
        <span style=3D"color:#689d6a">&quot;j&quot;</span> <span style=3D"c=
olor:#d79921">slist</span> =3D&gt; getvalues<span style=3D"color:#d79921">(=
</span> mergedata<span style=3D"color:#458588">(</span> <span style=3D"colo=
r:#689d6a">&quot;does_not_exist&quot;</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" rel=3D"nofollow" target=3D"_blank" data-=
saferedirecturl=3D"https://www.google.com/url?hl=3Den&amp;q=3Dhttp://exampl=
e2.cf&amp;source=3Dgmail&amp;ust=3D1757612822498000&amp;usg=3DAOvVaw182WhB7=
CmbpjxBJ_-N6FLC">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" rel=
=3D"nofollow" target=3D"_blank" data-saferedirecturl=3D"https://www.google.=
com/url?hl=3Den&amp;q=3Dhttps://northerntech.atlassian.net/browse/CFE-4588&=
amp;source=3Dgmail&amp;ust=3D1757612822498000&amp;usg=3DAOvVaw1b1Jg4A31PWg_=
3xdRXoIEF">https://northerntech.atlassian.net/browse/CFE-4588</a>
</p>
</blockquote></div></blockquote></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;help-cfengine&quot; 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/85c72bb6-9d9c-4977-b13d-ed81aef4d7b0n%40googlegroups.com?utm_=
medium=3Demail&utm_source=3Dfooter">https://groups.google.com/d/msgid/help-=
cfengine/85c72bb6-9d9c-4977-b13d-ed81aef4d7b0n%40googlegroups.com</a>.<br /=
>

------=_Part_107329_1462458281.1757526434530--

------=_Part_107328_1471506313.1757526434530--