Bug #10712
closedBug #10711: Improve generated inventory checks when inventory is missing
cf-agent: filesexist returns true on empty slist
Description
As seen in the parent class, cfengine returns somehow true if you try to search a bunch of files "*.ocs" in an empty folder via findfiles
and use filesexist
on the resulting slist:
See rudder agent run -d
proper part:
rudder debug: Evaluating function: findfiles("${g.rudder_var_tmp}/inventory/*.ocs") rudder debug: Evaluating vars promise: inventory_file rudder debug: DeRefCopyPromise(): promiser:'perl_command' rudder debug: DeRefCopyPromise(): copying constraint: 'string' rudder debug: Evaluating vars promise: perl_command rudder verbose: V: ......................................................... rudder verbose: V: BEGIN variables (pass 1) rudder debug: DeRefCopyPromise(): promiser:'inventory_file' rudder debug: DeRefCopyPromise(): copying constraint: 'slist' rudder debug: Evaluating function: findfiles("${g.rudder_var_tmp}/inventory/*.ocs") <<========== This directory is empty rudder verbose: V: Computing value of 'inventory_file' rudder debug: Evaluating vars promise: inventory_file rudder debug: V: 'inventory_file' => '' <<=========================================== The result is empty rudder debug: Evaluating vars promise: inventory_file rudder debug: DeRefCopyPromise(): promiser:'perl_command' rudder debug: DeRefCopyPromise(): copying constraint: 'string' rudder verbose: V: Computing value of 'perl_command' rudder debug: Evaluating vars promise: perl_command rudder debug: V: 'perl_command' => '/usr/bin/perl' rudder debug: Evaluating vars promise: perl_command rudder verbose: C: ......................................................... rudder verbose: C: BEGIN classes / conditions (pass 1) rudder debug: DeRefCopyPromise(): promiser:'inventory_file_exist' rudder debug: DeRefCopyPromise(): copying constraint: 'expression' rudder debug: Evaluating function: filesexist("@{inventory_file}") <<============================== The check runs on the empty slist rudder debug: Evaluating classes promise: inventory_file_exist rudder verbose: C: + Private class: inventory_file_exist <<=================================== Class is defined !!! rudder debug: Setting class: default:inventory_file_exist
But the directory is empty:
# ll /var/rudder/tmp/inventory total 0
Here is an example code what I have copy-pasted together to demonstrate the behavior:
Run mkdir /tmp/empty
before :-)
test.cf:
body common control { bundlesequence => { "example" }; } bundle agent example { vars: "tmpdir" string => "/tmp/empty"; "mylist" slist => findfiles("${tmpdir}/*.ocs"); classes: "exists" expression => filesexist("@{mylist}"); reports: "My list: @{mylist}"; exists:: "Case exist!"; !exists:: "Case does not exist!"; }
Output is basically a "true" class even if the files don't exist!
# cf-agent -f ./test.cf R: My list: @{mylist} R: Case exist!
Updated by Janos Mattyasovszky over 7 years ago
Reported upstream @ https://tracker.mender.io/browse/CFE-2631
Updated by François ARMAND over 7 years ago
- Severity changed from Critical - prevents main use of Rudder | no workaround | data loss | security to Minor - inconvenience | misleading | easy workaround
- User visibility changed from Operational - other Techniques | Technique editor | Rudder settings to Infrequent - complex configurations | third party integrations
- Priority changed from 0 to 6
Thanks for reporting.
For the level: we believe it is misleading, not blocking, because it can be avoid if/when you know the problem (and are able to code CFEngine), which lead us to the "infrequent" user visibility, because it is rare to have to do so for typical rudder users. Hope it help understanding these levels.
Updated by Janos Mattyasovszky over 7 years ago
Yes, you are right, there is an easy workaround for this as seen in the parent.
Updated by Alexis Mousset over 5 years ago
- Target version set to 4.1.22
- Priority changed from 20 to 18
Updated by Vincent MEMBRÉ over 5 years ago
- Target version changed from 4.1.22 to 4.1.23
Updated by Vincent MEMBRÉ over 5 years ago
- Target version changed from 4.1.23 to 4.1.24
Updated by Vincent MEMBRÉ over 5 years ago
- Target version changed from 4.1.24 to 588
Updated by Alexis Mousset over 5 years ago
- Status changed from New to Rejected
This bug has been fixed in recent 4.1+ releases by updating the CFEngine agent to 3.10.5. Closing.
Updated by Alexis Mousset almost 5 years ago
- Target version changed from 588 to 4.1.24