| import java.text.SimpleDateFormat |
| |
| def dateFormat = new SimpleDateFormat("yyyyMMddHHmm") |
| def date = new Date() |
| def common_scripts_commit = "${COMMON_SCRIPTS_COMMIT}" |
| def iso_name = "${CONFIG_DRIVE_ISO_NAME}" ?: "cfg01.${CLUSTER_NAME}-config-${dateFormat.format(date)}.iso" |
| def node_name = "${NODE_NAME}" |
| |
| def smc = [:] |
| smc['SALT_MASTER_MINION_ID'] = "cfg01.${CLUSTER_NAME}.local" |
| smc['SALT_MASTER_DEPLOY_IP'] = "${SALT_MASTER_DEPLOY_IP}" |
| smc['DEPLOY_NETWORK_GW'] = "${DEPLOY_NETWORK_GW}" |
| smc['DEPLOY_NETWORK_NETMASK'] = "${DEPLOY_NETWORK_NETMASK}" |
| smc['DNS_SERVERS'] = "${DNS_SERVERS}" |
| smc['PIPELINES_FROM_ISO'] = '${PIPELINES_FROM_ISO}' |
| smc['PIPELINE_REPO_URL'] = '${PIPELINE_REPO_URL}' |
| smc['MCP_VERSION'] = "${MCP_VERSION}" |
| // smc['LOCAL_REPOS'] = 'true' |
| smc['MCP_SALT_REPO_KEY'] = "${MCP_SALT_REPO_KEY}" |
| smc['MCP_SALT_REPO_URL'] = "${MCP_SALT_REPO_URL}" |
| |
| def entries(m) { |
| m.collect {k, v -> [k, v]} |
| } |
| |
| node (node_name) { |
| |
| timestamps(){ |
| |
| stage("Clean Workspace") { |
| step([$class: 'WsCleanup']) |
| } |
| |
| stage("Get scripts") { |
| // apt package genisoimage is required for this stage |
| // download create-config-drive |
| |
| def config_drive_script_url = "https://raw.githubusercontent.com/Mirantis/mcp-common-scripts/${common_scripts_commit}/config-drive/create_config_drive.sh" |
| sh "wget -O create-config-drive ${config_drive_script_url} && chmod +x create-config-drive" |
| |
| def user_data_script_url = "https://raw.githubusercontent.com/Mirantis/mcp-common-scripts/${common_scripts_commit}/config-drive/master_config.yaml" |
| sh "wget -O user_data ${user_data_script_url}" |
| } |
| |
| stage("Clone mk-pipelines and pipeline-library") { |
| sh "git clone --mirror https://github.com/Mirantis/mk-pipelines.git -b ${MCP_VERSION} mk-pipelines" |
| sh "git clone --mirror https://github.com/Mirantis/pipeline-library.git -b ${MCP_VERSION} pipeline-library" |
| if (PIPELINE_LIBRARY_REF != '') { |
| sh "cd pipeline-library; git fetch https://gerrit.mcp.mirantis.net/mcp-ci/pipeline-library ${PIPELINE_LIBRARY_REF} ; git tag ${MCP_VERSION} FETCH_HEAD -f ; cd .." |
| } |
| if (MK_PIPELINES_REF != '') { |
| sh "cd mk-pipelines; git fetch https://gerrit.mcp.mirantis.net/mcp-ci/mk-pipelines ${MK_PIPELINES_REF} ; git tag ${MCP_VERSION} FETCH_HEAD -f; cd .." |
| } |
| //args = "--user-data user_data --vendor-data user_data2 --hostname cfg01 --model model --mk-pipelines mk-pipelines/ --pipeline-library pipeline-library/ ${iso_name}" |
| args = "--user-data user_data2 --vendor-data user_data --hostname cfg01 --model model --mk-pipelines mk-pipelines/ --pipeline-library pipeline-library/ ${iso_name}" |
| } |
| |
| stage("Get cluster model") { |
| def model_url = "${MODEL_URL}" |
| sh "rm -rf model" |
| if (MODEL_URL_OBJECT_TYPE == 'tar.gz') { |
| sh "wget -O model.tar.gz '${model_url}'" |
| sh "mkdir model && cd model && tar zxfv ../model.tar.gz" |
| } else { |
| sh "git clone --recursive $model_url -b ${MCP_VERSION} model" |
| // remove .git file with hardcoded path |
| sh "rm model/classes/system/.git" |
| } |
| } |
| |
| stage("Set data"){ |
| for (i in entries(smc)) { |
| sh "sed -i \"s,export ${i[0]}=.*,export ${i[0]}=${i[1]},\" user_data" |
| } |
| } |
| |
| stage("Create user_data2"){ |
| //http://jen20.com/2015/10/04/cloudconfig-merging.html |
| //TODO(ddmitriev): allow to read such file from |
| // ./tcp_tests/templates/${LAB_CONFIG_NAME}/ directory for each lab |
| def user_data2 = """\ |
| #cloud-config, see http://cloudinit.readthedocs.io/en/latest/topics/examples.html |
| |
| #write_files: # write_files don't work as expected because overwrites this key from mcp-common-scripts YAML, losing data |
| # - path: /etc/default/grub.d/97-enable-grub-menu.cfg |
| # content: | |
| # GRUB_RECORDFAIL_TIMEOUT=30 |
| # GRUB_TIMEOUT=10 |
| # GRUB_TIMEOUT_STYLE=menu |
| # |
| # - path: /root/interfaces |
| # content: | |
| # auto lo |
| # iface lo inet loopback |
| # |
| # auto ens3 |
| # iface ens3 inet dhcp |
| # |
| # - path: /root/.ssh/config |
| # owner: root:root |
| # permissions: '0600' |
| # content: | |
| # Host * |
| # ServerAliveInterval 60 |
| # ServerAliveCountMax 0 |
| # StrictHostKeyChecking no |
| # UserKnownHostsFile /dev/null |
| # |
| # - path: /etc/cloud/master_environment_override |
| # owner: root:root |
| # permissions: '0600' |
| # content: | |
| # export SALT_MASTER_MINION_ID="cfg01.${CLUSTER_NAME}.local" |
| # export SALT_MASTER_DEPLOY_IP="${SALT_MASTER_DEPLOY_IP}" |
| # export DEPLOY_NETWORK_GW="${DEPLOY_NETWORK_GW}" |
| # export DEPLOY_NETWORK_NETMASK="${DEPLOY_NETWORK_NETMASK}" |
| # export DNS_SERVERS="${DNS_SERVERS}" |
| # export PIPELINES_FROM_ISO="${PIPELINES_FROM_ISO}" |
| # export PIPELINE_REPO_URL="${PIPELINE_REPO_URL}" |
| # export MCP_VERSION="${MCP_VERSION}" |
| # export LOCAL_REPOS="true" |
| # export MCP_SALT_REPO_KEY="${MCP_SALT_REPO_KEY}" |
| # export MCP_SALT_REPO_URL="${MCP_SALT_REPO_URL}" |
| |
| output: |
| all: '| tee -a /var/log/cloud-init-output.log /dev/tty0' |
| |
| ssh_pwauth: True |
| users: |
| - name: root |
| sudo: ALL=(ALL) NOPASSWD:ALL |
| shell: /bin/bash |
| |
| disable_root: false |
| chpasswd: |
| list: | |
| root:r00tme |
| expire: False |
| |
| bootcmd: |
| # Block access to SSH while node is preparing |
| - cloud-init-per once sudo touch /is_cloud_init_started |
| # Enable root access |
| - sed -i -e '/^PermitRootLogin/s/.*/PermitRootLogin yes/' /etc/ssh/sshd_config |
| - service sshd restart |
| |
| merge_how: "dict(recurse_array)+list(append)" |
| """ |
| writeFile(file: "user_data2", text: user_data2, encoding: "UTF-8") |
| } |
| |
| stage("Create config-drive"){ |
| // create cfg config-drive |
| //sh "sed -i 's,config_dir/vendor-data,config_dir/user-data1,g' ./create-config-drive" |
| sh "./create-config-drive ${args}" |
| } |
| |
| stage("Save artifacts") { |
| archiveArtifacts allowEmptyArchive: false, |
| artifacts: "${iso_name}" |
| } |
| |
| stage("Download config drive to slave") { |
| if (DOWNLOAD_CONFIG_DRIVE == 'true') { |
| def b_res = build job: 'download-config-drive', |
| parameters: [ |
| string(name: 'IMAGE_URL', value: "${BUILD_URL}/artifact/${iso_name}"), |
| string(name: 'NODE_NAME', value: "${NODE_NAME}") |
| ] |
| } else { |
| echo "Drive only generated. But didn't download" |
| } |
| } |
| } |
| } |