Merge "Address python3 string issues with subprocess"
This commit is contained in:
commit
d385118e8d
|
@ -102,8 +102,9 @@ def short_hostname():
|
||||||
def pull_image(name):
|
def pull_image(name):
|
||||||
|
|
||||||
subproc = subprocess.Popen([cli_cmd, 'inspect', name],
|
subproc = subprocess.Popen([cli_cmd, 'inspect', name],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE,
|
||||||
|
universal_newlines=True)
|
||||||
cmd_stdout, cmd_stderr = subproc.communicate()
|
cmd_stdout, cmd_stderr = subproc.communicate()
|
||||||
retval = subproc.returncode
|
retval = subproc.returncode
|
||||||
if retval == 0:
|
if retval == 0:
|
||||||
|
@ -117,7 +118,8 @@ def pull_image(name):
|
||||||
count += 1
|
count += 1
|
||||||
subproc = subprocess.Popen([cli_cmd, 'pull', name],
|
subproc = subprocess.Popen([cli_cmd, 'pull', name],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE,
|
||||||
|
universal_newlines=True)
|
||||||
|
|
||||||
cmd_stdout, cmd_stderr = subproc.communicate()
|
cmd_stdout, cmd_stderr = subproc.communicate()
|
||||||
retval = subproc.returncode
|
retval = subproc.returncode
|
||||||
|
@ -162,7 +164,8 @@ def rm_container(name):
|
||||||
log.info('Diffing container: %s' % name)
|
log.info('Diffing container: %s' % name)
|
||||||
subproc = subprocess.Popen([cli_cmd, 'diff', name],
|
subproc = subprocess.Popen([cli_cmd, 'diff', name],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE,
|
||||||
|
universal_newlines=True)
|
||||||
cmd_stdout, cmd_stderr = subproc.communicate()
|
cmd_stdout, cmd_stderr = subproc.communicate()
|
||||||
if cmd_stdout:
|
if cmd_stdout:
|
||||||
log.debug(cmd_stdout)
|
log.debug(cmd_stdout)
|
||||||
|
@ -172,7 +175,8 @@ def rm_container(name):
|
||||||
log.info('Removing container: %s' % name)
|
log.info('Removing container: %s' % name)
|
||||||
subproc = subprocess.Popen([cli_cmd, 'rm', name],
|
subproc = subprocess.Popen([cli_cmd, 'rm', name],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE,
|
||||||
|
universal_newlines=True)
|
||||||
cmd_stdout, cmd_stderr = subproc.communicate()
|
cmd_stdout, cmd_stderr = subproc.communicate()
|
||||||
if cmd_stdout:
|
if cmd_stdout:
|
||||||
log.debug(cmd_stdout)
|
log.debug(cmd_stdout)
|
||||||
|
@ -270,21 +274,21 @@ if not os.path.exists(sh_script):
|
||||||
if [ -n "$PUPPET_TAGS" ]; then
|
if [ -n "$PUPPET_TAGS" ]; then
|
||||||
TAGS="--tags \"$PUPPET_TAGS\""
|
TAGS="--tags \"$PUPPET_TAGS\""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
CHECK_MODE=""
|
CHECK_MODE=""
|
||||||
if [ -d "/tmp/puppet-check-mode" ]; then
|
if [ -d "/tmp/puppet-check-mode" ]; then
|
||||||
mkdir -p /etc/puppet/check-mode
|
mkdir -p /etc/puppet/check-mode
|
||||||
cp -a /tmp/puppet-check-mode/* /etc/puppet/check-mode
|
cp -a /tmp/puppet-check-mode/* /etc/puppet/check-mode
|
||||||
CHECK_MODE="--hiera_config /etc/puppet/check-mode/hiera.yaml"
|
CHECK_MODE="--hiera_config /etc/puppet/check-mode/hiera.yaml"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create a reference timestamp to easily find all files touched by
|
# Create a reference timestamp to easily find all files touched by
|
||||||
# puppet. The sync ensures we get all the files we want due to
|
# puppet. The sync ensures we get all the files we want due to
|
||||||
# different timestamp.
|
# different timestamp.
|
||||||
origin_of_time=/var/lib/config-data/${NAME}.origin_of_time
|
origin_of_time=/var/lib/config-data/${NAME}.origin_of_time
|
||||||
touch $origin_of_time
|
touch $origin_of_time
|
||||||
sync
|
sync
|
||||||
|
|
||||||
export NET_HOST="${NET_HOST:-false}"
|
export NET_HOST="${NET_HOST:-false}"
|
||||||
set +e
|
set +e
|
||||||
if [ "$NET_HOST" == "false" ]; then
|
if [ "$NET_HOST" == "false" ]; then
|
||||||
|
@ -307,7 +311,7 @@ if not os.path.exists(sh_script):
|
||||||
if [ $rc -ne 2 -a $rc -ne 0 ]; then
|
if [ $rc -ne 2 -a $rc -ne 0 ]; then
|
||||||
exit $rc
|
exit $rc
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Disables archiving
|
# Disables archiving
|
||||||
if [ -z "$NO_ARCHIVE" ]; then
|
if [ -z "$NO_ARCHIVE" ]; then
|
||||||
archivedirs=("/etc" "/root" "/opt" "/var/lib/ironic/tftpboot" "/var/lib/ironic/httpboot" "/var/www" "/var/spool/cron" "/var/lib/nova/.ssh")
|
archivedirs=("/etc" "/root" "/opt" "/var/lib/ironic/tftpboot" "/var/lib/ironic/httpboot" "/var/www" "/var/spool/cron" "/var/lib/nova/.ssh")
|
||||||
|
@ -331,14 +335,14 @@ if not os.path.exists(sh_script):
|
||||||
else
|
else
|
||||||
password_files=""
|
password_files=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exclude_files=""
|
exclude_files=""
|
||||||
for p in $password_files; do
|
for p in $password_files; do
|
||||||
exclude_files+=" --exclude=$p"
|
exclude_files+=" --exclude=$p"
|
||||||
done
|
done
|
||||||
rsync -a -R --delay-updates --delete-after $exclude_files $rsync_srcs /var/lib/config-data/${NAME}
|
rsync -a -R --delay-updates --delete-after $exclude_files $rsync_srcs /var/lib/config-data/${NAME}
|
||||||
|
|
||||||
|
|
||||||
# Also make a copy of files modified during puppet run
|
# Also make a copy of files modified during puppet run
|
||||||
# This is useful for debugging
|
# This is useful for debugging
|
||||||
echo "Gathering files modified after $(stat -c '%y' $origin_of_time)"
|
echo "Gathering files modified after $(stat -c '%y' $origin_of_time)"
|
||||||
|
@ -346,7 +350,7 @@ if not os.path.exists(sh_script):
|
||||||
rsync -a -R -0 --delay-updates --delete-after $exclude_files \
|
rsync -a -R -0 --delay-updates --delete-after $exclude_files \
|
||||||
--files-from=<(find $rsync_srcs -newer $origin_of_time -not -path '/etc/puppet*' -print0) \
|
--files-from=<(find $rsync_srcs -newer $origin_of_time -not -path '/etc/puppet*' -print0) \
|
||||||
/ /var/lib/config-data/puppet-generated/${NAME}
|
/ /var/lib/config-data/puppet-generated/${NAME}
|
||||||
|
|
||||||
# Write a checksum of the config-data dir, this is used as a
|
# Write a checksum of the config-data dir, this is used as a
|
||||||
# salt to trigger container restart when the config changes
|
# salt to trigger container restart when the config changes
|
||||||
# note: while being excluded from the output, password files
|
# note: while being excluded from the output, password files
|
||||||
|
@ -462,7 +466,8 @@ def mp_puppet_config(*args):
|
||||||
cmd = [cli_cmd, 'start', '-a', uname]
|
cmd = [cli_cmd, 'start', '-a', uname]
|
||||||
count += 1
|
count += 1
|
||||||
subproc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
subproc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE, env=env)
|
stderr=subprocess.PIPE, env=env,
|
||||||
|
universal_newlines=True)
|
||||||
cmd_stdout, cmd_stderr = subproc.communicate()
|
cmd_stdout, cmd_stderr = subproc.communicate()
|
||||||
retval = subproc.returncode
|
retval = subproc.returncode
|
||||||
# puppet with --detailed-exitcodes will return 0 for success and no changes
|
# puppet with --detailed-exitcodes will return 0 for success and no changes
|
||||||
|
|
|
@ -200,7 +200,7 @@ def process_templates_and_get_reference_parameters():
|
||||||
'--network-data ' + OPTS.network_data,
|
'--network-data ' + OPTS.network_data,
|
||||||
'--output-dir ' + temp_dir]
|
'--output-dir ' + temp_dir]
|
||||||
child = subprocess.Popen(' '.join(cmd), shell=True, stdout=subprocess.PIPE,
|
child = subprocess.Popen(' '.join(cmd), shell=True, stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE, universal_newlines=True)
|
||||||
out, err = child.communicate()
|
out, err = child.communicate()
|
||||||
if not child.returncode == 0:
|
if not child.returncode == 0:
|
||||||
raise RuntimeError('Error processing templates: %s' % err)
|
raise RuntimeError('Error processing templates: %s' % err)
|
||||||
|
|
Loading…
Reference in New Issue