blob: 72d278fa6bcb805f091179be2ed46d0e7ffe5b42 [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}"
9
10def smc = [:]
11smc['SALT_MASTER_MINION_ID'] = "cfg01.${CLUSTER_NAME}.local"
12smc['SALT_MASTER_DEPLOY_IP'] = "${SALT_MASTER_DEPLOY_IP}"
13smc['DEPLOY_NETWORK_GW'] = "${DEPLOY_NETWORK_GW}"
14smc['DEPLOY_NETWORK_NETMASK'] = "${DEPLOY_NETWORK_NETMASK}"
15smc['DNS_SERVERS'] = "${DNS_SERVERS}"
16smc['PIPELINES_FROM_ISO'] = '${PIPELINES_FROM_ISO}'
17smc['PIPELINE_REPO_URL'] = '${PIPELINE_REPO_URL}'
18smc['MCP_VERSION'] = "${MCP_VERSION}"
19// smc['LOCAL_REPOS'] = 'true'
20smc['MCP_SALT_REPO_KEY'] = "${MCP_SALT_REPO_KEY}"
21smc['MCP_SALT_REPO_URL'] = "${MCP_SALT_REPO_URL}"
22
23def entries(m) {
24 m.collect {k, v -> [k, v]}
25}
26
27node (node_name) {
28
29 timestamps(){
30
31 stage("Clean Workspace") {
32 step([$class: 'WsCleanup'])
33 }
34
Dennis Dmitriev87c22d72018-11-09 17:18:00 +020035 stage("Get mk-pipelines, pipeline-library and mcp-common-scripts repositories") {
36 def cloned = true
37 withCredentials([[$class: 'SSHUserPrivateKeyBinding',
38 keyFileVariable: "GERRIT_KEY",
39 credentialsId: env.GERRIT_MCP_CREDENTIALS_ID,
40 usernameVariable: "GERRIT_USERNAME",
41 passwordVariable: "GERRIT_PASSWORD"]]) {
Dennis Dmitrievf220d972018-10-10 15:19:14 +030042
Dennis Dmitriev87c22d72018-11-09 17:18:00 +020043 dir("mcp-common-scripts-git") {
44 cloned = gerrit.gerritPatchsetCheckout([
45 credentialsId : "${GERRIT_MCP_CREDENTIALS_ID}",
46 gerritBranch: "${MCP_VERSION}",
47 gerritRefSpec: "${MCP_COMMON_SCRIPTS_REFS}",
48 gerritScheme: "ssh",
49 gerritName: "${GERRIT_USERNAME}",
50 gerritHost: "gerrit.mcp.mirantis.net",
51 gerritPort: "29418",
52 gerritProject: "mcp/mcp-common-scripts"
53 ])
54 }
55 if (!cloned) {
56 error("Failed to clone the repository mcp/mcp-common-scripts")
57 }
Dennis Dmitrievf220d972018-10-10 15:19:14 +030058
Dennis Dmitrievc4a14ba2018-11-12 23:31:40 +020059 sh ("""\
60 set -ex
61 eval \$(ssh-agent)
62 ssh-add ${GERRIT_KEY}
63 git clone --mirror ssh://${GERRIT_USERNAME}@gerrit.mcp.mirantis.net:29418/mk/mk-pipelines mk-pipelines
64 git clone --mirror ssh://${GERRIT_USERNAME}@gerrit.mcp.mirantis.net:29418/mcp-ci/pipeline-library pipeline-library
65 """)
66
67 if (PIPELINE_LIBRARY_REF != '') {
68 sh ("""\
69 set -ex
70 eval \$(ssh-agent)
71 ssh-add ${GERRIT_KEY}
72 cd pipeline-library
73 git fetch https://gerrit.mcp.mirantis.net/mcp-ci/pipeline-library ${PIPELINE_LIBRARY_REF}
74 git tag ${MCP_VERSION} FETCH_HEAD -f
75 """)
Dennis Dmitriev87c22d72018-11-09 17:18:00 +020076 }
Dennis Dmitrievc4a14ba2018-11-12 23:31:40 +020077 if (MK_PIPELINES_REF != '') {
78 sh ("""\
79 set -ex
80 eval \$(ssh-agent)
81 ssh-add ${GERRIT_KEY}
82 cd mk-pipelines
83 git fetch https://gerrit.mcp.mirantis.net/mcp-ci/mk-pipelines ${MK_PIPELINES_REF}
84 git tag ${MCP_VERSION} FETCH_HEAD -f
85 """)
Dennis Dmitriev87c22d72018-11-09 17:18:00 +020086 }
Dennis Dmitrievf220d972018-10-10 15:19:14 +030087
Dennis Dmitrievc4a14ba2018-11-12 23:31:40 +020088 // dir("mk-pipelines-git") {
89 // cloned = gerrit.gerritPatchsetCheckout([
90 // credentialsId : "${GERRIT_MCP_CREDENTIALS_ID}",
91 // gerritRefSpec: "${MK_PIPELINES_REF}",
92 // gerritScheme: "ssh",
93 // gerritName: "${GERRIT_USERNAME}",
94 // gerritHost: "gerrit.mcp.mirantis.net",
95 // gerritPort: "29418",
96 // gerritProject: "mk/mk-pipelines"
97 // ])
98 // }
99 // if (!cloned) {
100 // error("Failed to clone the repository mk/mk-pipelines")
101 // }
102
103 // dir("pipeline-library-git") {
104 // cloned = gerrit.gerritPatchsetCheckout([
105 // credentialsId : "${GERRIT_MCP_CREDENTIALS_ID}",
106 // gerritRefSpec: "${PIPELINE_LIBRARY_REF}",
107 // gerritScheme: "ssh",
108 // gerritName: "${GERRIT_USERNAME}",
109 // gerritHost: "gerrit.mcp.mirantis.net",
110 // gerritPort: "29418",
111 // gerritProject: "mcp-ci/pipeline-library"
112 // ])
113 // }
114 // if (!cloned) {
115 // error("Failed to clone the repository mcp-ci/pipeline-library")
116 // }
Dennis Dmitriev87c22d72018-11-09 17:18:00 +0200117 }
Dennis Dmitrievc4a14ba2018-11-12 23:31:40 +0200118 //if (PIPELINE_LIBRARY_REF != '') {
119 // sh "cd pipeline-library; git tag ${MCP_VERSION} FETCH_HEAD -f ; cd .."
120 //}
121 //if (MK_PIPELINES_REF != '') {
122 // sh "cd mk-pipelines; git tag ${MCP_VERSION} FETCH_HEAD -f; cd .."
123 //}
Dennis Dmitriev87c22d72018-11-09 17:18:00 +0200124
125 // gerrit.gerritPatchsetCheckout() doesn't support clonning bare repository
Dennis Dmitrievc4a14ba2018-11-12 23:31:40 +0200126 // sh "git clone --mirror mk-pipelines-git mk-pipelines"
127 // sh "git clone --mirror pipeline-library-git pipeline-library"
Dennis Dmitriev87c22d72018-11-09 17:18:00 +0200128 }
129
130 stage("Prepare arguments for generation config drive") {
131
132 config_drive_script_path = "mcp-common-scripts-git/config-drive/create_config_drive.sh"
133 user_data_script_path = "mcp-common-scripts-git/config-drive/master_config.yaml"
134 sh "chmod +x ${config_drive_script_path}"
135
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300136 //args = "--user-data user_data --vendor-data user_data2 --hostname cfg01 --model model --mk-pipelines mk-pipelines/ --pipeline-library pipeline-library/ ${iso_name}"
Dennis Dmitriev87c22d72018-11-09 17:18:00 +0200137 args = "--user-data user_data2 --vendor-data ${user_data_script_path} --hostname cfg01 --model model --mk-pipelines mk-pipelines/ --pipeline-library pipeline-library/ ${iso_name}"
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300138 }
139
140 stage("Get cluster model") {
141 def model_url = "${MODEL_URL}"
142 sh "rm -rf model"
143 if (MODEL_URL_OBJECT_TYPE == 'tar.gz') {
144 sh "wget -O model.tar.gz '${model_url}'"
145 sh "mkdir model && cd model && tar zxfv ../model.tar.gz"
146 } else {
147 sh "git clone --recursive $model_url -b ${MCP_VERSION} model"
148 // remove .git file with hardcoded path
149 sh "rm model/classes/system/.git"
150 }
151 }
152
153 stage("Set data"){
154 for (i in entries(smc)) {
Dennis Dmitriev87c22d72018-11-09 17:18:00 +0200155 sh "sed -i \"s,export ${i[0]}=.*,export ${i[0]}=${i[1]},\" ${user_data_script_path}"
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300156 }
157 }
158
159 stage("Create user_data2"){
160 //http://jen20.com/2015/10/04/cloudconfig-merging.html
161 //TODO(ddmitriev): allow to read such file from
162 // ./tcp_tests/templates/${LAB_CONFIG_NAME}/ directory for each lab
163 def user_data2 = """\
164#cloud-config, see http://cloudinit.readthedocs.io/en/latest/topics/examples.html
165
166#write_files: # write_files don't work as expected because overwrites this key from mcp-common-scripts YAML, losing data
167# - path: /etc/default/grub.d/97-enable-grub-menu.cfg
168# content: |
169# GRUB_RECORDFAIL_TIMEOUT=30
170# GRUB_TIMEOUT=10
171# GRUB_TIMEOUT_STYLE=menu
172#
173# - path: /root/interfaces
174# content: |
175# auto lo
176# iface lo inet loopback
177#
178# auto ens3
179# iface ens3 inet dhcp
180#
181# - path: /root/.ssh/config
182# owner: root:root
183# permissions: '0600'
184# content: |
185# Host *
186# ServerAliveInterval 60
187# ServerAliveCountMax 0
188# StrictHostKeyChecking no
189# UserKnownHostsFile /dev/null
190#
191# - path: /etc/cloud/master_environment_override
192# owner: root:root
193# permissions: '0600'
194# content: |
195# export SALT_MASTER_MINION_ID="cfg01.${CLUSTER_NAME}.local"
196# export SALT_MASTER_DEPLOY_IP="${SALT_MASTER_DEPLOY_IP}"
197# export DEPLOY_NETWORK_GW="${DEPLOY_NETWORK_GW}"
198# export DEPLOY_NETWORK_NETMASK="${DEPLOY_NETWORK_NETMASK}"
199# export DNS_SERVERS="${DNS_SERVERS}"
200# export PIPELINES_FROM_ISO="${PIPELINES_FROM_ISO}"
201# export PIPELINE_REPO_URL="${PIPELINE_REPO_URL}"
202# export MCP_VERSION="${MCP_VERSION}"
203# export LOCAL_REPOS="true"
204# export MCP_SALT_REPO_KEY="${MCP_SALT_REPO_KEY}"
205# export MCP_SALT_REPO_URL="${MCP_SALT_REPO_URL}"
206
207output:
208 all: '| tee -a /var/log/cloud-init-output.log /dev/tty0'
209
210ssh_pwauth: True
211users:
212 - name: root
213 sudo: ALL=(ALL) NOPASSWD:ALL
214 shell: /bin/bash
215
216disable_root: false
217chpasswd:
218 list: |
219 root:r00tme
220 expire: False
221
222bootcmd:
223 # Block access to SSH while node is preparing
224 - cloud-init-per once sudo touch /is_cloud_init_started
225 # Enable root access
226 - sed -i -e '/^PermitRootLogin/s/.*/PermitRootLogin yes/' /etc/ssh/sshd_config
227 - service sshd restart
228
229merge_how: "dict(recurse_array)+list(append)"
230"""
231 writeFile(file: "user_data2", text: user_data2, encoding: "UTF-8")
232 }
233
234 stage("Create config-drive"){
235 // create cfg config-drive
Dennis Dmitriev87c22d72018-11-09 17:18:00 +0200236 // apt package genisoimage is required for this stage
237 sh "./${config_drive_script_path} ${args}"
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300238 }
239
240 stage("Save artifacts") {
241 archiveArtifacts allowEmptyArchive: false,
242 artifacts: "${iso_name}"
243 }
244
245 stage("Download config drive to slave") {
246 if (DOWNLOAD_CONFIG_DRIVE == 'true') {
247 def b_res = build job: 'download-config-drive',
248 parameters: [
249 string(name: 'IMAGE_URL', value: "${BUILD_URL}/artifact/${iso_name}"),
250 string(name: 'NODE_NAME', value: "${NODE_NAME}")
251 ]
252 } else {
253 echo "Drive only generated. But didn't download"
254 }
255 }
256 }
257}