Project

General

Profile

Actions

Bug #10712

closed

Bug #10711: Improve generated inventory checks when inventory is missing

cf-agent: filesexist returns true on empty slist

Added by Janos Mattyasovszky over 7 years ago. Updated almost 5 years ago.

Status:
Rejected
Priority:
N/A
Assignee:
-
Category:
Agent
Target version:
Severity:
Minor - inconvenience | misleading | easy workaround
UX impact:
User visibility:
Infrequent - complex configurations | third party integrations
Effort required:
Priority:
18
Name check:
Fix check:
Regression:

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

Also available in: Atom PDF