blob: e9219630edba8c82e3ecd2d2a202c6497c8db797 [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 Dmitriev87c22d72018-11-09 17:18:00 +020059 dir("mk-pipelines-git") {
60 cloned = gerrit.gerritPatchsetCheckout([
61 credentialsId : "${GERRIT_MCP_CREDENTIALS_ID}",
62 gerritBranch: "${MCP_VERSION}",
63 gerritRefSpec: "${MK_PIPELINES_REF}",
64 gerritScheme: "ssh",
65 gerritName: "${GERRIT_USERNAME}",
66 gerritHost: "gerrit.mcp.mirantis.net",
67 gerritPort: "29418",
68 gerritProject: "mk/mk-pipelines"
69 ])
70 }
71 if (!cloned) {
72 error("Failed to clone the repository mk/mk-pipelines")
73 }
Dennis Dmitrievf220d972018-10-10 15:19:14 +030074
Dennis Dmitriev87c22d72018-11-09 17:18:00 +020075 dir("pipeline-library-git") {
76 cloned = gerrit.gerritPatchsetCheckout([
77 credentialsId : "${GERRIT_MCP_CREDENTIALS_ID}",
78 gerritBranch: "${MCP_VERSION}",
79 gerritRefSpec: "${PIPELINE_LIBRARY_REF}",
80 gerritScheme: "ssh",
81 gerritName: "${GERRIT_USERNAME}",
82 gerritHost: "gerrit.mcp.mirantis.net",
83 gerritPort: "29418",
84 gerritProject: "mcp-ci/pipeline-library"
85 ])
86 }
87 if (!cloned) {
88 error("Failed to clone the repository mcp-ci/pipeline-library")
89 }
90 }
Dennis Dmitrievf220d972018-10-10 15:19:14 +030091 if (PIPELINE_LIBRARY_REF != '') {
Dennis Dmitriev87c22d72018-11-09 17:18:00 +020092 sh "cd pipeline-library-git; git tag ${MCP_VERSION} FETCH_HEAD -f ; cd .."
Dennis Dmitrievf220d972018-10-10 15:19:14 +030093 }
94 if (MK_PIPELINES_REF != '') {
Dennis Dmitriev87c22d72018-11-09 17:18:00 +020095 sh "cd mk-pipelines-git; git tag ${MCP_VERSION} FETCH_HEAD -f; cd .."
Dennis Dmitrievf220d972018-10-10 15:19:14 +030096 }
Dennis Dmitriev87c22d72018-11-09 17:18:00 +020097
98 // gerrit.gerritPatchsetCheckout() doesn't support clonning bare repository
99 sh "git clone --mirror mk-pipelines-git -b ${MCP_VERSION} mk-pipelines"
100 sh "git clone --mirror pipeline-library-git -b ${MCP_VERSION} pipeline-library"
101 }
102
103 stage("Prepare arguments for generation config drive") {
104
105 config_drive_script_path = "mcp-common-scripts-git/config-drive/create_config_drive.sh"
106 user_data_script_path = "mcp-common-scripts-git/config-drive/master_config.yaml"
107 sh "chmod +x ${config_drive_script_path}"
108
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300109 //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 +0200110 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 +0300111 }
112
113 stage("Get cluster model") {
114 def model_url = "${MODEL_URL}"
115 sh "rm -rf model"
116 if (MODEL_URL_OBJECT_TYPE == 'tar.gz') {
117 sh "wget -O model.tar.gz '${model_url}'"
118 sh "mkdir model && cd model && tar zxfv ../model.tar.gz"
119 } else {
120 sh "git clone --recursive $model_url -b ${MCP_VERSION} model"
121 // remove .git file with hardcoded path
122 sh "rm model/classes/system/.git"
123 }
124 }
125
126 stage("Set data"){
127 for (i in entries(smc)) {
Dennis Dmitriev87c22d72018-11-09 17:18:00 +0200128 sh "sed -i \"s,export ${i[0]}=.*,export ${i[0]}=${i[1]},\" ${user_data_script_path}"
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300129 }
130 }
131
132 stage("Create user_data2"){
133 //http://jen20.com/2015/10/04/cloudconfig-merging.html
134 //TODO(ddmitriev): allow to read such file from
135 // ./tcp_tests/templates/${LAB_CONFIG_NAME}/ directory for each lab
136 def user_data2 = """\
137#cloud-config, see http://cloudinit.readthedocs.io/en/latest/topics/examples.html
138
139#write_files: # write_files don't work as expected because overwrites this key from mcp-common-scripts YAML, losing data
140# - path: /etc/default/grub.d/97-enable-grub-menu.cfg
141# content: |
142# GRUB_RECORDFAIL_TIMEOUT=30
143# GRUB_TIMEOUT=10
144# GRUB_TIMEOUT_STYLE=menu
145#
146# - path: /root/interfaces
147# content: |
148# auto lo
149# iface lo inet loopback
150#
151# auto ens3
152# iface ens3 inet dhcp
153#
154# - path: /root/.ssh/config
155# owner: root:root
156# permissions: '0600'
157# content: |
158# Host *
159# ServerAliveInterval 60
160# ServerAliveCountMax 0
161# StrictHostKeyChecking no
162# UserKnownHostsFile /dev/null
163#
164# - path: /etc/cloud/master_environment_override
165# owner: root:root
166# permissions: '0600'
167# content: |
168# export SALT_MASTER_MINION_ID="cfg01.${CLUSTER_NAME}.local"
169# export SALT_MASTER_DEPLOY_IP="${SALT_MASTER_DEPLOY_IP}"
170# export DEPLOY_NETWORK_GW="${DEPLOY_NETWORK_GW}"
171# export DEPLOY_NETWORK_NETMASK="${DEPLOY_NETWORK_NETMASK}"
172# export DNS_SERVERS="${DNS_SERVERS}"
173# export PIPELINES_FROM_ISO="${PIPELINES_FROM_ISO}"
174# export PIPELINE_REPO_URL="${PIPELINE_REPO_URL}"
175# export MCP_VERSION="${MCP_VERSION}"
176# export LOCAL_REPOS="true"
177# export MCP_SALT_REPO_KEY="${MCP_SALT_REPO_KEY}"
178# export MCP_SALT_REPO_URL="${MCP_SALT_REPO_URL}"
179
180output:
181 all: '| tee -a /var/log/cloud-init-output.log /dev/tty0'
182
183ssh_pwauth: True
184users:
185 - name: root
186 sudo: ALL=(ALL) NOPASSWD:ALL
187 shell: /bin/bash
188
189disable_root: false
190chpasswd:
191 list: |
192 root:r00tme
193 expire: False
194
195bootcmd:
196 # Block access to SSH while node is preparing
197 - cloud-init-per once sudo touch /is_cloud_init_started
198 # Enable root access
199 - sed -i -e '/^PermitRootLogin/s/.*/PermitRootLogin yes/' /etc/ssh/sshd_config
200 - service sshd restart
201
202merge_how: "dict(recurse_array)+list(append)"
203"""
204 writeFile(file: "user_data2", text: user_data2, encoding: "UTF-8")
205 }
206
207 stage("Create config-drive"){
208 // create cfg config-drive
Dennis Dmitriev87c22d72018-11-09 17:18:00 +0200209 // apt package genisoimage is required for this stage
210 sh "./${config_drive_script_path} ${args}"
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300211 }
212
213 stage("Save artifacts") {
214 archiveArtifacts allowEmptyArchive: false,
215 artifacts: "${iso_name}"
216 }
217
218 stage("Download config drive to slave") {
219 if (DOWNLOAD_CONFIG_DRIVE == 'true') {
220 def b_res = build job: 'download-config-drive',
221 parameters: [
222 string(name: 'IMAGE_URL', value: "${BUILD_URL}/artifact/${iso_name}"),
223 string(name: 'NODE_NAME', value: "${NODE_NAME}")
224 ]
225 } else {
226 echo "Drive only generated. But didn't download"
227 }
228 }
229 }
230}