blob: b64e8670ac9886a05d3311fa29f7190530488fa4 [file] [log] [blame]
Dennis Dmitrievf220d972018-10-10 15:19:14 +03001import java.text.SimpleDateFormat
2
Dennis Dmitriev87c22d72018-11-09 17:18:00 +02003def gerrit = new com.mirantis.mk.Gerrit()
Dennis Dmitrievf220d972018-10-10 15:19:14 +03004def dateFormat = new SimpleDateFormat("yyyyMMddHHmm")
5def date = new Date()
6def common_scripts_commit = "${COMMON_SCRIPTS_COMMIT}"
7def iso_name = "${CONFIG_DRIVE_ISO_NAME}" ?: "cfg01.${CLUSTER_NAME}-config-${dateFormat.format(date)}.iso"
8def node_name = "${NODE_NAME}"
Dmitriy Kruglov7844a6c2019-11-21 13:11:17 +01009def ssh = new com.mirantis.mk.Ssh()
Dennis Dmitrievf220d972018-10-10 15:19:14 +030010
11def smc = [:]
12smc['SALT_MASTER_MINION_ID'] = "cfg01.${CLUSTER_NAME}.local"
13smc['SALT_MASTER_DEPLOY_IP'] = "${SALT_MASTER_DEPLOY_IP}"
14smc['DEPLOY_NETWORK_GW'] = "${DEPLOY_NETWORK_GW}"
15smc['DEPLOY_NETWORK_NETMASK'] = "${DEPLOY_NETWORK_NETMASK}"
Dennis Dmitriev18319fa2019-03-19 22:39:02 +020016smc['DEPLOY_NETWORK_MTU'] = "${DEPLOY_NETWORK_MTU}"
Dennis Dmitrievf220d972018-10-10 15:19:14 +030017smc['DNS_SERVERS'] = "${DNS_SERVERS}"
18smc['PIPELINES_FROM_ISO'] = '${PIPELINES_FROM_ISO}'
19smc['PIPELINE_REPO_URL'] = '${PIPELINE_REPO_URL}'
20smc['MCP_VERSION'] = "${MCP_VERSION}"
21// smc['LOCAL_REPOS'] = 'true'
22smc['MCP_SALT_REPO_KEY'] = "${MCP_SALT_REPO_KEY}"
23smc['MCP_SALT_REPO_URL'] = "${MCP_SALT_REPO_URL}"
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +030024smc['MCP_SALT_REPO_UPDATES'] = "${MCP_SALT_REPO_UPDATES}"
25
Dennis Dmitrievf220d972018-10-10 15:19:14 +030026
27def entries(m) {
28 m.collect {k, v -> [k, v]}
29}
30
Dennis Dmitriev1f08b0c2019-05-27 17:03:53 +030031timeout(time: 2, unit: 'HOURS') {
Dennis Dmitrievf220d972018-10-10 15:19:14 +030032node (node_name) {
33
34 timestamps(){
35
36 stage("Clean Workspace") {
37 step([$class: 'WsCleanup'])
38 }
39
Dennis Dmitriev87c22d72018-11-09 17:18:00 +020040 stage("Get mk-pipelines, pipeline-library and mcp-common-scripts repositories") {
41 def cloned = true
42 withCredentials([[$class: 'SSHUserPrivateKeyBinding',
43 keyFileVariable: "GERRIT_KEY",
44 credentialsId: env.GERRIT_MCP_CREDENTIALS_ID,
Vladimir Khlyunev20e80462023-06-27 21:43:42 +040045 usernameVariable: "GERRIT_USERNAME"]]) {
Dmitriy Kruglov7844a6c2019-11-21 13:11:17 +010046 def gerrit_user = env.GERRIT_USERNAME
Hanna Arhipova33f15752020-12-07 13:44:40 +020047 String gerrit_host = "gerrit.mcp.mirantis.com"
Dmitriy Kruglov7844a6c2019-11-21 13:11:17 +010048 String gerrit_port = "29418"
Vladimir Khlyunev20e80462023-06-27 21:43:42 +040049 sshagent([env.GERRIT_MCP_CREDENTIALS_ID]) {
50 sh (
Dmitriy Kruglov7844a6c2019-11-21 13:11:17 +010051 "set -ex; " +
Vladimir Khlyunev20e80462023-06-27 21:43:42 +040052 "git clone ssh://${gerrit_user}@${gerrit_host}:${gerrit_port}/mcp/mcp-common-scripts mcp-common-scripts-git; " +
53 "git clone --mirror ssh://${gerrit_user}@${gerrit_host}:${gerrit_port}/mk/mk-pipelines mk-pipelines; " +
54 "git clone --mirror ssh://${gerrit_user}@${gerrit_host}:${gerrit_port}/mcp-ci/pipeline-library pipeline-library")
Dennis Dmitrieve3884652019-03-05 14:26:44 +020055
Vladimir Khlyunev20e80462023-06-27 21:43:42 +040056 if (COMMON_SCRIPTS_COMMIT != '') {
57 sh ("""\
58 set -ex
59 cd mcp-common-scripts-git
60 git checkout ${COMMON_SCRIPTS_COMMIT}
61 git log -1
62 """)
63 }
64
65 if (MCP_COMMON_SCRIPTS_REFS != '') {
66 sh (
67 "set -ex; " +
68 "cd mcp-common-scripts-git; " +
69 "git fetch https://${gerrit_host}/mcp/mcp-common-scripts ${MCP_COMMON_SCRIPTS_REFS} && git checkout FETCH_HEAD; " +
70 "git log -1")
71 }
72
73 if (PIPELINE_LIBRARY_REF != '') {
74 sh (
75 "set -ex; " +
76 "cd pipeline-library; " +
77 "git fetch https://${gerrit_host}/mcp-ci/pipeline-library ${PIPELINE_LIBRARY_REF}; " +
78 "git tag ${MCP_VERSION} FETCH_HEAD -f; " +
79 "git branch -f release/${MCP_VERSION} FETCH_HEAD; " +
80 "git log -1")
81 }
82 if (MK_PIPELINES_REF != '') {
83 sh (
84 "set -ex; " +
85 "cd mk-pipelines; " +
86 "git fetch https://${gerrit_host}/mk/mk-pipelines ${MK_PIPELINES_REF}; " +
87 "git tag ${MCP_VERSION} FETCH_HEAD -f; " +
88 "git branch -f release/${MCP_VERSION} FETCH_HEAD; " +
89 "git log -1")
90 }
Dennis Dmitriev87c22d72018-11-09 17:18:00 +020091 }
Dennis Dmitriev87c22d72018-11-09 17:18:00 +020092 }
Dennis Dmitriev87c22d72018-11-09 17:18:00 +020093 }
94
Dennis Dmitrievf220d972018-10-10 15:19:14 +030095 stage("Get cluster model") {
96 def model_url = "${MODEL_URL}"
97 sh "rm -rf model"
98 if (MODEL_URL_OBJECT_TYPE == 'tar.gz') {
99 sh "wget -O model.tar.gz '${model_url}'"
100 sh "mkdir model && cd model && tar zxfv ../model.tar.gz"
101 } else {
102 sh "git clone --recursive $model_url -b ${MCP_VERSION} model"
Dennis Dmitrieveaaafb22019-02-18 12:24:43 +0200103 // remove .git file with absolute path and re-init the file with relative path
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300104 sh "rm model/classes/system/.git"
Dennis Dmitrieveaaafb22019-02-18 12:24:43 +0200105 sh "cd model && git submodule update"
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300106 }
107 }
108
Dmitry Tyzhnenkofcb4dab2019-03-05 20:11:59 +0200109 stage("Prepare arguments for generation config drive") {
110
111 config_drive_script_path = "mcp-common-scripts-git/config-drive/create_config_drive.sh"
112 user_data_script_path = "mcp-common-scripts-git/config-drive/master_config.yaml"
113 sh "chmod +x ${config_drive_script_path}"
114
115 //args = "--user-data user_data --vendor-data user_data2 --hostname cfg01 --model model --mk-pipelines mk-pipelines/ --pipeline-library pipeline-library/ ${iso_name}"
116 args = "--user-data user_data2 --vendor-data ${user_data_script_path} --hostname cfg01 --model model --mk-pipelines mk-pipelines/ --pipeline-library pipeline-library/"
117 try {
118 sh "test -f model/encryption-key.asc"
119 args = "${args} --gpg-key model/encryption-key.asc ${iso_name}"
120
121 } catch (e) {
122 args = "${args} ${iso_name}"
123 }
124 }
125
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300126 stage("Set data"){
127 for (i in entries(smc)) {
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200128 // Replace only if the variable is non-empty, leave default otherwise
129 if (i[1]) {
130 sh "sed -i \"s,export ${i[0]}=.*,export ${i[0]}=${i[1]},\" ${user_data_script_path}"
131 }
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300132 }
133 }
134
135 stage("Create user_data2"){
136 //http://jen20.com/2015/10/04/cloudconfig-merging.html
137 //TODO(ddmitriev): allow to read such file from
138 // ./tcp_tests/templates/${LAB_CONFIG_NAME}/ directory for each lab
139 def user_data2 = """\
140#cloud-config, see http://cloudinit.readthedocs.io/en/latest/topics/examples.html
141
142#write_files: # write_files don't work as expected because overwrites this key from mcp-common-scripts YAML, losing data
143# - path: /etc/default/grub.d/97-enable-grub-menu.cfg
144# content: |
145# GRUB_RECORDFAIL_TIMEOUT=30
146# GRUB_TIMEOUT=10
147# GRUB_TIMEOUT_STYLE=menu
148#
149# - path: /root/interfaces
150# content: |
151# auto lo
152# iface lo inet loopback
153#
154# auto ens3
155# iface ens3 inet dhcp
156#
157# - path: /root/.ssh/config
158# owner: root:root
159# permissions: '0600'
160# content: |
161# Host *
162# ServerAliveInterval 60
163# ServerAliveCountMax 0
164# StrictHostKeyChecking no
165# UserKnownHostsFile /dev/null
166#
167# - path: /etc/cloud/master_environment_override
168# owner: root:root
169# permissions: '0600'
170# content: |
171# export SALT_MASTER_MINION_ID="cfg01.${CLUSTER_NAME}.local"
172# export SALT_MASTER_DEPLOY_IP="${SALT_MASTER_DEPLOY_IP}"
173# export DEPLOY_NETWORK_GW="${DEPLOY_NETWORK_GW}"
174# export DEPLOY_NETWORK_NETMASK="${DEPLOY_NETWORK_NETMASK}"
175# export DNS_SERVERS="${DNS_SERVERS}"
176# export PIPELINES_FROM_ISO="${PIPELINES_FROM_ISO}"
177# export PIPELINE_REPO_URL="${PIPELINE_REPO_URL}"
178# export MCP_VERSION="${MCP_VERSION}"
179# export LOCAL_REPOS="true"
180# export MCP_SALT_REPO_KEY="${MCP_SALT_REPO_KEY}"
181# export MCP_SALT_REPO_URL="${MCP_SALT_REPO_URL}"
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +0300182# export MCP_SALT_REPO_UPDATES="${MCP_SALT_REPO_UPDATES}"
183# export ENABLE_MCP_SALT_REPO_UPDATES="true"
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300184
185output:
186 all: '| tee -a /var/log/cloud-init-output.log /dev/tty0'
187
188ssh_pwauth: True
189users:
190 - name: root
191 sudo: ALL=(ALL) NOPASSWD:ALL
192 shell: /bin/bash
193
194disable_root: false
195chpasswd:
196 list: |
197 root:r00tme
198 expire: False
199
200bootcmd:
201 # Block access to SSH while node is preparing
202 - cloud-init-per once sudo touch /is_cloud_init_started
203 # Enable root access
204 - sed -i -e '/^PermitRootLogin/s/.*/PermitRootLogin yes/' /etc/ssh/sshd_config
205 - service sshd restart
206
Vladimir Khlyunev3a094152022-04-27 22:19:49 +0400207apt:
208 sources:
209 jenkins-formula:
Pavel Glazov42359f02023-03-21 15:46:57 +0400210 source: deb [trusted=yes] http://cz7780.bud.mirantis.net:8080/salt-formula-jenkins-2019.2.19/ xenial main
Vladimir Khlyunev3a094152022-04-27 22:19:49 +0400211
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300212merge_how: "dict(recurse_array)+list(append)"
213"""
214 writeFile(file: "user_data2", text: user_data2, encoding: "UTF-8")
215 }
216
217 stage("Create config-drive"){
218 // create cfg config-drive
Dennis Dmitriev87c22d72018-11-09 17:18:00 +0200219 // apt package genisoimage is required for this stage
220 sh "./${config_drive_script_path} ${args}"
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300221 }
222
223 stage("Save artifacts") {
224 archiveArtifacts allowEmptyArchive: false,
225 artifacts: "${iso_name}"
226 }
227
228 stage("Download config drive to slave") {
229 if (DOWNLOAD_CONFIG_DRIVE == 'true') {
Dennis Dmitrieve3884652019-03-05 14:26:44 +0200230 println "Remove previous config drive ISO"
231 sh("""\
232 rm /home/jenkins/images/${iso_name} || true
233 """)
234
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300235 def b_res = build job: 'download-config-drive',
236 parameters: [
237 string(name: 'IMAGE_URL', value: "${BUILD_URL}/artifact/${iso_name}"),
238 string(name: 'NODE_NAME', value: "${NODE_NAME}")
239 ]
240 } else {
241 echo "Drive only generated. But didn't download"
242 }
243 }
244 }
245}
Dennis Dmitriev1f08b0c2019-05-27 17:03:53 +0300246} // timeout