refactor so that there is no interaction between code-local and code-remote

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
Steven Armstrong 2013-11-26 16:30:03 +01:00
parent a3dea70a97
commit fcfd2d0a3c
3 changed files with 19 additions and 20 deletions

View file

@ -53,11 +53,24 @@ if [ "$state_should" = "present" -o "$state_should" = "exists" ]; then
fi
fi
if [ "$create_file" -o "$upload_file" ]; then
# tell gencode-remote that we created or uploaded a file and that it must
# set all attributes no matter what the explorer retreived
mkdir "$__object/files"
touch "$__object/files/set-attributes"
# upload file to temp location
tempfile_template="${destination}.cdist.XXXXXXXXXX"
echo "$__remote_exec ${__target_host} \"mktemp $tempfile_template\" > \"$__object/files/destination_upload\""
cat << DONE
destination_upload="\$($__remote_exec $__target_host "mktemp $tempfile_template")"
DONE
if [ "$upload_file" ]; then
echo "$__remote_copy $source ${__target_host}:\$(cat \"$__object/files/destination_upload\")"
fi
cat << DONE
$__remote_copy $source ${__target_host}:\$destination_upload
DONE
fi
# move uploaded file into place
cat << DONE
$__remote_exec $__target_host "rm -rf \"$destination\"; mv \"\$destination_upload\" \"$destination\""
DONE
fi
fi

View file

@ -57,29 +57,13 @@ set_mode() {
set_attributes=
case "$state_should" in
present|exists)
if [ -f "$__object/files/destination_upload" ]; then
# we uploaded a file, move it into place and set all attributes
destination_upload="$(cat "$__object/files/destination_upload")"
set_attributes=1
if [ "$type" = "directory" ]; then
# our destination is currently a directory, delete it
cat << DONE
rm -rf "$destination"
DONE
fi
# move our upload into place
cat << DONE
mv "$destination_upload" "$destination"
DONE
fi
# Note: Mode - needs to happen last as a chown/chgrp can alter mode by
# clearing S_ISUID and S_ISGID bits (see chown(2))
for attribute in group owner mode; do
if [ -f "$__object/parameter/$attribute" ]; then
value_should="$(cat "$__object/parameter/$attribute")"
value_is="$(get_current_value "$attribute" "$value_should")"
if [ "$set_attributes" -o "$value_should" != "$value_is" ]; then
if [ -f "$__object/files/set-attributes" -o "$value_should" != "$value_is" ]; then
"set_$attribute" "$value_should"
fi
fi

View file

@ -249,7 +249,7 @@ class Config(object):
cdist_type = cdist_object.cdist_type
# Generate
self.log.info("Generating and executing code for %s" % (cdist_object.name))
self.log.info("Generating code for %s" % (cdist_object.name))
cdist_object.code_local = self.code.run_gencode_local(cdist_object)
cdist_object.code_remote = self.code.run_gencode_remote(cdist_object)
if cdist_object.code_local or cdist_object.code_remote:
@ -257,6 +257,8 @@ class Config(object):
# Execute
if not self.dry_run:
if cdist_object.code_local or cdist_object.code_remote:
self.log.info("Executing code for %s" % (cdist_object.name))
if cdist_object.code_local:
self.code.run_code_local(cdist_object)
if cdist_object.code_remote: