Merge branch 'master' into autorequire

This commit is contained in:
Steven Armstrong 2011-11-18 15:13:52 +01:00
commit 30da237405
5 changed files with 20 additions and 10 deletions

View file

@ -31,8 +31,6 @@ if [ -f "$__object/parameter/source" ]; then
remote_cksum="$(cat "$__object/explorer/cksum")" remote_cksum="$(cat "$__object/explorer/cksum")"
if [ "$local_cksum" != "$remote_cksum" ]; then if [ "$local_cksum" != "$remote_cksum" ]; then
# Export target_host so remote_copy script has access to it
echo "export __target_host=\"$__target_host\""
echo "$__remote_copy" "$source" "${__target_host}:${destination}" echo "$__remote_copy" "$source" "${__target_host}:${destination}"
fi fi
else else

View file

@ -13,6 +13,10 @@ TESTS
- multiple defines of object: - multiple defines of object:
- fail if different parameters - fail if different parameters
- succeed if same parameters - succeed if same parameters
- verify that all env variables in doc/man/cdist-reference.text.sh
exist in the right stages
- test DependencyResolver
USER INTERFACE USER INTERFACE
-------------- --------------

View file

@ -188,9 +188,6 @@ __object_name::
__target_host:: __target_host::
The host we are deploying to. The host we are deploying to.
Available for: initial manifest, type manifest, type gencode Available for: initial manifest, type manifest, type gencode
__target_user::
User to use for authentication on remote host.
Currently static in core.
__type:: __type::
Path to the current type. Path to the current type.
Available for: type manifest, type gencode Available for: type manifest, type gencode

View file

@ -95,6 +95,12 @@ class Local(object):
""" """
assert isinstance(command, (list, tuple)), "list or tuple argument expected, got: %s" % command assert isinstance(command, (list, tuple)), "list or tuple argument expected, got: %s" % command
self.log.debug("Local run: %s", command) self.log.debug("Local run: %s", command)
if env is None:
env = os.environ.copy()
# Export __target_host for use in __remote_{copy,exec} scripts
env['__target_host'] = self.target_host
try: try:
if return_output: if return_output:
return subprocess.check_output(command, env=env).decode() return subprocess.check_output(command, env=env).decode()
@ -114,8 +120,13 @@ class Local(object):
command.append(script) command.append(script)
self.log.debug("Local run script: %s", command) self.log.debug("Local run script: %s", command)
if env:
self.log.debug("Local run script env: %s", env) if env is None:
env = os.environ.copy()
# Export __target_host for use in __remote_{copy,exec} scripts
env['__target_host'] = self.target_host
self.log.debug("Local run script env: %s", env)
try: try:
if return_output: if return_output:

View file

@ -91,7 +91,7 @@ class Remote(object):
self.rmdir(destination) self.rmdir(destination)
command = self._copy.split() command = self._copy.split()
command.extend(["-r", source, self.target_host + ":" + destination]) command.extend(["-r", source, self.target_host + ":" + destination])
self.run_command(command) self._run_command(command)
def run(self, command, env=None, return_output=False): def run(self, command, env=None, return_output=False):
"""Run the given command with the given environment on the remote side. """Run the given command with the given environment on the remote side.
@ -102,9 +102,9 @@ class Remote(object):
cmd = self._exec.split() cmd = self._exec.split()
cmd.append(self.target_host) cmd.append(self.target_host)
cmd.extend(command) cmd.extend(command)
return self.run_command(cmd, env=env, return_output=return_output) return self._run_command(cmd, env=env, return_output=return_output)
def run_command(self, command, env=None, return_output=False): def _run_command(self, command, env=None, return_output=False):
"""Run the given command with the given environment. """Run the given command with the given environment.
Return the output as a string. Return the output as a string.