From: Vladimir Khlyunev Date: Mon, 22 Jul 2019 11:15:00 +0000 (+0400) Subject: Enhance slave deploy job with per-cloud templates X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F89%2F41389%2F7;p=tools%2Fsustaining.git Enhance slave deploy job with per-cloud templates For EU cloud we want to pin mos executors to specific set of compute hosts Change-Id: I1ef8528f554b9258b3818608f469fa1f09ad4b11 --- diff --git a/maintenance-ci/common/data/mos-dev-slave-eu.yml b/maintenance-ci/common/data/mos-dev-slave-eu.yml new file mode 100644 index 0000000..1cfd69f --- /dev/null +++ b/maintenance-ci/common/data/mos-dev-slave-eu.yml @@ -0,0 +1,161 @@ + +heat_template_version: 2017-09-01 + +parameters: + key_name: + type: string + description: Name of keypair to assign to servers + default: maintenance-ci-public-key + constraints: + - custom_constraint: nova.keypair + description: Must name a public key (pair) known to Nova + image: + type: string + description: Name of image to use for servers + default: maintenance-ci-mos-image + constraints: + - custom_constraint: glance.image + description: Must identify an image known to Glance + flavor: + type: string + description: Flavor to use for servers + constraints: + - custom_constraint: nova.flavor + description: Must be a flavor known to Nova + public_net: + type: string + default: public + description: Id of the public network for the compute server + jenkins_labels: + type: string + default: '' + description: List of labels for jenkins swarm agent separated by whitespace + location: + type: string + default: 'EU' + description: Backend cluster location (available "EU" and "US") + +resources: + wait_condition: + type: OS::Heat::WaitCondition + properties: + handle: {get_resource: wait_handle} + count: 1 + timeout: 300 + + wait_handle: + type: OS::Heat::WaitConditionHandle + + private_net: + type: OS::Neutron::Net + + private_subnet: + type: OS::Neutron::Subnet + properties: + network_id: { get_resource: private_net } + cidr: 10.10.0.0/24 + dns_nameservers: + - 172.18.176.6 + - 172.18.208.44 + + router: + type: OS::Neutron::Router + properties: + external_gateway_info: + network: { get_param: public_net } + + router_interface: + type: OS::Neutron::RouterInterface + properties: + router_id: { get_resource: router } + subnet_id: { get_resource: private_subnet } + + security_group: + type: OS::Neutron::SecurityGroup + properties: + rules: [ + {direction: ingress, + remote_ip_prefix: 0.0.0.0/0, + protocol: tcp, + port_range_min: 1, + port_range_max: 65535}, + {direction: ingress, + remote_ip_prefix: 0.0.0.0/0, + protocol: udp, + port_range_min: 1, + port_range_max: 65535}, + {remote_ip_prefix: 0.0.0.0/0, + protocol: icmp, + direction: ingress}] + + public_port: + type: OS::Neutron::Port + properties: + network_id: { get_resource: private_net } + fixed_ips: + - subnet_id: { get_resource: private_subnet } + security_groups: + - { get_resource: security_group } + + floating_ip: + type: OS::Neutron::FloatingIP + properties: + floating_network_id: { get_param: public_net } + port_id: { get_resource: public_port } + + node: + type: OS::Nova::Server + properties: + image: { get_param: image } + availability_zone: nova + flavor: { get_param: flavor } + key_name: { get_param: key_name } + networks: + - port: { get_resource: public_port } + scheduler_hints: + query: '["in","$hypervisor_hostname", + "cmp015.eu.intcloud.mirantis.net", + "cmp016.eu.intcloud.mirantis.net", + "cmp017.eu.intcloud.mirantis.net", + "cmp018.eu.intcloud.mirantis.net", + "cmp019.eu.intcloud.mirantis.net", + "cmp020.eu.intcloud.mirantis.net", + "cmp021.eu.intcloud.mirantis.net", + "cmp022.eu.intcloud.mirantis.net", + "cmp023.eu.intcloud.mirantis.net", + "cmp024.eu.intcloud.mirantis.net", + "cmp025.eu.intcloud.mirantis.net", + "cmp026.eu.intcloud.mirantis.net", + "cmp027.eu.intcloud.mirantis.net", + "cmp028.eu.intcloud.mirantis.net", + "cmp029.eu.intcloud.mirantis.net", + "cmp030.eu.intcloud.mirantis.net"]' + user_data: + str_replace: + template: | + #!/bin/bash + mkdir -p /etc/jenkins-agent/ + echo "LABELS" > /etc/jenkins-agent/labels + echo "127.0.0.1 $(hostname)" >> /etc/hosts + echo "FLOATING" > /etc/jenkins-agent/description + echo "OPENSTACK_ENVIRONMENT" > /etc/jenkins-agent/location + + apt update + sed -i 's/^\(GRUB_CMDLINE_LINUX_DEFAULT=\).*$/\1\"console=tty1 console=ttyS0 noibrs noibpb nopti nospectre_v2 nospectre_v1 l1tf=off nospec_store_bypass_disable no_stf_barrier\"/g' /etc/default/grub.d/50-cloudimg-settings.cfg + apt install -y linux-generic-hwe-16.04 linux-tools-generic-hwe-16.04 linux-cloud-tools-generic-hwe-16.04 linux-tools-common + update-grub + + systemctl enable jenkins-swarm-agent + wc_notify --data-binary '{"status": "SUCCESS"}' + reboot + params: + LABELS: {get_param: jenkins_labels} + wc_notify: { get_attr: [wait_handle, curl_cli] } + FLOATING: { get_attr: [ floating_ip, floating_ip_address ] } + OPENSTACK_ENVIRONMENT: {get_param: location} + + +outputs: + floating_ip: + description: Floating IP + value: { get_attr: [ floating_ip, floating_ip_address ] } diff --git a/maintenance-ci/common/data/mos-dev-slave.yml b/maintenance-ci/common/data/mos-dev-slave-us.yml similarity index 100% rename from maintenance-ci/common/data/mos-dev-slave.yml rename to maintenance-ci/common/data/mos-dev-slave-us.yml diff --git a/maintenance-ci/common/data/mos-slave.yml b/maintenance-ci/common/data/mos-slave-eu.yml similarity index 81% rename from maintenance-ci/common/data/mos-slave.yml rename to maintenance-ci/common/data/mos-slave-eu.yml index 852a53e..6b1bd6c 100644 --- a/maintenance-ci/common/data/mos-slave.yml +++ b/maintenance-ci/common/data/mos-slave-eu.yml @@ -112,6 +112,24 @@ resources: key_name: { get_param: key_name } networks: - port: { get_resource: public_port } + scheduler_hints: + query: '["in","$hypervisor_hostname", + "cmp015.eu.intcloud.mirantis.net", + "cmp016.eu.intcloud.mirantis.net", + "cmp017.eu.intcloud.mirantis.net", + "cmp018.eu.intcloud.mirantis.net", + "cmp019.eu.intcloud.mirantis.net", + "cmp020.eu.intcloud.mirantis.net", + "cmp021.eu.intcloud.mirantis.net", + "cmp022.eu.intcloud.mirantis.net", + "cmp023.eu.intcloud.mirantis.net", + "cmp024.eu.intcloud.mirantis.net", + "cmp025.eu.intcloud.mirantis.net", + "cmp026.eu.intcloud.mirantis.net", + "cmp027.eu.intcloud.mirantis.net", + "cmp028.eu.intcloud.mirantis.net", + "cmp029.eu.intcloud.mirantis.net", + "cmp030.eu.intcloud.mirantis.net"]' user_data: str_replace: template: | diff --git a/maintenance-ci/common/data/mos-slave-us.yml b/maintenance-ci/common/data/mos-slave-us.yml new file mode 100644 index 0000000..6b1bd6c --- /dev/null +++ b/maintenance-ci/common/data/mos-slave-us.yml @@ -0,0 +1,162 @@ + +heat_template_version: 2017-09-01 + +parameters: + key_name: + type: string + description: Name of keypair to assign to servers + default: maintenance-ci-public-key + constraints: + - custom_constraint: nova.keypair + description: Must name a public key (pair) known to Nova + image: + type: string + description: Name of image to use for servers + default: maintenance-ci-mos-image + constraints: + - custom_constraint: glance.image + description: Must identify an image known to Glance + flavor: + type: string + description: Flavor to use for servers + constraints: + - custom_constraint: nova.flavor + description: Must be a flavor known to Nova + public_net: + type: string + default: public + description: Id of the public network for the compute server + jenkins_labels: + type: string + default: '' + description: List of labels for jenkins swarm agent separated by whitespace + location: + type: string + default: 'EU' + description: Backend cluster location (available "EU" and "US") + +resources: + wait_condition: + type: OS::Heat::WaitCondition + properties: + handle: {get_resource: wait_handle} + count: 1 + timeout: 300 + + wait_handle: + type: OS::Heat::WaitConditionHandle + + private_net: + type: OS::Neutron::Net + + private_subnet: + type: OS::Neutron::Subnet + properties: + network_id: { get_resource: private_net } + cidr: 10.10.0.0/24 + dns_nameservers: + - 172.18.176.6 + - 172.18.208.44 + + router: + type: OS::Neutron::Router + properties: + external_gateway_info: + network: { get_param: public_net } + + router_interface: + type: OS::Neutron::RouterInterface + properties: + router_id: { get_resource: router } + subnet_id: { get_resource: private_subnet } + + security_group: + type: OS::Neutron::SecurityGroup + properties: + rules: [ + {direction: ingress, + remote_ip_prefix: 0.0.0.0/0, + protocol: tcp, + port_range_min: 1, + port_range_max: 65535}, + {direction: ingress, + remote_ip_prefix: 0.0.0.0/0, + protocol: udp, + port_range_min: 1, + port_range_max: 65535}, + {remote_ip_prefix: 0.0.0.0/0, + protocol: icmp, + direction: ingress}] + + public_port: + type: OS::Neutron::Port + properties: + network_id: { get_resource: private_net } + fixed_ips: + - subnet_id: { get_resource: private_subnet } + security_groups: + - { get_resource: security_group } + + floating_ip: + type: OS::Neutron::FloatingIP + properties: + floating_network_id: { get_param: public_net } + port_id: { get_resource: public_port } + + node: + type: OS::Nova::Server + properties: + image: { get_param: image } + availability_zone: nova + flavor: { get_param: flavor } + key_name: { get_param: key_name } + networks: + - port: { get_resource: public_port } + scheduler_hints: + query: '["in","$hypervisor_hostname", + "cmp015.eu.intcloud.mirantis.net", + "cmp016.eu.intcloud.mirantis.net", + "cmp017.eu.intcloud.mirantis.net", + "cmp018.eu.intcloud.mirantis.net", + "cmp019.eu.intcloud.mirantis.net", + "cmp020.eu.intcloud.mirantis.net", + "cmp021.eu.intcloud.mirantis.net", + "cmp022.eu.intcloud.mirantis.net", + "cmp023.eu.intcloud.mirantis.net", + "cmp024.eu.intcloud.mirantis.net", + "cmp025.eu.intcloud.mirantis.net", + "cmp026.eu.intcloud.mirantis.net", + "cmp027.eu.intcloud.mirantis.net", + "cmp028.eu.intcloud.mirantis.net", + "cmp029.eu.intcloud.mirantis.net", + "cmp030.eu.intcloud.mirantis.net"]' + user_data: + str_replace: + template: | + #!/bin/bash + mkdir -p /etc/jenkins-agent/ + echo "FLAVOR LABELS" > /etc/jenkins-agent/labels + echo "127.0.0.1 $(hostname)" >> /etc/hosts + echo "FLOATING" > /etc/jenkins-agent/description + echo "OPENSTACK_ENVIRONMENT" > /etc/jenkins-agent/location + + apt update + sed -i 's/^\(GRUB_CMDLINE_LINUX_DEFAULT=\).*$/\1\"console=tty1 console=ttyS0 noibrs noibpb nopti nospectre_v2 nospectre_v1 l1tf=off nospec_store_bypass_disable no_stf_barrier\"/g' /etc/default/grub.d/50-cloudimg-settings.cfg + apt install -y linux-generic-hwe-16.04 linux-tools-generic-hwe-16.04 linux-cloud-tools-generic-hwe-16.04 linux-tools-common + update-grub + + systemctl enable jenkins-swarm-agent + wc_notify --data-binary '{"status": "SUCCESS"}' + reboot + params: + FLAVOR: {get_param: flavor} + LABELS: {get_param: jenkins_labels} + wc_notify: { get_attr: [wait_handle, curl_cli] } + FLOATING: { get_attr: [ floating_ip, floating_ip_address ] } + OPENSTACK_ENVIRONMENT: {get_param: location} + + +outputs: + floating_ip: + description: Floating IP + value: { get_attr: [ floating_ip, floating_ip_address ] } diff --git a/maintenance-ci/common/jobs/deploy-jenkins-swarm.yaml b/maintenance-ci/common/jobs/deploy-jenkins-swarm.yaml index 8bb6b55..9eb542d 100644 --- a/maintenance-ci/common/jobs/deploy-jenkins-swarm.yaml +++ b/maintenance-ci/common/jobs/deploy-jenkins-swarm.yaml @@ -39,7 +39,7 @@ step: 1 predefined-parameters: | OPENSTACK_ENVIRONMENT=${OPENSTACK_ENVIRONMENT} - HEAT_STACK_YAML=${CUSTOM_HEAT_STACK_YAML} + CUSTOM_HEAT_STACK_YAML=${CUSTOM_HEAT_STACK_YAML} STACK_PREFIX=${STACK_PREFIX} FLAVOR_NAME=${CUSTOM_FLAVOR_NAME} JENKINS_LABELS=${CUSTOM_FLAVOR_JENKINS_LABELS} @@ -61,7 +61,7 @@ step: 1 predefined-parameters: | OPENSTACK_ENVIRONMENT=${OPENSTACK_ENVIRONMENT} - HEAT_STACK_YAML=${HEAT_STACK_YAML} + HEAT_STACK_TEMPLATE_NAME=${HEAT_STACK_TEMPLATE_NAME} STACK_PREFIX=${STACK_PREFIX} FLAVOR_NAME=mos.tempest IMAGE_NAME=${IMAGE_NAME} @@ -82,7 +82,7 @@ step: 1 predefined-parameters: | OPENSTACK_ENVIRONMENT=${OPENSTACK_ENVIRONMENT} - HEAT_STACK_YAML=${HEAT_STACK_YAML} + HEAT_STACK_TEMPLATE_NAME=${HEAT_STACK_TEMPLATE_NAME} STACK_PREFIX=${STACK_PREFIX} FLAVOR_NAME=mos.fuel.huge IMAGE_NAME=${IMAGE_NAME} @@ -103,7 +103,7 @@ step: 1 predefined-parameters: | OPENSTACK_ENVIRONMENT=${OPENSTACK_ENVIRONMENT} - HEAT_STACK_YAML=${HEAT_STACK_YAML} + HEAT_STACK_TEMPLATE_NAME=${HEAT_STACK_TEMPLATE_NAME} STACK_PREFIX=${STACK_PREFIX} FLAVOR_NAME=mos.fuel.base IMAGE_NAME=${IMAGE_NAME} diff --git a/maintenance-ci/common/jobs/deploy-stack.yaml b/maintenance-ci/common/jobs/deploy-stack.yaml index 1e08ab1..ebef35e 100644 --- a/maintenance-ci/common/jobs/deploy-stack.yaml +++ b/maintenance-ci/common/jobs/deploy-stack.yaml @@ -9,11 +9,15 @@ parameters: - openstack-cloud-selector - choice: - name: HEAT_STACK_YAML + name: HEAT_STACK_TEMPLATE_NAME choices: - - "maintenance-ci/common/data/jenkins-slave.yml" - - "maintenance-ci/common/data/mos-slave.yml" - - "maintenance-ci/common/data/mos-dev-slave.yml" + - "mos-dev-slave" + - "jenkins-slave" + - "mos-slave" + - string: + name: CUSTOM_HEAT_STACK_YAML + description: "Overwrites HEAT_STACK_TEMPLATE_NAME with relative path to template file. Leave empty by default" + default: "" - string: name: STACK_PREFIX description: "Stack prefix" diff --git a/maintenance-ci/common/jobs/multijob-build-image.yaml b/maintenance-ci/common/jobs/multijob-build-image.yaml index fdaa915..bf4c293 100644 --- a/maintenance-ci/common/jobs/multijob-build-image.yaml +++ b/maintenance-ci/common/jobs/multijob-build-image.yaml @@ -36,7 +36,7 @@ - project: "deploy-heat-stack" predefined-parameters: | OPENSTACK_ENVIRONMENT=${OPENSTACK_ENVIRONMENT} - HEAT_STACK_YAML=maintenance-ci/common/data/jenkins-slave.yml + HEAT_STACK_TEMPLATE_NAME=jenkins-slave STACK_PREFIX=image-builder FLAVOR_NAME=dev.cmn JENKINS_LABELS=image-builder diff --git a/maintenance-ci/common/macroses/mos-jenkins-swarm-params.yaml b/maintenance-ci/common/macroses/mos-jenkins-swarm-params.yaml index e99b532..f07145f 100644 --- a/maintenance-ci/common/macroses/mos-jenkins-swarm-params.yaml +++ b/maintenance-ci/common/macroses/mos-jenkins-swarm-params.yaml @@ -4,9 +4,9 @@ parameters: - openstack-cloud-selector - string: - name: HEAT_STACK_YAML - description: "Stack yaml file" - default: "maintenance-ci/common/data/mos-slave.yml" + name: HEAT_STACK_TEMPLATE_NAME + description: "Stack yaml file name" + default: "mos-slave" - string: name: STACK_PREFIX description: "Stack prefix" @@ -39,4 +39,7 @@ default: "" - string: name: CUSTOM_FLAVOR_NODE_COUNT - default: "0" \ No newline at end of file + default: "0" + - string: + name: GERRIT_REVIEW + default: "" \ No newline at end of file diff --git a/maintenance-ci/common/scripts/deploy_heat_stack.sh b/maintenance-ci/common/scripts/deploy_heat_stack.sh index ec3e126..1daaa62 100755 --- a/maintenance-ci/common/scripts/deploy_heat_stack.sh +++ b/maintenance-ci/common/scripts/deploy_heat_stack.sh @@ -2,6 +2,12 @@ set -ex +if [ ! -z ${GERRIT_REVIEW} ] ; then + refspec=$(curl "https://review.fuel-infra.org/changes/?q=${GERRIT_REVIEW}&o=CURRENT_REVISION" | grep '"ref":' | awk -F ": " '{print $2}' | tr -d '"') + git fetch https://review.fuel-infra.org/tools/sustaining "${refspec}" && git cherry-pick -n FETCH_HEAD +fi + + OPENSTACK_CLIENTS_VENV="${OPENSTACK_CLIENTS_VENV:-/home/jenkins/venv-openstack-clients}" if [[ ! -d "${OPENSTACK_CLIENTS_VENV}" ]] ; then @@ -32,11 +38,24 @@ fi STACK_NAME="${STACK_PREFIX:-swarm_slave}-${OPENSTACK_ENVIRONMENT,,}-$(head -c 100 /dev/urandom | "${md5_cmd}" | head -c 4)" +if [[ ! -z "${CUSTOM_HEAT_STACK_YAML}" ]] ; then + TEMPLATE_FILE="${CUSTOM_HEAT_STACK_YAML}" +elif [[ -f "${HEAT_STACK_YAML}" ]] ; then + TEMPLATE_FILE="${HEAT_STACK_YAML}" +elif [[ ! -z "{HEAT_STACK_TEMPLATE_NAME}" ]] ; then + TEMPLATE_FILE="${WORKSPACE}/maintenance-ci/common/data/${HEAT_STACK_TEMPLATE_NAME}-${OPENSTACK_ENVIRONMENT,,}.yml" +fi + +if [[ ! -f "${TEMPLATE_FILE}" ]] ; then + echo "Can not detect TEMPLATE_FILE file, nothing at ${TEMPLATE_FILE}, aborting" + exit 1 +fi + set +x source "${OPENSTACK_CLIENTS_VENV}"/bin/activate set -x echo "Using ${OS_AUTH_URL?} endpoint" - openstack stack create --wait -t ${HEAT_STACK_YAML} --parameter "${parameter_string}" ${STACK_NAME} + openstack stack create --wait -t ${TEMPLATE_FILE} --parameter "${parameter_string}" ${STACK_NAME} openstack stack output show "${STACK_NAME}" --all cat >stack_data.sh <