data_regextract failure; passes entire string instead of just the capture

25 views
Skip to first unread message

Louis Gillette

unread,
Jul 21, 2016, 3:25:38 PM7/21/16
to help-cfengine
Inside of one promise I have the following variables declared ( new_SD_version being the desired end point ) in my first bundle;

bundle agent initalize
{

vars:


"new_SD_version"
data => data_regextract("seadragon-(?<capture>.*)-service.zip", "$(standalone_directory_string)");

"standalone_directory_string"
string => nth(standalone_directory_listing, 0);

"standalone_directory_listing"
slist => lsdir("$(sys.inputdir)/standalone","seadragon.*","false");


etc...

which allows me to pull a numbered revision of my companies software in our distributed format. No issue in the bundle where these are all declared.

In another bundle later, I reference it again as follows;

unzipped_software_update&!sdfilecopy_happened::
"$(sys.inputdir)/standalone/sdfilecopy.sh"
args => "$(initalize.new_SD_version)";


to pass it into a shell script; the issue happens with how CFE completes its operations.

 verbose: Promiser string contains a valid executable '/var/cfengine/inputs/standalone/sdfilecopy.sh' - ok
    info: Executing 'no timeout' ... '/var/cfengine/inputs/standalone/sdfilecopy.sh seadragon-4.28.0-service.zip'
 verbose: Setting umask to 77
   error: Finished command related to promiser '/var/cfengine/inputs/standalone/sdfilecopy.sh' -- an error occurred, returned 1
27
  notice: Q: "...ilecopy.sh sead": ln -sf  /opt/seadragon/service/         /home/zaps/sdservice
Q: "...ilecopy.sh sead": /var/cfengine/inputs/standalone/sdfilecopy.sh: line 26: /etc/init.d/zaps-seadragon: No such file or di
rectory
Q: "...ilecopy.sh sead": cp: cannot stat `/opt/seadragon/zipfiles/seadragon-seadragon-4.28.0-service.zip-client-linux.tgz': No
such file or directory
Q: "...ilecopy.sh sead": tar (child): /opt/seadragon/client/seadragon-seadragon-4.28.0-service.zip-client-gtk-linux-x86.tgz: Ca
nnot open: No such file or directory
Q: "...ilecopy.sh sead": tar (child): Error is not recoverable: exiting now
Q: "...ilecopy.sh sead": tar: Child returned status 2
Q: "...ilecopy.sh sead": tar: Error is not recoverable: exiting now

Q: "...ilecopy.sh sead": cp: cannot stat `/opt/seadragon/zipfiles/seadragon-seadragon-4.28.0-service.zip-service.tar.xz': No such file or directory
Q: "...ilecopy.sh sead": tar (child): /opt/seadragon/service/seadragon-seadragon-4.28.0-service.zip-service.tar.xz: Cannot open: No such file or directory
Q: "...ilecopy.sh sead": tar (child): Error is not recoverable: exiting now
Q: "...ilecopy.sh sead": tar: Child returned status 2
Q: "...ilecopy.sh sead": tar: Error is not recoverable: exiting now
Q: "...ilecopy.sh sead": mv: cannot stat `/opt/seadragon/service/equations-lib/*.jar': No such file or directory
Q: "...ilecopy.sh sead": cp: cannot create regular file `/opt/seadragon/service/equations-lib/': Is a directory
Q: "...ilecopy.sh sead": /var/cfengine/inputs/standalone/sdfilecopy.sh: line 55: /etc/init.d/zaps-seadragon: No such file or directory
    info: Last 15 quoted lines were generated by promiser '/var/cfengine/inputs/standalone/sdfilecopy.sh seadragon-4.28.0-service.zip'
    info: Completed execution of '/var/cfengine/inputs/standalone/sdfilecopy.sh seadragon-4.28.0-service.zip'
 verbose: A: Promise NOT KEPT!
 verbose: P: END commands promise (/var/cfengine/inputs/standalon...)
 verbose: P: .........................................................
 verbose: P: BEGIN un-named promise of type "commands" (pass 1)
 verbose: P:    Promiser/affected object: '/var/cfengine/inputs/standalone/sdfileco'
 verbose: P:    Part of bundle: sd_update_2
 verbose: P:    Base context class: unzipped_software_update&!sdfilecopy_happened
 verbose: P:    Container path : '/default/initalize/methods/'start_update'/default/sd_update_1/methods/'chain_link_3'/default/sd_update_2/commands/'/var/cfengine/inputs/standalone/sdfilecopy.sh'[1]'
 verbose: P: .........................................................
 verbose:
 verbose: Promiser string contains a valid executable '/var/cfengine/inputs/standalone/sdfilecopy.sh' - ok
    info: Executing 'no timeout' ... '/var/cfengine/inputs/standalone/sdfilecopy.sh 4.28.0'
 verbose: Setting umask to 77
   error: Finished command related to promiser '/var/cfengine/inputs/standalone/sdfilecopy.sh' -- an error occurred, returned 127
  notice: Q: "...ilecopy.sh 4.28": ln -sf  /opt/seadragon/service/         /home/zaps/sdservice
Q: "...ilecopy.sh 4.28": /var/cfengine/inputs/standalone/sdfilecopy.sh: line 26: /etc/init.d/zaps-seadragon: No such file or directory
Q: "...ilecopy.sh 4.28": cp: cannot stat `/opt/seadragon/zipfiles/seadragon-4.28.0-client-linux.tgz': No such file or directory
Q: "...ilecopy.sh 4.28": tar (child): /opt/seadragon/client/seadragon-4.28.0-client-gtk-linux-x86.tgz: Cannot open: No such file or directory
Q: "...ilecopy.sh 4.28": tar (child): Error is not recoverable: exiting now
Q: "...ilecopy.sh 4.28": tar: Child returned status 2
Q: "...ilecopy.sh 4.28": tar: Error is not recoverable: exiting now
Q: "...ilecopy.sh 4.28": mv: cannot stat `/opt/seadragon/service/equations-lib/*.jar': No such file or directory
Q: "...ilecopy.sh 4.28": cp: cannot create regular file `/opt/seadragon/service/equations-lib/': Is a directory
Q: "...ilecopy.sh 4.28": /var/cfengine/inputs/standalone/sdfilecopy.sh: line 55: /etc/init.d/zaps-seadragon: No such file or directory
    info: Last 10 quoted lines were generated by promiser '/var/cfengine/inputs/standalone/sdfilecopy.sh 4.28.0'
    info: Completed execution of '/var/cfengine/inputs/standalone/sdfilecopy.sh 4.28.0'
 verbose: A: Promise NOT KEPT!
 verbose: P: END commands promise (/var/cfengine/inputs/standalon...)


CFE does a first go around and passes the entire string ( seadragon-4.28.0-service.zip ) into my shell script, but then comes back immediately and passes the desired data_regextract ( 4.28.0 in this case )

I'm wondering if I'm doing something wrong to have CFE perform like this, or if I need to change how I plan to manage my software/shell scripts

Nick Anderson

unread,
Jul 21, 2016, 4:29:49 PM7/21/16
to Louis Gillette, help-cfengine
On 07/21/2016 02:25 PM, Louis Gillette wrote:
> CFE does a first go around and passes the entire string (
> seadragon-4.28.0-service.zip ) into my shell script, but then comes back
> immediately and passes the desired data_regextract ( 4.28.0 in this case )
>
> I'm wondering if I'm doing something wrong to have CFE perform like
> this, or if I need to change how I plan to manage my software/shell scripts

Can you please post a self contained runnable example?

It seems like its iterating on the container. Try referencing it with

Perhaps you need to do this:

"$(sys.inputdir)/standalone/sdfilecopy.sh"
args => "$(initalize.new_SD_version[1])";

signature.asc

Louis Gillette

unread,
Jul 21, 2016, 5:15:47 PM7/21/16
to help-cfengine, lggil...@gmail.com

> Can you please post a self contained runnable example?


This work?

bundle agent initalize
{

vars:


"standalone_directory_string"
string => nth(standalone_directory_listing, 0);

"new_SD_version"
data => data_regextract("seadragon-(?<capture>.*)-service.zip", "$(standalone_directory_string)");

"standalone_directory_listing"
slist => lsdir("$(sys.inputdir)/standalone","seadragon.*","false");

"service_directory"
string => "/opt/seadragon/service";


viable_upgrade_versoin&!they_match::
"start_update"
usebundle => "sd_update_1";

}

bundle agent sd_update_1
{

classes:

"unzipped_software_update"
expression => fileexists("/opt/seadragon/zipfiles/seadragon-$(initalize.new_SD_version)-service.tar.xz");

files:

!unzipped_software_update::
"/opt/seadragon/zipfiles/seadragon-$(initalize.new_SD_version)-service.zip"
copy_from => local_cp("$(sys.inputdir)/standalone/seadragon-$(initalize.new_SD_version)-service.zip"),
perms => mog("770","zaps","zaps");
                                                    
!unzipped_software_update::
"/opt/seadragon/config/."
copy_from => local_dcp("$(initalize.service_directory)/config"),
depth_search => recurse ("inf"),
perms => mog("400","root","root");

"/opt/seadragon/service/archive/."
create => "true";


"/opt/seadragon/zipfiles/clean_up_executed"
delete => tidy;

commands:

!unzipped_software_update::
"$(sys.inputdir)/standalone/unzip_SD.sh";

methods:

unzipped_software_update::
"chain_link_3"
usebundle => sd_update_2;

}

bundle agent sd_update_2
{

vars:

#"new_SD_version"
#data => data_regextract("seadragon-(?<capture>.*)-service.zip", "$(initalize.standalone_directory_string)");

classes:

"unzipped_software_update"
expression => fileexists("/opt/seadragon/zipfiles/seadragon-$(initalize.new_SD_version)-service.tar.xz");

"sdfilecopy_happened"
expression => fileexists("/opt/seadragon/service/seadragon-$(initalize.new_SD_version)-service");

files:

"/opt/seadragon/zipfiles/install_scripts_ran"
delete => tidy;

commands:

"$(sys.inputdir)/standalone/sdremoval.sh";


unzipped_software_update&!sdfilecopy_happened::
"$(sys.inputdir)/standalone/sdfilecopy.sh"
args => "$(initalize.new_SD_version)";

methods:
sdfilecopy_happened::
"chain_link_4"
usebundle => sd_update_3;

}

Nick Anderson

unread,
Jul 21, 2016, 5:34:58 PM7/21/16
to Louis Gillette, help-cfengine
On 07/21/2016 04:15 PM, Louis Gillette wrote:
> This work?

No I cant just execute it (missing a lot of the peripheral stuff).

But I was able to synthesize a bit of it. I believe your issue is in how
your referencing the extracted data.

See this Gist.

https://gist.github.com/90b25f9e66dbcd2d5292d79e142a03be

bundle agent main
{

methods:
"init" usebundle => init;

"test" usebundle => test;
}

bundle agent init
{
files:
"$(this.promise_dirname)/seadragon-4.28.0-service.zip"
create => "true";
}

bundle agent test
{
vars:
"standalone_directory_listing"
slist => lsdir("$(this.promise_dirname)","seadragon.*","false");

"standalone_directory_string"
string => nth(standalone_directory_listing, 0);

"new_SD_version"
data => data_regextract("seadragon-(?<capture>.*)-service.zip",
$(standalone_directory_string) );

reports:
"Note how new_SD_version iterates:";
"$(new_SD_version)";

"If you only want the named capture: $(new_SD_version[capture])";
}

> $ cf-agent -KIf ./h.cf
R: Note how new_SD_version iterates:
R: seadragon-4.28.0-service.zip
R: 4.28.0
R: If you only want the named capture: 4.28.0


signature.asc

Louis Gillette

unread,
Jul 21, 2016, 5:54:28 PM7/21/16
to help-cfengine, lggil...@gmail.com
And in spite of my poor communicating of the issue, you've nailed it again. Using [capture] gives up the number sequence as expected. Thanks!

Nick Anderson

unread,
Jul 21, 2016, 7:12:01 PM7/21/16
to help-cfengine, Louis Gillette, lggil...@gmail.com
Great! Glad it's working for you.

Sent from my mobile device.
--
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 email to help-cfengin...@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