summaryrefslogtreecommitdiffstats
path: root/mcp/scripts
diff options
context:
space:
mode:
authorMichael Polenchuk <mpolenchuk@mirantis.com>2017-06-29 15:52:28 +0400
committerMichael Polenchuk <mpolenchuk@mirantis.com>2017-07-03 11:18:25 +0400
commite49e91d7aa740437c01e6531ef648d2dae97c11d (patch)
tree4227d9f205f59d5a6a1cdf086ad689dfc4bcb477 /mcp/scripts
parent3fb5e5454045860463a92c18d4d859967002e6fb (diff)
Rewrite infra deployment scripts
* bring in scenario files * shift infra code into functions Change-Id: I650a26d03d842c3afcc7fcb97b84ef4826827a38 Signed-off-by: Michael Polenchuk <mpolenchuk@mirantis.com>
Diffstat (limited to 'mcp/scripts')
-rwxr-xr-xmcp/scripts/create-config-drive.sh102
-rwxr-xr-xmcp/scripts/dpdk.sh16
-rw-r--r--mcp/scripts/lib.sh128
-rw-r--r--mcp/scripts/net_internal.xml4
-rw-r--r--mcp/scripts/net_mgmt.xml5
-rw-r--r--mcp/scripts/net_public.xml6
-rw-r--r--mcp/scripts/net_pxe.xml10
-rwxr-xr-xmcp/scripts/openstack.sh44
-rwxr-xr-xmcp/scripts/salt.sh23
-rw-r--r--mcp/scripts/user-data.template10
10 files changed, 348 insertions, 0 deletions
diff --git a/mcp/scripts/create-config-drive.sh b/mcp/scripts/create-config-drive.sh
new file mode 100755
index 000000000..df3f72f1f
--- /dev/null
+++ b/mcp/scripts/create-config-drive.sh
@@ -0,0 +1,102 @@
+#!/bin/bash
+
+# This will generate a openstack-style config drive image suitable for
+# use with cloud-init. You may optionally pass in an ssh public key
+# (using the -k/--ssh-key option) and a user-data blog (using the
+# -u/--user-data option).
+
+usage () {
+ echo "usage: ${0##*/}: [--ssh-key <pubkey>] [--vendor-data <file>] [--user-data <file>] [--hostname <hostname>] <imagename>"
+}
+
+ARGS=$(getopt \
+ -o k:u:v:h: \
+ --long help,hostname:,ssh-key:,user-data:,vendor-data: -n ${0##*/} \
+ -- "$@")
+
+if [ $? -ne 0 ]; then
+ usage >&2
+ exit 2
+fi
+
+eval set -- "$ARGS"
+
+while :; do
+ case "$1" in
+ --help)
+ usage
+ exit 0
+ ;;
+ -k|--ssh-key)
+ ssh_key="$2"
+ shift 2
+ ;;
+ -u|--user-data)
+ user_data="$2"
+ shift 2
+ ;;
+ -v|--vendor-data)
+ vendor_data="$2"
+ shift 2
+ ;;
+ -h|--hostname)
+ hostname="$2"
+ shift 2
+ ;;
+ --) shift
+ break
+ ;;
+ esac
+done
+
+config_image=$1
+shift
+
+if [ "$ssh_key" ] && [ -f "$ssh_key" ]; then
+ echo "adding pubkey from $ssh_key"
+ ssh_key_data=$(cat "$ssh_key")
+fi
+
+uuid=$(uuidgen)
+if ! [ "$hostname" ]; then
+ hostname="$uuid"
+fi
+
+trap 'rm -rf $config_dir' EXIT
+config_dir=$(mktemp -t -d configXXXXXX)
+
+if [ "$user_data" ] && [ -f "$user_data" ]; then
+ echo "adding user data from $user_data"
+ cp ${user_data} ${config_dir}/user-data
+else
+ touch $config_dir/user-data
+fi
+
+if [ "$vendor_data" ] && [ -f "$vendor_data" ]; then
+ echo "adding vendor data from $vendor_data"
+ cp ${vendor_data} ${config_dir}/vendor-data
+fi
+
+cat > $config_dir/meta-data <<-EOF
+instance-id: $uuid
+hostname: $hostname
+local-hostname: $hostname
+EOF
+
+if [ "$ssh_key_data" ]; then
+ cat >> $config_dir/meta-data <<-EOF
+ public-keys:
+ - |
+ $ssh_key_data
+ EOF
+fi
+
+#PS1="debug> " bash --norc
+
+echo "generating configuration image at $config_image"
+if ! mkisofs -o $config_image -V cidata -r -J --quiet $config_dir; then
+ echo "ERROR: failed to create $config_image" >&2
+ exit 1
+fi
+chmod a+r $config_image
+
diff --git a/mcp/scripts/dpdk.sh b/mcp/scripts/dpdk.sh
new file mode 100755
index 000000000..faa4390d3
--- /dev/null
+++ b/mcp/scripts/dpdk.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+#
+# Enable DPDK on compute nodes
+#
+
+ssh ${SSH_OPTS} ubuntu@${SALT_MASTER} bash -s << DPDK_INSTALL_END
+ sudo -i
+
+ salt -C 'I@nova:compute' system.reboot
+ salt -C 'I@nova:compute' test.ping
+
+ salt -C 'I@nova:compute' state.sls linux
+ salt -C 'I@nova:compute' state.sls nova,neutron
+
+ salt -C 'I@keystone:server and *01*' cmd.run ". /root/keystonercv3; nova service-list; openstack network agent list"
+DPDK_INSTALL_END
diff --git a/mcp/scripts/lib.sh b/mcp/scripts/lib.sh
new file mode 100644
index 000000000..50f441a78
--- /dev/null
+++ b/mcp/scripts/lib.sh
@@ -0,0 +1,128 @@
+#
+# Library of shell functions
+#
+
+generate_ssh_key() {
+ [ -f "$SSH_KEY" ] || ssh-keygen -f ${SSH_KEY} -N ''
+ install -o jenkins -m 0600 ${SSH_KEY} /tmp/
+}
+
+get_base_image() {
+ local base_image=$1
+
+ mkdir -p images
+ wget -P /tmp -nc $base_image
+}
+
+cleanup_vms() {
+ # clean up existing nodes
+ for node in $(virsh list --name | grep -P '\w{3}\d{2}'); do
+ virsh destroy $node
+ virsh undefine $node
+ done
+}
+
+prepare_vms() {
+ local -n vnodes=$1
+ local base_image=$2
+
+ cleanup_vms
+ get_base_image $base_image
+ envsubst < user-data.template > user-data.sh
+
+ for node in "${vnodes[@]}"; do
+ # create/prepare images
+ ./create-config-drive.sh -k ${SSH_KEY}.pub -u user-data.sh -h ${node} images/mcp_${node}.iso
+ cp /tmp/${base_image/*\/} images/mcp_${node}.qcow2
+ qemu-img resize images/mcp_${node}.qcow2 100G
+ done
+}
+
+create_networks() {
+ # create required networks
+ for net in pxe mgmt internal public; do
+ if virsh net-info $net >/dev/null 2>&1; then
+ virsh net-destroy ${net}
+ virsh net-undefine ${net}
+ fi
+ virsh net-define net_${net}.xml
+ virsh net-autostart ${net}
+ virsh net-start ${net}
+ done
+}
+
+create_vms() {
+ local -n vnodes=$1
+ local -n vnodes_ram=$2
+
+ # create vms with specified options
+ for node in "${vnodes[@]}"; do
+ virt-install --name ${node} --ram ${vnodes_ram[$node]} --vcpus=2 --cpu host --accelerate \
+ --network network:pxe,model=virtio \
+ --network network:mgmt,model=virtio \
+ --network network:internal,model=virtio \
+ --network network:public,model=virtio \
+ --disk path=$(pwd)/images/mcp_${node}.qcow2,format=qcow2,bus=virtio,cache=none,io=native \
+ --os-type linux --os-variant none \
+ --boot hd --vnc --console pty --autostart --noreboot \
+ --disk path=$(pwd)/images/mcp_${node}.iso,device=cdrom
+ done
+}
+
+update_pxe_network() {
+ # set static ip address for salt master node
+ virsh net-update pxe add ip-dhcp-host \
+ "<host mac='$(virsh domiflist cfg01 | awk '/pxe/ {print $5}')' name='cfg01' ip='$SALT_MASTER'/>" --live
+}
+
+start_vms() {
+ local -n vnodes=$1
+
+ # start vms
+ for node in "${vnodes[@]}"; do
+ virsh start ${node}
+ sleep $[RANDOM%5+1]
+ done
+}
+
+check_connection() {
+ local total_attempts=60
+ local sleep_time=5
+ local attempt=1
+
+ set +e
+ echo '[INFO] Attempting to get into Salt master ...'
+
+ # wait until ssh on Salt master is available
+ while (($attempt <= $total_attempts)); do
+ ssh -i ${SSH_KEY} ubuntu@${SALT_MASTER} uptime
+ case $? in
+ 0) echo "${attempt}> Success"; break ;;
+ *) echo "${attempt}/${total_attempts}> ssh server ain't ready yet, waiting for ${sleep_time} seconds ..." ;;
+ esac
+ sleep $sleep_time
+ ((attempt+=1))
+ done
+ set -e
+}
+
+parse_yaml() {
+ local prefix=$2
+ local s
+ local w
+ local fs
+ s='[[:space:]]*'
+ w='[a-zA-Z0-9_]*'
+ fs="$(echo @|tr @ '\034')"
+ sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
+ -e "s|^\($s\)\($w\)$s[:-]$s\(.*\)$s\$|\1$fs\2$fs\3|p" "$1" |
+ awk -F"$fs" '{
+ indent = length($1)/2;
+ vname[indent] = $2;
+ for (i in vname) {if (i > indent) {delete vname[i]}}
+ if (length($3) > 0) {
+ vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
+ printf("%s%s%s=(\"%s\")\n", "'"$prefix"'",vn, $2, $3);
+ }
+ }' | sed 's/_=/+=/g'
+}
diff --git a/mcp/scripts/net_internal.xml b/mcp/scripts/net_internal.xml
new file mode 100644
index 000000000..a9abece70
--- /dev/null
+++ b/mcp/scripts/net_internal.xml
@@ -0,0 +1,4 @@
+<network>
+ <name>internal</name>
+ <bridge name="internal"/>
+</network>
diff --git a/mcp/scripts/net_mgmt.xml b/mcp/scripts/net_mgmt.xml
new file mode 100644
index 000000000..0ba613152
--- /dev/null
+++ b/mcp/scripts/net_mgmt.xml
@@ -0,0 +1,5 @@
+<network>
+ <name>mgmt</name>
+ <bridge name="mgmt"/>
+ <ip address="172.16.10.1" netmask="255.255.255.0"/>
+</network>
diff --git a/mcp/scripts/net_public.xml b/mcp/scripts/net_public.xml
new file mode 100644
index 000000000..61650d5a6
--- /dev/null
+++ b/mcp/scripts/net_public.xml
@@ -0,0 +1,6 @@
+<network>
+ <name>public</name>
+ <bridge name="public"/>
+ <forward mode="nat"/>
+ <ip address="10.16.0.1" netmask="255.255.255.0" />
+</network>
diff --git a/mcp/scripts/net_pxe.xml b/mcp/scripts/net_pxe.xml
new file mode 100644
index 000000000..92eaa6b52
--- /dev/null
+++ b/mcp/scripts/net_pxe.xml
@@ -0,0 +1,10 @@
+<network>
+ <name>pxe</name>
+ <bridge name="pxe"/>
+ <forward mode="nat"/>
+ <ip address="192.168.10.1" netmask="255.255.255.0">
+ <dhcp>
+ <range start="192.168.10.100" end="192.168.10.254"/>
+ </dhcp>
+ </ip>
+</network>
diff --git a/mcp/scripts/openstack.sh b/mcp/scripts/openstack.sh
new file mode 100755
index 000000000..88db83d49
--- /dev/null
+++ b/mcp/scripts/openstack.sh
@@ -0,0 +1,44 @@
+#!/bin/bash
+#
+# Deploy Openstack
+#
+
+ssh ${SSH_OPTS} ubuntu@${SALT_MASTER} bash -s << OPENSTACK_INSTALL_END
+ sudo -i
+
+ salt-call state.apply salt
+ salt '*' state.apply salt || salt '*' state.apply salt
+
+ salt -C 'I@salt:master' state.sls linux
+ salt -C '* and not cfg01*' state.sls linux
+
+ salt '*' state.sls ntp
+
+ salt -C 'I@rabbitmq:server' state.sls rabbitmq
+ salt -C 'I@rabbitmq:server' cmd.run "rabbitmqctl status"
+
+ salt -C 'I@mysql:server' state.sls mysql
+
+ salt -C 'I@memcached:server' state.sls memcached
+
+ salt -C 'I@keystone:server' state.sls keystone.server
+ salt -C 'I@keystone:server' cmd.run "systemctl restart apache2"
+ while true; do salt -C 'I@keystone:server' state.sls keystone.client && break; done
+ salt -C 'I@keystone:server' cmd.run ". /root/keystonercv3; openstack service list"
+
+ salt -C 'I@glance:server' state.sls glance
+ salt -C 'I@nova:controller' state.sls nova
+ salt -C 'I@heat:server' state.sls heat
+ salt -C 'I@cinder:controller' state.sls cinder
+
+ salt -C 'I@neutron:server' state.sls neutron
+ salt -C 'I@neutron:gateway' state.sls neutron
+
+ salt -C 'I@nova:compute' state.sls nova
+ salt -C 'I@neutron:compute' state.sls neutron
+
+ salt 'ctl01*' cmd.run ". /root/keystonercv3; openstack compute service list; openstack network agent list; openstack stack list; openstack volume list"
+
+ salt 'ctl01*' cmd.run ". /root/keystonercv3; openstack network create --share --external --provider-network-type flat --provider-physical-network physnet1 floating_net"
+ salt 'ctl01*' cmd.run ". /root/keystonercv3; openstack subnet create --gateway 10.16.0.1 --no-dhcp --allocation-pool start=10.16.0.130,end=10.16.0.254 --network floating_net --subnet-range 10.16.0.0/24 floating_subnet"
+OPENSTACK_INSTALL_END
diff --git a/mcp/scripts/salt.sh b/mcp/scripts/salt.sh
new file mode 100755
index 000000000..56a6fb3b8
--- /dev/null
+++ b/mcp/scripts/salt.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+#
+# Deploy Salt Master
+#
+
+# ssh to cfg01
+ssh ${SSH_OPTS} ubuntu@${SALT_MASTER} bash -s << SALT_INSTALL_END
+ sudo -i
+
+ echo -n 'Checking out cloud-init has finished running ...'
+ while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo -n '.'; sleep 1; done
+ echo ' done'
+
+ apt-get install -y git curl subversion
+
+ svn export --force https://github.com/salt-formulas/salt-formulas/trunk/deploy/scripts /srv/salt/scripts
+ git clone --depth=1 --recurse-submodules https://git.opnfv.org/fuel
+ ln -s /root/fuel/mcp/reclass /srv/salt/reclass
+
+ cd /srv/salt/scripts
+ MASTER_HOSTNAME=cfg01.${CLUSTER_DOMAIN} DISTRIB_REVISION=nightly ./salt-master-init.sh
+ salt-key -Ay
+SALT_INSTALL_END
diff --git a/mcp/scripts/user-data.template b/mcp/scripts/user-data.template
new file mode 100644
index 000000000..811a58c70
--- /dev/null
+++ b/mcp/scripts/user-data.template
@@ -0,0 +1,10 @@
+#!/bin/bash
+wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/latest/SALTSTACK-GPG-KEY.pub | sudo apt-key add -
+echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/latest xenial main" > /etc/apt/sources.list.d/salt.list
+apt update
+apt-get install -y salt-minion
+rm /etc/salt/minion_id
+rm -f /etc/salt/pki/minion/minion_master.pub
+echo "id: $(hostname).${CLUSTER_DOMAIN}" > /etc/salt/minion
+echo "master: ${SALT_MASTER}" >> /etc/salt/minion
+service salt-minion restart