+++ /dev/null
----
-- job:
- name: openstack-tester
- parameters:
- - string:
- name: STACK_NAME
- default: test-lf-stack-delete
- publishers:
- - lf-stack-delete
-
-- project:
- name: openstack-jobs-view
- views:
- - project-view
-
- project-name: openstack
--- /dev/null
+---
+- job-template:
+ name: stack-create-test
+
+ #####################
+ # Default variables #
+ #####################
+
+ openstack-cloud: lf-cloud
+ openstack-heat-template: csit-2-instance-type.yaml
+ openstack-heat-template-dir: 'openstack-hot'
+
+ odl_system_count: 1
+ odl_system_flavor: odl-highcpu-4
+ odl_system_image: ZZCI - CentOS 7 - builder - x86_64 - 20181010-215635.956
+ tools_system_count: 2
+ tools_system_flavor: odl-highcpu-2
+ tools_system_image: ZZCI - Ubuntu 16.04 - mininet-ovs-25 - 20181029-223449.514
+
+ #####################
+ # Job configuration #
+ #####################
+
+ builders:
+ - lf-infra-pre-build
+ - lf-stack-create:
+ openstack-cloud: '{openstack-cloud}'
+ openstack-heat-template: '{openstack-heat-template}'
+ openstack-heat-template-dir: '{openstack-heat-template-dir}'
+ openstack-heat-parameters: |
+ vm_0_count: '{odl_system_count}'
+ vm_0_flavor: '{odl_system_flavor}'
+ vm_0_image: '{odl_system_image}'
+ vm_1_count: '{tools_system_count}'
+ vm_1_flavor: '{tools_system_flavor}'
+ vm_1_image: '{tools_system_image}'
--- /dev/null
+---
+- job-template:
+ name: stack-delete-test
+
+ #####################
+ # Default variables #
+ #####################
+
+ openstack-cloud: lf-cloud
+
+ #####################
+ # Job configuration #
+ #####################
+
+ publishers:
+ - lf-stack-delete:
+ openstack-cloud: '{openstack-cloud}'
--- /dev/null
+##############
+OpenStack Heat
+##############
+
+This section contains a series of macros for projects that need to spin up full
+test labs using HEAT scripts.
+
+Job Setup
+=========
+
+The 2 macros :ref:`lf-stack-create` & :ref:`lf-stack-delete` are companion
+macros and used together when constructing a job template that needs to spin up
+a full integration lab using Heat Orchestration Templates (HOT).
+
+Example Usage:
+
+.. code-block:: yaml
+
+ - job-template:
+ name: csit-test
+
+ #####################
+ # Default variables #
+ #####################
+
+ openstack-cloud: vex
+ openstack-heat-template: csit-2-instance-type.yaml
+ openstack-heat-template-dir: 'openstack-hot'
+
+ odl_system_count: 1
+ odl_system_flavor: odl-highcpu-4
+ odl_system_image: ZZCI - CentOS 7 - builder - x86_64 - 20181010-215635.956
+ tools_system_count: 1
+ tools_system_flavor: odl-highcpu-2
+ tools_system_image: ZZCI - Ubuntu 16.04 - mininet-ovs-25 - 20181029-223449.514
+
+ #####################
+ # Job configuration #
+ #####################
+
+ builders:
+ - lf-infra-pre-build
+ - lf-stack-create:
+ openstack-cloud: '{openstack-cloud}'
+ openstack-heat-template: '{openstack-heat-template}'
+ openstack-heat-template-dir: '{openstack-heat-template-dir}'
+ openstack-heat-parameters: |
+ vm_0_count: '{odl_system_count}'
+ vm_0_flavor: '{odl_system_flavor}'
+ vm_0_image: '{odl_system_image}'
+ vm_1_count: '{tools_system_count}'
+ vm_1_flavor: '{tools_system_flavor}'
+ vm_1_image: '{tools_system_image}'
+
+ publishers:
+ - lf-stack-delete:
+ openstack-cloud: '{openstack-cloud}'
+
+
+Macros
+======
+
+.. _lf-stack-create:
+
+lf-stack-create
+---------------
+
+Creates an OpenStack stack as configured by the job. Name pattern of stack is
+``$SILO-$JOB_NAME-$BUILD_NUMBER``.
+
+Requires ``lf-infra-pre-build`` macro to run first to install the
+``openstack`` and ``lftools`` packages.
+
+Requires a Config File Provider configuration for clouds.yaml named
+``clouds-yaml``.
+
+:Required Parameters:
+
+ :openstack-cloud: The ``OS_CLOUD`` variable to pass to OpenStack client.
+ (Docs: https://docs.openstack.org/python-openstackclient)
+ :openstack-heat-template: Name of template file to use when running stack
+ create.
+ :openstack-heat-template-dir: Directory in the ci-management repo
+ containing the OpenStack heat templates.
+
+Example:
+
+.. literalinclude:: ../../.jjb-test/lf-openstack/lf-stack-create-minimal.yaml
+
+.. _lf-stack-delete:
+
+lf-stack-delete
+---------------
+
+Deletes the stack associated with this job. Name pattern of stack is
+``$SILO-$JOB_NAME-$BUILD_NUMBER``.
+
+Requires ``lf-infra-pre-build`` macro to run first to install the
+``openstack`` and ``lftools`` packages.
+
+Requires a Config File Provider configuration for clouds.yaml named
+``clouds-yaml``.
+
+:Required Parameters:
+
+ :openstack-cloud: The ``OS_CLOUD`` variable to pass to OpenStack client.
+ (Docs: https://docs.openstack.org/python-openstackclient)
+
+Example:
+
+.. literalinclude:: ../../.jjb-test/lf-openstack/lf-stack-delete-minimal.yaml
- '**/*.jenkins-trigger'
fail-build: false
-- publisher:
- name: lf-stack-delete
- publishers:
- - postbuildscript:
- builders:
- - role: BOTH
- build-on:
- - ABORTED
- - FAILURE
- - SUCCESS
- - UNSTABLE
- build-steps:
- - shell: |
- #!/bin/bash -l
- echo "Deleting $STACK_NAME"
- lftools openstack stack delete "$STACK_NAME"
- mark-unstable-if-failed: false
-
#######
# SCM #
#######
--- /dev/null
+---
+- builder:
+ name: lf-stack-create
+ builders:
+ - inject:
+ properties-content: |
+ OS_CLOUD={openstack-cloud}
+ OS_STACK_NAME=$SILO-$JOB_NAME-$BUILD_NUMBER
+ OS_STACK_TEMPLATE={openstack-heat-template}
+ OS_STACK_TEMPLATE_DIR={openstack-heat-template-dir}
+ - config-file-provider:
+ files:
+ - file-id: clouds-yaml
+ target: '$HOME/.config/openstack/clouds.yaml'
+ - shell: !include-raw: ../shell/openstack-stack-parameters.sh
+ - shell: !include-raw-escape: ../shell/openstack-stack-create.sh
+ - shell: !include-raw-escape: ../shell/openstack-stack-copy-ssh-keys.sh
+
+- publisher:
+ name: lf-stack-delete
+ publishers:
+ - postbuildscript:
+ builders:
+ - role: BOTH
+ build-on:
+ - ABORTED
+ - FAILURE
+ - SUCCESS
+ - UNSTABLE
+ build-steps:
+ - inject:
+ properties-content: |
+ OS_CLOUD={openstack-cloud}
+ OS_STACK_NAME=$SILO-$JOB_NAME-$BUILD_NUMBER
+ - config-file-provider:
+ files:
+ - file-id: clouds-yaml
+ target: '$HOME/.config/openstack/clouds.yaml'
+ - shell: |
+ #!/bin/bash -l
+ echo "Deleting $OS_STACK_NAME"
+ lftools openstack --os-cloud "$OS_CLOUD" stack delete "$OS_STACK_NAME"
+ mark-unstable-if-failed: false
--- /dev/null
+---
+features:
+ - |
+ New ``lf-stack-create`` macro allows job-templates to setup a OpenStack
+ Heat stack, useful for spinning up CSIT labs to run integration tests
+ against. Use with the ``lf-stack-delete`` macro.
+
+upgrade:
+ - |
+ ``lf-stack-delete`` has been modified to be a companion macro to
+ ``lf-stack-create`` in order to cleanup the stack at the end of a job run.
+ It now includes a required parameter **openstack-cloud** to choose the
+ ``clouds.yaml`` cloud configuration for the project. Existing users of
+ this macro will need to update their job templates accordingly.
--- /dev/null
+#!/bin/bash -l
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2017, 2018 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+echo "---> Copy SSH public keys to CSIT lab"
+
+os_cloud="${OS_CLOUD:-vex}"
+stack_name="${OS_STACK_NAME}"
+
+function copy_ssh_keys() {
+ if [ -z "$1" ]; then
+ >&2 echo "ERROR: Missing required arguments."
+ >&2 echo "Usage: copy_ssh_keys IP_ADDRESS"
+ exit 1
+ fi
+
+ local ip_address="$1"
+ RETRIES=60
+
+ for i in $(seq 1 $RETRIES); do
+ if ssh-copy-id -i /home/jenkins/.ssh/id_rsa.pub "jenkins@${ip_address}" > /dev/null 2>&1; then
+ ssh "jenkins@${ip_address}" 'echo "$(facter ipaddress_eth0) $(/bin/hostname)" | sudo tee -a /etc/hosts'
+ echo "Successfully copied public keys to slave ${ip_address}"
+ break
+ elif [ "$i" -eq $RETRIES ]; then
+ echo "SSH not responding on ${ip_address} after $RETIRES tries. Giving up."
+
+ server=$(openstack port list -f value -c device_id --fixed-ip ip-address="${ip_address}")
+ echo "Dumping console logs for $server ${ip_address}"
+ openstack --os-cloud "$os_cloud" console log show "$server"
+
+ exit 1
+ else
+ echo "SSH not responding on ${ip_address}. Retrying in 10 seconds..."
+ sleep 10
+ fi
+
+ # ping test to see if connectivity is available
+ if ping -c1 "${ip_address}" &> /dev/null; then
+ echo "Ping to ${ip_address} successful."
+ else
+ echo "Ping to ${ip_address} failed."
+ fi
+ done
+}
+
+# IP Addresses are returned as a space separated list so word splitting is ok
+# shellcheck disable=SC2207
+ip_addresses=($(openstack --os-cloud "$os_cloud" stack show -f json -c outputs "$stack_name" |
+ jq -r '.outputs[] |
+ select(.output_key | match("^vm_[0-9]+_ips$")) |
+ .output_value | .[]'))
+pids=""
+for ip in "${ip_addresses[@]}"; do
+ ( copy_ssh_keys "$ip" ) &
+ # Store PID of process
+ pids+=" $!"
+done
+for p in $pids; do
+ if wait "$p"; then
+ echo "Process $p ready."
+ else
+ echo "Process $p timed out waiting for SSH."
+ exit 1
+ fi
+done
+echo "SSH ready on all stack servers."
--- /dev/null
+#!/bin/bash -l
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2017, 2018 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+echo "---> Create HEAT stack"
+
+os_cloud="${OS_CLOUD:-vex}"
+stack_name="${OS_STACK_NAME}"
+stack_template="${OS_STACK_TEMPLATE}"
+stack_template_dir="/opt/ciman/${OS_STACK_TEMPLATE_DIR:-openstack-hot}"
+stack_parameters="$WORKSPACE/stack-parameters.yaml"
+
+set -eux -o pipefail
+
+openstack --os-cloud "$os_cloud" limits show --absolute
+
+pushd "$stack_template_dir" || exit 1
+lftools openstack --os-cloud "$os_cloud" stack create \
+ "$stack_name" "$stack_template" "$stack_parameters"
+popd
--- /dev/null
+#!/bin/bash
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2018 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+echo "---> Create parameters file for OpenStack HOT"
+stack_parameters="$WORKSPACE/stack-parameters.yaml"
+tmp_params="$WORKSPACE/params.yaml"
+JOB_SUM=$(echo "$JOB_NAME" | sum | awk '{{ print $1 }}')
+VM_NAME="$JOB_SUM-$BUILD_NUMBER"
+
+cat > "$tmp_params" << EOF
+{openstack-heat-parameters}
+job_name: '$VM_NAME'
+silo: '$SILO'
+EOF
+
+echo "OpenStack Heat parameters generated"
+echo "-----------------------------------"
+echo "parameters:" > "$stack_parameters"
+cat "$tmp_params" | sed 's/^/ /' >> "$stack_parameters"
+cat "$stack_parameters"
+rm "$tmp_params"