-
Notifications
You must be signed in to change notification settings - Fork 22
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
Fixes #11142: filetemplate technique posthook #1177
Conversation
</ITEM> | ||
|
||
<CONSTRAINT> | ||
<DEFAULT>false</DEFAULT> |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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:: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Commit modified |
187efc5
to
fba936d
Compare
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"; |
There was a problem hiding this comment.
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:: |
There was a problem hiding this comment.
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}"); |
There was a problem hiding this comment.
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}"); |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still to do
There was a problem hiding this comment.
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" | ||
} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a meaningful name
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Force
Commit modified |
fba936d
to
967426c
Compare
it { should be_mode 750 } | ||
it { should be_owned_by "root" } | ||
end | ||
|
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still
Commit modified |
967426c
to
b5c19be
Compare
OK, merging this PR |
https://www.rudder-project.org/redmine/issues/11142