Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
90 lines (73 sloc) 3.18 KB
#! /usr/bin/env bash
# Sets up a slave Jenkins server intended to run devstack-based Jenkins jobs
set -e
THIS_DIR=`pwd`
DATA_REPO_INFO_FILE=$THIS_DIR/.data_repo_info
DATA_PATH=$THIS_DIR/data
OSEXT_PATH=$THIS_DIR/os-ext-testing
OSEXT_REPO=https://github.com/jaypipes/os-ext-testing
PUPPET_MODULE_PATH="--modulepath=$OSEXT_PATH/puppet/modules:/root/config/modules:/etc/puppet/modules"
# Install Puppet and the OpenStack Infra Config source tree
if [[ ! -e install_puppet.sh ]]; then
wget https://git.openstack.org/cgit/openstack-infra/config/plain/install_puppet.sh
sudo bash -xe install_puppet.sh
sudo git clone https://review.openstack.org/p/openstack-infra/config.git \
/root/config
sudo /bin/bash /root/config/install_modules.sh
fi
# Clone or pull the the os-ext-testing repository
if [[ ! -d $OSEXT_PATH ]]; then
echo "Cloning os-ext-testing repo..."
git clone $OSEXT_REPO $OSEXT_PATH
fi
if [[ "$PULL_LATEST_OSEXT_REPO" == "1" ]]; then
echo "Pulling latest os-ext-testing repo master..."
cd $OSEXT_PATH; git checkout master && sudo git pull; cd $THIS_DIR
fi
if [[ ! -e $DATA_PATH ]]; then
echo "Enter the URI for the location of your config data repository. Example: https://github.com/jaypipes/os-ext-testing-data"
read data_repo_uri
if [[ "$data_repo_uri" == "" ]]; then
echo "Data repository is required to proceed. Exiting."
exit 1
fi
git clone $data_repo_uri $DATA_PATH
fi
if [[ "$PULL_LATEST_DATA_REPO" == "1" ]]; then
echo "Pulling latest data repo master."
cd $DATA_PATH; git checkout master && git pull; cd $THIS_DIR;
fi
# Pulling in variables from data repository
. $DATA_PATH/vars.sh
# Validate that the upstream gerrit user and key are present in the data
# repository
if [[ -z $UPSTREAM_GERRIT_USER ]]; then
echo "Expected to find UPSTREAM_GERRIT_USER in $DATA_PATH/vars.sh. Please correct. Exiting."
exit 1
else
echo "Using upstream Gerrit user: $UPSTREAM_GERRIT_USER"
fi
if [[ ! -e "$DATA_PATH/$UPSTREAM_GERRIT_SSH_KEY_PATH" ]]; then
echo "Expected to find $UPSTREAM_GERRIT_SSH_KEY_PATH in $DATA_PATH. Please correct. Exiting."
exit 1
fi
export UPSTREAM_GERRIT_SSH_PRIVATE_KEY_CONTENTS=`cat "$DATA_PATH/$UPSTREAM_GERRIT_SSH_KEY_PATH"`
# Validate there is a Jenkins SSH key pair in the data repository
if [[ -z $JENKINS_SSH_KEY_PATH ]]; then
echo "Expected to find JENKINS_SSH_KEY_PATH in $DATA_PATH/vars.sh. Please correct. Exiting."
exit 1
elif [[ ! -e "$DATA_PATH/$JENKINS_SSH_KEY_PATH" ]]; then
echo "Expected to find Jenkins SSH key pair at $DATA_PATH/$JENKINS_SSH_KEY_PATH, but wasn't found. Please correct. Exiting."
exit 1
else
echo "Using Jenkins SSH key path: $DATA_PATH/$JENKINS_SSH_KEY_PATH"
JENKINS_SSH_PRIVATE_KEY_CONTENTS=`sudo cat $DATA_PATH/$JENKINS_SSH_KEY_PATH`
JENKINS_SSH_PUBLIC_KEY_CONTENTS=`sudo cat $DATA_PATH/$JENKINS_SSH_KEY_PATH.pub`
fi
CLASS_ARGS="ssh_key => '$JENKINS_SSH_PUBLIC_KEY_CONTENTS', "
sudo puppet apply --verbose $PUPPET_MODULE_PATH -e "class {'os_ext_testing::devstack_slave': $CLASS_ARGS }"
if [[ ! -e /opt/git ]]; then
sudo mkdir -p /opt/git
sudo -i python /opt/nodepool-scripts/cache_git_repos.py
sudo /opt/nodepool-scripts/prepare_devstack.sh
fi