Merge "Handle python binary look for scripts"

This commit is contained in:
Zuul 2018-12-08 11:42:23 +00:00 committed by Gerrit Code Review
commit a0b72fa415
4 changed files with 24 additions and 5 deletions

View File

@ -14,8 +14,13 @@ SSH_HOSTKEY_OPTIONS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
SHORT_TERM_KEY_COMMENT="TripleO split stack short term key" SHORT_TERM_KEY_COMMENT="TripleO split stack short term key"
SLEEP_TIME=5 SLEEP_TIME=5
# needed to handle where python lives
function get_python() {
command -v python3 || command -v python2 || command -v python || exit 1
}
function overcloud_ssh_hosts_json { function overcloud_ssh_hosts_json {
echo "$OVERCLOUD_HOSTS" | python -c ' echo "$OVERCLOUD_HOSTS" | $(get_python) -c '
from __future__ import print_function from __future__ import print_function
import json, re, sys import json, re, sys
print(json.dumps(re.split("\s+", sys.stdin.read().strip())))' print(json.dumps(re.split("\s+", sys.stdin.read().strip())))'
@ -24,7 +29,7 @@ print(json.dumps(re.split("\s+", sys.stdin.read().strip())))'
function overcloud_ssh_key_json { function overcloud_ssh_key_json {
# we pass the contents to Mistral instead of just path, otherwise # we pass the contents to Mistral instead of just path, otherwise
# the key file would have to be readable for the mistral user # the key file would have to be readable for the mistral user
cat "$1" | python -c 'import json,sys; print(json.dumps(sys.stdin.read()))' cat "$1" | $(get_python) -c 'import json,sys; print(json.dumps(sys.stdin.read()))'
} }
function workflow_finished { function workflow_finished {

View File

@ -61,10 +61,15 @@ resources:
eth_addr=$(cat /sys/class/net/*/address | tr '\n' ',') eth_addr=$(cat /sys/class/net/*/address | tr '\n' ',')
mkdir -p /etc/os-net-config mkdir -p /etc/os-net-config
# needed to handle where python lives
function get_python() {
command -v python3 || command -v python2 || command -v python || exit 1
}
# Create an os-net-config mapping file, note this defaults to # Create an os-net-config mapping file, note this defaults to
# /etc/os-net-config/mapping.yaml, so we use that name despite # /etc/os-net-config/mapping.yaml, so we use that name despite
# rendering the result as json # rendering the result as json
echo '$node_lookup' | python -c " echo '$node_lookup' | $(get_python) -c "
import json import json
import sys import sys
import copy import copy

View File

@ -33,10 +33,14 @@ resources:
/[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}/) \ /[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}/) \
{ print substr($0, RSTART, RLENGTH) }' | tr '[:upper:]' '[:lower:]') { print substr($0, RSTART, RLENGTH) }' | tr '[:upper:]' '[:lower:]')
# needed to handle where python lives
function get_python() {
command -v python3 || command -v python2 || command -v python || exit 1
}
# Create a /etc/puppet/hieradata/UUID.json file to provide # Create a /etc/puppet/hieradata/UUID.json file to provide
# the data of the NodeDataLookup parameter that matches the # the data of the NodeDataLookup parameter that matches the
# system UUID # system UUID
echo $node_lookup | python -c " echo $node_lookup | $(get_python) -c "
import json import json
import sys import sys
input = sys.stdin.readline() or '{}' input = sys.stdin.readline() or '{}'

View File

@ -1,6 +1,11 @@
#!/bin/bash #!/bin/bash
set -e set -e
# needed to handle where python lives
function get_python() {
command -v python3 || command -v python2 || command -v python || exit 1
}
function ping_retry() { function ping_retry() {
local IP_ADDR=$1 local IP_ADDR=$1
local TIMES=${2:-'10'} local TIMES=${2:-'10'}
@ -33,7 +38,7 @@ function ping_controller_ips() {
networks=$(ip r | grep -v default | cut -d " " -f 1) networks=$(ip r | grep -v default | cut -d " " -f 1)
fi fi
for LOCAL_NETWORK in $networks; do for LOCAL_NETWORK in $networks; do
in_network=$(python -c "import ipaddress; net=ipaddress.ip_network(u'$LOCAL_NETWORK'); addr=ipaddress.ip_address(u'$REMOTE_IP'); print(addr in net)") in_network=$($(get_python) -c "import ipaddress; net=ipaddress.ip_network(u'$LOCAL_NETWORK'); addr=ipaddress.ip_address(u'$REMOTE_IP'); print(addr in net)")
if [[ $in_network == "True" ]]; then if [[ $in_network == "True" ]]; then
echo "Trying to ping $REMOTE_IP for local network ${LOCAL_NETWORK}." echo "Trying to ping $REMOTE_IP for local network ${LOCAL_NETWORK}."
set +e set +e