Possible bug, just want to confirm before submitting bug report

25 views
Skip to first unread message

Bill G

unread,
Apr 13, 2018, 8:16:34 PM4/13/18
to help-cfengine
Hi All,  

I believe I have run across a bug with local_cp (pertinent snippets from promise):

...

"$(this.promise_dirname)/logstash/."
    create
=> "true",
    copy_from
=> secure_cp("/var/cfengine/masterfiles/services/ELK/logstash/templates/.", "$(sys.policy_hub)"),
    file_select
=> by_name(".*"),
    depth_search
=> recurse("inf");


...

"$(logstash_config_dir)/."
    create
=> "true",
    copy_from
=> local_cp("$(this.promise_dirname)/logstash/templates/."),
    file_select
=> by_name(".*"),
    depth_search
=> recurse("inf"),
    move_obstructions
=> "true",



...

which results in:

cf-agent[9539]: CFEngine(agent)  Can't stat file '$(this.promise_dir)/logstash/templates/.' on 'localhost' in files.copy_from promise

However, if I change the local_cp to secure_cp and use the full path of the 'masterfiles' location it works as expected, just becomes a heavier operation than what I would like to see.  I will also note that the local directories do exist and contain the expected files and directories.

Version information:
cfengine version: cfengine-nova-3.10.3-1.x86_64
OS: Centos 7
Kernel: 3.10.0-693.21.1.el7.x86_64

Other than that, it is fun to knock the rust off.

Thanks for you time,
Bill 

Nick Anderson

unread,
Apr 13, 2018, 10:21:36 PM4/13/18
to Bill G, help-cfengine

Hi Bill,

Bill G <tc3d...@gmail.com> writes:
> I believe I have run across a bug with localcp (pertinent snippets from
> promise):

"$(this.promise_dirname)/logstash/."
    create => "true",
    copy_from => secure_cp(
"/var/cfengine/masterfiles/services/ELK/logstash/templates/.", 
"$(sys.policy_hub)"),
    file_select => by_name(".*"),
    depth_search => recurse("inf");

"$(logstash_config_dir)/."
    create => "true",
    copy_from => local_cp("$(this.promise_dirname)/logstash/templates/."),
    file_select => by_name(".*"),
    depth_search => recurse("inf"),
    move_obstructions => "true",

> which results in:

cf-agent[9539]: CFEngine(agent)  Can't stat file 
'$(this.promise_dir)/logstash/templates/.' on 'localhost' in 
files.copy_from promise

Hum, the error message here looks like there is a typo. It contains
$(this.promise_dir) instead of $(this.promise_dirname). Ref
this.promisedirname. However in the policy snippet above it looks to be
correct.

bundle agent main
{
  methods:
      "init";
      "test";
      "check";
}

bundle agent init
# Make sure there are files to copy from.
{
  vars:
      "files" slist => { "dir1/file1.txt", "dir2/file2.txt", "file3.txt" };

  files:
      "$(this.promise_dirname)/logstash/templates/$(files)"
        create => "true",
        edit_defaults => empty,
        edit_line => insert_lines( $(sys.date) );
}
bundle agent test
{
  vars:
      "logstash_config_dir" string => "/tmp/dest";

  files:
      
"$(logstash_config_dir)/."
        create => "true",
        copy_from => local_cp("$(this.promise_dirname)/logstash/templates/."),
        file_select => by_name(".*"),
        depth_search => recurse("inf")
,
        move_obstructions => "true";
}
bundle agent check
{
  reports:
      "Files in destination: $(with)"
        with => join( ", ", findfiles("$(test.logstash_config_dir)/**/*") );
}
body edit_defaults empty
# @brief Empty the file before editing
#
# No backup is made
{
      empty_file_before_editing => "true";
      edit_backup => "false";
      #max_file_size => "300000";
}
body depth_search recurse(d)
# @brief Search files and direcories recursively, up to the specified depth
# Directories on different devices are included.
#
# @param d The maximum search depth
{
        depth => "$(d)";
        xdev  => "true";
}
body file_select by_name(names)
# @brief Select files that match `names`
# @param names A regular expression
{
        leaf_name  => { @(names)};
        file_result => "leaf_name";
}
body copy_from local_cp(from)
# @brief Copy a file if the modification time or creation time of the source
# file is newer (the default comparison mechanism).
# @param from The path to the source file.
#
# **Example:**
#
# ```cf3
# bundle agent example
# {
#   files:
#       "/tmp/file.bak"
#         copy_from => local_cp("/tmp/file");
# }
# ```
#
# **See Also:** `local_dcp()`
{
        source      => "$(from)";
}

bundle edit_line insert_lines(lines)
# @brief Alias for `lines_present`
{
  insert_lines:

      "$(lines)"
        comment => "Append lines if they don't exist";
}
> $ cf-agent -KIf ./example.cf                                                                     
    info: Created file '/tmp/source/./logstash/templates/dir1/file1.txt', mode 0600
    info: Edit file '/tmp/source/./logstash/templates/dir1/file1.txt'
    info: Created file '/tmp/source/./logstash/templates/dir2/file2.txt', mode 0600
    info: Edit file '/tmp/source/./logstash/templates/dir2/file2.txt'
    info: Created file '/tmp/source/./logstash/templates/file3.txt', mode 0600
    info: Edit file '/tmp/source/./logstash/templates/file3.txt'
    info: Created directory '/tmp/dest/.'
    info: Copying from 'localhost:/tmp/source/./logstash/templates/./dir2/file2.txt'
    info: Copying from 'localhost:/tmp/source/./logstash/templates/./dir1/file1.txt'
    info: Copying from 'localhost:/tmp/source/./logstash/templates/./file3.txt'
R: Files in destination: /tmp/dest/dir1/file1.txt, /tmp/dest/dir2/file2.txt

However, if I change the localcp to securecp and use the full path of the


'masterfiles' location it works as expected, just becomes a heavier
operation than what I would like to see. I will also note that the local
directories do exist and contain the expected files and directories.

Can you double check? It seems to work fine in my testing. Have I overlooked something?

> Other than that, it is fun to knock the rust off.

Hopefully it won't get rusty again. :-)


Nick Anderson
Doer of things, CFEngine

Bill G.

unread,
Apr 14, 2018, 4:49:04 AM4/14/18
to Nick Anderson, help-cfengine
Nick,

Thanks... That was definitely my screw up (insert face-palm here).

This is why I like to double check.  At any rate I will test again on Monday and confirm 

Thanks again,
Bill
--
Thanks,
Bill G.
tc3d...@gmail.com

Nick Anderson

unread,
Apr 14, 2018, 7:28:53 AM4/14/18
to help-cfengine
Ok, please let us know how it works out.

Have a great weekend.

Bill G.

unread,
Apr 16, 2018, 7:10:05 PM4/16/18
to Nick Anderson, help-cfengine
Yeah, completely my mistake with the typo.

Sorry for the confusion.

Hope you all have a great week.

On Sat, Apr 14, 2018 at 4:28 AM, Nick Anderson <ni...@cmdln.org> wrote:
Ok, please let us know how it works out.

Have a great weekend.

--
You received this message because you are subscribed to a topic in the Google Groups "help-cfengine" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/help-cfengine/68_UnlLZHIQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to help-cfengine+unsubscribe@googlegroups.com.
To post to this group, send email to help-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/help-cfengine.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages