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