Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #11142: filetemplate technique posthook #1177

Conversation

Fdall
Copy link
Contributor

@Fdall Fdall commented Jul 17, 2017

</ITEM>

<CONSTRAINT>
<DEFAULT>false</DEFAULT>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the default should be true

@@ -132,6 +132,24 @@
</CONSTRAINT>
</INPUT>

<SELECT1>
<NAME>FILE_TEMPLATE_PERSISTENT_POST_HOOK</NAME>
<DESCRIPTION>Persistent posthook command</DESCRIPTION>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retry hook on error

"src_canon[${index}]" string => canonify("${relative_src}/${src[${index}]}");
"dst_canon[${index}]" string => canonify("${dst[${index}]}");
"temp_canon[${index}]" string => canonify("${temp}/${name[${index}]}");
"temp_dir_canon" string => canonify("${temp}");
"posthook_canon[${index}]" string => canonify("${posthook[${index}]}");

#Cancel persistent classes
pass3::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if posthook is ok, there should be no need for a pass3

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still there

"posthook_not_launch_${index}" expression =>"posthook_specified_${index}.!(file_modified_${index})";
"posthook_persistent_${index}" expression => strcmp("${persist[${index}]}", "true");

#Check if we are on the second posthook run or more
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is not true : we are saving the "posthook failed" information for next run

#Check if we are on the second posthook run or more
"posthook_multi_runs_${index}" expression => "posthook_persistent_${index}.command_execution_${posthook_canon[${index}]}_failed",
scope => "namespace",
persistence => "10000";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please comment on how long this number represents

"posthook_persistent_${index}" expression => strcmp("${persist[${index}]}", "true");

#Check if we are on the second posthook run or more
"posthook_multi_runs_${index}" expression => "posthook_persistent_${index}.command_execution_${posthook_canon[${index}]}_failed",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer a name like post_hook_rerun



#Case without execution

"report_${index}" usebundle => rudder_common_report("fileTemplate", "result_na", "${trackingkey[${index}]}", "Posthook", "${dst[${index}]}", "No post-modification needed to run"),
ifvarclass => "!file_modified_${index}.posthook_specified_${index}";
ifvarclass => "!file_modified_${index}.posthook_specified_${index}.!command_execution_${posthook_canon[${index}]}_reached";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a problem here, the posthook can be not reached if it has not yet been executed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't understand: if we erase this conditional state, persistent posthook in error will report as a N/A and not as a posthook execution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A class can only be defined or not defined.
A class can be not defined, be be defined on next pass.
That's why using negation in class expressions is touchy.

But i see that this is enclosed in pass3, so there is no problem.

@Fdall
Copy link
Contributor Author

Fdall commented Jul 19, 2017

Commit modified

@Fdall Fdall force-pushed the ust_11142/filetemplate_technique_posthook branch 2 times, most recently from 187efc5 to fba936d Compare July 19, 2017 11:04
@Fdall
Copy link
Contributor Author

Fdall commented Jul 19, 2017

Commit modified



#Case without execution

"report_${index}" usebundle => rudder_common_report("fileTemplate", "result_na", "${trackingkey[${index}]}", "Posthook", "${dst[${index}]}", "No post-modification needed to run"),
ifvarclass => "!file_modified_${index}.posthook_specified_${index}";
ifvarclass => "!file_modified_${index}.posthook_specified_${index}.!command_execution_${posthook_canon[${index}]}_reached";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A class can only be defined or not defined.
A class can be not defined, be be defined on next pass.
That's why using negation in class expressions is touchy.

But i see that this is enclosed in pass3, so there is no problem.

"src_canon[${index}]" string => canonify("${relative_src}/${src[${index}]}");
"dst_canon[${index}]" string => canonify("${dst[${index}]}");
"temp_canon[${index}]" string => canonify("${temp}/${name[${index}]}");
"temp_dir_canon" string => canonify("${temp}");
"posthook_canon[${index}]" string => canonify("${posthook[${index}]}");

#Cancel persistent classes
pass3::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still there

"other_files" slist => {"/tmp/aDirectory"};

methods:
"any" usebundle => command_execution("rm -f /tmp/${gen_files}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a file_remove method for this

methods:
"any" usebundle => command_execution("rm -f /tmp/${gen_files}");
"any" usebundle => command_execution("rm -f /var/rudder/templates/${src_files}");
"any" usebundle => command_execution("rm -Rf ${other_files}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not yet for this

{
"var": {
"name": "FILE_TEMPLATE_TEMPLATE",
"value": "lmqoivuqiuvh"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a value that is meaningful, like "not-a-file"

@@ -0,0 +1,3 @@
#!/usr/local/bin/ncf -f
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have nothing to do, you should just have no init at all

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still to do

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still

"shortDescription": "",
"techniqueName": "fileTemplate",
"techniqueVersion": "1.0"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline

its(:exit_status) { should eq 0 }
end

describe command("rm -f /var/rudder/tmp/templates/*") do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the goal is just to clean up you can also remove all files in a single rm command

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That way we can see easily which case failed in case of failure

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a cleanup code, not a test.
Moreover, the -f prevents rm from returning errors.

{
"var": {
"name": "FILE_TEMPLATE_TEMPLATE_POST_HOOK_COMMAND",
"value": "/bin/ls /tmp/aDirectory"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a meaningful name

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still

its(:stdout) { should match /^R: @@fileTemplate@@result_error@@.*?@@.*?@@.*?@@Posthook@@\/tmp\/persistentPosthooktest@@.*?The command .*?from postHook execution could not be repaired$/m}
end

# Forced the execution of the posthook
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Force

@Fdall
Copy link
Contributor Author

Fdall commented Jul 20, 2017

Commit modified

@Fdall Fdall force-pushed the ust_11142/filetemplate_technique_posthook branch from fba936d to 967426c Compare July 20, 2017 14:30
it { should be_mode 750 }
it { should be_owned_by "root" }
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still there

@@ -0,0 +1,3 @@
#!/usr/local/bin/ncf -f
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still

its(:exit_status) { should eq 0 }
end

describe command("rm -f /var/rudder/tmp/templates/*") do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a cleanup code, not a test.
Moreover, the -f prevents rm from returning errors.

{
"var": {
"name": "FILE_TEMPLATE_TEMPLATE_POST_HOOK_COMMAND",
"value": "/bin/ls /tmp/aDirectory"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still

@Fdall
Copy link
Contributor Author

Fdall commented Jul 21, 2017

Commit modified

@Fdall Fdall force-pushed the ust_11142/filetemplate_technique_posthook branch from 967426c to b5c19be Compare July 21, 2017 16:46
@Normation-Quality-Assistant
Copy link
Contributor

OK, merging this PR

@Normation-Quality-Assistant Normation-Quality-Assistant merged commit b5c19be into Normation:branches/rudder/4.1 Jul 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants