Uploaded image for project: 'CFEngine Community'
  1. CFEngine Community
  2. CFE-3858

if does not prevent promise from actuating resulting in CfReadFile error

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: (None)
    • Resolution: Unresolved
    • Affects Version/s: 3.19.0
    • Fix Version/s: None
    • Component/s: cf-agent
    • Labels:
      None

      Description

      if should be evaluated before with if $(with) is not used in if

      bundle agent var_if_test {
      
        vars:
            "user" slist => {"schast", "wimm", "schama" };
      
            #"ssh_key_dir" string => "/root/cfe_testbed/user_ssh_keys";
            "ssh_key_dir" string => "/tmp";
      
        classes:
      
            "exists_ssh_key_$(user)"
              expression => fileexists("$(ssh_key_dir)/$(user).cf");
      
        reports:
      
            "CFEngine $(sys.cf_version)";
      
            "$(user) -> $(with)"
            # This generates CfReadFile errors because it's trying to read a file that doesn't exist
              with => readfile("$(ssh_key_dir)/$(user).cf"),
            # But, the read should have been guarded by the check for the presence of this condition
              if => "exists_ssh_key_$(user)";
      
            "ABSENT: $(user)"
              unless => "exists_ssh_key_$(user)";
      
      }
      
      bundle agent __main__
      {
        methods:
            "var_if_test";
      }
      
         error: CfReadFile: Could not examine file '/tmp/schast.cf' (stat: No such file or directory)
         error: CfReadFile: Could not examine file '/tmp/schama.cf' (stat: No such file or directory)
      R: CFEngine 3.19.0a.da01eaa81
         error: CfReadFile: Could not examine file '/tmp/schast.cf' (stat: No such file or directory)
      R: wimm -> hello
         error: CfReadFile: Could not examine file '/tmp/schama.cf' (stat: No such file or directory)
      R: ABSENT: schast
      R: ABSENT: schama
         error: CfReadFile: Could not examine file '/tmp/schast.cf' (stat: No such file or directory)
         error: CfReadFile: Could not examine file '/tmp/schama.cf' (stat: No such file or directory)
         error: CfReadFile: Could not examine file '/tmp/schast.cf' (stat: No such file or directory)
         error: CfReadFile: Could not examine file '/tmp/schama.cf' (stat: No such file or directory)
      

      https://groups.google.com/g/help-cfengine/c/xZmbOai_kis/m/v3ULNkNRAwAJ

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            a10042 Nick Anderson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: