tripleo-ci/elements/testenv-worker/bin/ensure-test-env

57 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
#
# Copyright 2013 Red Hat, Inc.
# Copyright 2014 Hewlett-Packard Development Company, L.P.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
set -eux
HOSTIP=$1
OVSBRIDGE=$2
NUM=$3
DATAFILE=/etc/test_env_${NUM}.json
trap 'rm -f $DATAFILE' ERR
LOGFILE=/var/log/testenv-worker_${NUM}.log
NODE_CPU=1 NODE_MEM=4096 NODE_DISK=30 NODE_ARCH=amd64
export OVERCLOUD_COMPUTESCALE=2 # Creates this + 2 nodes in testenv.
devtest_testenv.sh $DATAFILE -n $NUM -b $OVSBRIDGE
SEEDMAC=$(virsh dumpxml seed_$NUM | grep 'mac address' | awk -F \' 'NR==1,/mac address/ {print $2}')
NETWORKNAME=$(os-apply-config --key gearman-worker.network_name --type netdevice)
PORTOUTPUT=$(neutron port-create --name te_$(hostname)_$NUM --mac-address $SEEDMAC --format shell --column fixed_ips $NETWORKNAME)
echo "$PORTOUTPUT"
SEEDIP=$(echo "$PORTOUTPUT" | grep -E -o "([0-9]+\.){3}[0-9]+")
NEW_JSON=$(mktemp)
jq -s add $DATAFILE - <<EOF > $NEW_JSON
{
"env-num":"$NUM",
"remote-operations":"1",
"remote-host":"$(hostname)",
"seed-ip":"$SEEDIP",
"seed-route-dev":"eth1",
"ssh-key":"$(python -c 'print open("/root/.ssh/test_env_rsa").read().replace("\n", "\\n")')"
}
EOF
mv $NEW_JSON $DATAFILE
BROKER=$(os-apply-config --key gearman-worker.host --type netaddress):$(os-apply-config --key gearman-worker.port --key-default 4730 --type int)
# FIXME : not idempotent, just starts more workers, we need a way cleanly kill then
testenv-worker -b $BROKER $DATAFILE >> $LOGFILE 2>&1 &