]> review.fuel-infra Code Review - tools/sustaining.git/commitdiff
Add deploy_swarm job 76/40576/1
authorVladimir Khlyunev <vkhlyunev@mirantis.com>
Thu, 21 Feb 2019 09:50:06 +0000 (13:50 +0400)
committerVladimir Khlyunev <vkhlyunev@mirantis.com>
Thu, 21 Feb 2019 10:37:50 +0000 (14:37 +0400)
For delpoying several instances using one job.
Currenly contains built-in MOS flavors but it's possible to deploy
"custom flavor"-based several instances.

Change-Id: I279f96425baf5bf4ac6da44ec00312368c6d36f5

maintenance-ci/common/jobs/deploy-jenkins-swarm.yaml [new file with mode: 0644]
maintenance-ci/common/scripts/deploy_jenkins_swarm.sh [new file with mode: 0755]

diff --git a/maintenance-ci/common/jobs/deploy-jenkins-swarm.yaml b/maintenance-ci/common/jobs/deploy-jenkins-swarm.yaml
new file mode 100644 (file)
index 0000000..3c1ee9f
--- /dev/null
@@ -0,0 +1,60 @@
+- job:
+    name: 'deploy-jenkins-swarm'
+    description: |
+            Create given jenkins slaves on internal cloud in maintenance-team tenant
+
+    concurrent: false
+    node: 'jenkins-master'
+
+    parameters:
+    - string:
+        name: HEAT_STACK_YAML
+        description: "Stack yaml file"
+        default: "maintenance-ci/common/data/base_heat.yml"
+    - string:
+        name: STACK_PREFIX
+        description: "Stack prefix"
+        default: "swarm-slave"
+    - string:
+        name: MOS_BASE_NODE_COUNT
+        default: "0"
+    - string:
+        name: MOS_HUGE_NODE_COUNT
+        default: "0"
+    - string:
+        name: MOS_TEMPEST_NODE_COUNT
+        default: "0"
+
+    - string:
+          name: IMAGE_NAME
+          default: xenial-server-cloudimg-amd64-qcow
+    - string:
+          name: JENKINS_LABELS
+          default: ''
+
+    - string:
+          name: CUSTOM_FLAVOR_NAME
+          default: "0"
+    - string:
+          name: CUSTOM_FLAVOR_JENKINS_LABELS
+          default: ""
+    - string:
+          name: CUSTOM_FLAVOR_NODE_COUNT
+          default: "0"
+
+    scm:
+        - git:
+            url: 'https://review.fuel-infra.org/tools/sustaining/'
+            branches:
+                - origin/master
+
+    wrappers:
+        - timestamps
+        - openstack-creds
+        - timeout:
+            fail: true
+            timeout: 30
+
+    builders:
+    - shell:
+        !include-raw: common/scripts/deploy_jenkins_swarm.sh
diff --git a/maintenance-ci/common/scripts/deploy_jenkins_swarm.sh b/maintenance-ci/common/scripts/deploy_jenkins_swarm.sh
new file mode 100755 (executable)
index 0000000..313a75b
--- /dev/null
@@ -0,0 +1,58 @@
+#!/bin/bash
+
+set -ex
+
+OPENSTACK_CLIENTS_VENV="${OPENSTACK_CLIENTS_VENV:-/home/jenkins/venv-openstack-clients}"
+
+if [[ ! -d "${OPENSTACK_CLIENTS_VENV}" ]] ; then
+    virtualenv "${OPENSTACK_CLIENTS_VENV}"
+    source "${OPENSTACK_CLIENTS_VENV}"/bin/activate
+    pip install openstackclient
+    deactivate
+fi
+
+function deploy_stacks() {
+    FLAVOR_NAME=$1
+    IMAGE_NAME=$2
+    JENKINS_LABELS=$3
+    parameter_string=""
+    if [[ ! -z "${FLAVOR_NAME}" ]] ; then
+      parameter_string="$parameter_string --parameter \"flavor=${FLAVOR_NAME}\""
+    fi
+    if [[ ! -z "${IMAGE_NAME}" ]] ; then
+      parameter_string="$parameter_string --parameter \"image=${IMAGE_NAME}\""
+    fi
+    if [[ ! -z "${JENKINS_LABELS}" ]] ; then
+      parameter_string="$parameter_string --parameter \"jenkins_labels=${JENKINS_LABELS}\""
+    fi
+
+    # MAC OS compatibility, for manual usage
+    if command -v md5sum ; then
+      md5_cmd="md5sum"
+    else
+      md5_cmd="md5"
+    fi
+
+    STACK_NAME="${STACK_PREFIX:-swarm_slave}_$(date +%s | "${md5_cmd}" | head -c 4)"
+
+    set +x
+    source "${OPENSTACK_CLIENTS_VENV}"/bin/activate
+    set -x
+      source "${OPENRC_FILE?}"
+      echo "openstack stack create --wait -t ${HEAT_STACK_YAML} ${parameter_string} ${STACK_NAME}" | bash -
+      openstack stack output show "${STACK_NAME}" --all
+    deactivate
+}
+
+for (( node = 0; node < ${CUSTOM_FLAVOR_NODE_COUNT}; ++node )); do
+    deploy_stacks "${CUSTOM_FLAVOR_NAME}" "${IMAGE_NAME}" "${CUSTOM_FLAVOR_JENKINS_LABELS}"
+done
+for (( node = 0; node < ${MOS_TEMPEST_NODE_COUNT}; ++node )); do
+    deploy_stacks mos.tempest "${IMAGE_NAME}" "${JENKINS_LABELS}"
+done
+for (( node = 0; node < ${MOS_HUGE_NODE_COUNT}; ++node )); do
+    deploy_stacks mos.fuel.huge "${IMAGE_NAME}" "${JENKINS_LABELS}"
+done
+for (( node = 0; node < ${MOS_BASE_NODE_COUNT}; ++node )); do
+    deploy_stacks mos.fuel.base "${IMAGE_NAME}" "${JENKINS_LABELS}"
+done