Convert gate to Ansible setup

To support multinode we must now distribute our setup to multiple
hosts. Instead of making special rules for this, we are going to
convert our existing setup to Ansible. This way both setup proceedures
take place in the exact same fashion.

Partially-Implements: blueprint multinode-gate
Change-Id: I43ece298bba994e9b5083403ef3cf6d4245cda6d
This commit is contained in:
Sam Yaple 2015-11-07 15:58:10 +00:00
parent 4d69166e57
commit f9ee96f216
6 changed files with 126 additions and 51 deletions

View File

@ -3,7 +3,10 @@
set -o xtrace
set -o errexit
sudo mount
DEV=$1
# (SamYaple)TODO: Remove the path overriding
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# Setup Docker repo and add signing key
echo 'deb http://apt.dockerproject.org/repo ubuntu-trusty main' | sudo tee /etc/apt/sources.list.d/docker.list

View File

@ -3,6 +3,11 @@
set -o xtrace
set -o errexit
DEV=$1
# (SamYaple)TODO: Remove the path overriding
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
cat | sudo tee /etc/yum.repos.d/docker.repo << EOF
[docker]
name=Docker Main Repository

View File

@ -1,31 +0,0 @@
#!/bin/bash
set -o xtrace
set -o errexit
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
function create_keys {
# Setup ssh key as required
sudo -H ssh-keygen -f /root/.ssh/id_rsa -N ""
sudo -H cat /root/.ssh/id_rsa.pub | sudo -H tee /root/.ssh/authorized_keys
}
function install_deps {
# Install Ansible and docker-py
sudo -H pip install "ansible<2" docker-py
pip freeze | egrep "docker|ansible"
}
function copy_configs {
# Copy configs
sudo cp -a etc/kolla /etc/
}
create_keys
install_deps
copy_configs
# Link the logs directory into root
mkdir -p logs
sudo ln -s $(pwd)/logs /root/logs

View File

@ -3,25 +3,98 @@
set -o xtrace
set -o errexit
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# TODO(SamYaple): This check could be much better, but should work for now
if [[ $(hostname | grep rax) ]]; then
export DEV="xvde"
else
echo "Assuming this is an hpcloud box"
export DEV="vdb"
fi
# Just for mandre :)
if [[ ! -f /etc/sudoers.d/jenkins ]]; then
echo "jenkins ALL=(:docker) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/jenkins
fi
# This creates a logs directory for the devstack logs publisher
mkdir logs
# We symlink the logs dir to a known location
ln -s $(pwd)/logs /tmp/logs
function detect_disk {
# TODO(SamYaple): This check could be much better, but should work for now
if [[ $(hostname | grep rax) ]]; then
export DEV="xvde"
else
echo "Assuming this is an hpcloud box"
export DEV="vdb"
fi
}
distro=$(awk -F'[="]'+ '/^ID/ {print tolower($2); exit}' /etc/*-release)
exec tests/setup_${distro}.sh
function setup_config {
# Copy configs
sudo cp -a etc/kolla /etc/
}
function detect_distro {
DISTRO=$(ansible all -i "localhost," -msetup -clocal | awk -F\" '/ansible_os_family/ {print $4}')
}
function setup_ssh {
# Generate a new keypair that Ansible will use
ssh-keygen -f /home/jenkins/.ssh/kolla -N ''
cat /home/jenkins/.ssh/kolla.pub >> /home/jenkins/.ssh/authorized_keys
# Push the the public key around to all of the nodes
for ip in $(cat /etc/nodepool/sub_nodes_private); do
scp /home/jenkins/.ssh/kolla.pub ${ip}:/home/jenkins/.ssh/authorized_keys
# TODO(SamYaple): Remove this root key pushing once Kolla doesn't
# require root anymore.
ssh ${ip} -i /home/jenkins/.ssh/kolla 'sudo mkdir -p /root/.ssh; sudo cp /home/jenkins/.ssh/* /root/.ssh/'
done
# From now on use the new IdentityFile for connecting to other hosts
echo "IdentityFile /home/jenkins/.ssh/kolla" >> /home/jenkins/.ssh/config
}
function setup_inventory {
local counter=0
detect_distro
if [[ "${DISTRO}" == "Debian" ]]; then
ANSIBLE_CONNECTION_TYPE=ssh
else
ANSIBLE_CONNECTION_TYPE=local
fi
echo -e "127.0.0.1\tlocalhost" > /tmp/hosts
for ip in $(cat /etc/nodepool/{node_private,sub_nodes_private}); do
: $((counter++))
echo -e "${ip}\tnode${counter} $(ssh ${ip} hostname)" >> /tmp/hosts
echo "node${counter} ansible_connection=${ANSIBLE_CONNECTION_TYPE}" >> ${RAW_INVENTORY}
done
sudo chown root: /tmp/hosts
sudo chmod 644 /tmp/hosts
sudo mv /tmp/hosts /etc/hosts
}
function setup_ansible {
RAW_INVENTORY=/tmp/kolla/raw_inventory
mkdir /tmp/kolla
sudo -H pip install "ansible<2" docker-py
setup_inventory
# Record the running state of the environment as seen by the setup module
ansible all -i ${RAW_INVENTORY} -m setup > /tmp/logs/ansible/initial-setup
}
function setup_node {
detect_disk
ansible-playbook -i ${RAW_INVENTORY} -edocker_dev=${DEV} tests/setup_nodes.yml
}
function setup_logging {
# This directory is the directory that is copied with the devstack-logs
# publisher. It must exist at /home/jenkins/workspace/<job-name>/logs
mkdir logs
# For ease of access we symlink that logs directory to a known path
ln -s $(pwd)/logs /tmp/logs
mkdir -p /tmp/logs/{ansible,build}
}
setup_logging
setup_ssh
setup_ansible
setup_node
setup_config

28
tests/setup_nodes.yml Normal file
View File

@ -0,0 +1,28 @@
---
- hosts: all
sudo: yes
tasks:
- name: Setup /etc/hosts
copy:
src: /etc/hosts
dest: /etc/hosts
- name: Assign hostname
hostname:
name: "{{ inventory_hostname }}"
- name: Copy setup script
copy:
src: setup_{{ ansible_os_family }}.sh
dest: /tmp/setup.sh
mode: 0755
- hosts: all
tasks:
- name: Create log directory for node
file:
state: directory
path: /tmp/{{ inventory_hostname }}
- name: Run node setup
shell: sudo /tmp/setup.sh {{ docker_dev }}

View File

@ -70,7 +70,6 @@ commands =
find . -type f -name "*.pyc" -delete
bash -c "if [ ! -d .testrepository ]; then testr init; fi"
sudo -g docker testr run test_build.DeployTestCentosBinary
bash tests/setup_deploy.sh
sudo tests/deploy_aio.sh centos binary
[testenv:deploy-centos-source]
@ -81,7 +80,6 @@ commands =
find . -type f -name "*.pyc" -delete
bash -c "if [ ! -d .testrepository ]; then testr init; fi"
sudo -g docker testr run test_build.DeployTestCentosSource
bash tests/setup_deploy.sh
sudo tests/deploy_aio.sh centos source
[testenv:deploy-ubuntu-source]
@ -92,7 +90,6 @@ commands =
find . -type f -name "*.pyc" -delete
bash -c "if [ ! -d .testrepository ]; then testr init; fi"
sudo -g docker testr run test_build.DeployTestUbuntuSource
bash tests/setup_deploy.sh
sudo tests/deploy_aio.sh ubuntu source
[testenv:deploy-multinode-ubuntu-source]