Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | * Create fuel-devops environment, generate a model for it |
| 4 | * and bootstrap a salt cluster on the environment nodes |
| 5 | * |
| 6 | * Expected parameters: |
| 7 | |
| 8 | * PARENT_NODE_NAME Name of the jenkins slave to create the environment |
| 9 | * PARENT_WORKSPACE Path to the workspace of the parent job to use tcp-qa repo |
| 10 | * LAB_CONFIG_NAME Name of the tcp-qa deployment template |
| 11 | * ENV_NAME Fuel-devops environment name |
| 12 | * MCP_VERSION MCP version, like 2018.4 or proposed |
| 13 | * MCP_IMAGE_PATH1604 Local path to the image http://ci.mcp.mirantis.net:8085/images/ubuntu-16-04-x64-mcpproposed.qcow2 |
| 14 | * IMAGE_PATH_CFG01_DAY01 Local path to the image http://ci.mcp.mirantis.net:8085/images/cfg01-day01-proposed.qcow2 |
| 15 | * CFG01_CONFIG_IMAGE_NAME Name for the creating config drive image, like cfg01.${LAB_CONFIG_NAME}-config-drive.iso |
Hanna Arhipova | 5173aad | 2019-11-11 12:42:31 +0200 | [diff] [blame] | 16 | * TCP_QA_REFS Reference to the tcp-qa change on Gerrit, like refs/changes/46/418546/41 |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 17 | * PIPELINE_LIBRARY_REF Reference to the pipeline-library change |
| 18 | * MK_PIPELINES_REF Reference to the mk-pipelines change |
| 19 | * COOKIECUTTER_TEMPLATE_COMMIT Commit/tag/branch for cookiecutter-templates repository. If empty, then takes ${MCP_VERSION} value |
| 20 | * SALT_MODELS_SYSTEM_COMMIT Commit/tag/branch for reclass-system repository. If empty, then takes ${MCP_VERSION} value |
| 21 | * SHUTDOWN_ENV_ON_TEARDOWN optional, shutdown fuel-devops environment at the end of the job |
Dennis Dmitriev | d9168b5 | 2018-12-19 18:53:52 +0200 | [diff] [blame] | 22 | * MCP_SALT_REPO_URL Base URL for MCP repositories required to bootstrap cfg01 node. Leave blank to use default |
| 23 | * (http://mirror.mirantis.com/ from mcp-common-scripts) |
Tatyana Leontovich | 8ac26d7 | 2019-05-15 23:33:38 +0300 | [diff] [blame] | 24 | * JENKINS_PIPELINE_BRANCH Should be set in release/proposed/2019.2.0 when we test non-released version |
Dennis Dmitriev | d9168b5 | 2018-12-19 18:53:52 +0200 | [diff] [blame] | 25 | * MCP_SALT_REPO_KEY URL of the key file. Leave blank to use default |
| 26 | * (${MCP_SALT_REPO_URL}/${MCP_VERSION}/salt-formulas/xenial/archive-salt-formulas.key from mcp-common-scripts) |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 27 | * |
| 28 | */ |
| 29 | |
| 30 | @Library('tcp-qa')_ |
| 31 | |
Dennis Dmitriev | 4780016 | 2018-10-31 11:57:02 +0200 | [diff] [blame] | 32 | import groovy.xml.XmlUtil |
| 33 | |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 34 | common = new com.mirantis.mk.Common() |
| 35 | shared = new com.mirantis.system_qa.SharedPipeline() |
| 36 | |
| 37 | if (! env.PARENT_NODE_NAME) { |
| 38 | error "'PARENT_NODE_NAME' must be set from the parent deployment job!" |
| 39 | } |
| 40 | |
Dennis Dmitriev | 201a35e | 2018-08-06 01:37:05 +0300 | [diff] [blame] | 41 | currentBuild.description = "${PARENT_NODE_NAME}:${ENV_NAME}" |
| 42 | |
Dennis Dmitriev | 1f08b0c | 2019-05-27 17:03:53 +0300 | [diff] [blame] | 43 | timeout(time: 2, unit: 'HOURS') { |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 44 | node ("${PARENT_NODE_NAME}") { |
| 45 | if (! fileExists("${PARENT_WORKSPACE}")) { |
| 46 | error "'PARENT_WORKSPACE' contains path to non-existing directory ${PARENT_WORKSPACE} on the node '${PARENT_NODE_NAME}'." |
| 47 | } |
| 48 | dir("${PARENT_WORKSPACE}") { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 49 | if (env.TCP_QA_REFS) { |
| 50 | stage("Update working dir to patch ${TCP_QA_REFS}") { |
| 51 | shared.update_working_dir() |
| 52 | } |
| 53 | } |
| 54 | |
Dennis Dmitriev | efe5c0b | 2018-10-24 20:35:26 +0300 | [diff] [blame] | 55 | stage("Cleanup: erase ${ENV_NAME} and remove config drive") { |
| 56 | println "Remove environment ${ENV_NAME}" |
| 57 | shared.run_cmd("""\ |
| 58 | dos.py erase ${ENV_NAME} || true |
| 59 | """) |
| 60 | println "Remove config drive ISO" |
| 61 | shared.run_cmd("""\ |
| 62 | rm /home/jenkins/images/${CFG01_CONFIG_IMAGE_NAME} || true |
| 63 | """) |
| 64 | } |
| 65 | |
Dennis Dmitriev | efe5c0b | 2018-10-24 20:35:26 +0300 | [diff] [blame] | 66 | stage("Create an environment ${ENV_NAME} in disabled state") { |
| 67 | // deploy_hardware.xml |
| 68 | shared.run_cmd("""\ |
| 69 | export ENV_NAME=${ENV_NAME} |
| 70 | export LAB_CONFIG_NAME=${LAB_CONFIG_NAME} |
Dennis Dmitriev | 552454c | 2019-03-21 23:15:51 +0200 | [diff] [blame] | 71 | export ENV_MANAGER=devops |
Dennis Dmitriev | efe5c0b | 2018-10-24 20:35:26 +0300 | [diff] [blame] | 72 | export PYTHONIOENCODING=UTF-8 |
| 73 | export REPOSITORY_SUITE=${MCP_VERSION} |
Tatyana Leontovich | 4718bdf | 2019-05-24 12:37:06 +0300 | [diff] [blame] | 74 | export UPDATE_VERSION=${UPDATE_VERSION} |
Dennis Dmitriev | efe5c0b | 2018-10-24 20:35:26 +0300 | [diff] [blame] | 75 | export TEST_GROUP=test_create_environment |
Dennis Dmitriev | 2700732 | 2019-05-03 19:21:44 +0300 | [diff] [blame] | 76 | export LOG_NAME=swarm_test_create_environment.log |
Dennis Dmitriev | efe5c0b | 2018-10-24 20:35:26 +0300 | [diff] [blame] | 77 | py.test -vvv -s -p no:django -p no:ipdb --junit-xml=deploy_hardware.xml -k \${TEST_GROUP} |
| 78 | """) |
| 79 | } |
| 80 | |
| 81 | stage("Generate the model") { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 82 | def IPV4_NET_ADMIN=shared.run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep admin-pool01").trim().split().last() |
| 83 | def IPV4_NET_CONTROL=shared.run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep private-pool01").trim().split().last() |
| 84 | def IPV4_NET_TENANT=shared.run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep tenant-pool01").trim().split().last() |
| 85 | def IPV4_NET_EXTERNAL=shared.run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep external-pool01").trim().split().last() |
| 86 | shared.generate_cookied_model(IPV4_NET_ADMIN, IPV4_NET_CONTROL, IPV4_NET_TENANT, IPV4_NET_EXTERNAL) |
Dennis Dmitriev | efe5c0b | 2018-10-24 20:35:26 +0300 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | stage("Generate config drive ISO") { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 90 | def SALT_MASTER_IP=shared.run_cmd_stdout("""\ |
| 91 | SALT_MASTER_INFO=\$(for node in \$(dos.py slave-ip-list --address-pool-name admin-pool01 ${ENV_NAME}); do echo \$node; done|grep cfg01) |
| 92 | echo \$SALT_MASTER_INFO|cut -d',' -f2 |
| 93 | """).trim().split("\n").last() |
| 94 | def dhcp_ranges_json=shared.run_cmd_stdout("""\ |
| 95 | fgrep dhcp_ranges ${ENV_NAME}_hardware.ini | |
| 96 | fgrep "admin-pool01"| |
| 97 | cut -d"=" -f2 |
| 98 | """).trim().split("\n").last() |
| 99 | def dhcp_ranges = new groovy.json.JsonSlurperClassic().parseText(dhcp_ranges_json) |
| 100 | def ADMIN_NETWORK_GW = dhcp_ranges['admin-pool01']['gateway'] |
| 101 | shared.generate_configdrive_iso(SALT_MASTER_IP, ADMIN_NETWORK_GW) |
Dennis Dmitriev | efe5c0b | 2018-10-24 20:35:26 +0300 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | stage("Upload generated config drive ISO into volume on cfg01 node") { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 105 | def SALT_MASTER_HOSTNAME=shared.run_cmd_stdout("""\ |
| 106 | SALT_MASTER_INFO=\$(for node in \$(dos.py slave-ip-list --address-pool-name admin-pool01 ${ENV_NAME}); do echo \$node; done|grep cfg01) |
| 107 | echo \$SALT_MASTER_INFO|cut -d',' -f1 |
| 108 | """).trim().split("\n").last() |
Dennis Dmitriev | efe5c0b | 2018-10-24 20:35:26 +0300 | [diff] [blame] | 109 | shared.run_cmd("""\ |
| 110 | # Get SALT_MASTER_HOSTNAME to determine the volume name |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 111 | virsh vol-upload ${ENV_NAME}_${SALT_MASTER_HOSTNAME}_config /home/jenkins/images/${CFG01_CONFIG_IMAGE_NAME} --pool default |
Dennis Dmitriev | efe5c0b | 2018-10-24 20:35:26 +0300 | [diff] [blame] | 112 | virsh pool-refresh --pool default |
| 113 | """) |
| 114 | } |
| 115 | |
Dennis Dmitriev | 4780016 | 2018-10-31 11:57:02 +0200 | [diff] [blame] | 116 | stage("Run the 'underlay' and 'salt-deployed' fixtures to bootstrap salt cluster") { |
| 117 | def xml_report_name = "deploy_salt.xml" |
| 118 | try { |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 119 | // deploy_salt.xml |
Dennis Dmitriev | 4780016 | 2018-10-31 11:57:02 +0200 | [diff] [blame] | 120 | shared.run_sh("""\ |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 121 | export ENV_NAME=${ENV_NAME} |
| 122 | export LAB_CONFIG_NAME=${LAB_CONFIG_NAME} |
Dennis Dmitriev | 552454c | 2019-03-21 23:15:51 +0200 | [diff] [blame] | 123 | export ENV_MANAGER=devops |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 124 | export SHUTDOWN_ENV_ON_TEARDOWN=false |
Dennis Dmitriev | 87c22d7 | 2018-11-09 17:18:00 +0200 | [diff] [blame] | 125 | export BOOTSTRAP_TIMEOUT=1800 |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 126 | export PYTHONIOENCODING=UTF-8 |
| 127 | export REPOSITORY_SUITE=${MCP_VERSION} |
Tatyana Leontovich | 4718bdf | 2019-05-24 12:37:06 +0300 | [diff] [blame] | 128 | export UPDATE_VERSION=${UPDATE_VERSION} |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 129 | export TEST_GROUP=test_bootstrap_salt |
Dennis Dmitriev | 2700732 | 2019-05-03 19:21:44 +0300 | [diff] [blame] | 130 | export LOG_NAME=swarm_test_bootstrap_salt.log |
Dennis Dmitriev | 4780016 | 2018-10-31 11:57:02 +0200 | [diff] [blame] | 131 | py.test -vvv -s -p no:django -p no:ipdb --junit-xml=${xml_report_name} -k \${TEST_GROUP} |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 132 | """) |
Dennis Dmitriev | 44f6db2 | 2018-10-31 16:07:56 +0200 | [diff] [blame] | 133 | // Wait for jenkins to start and IO calm down |
| 134 | sleep(60) |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 135 | |
Dennis Dmitriev | 4780016 | 2018-10-31 11:57:02 +0200 | [diff] [blame] | 136 | } catch (e) { |
| 137 | common.printMsg("Saltstack cluster deploy is failed", "purple") |
| 138 | if (fileExists(xml_report_name)) { |
Dennis Dmitriev | 9cd5c13 | 2018-12-12 17:10:47 +0200 | [diff] [blame] | 139 | shared.download_logs("deploy_salt_${ENV_NAME}") |
Dennis Dmitriev | 4780016 | 2018-10-31 11:57:02 +0200 | [diff] [blame] | 140 | def String junit_report_xml = readFile(xml_report_name) |
| 141 | def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml) |
| 142 | throw new Exception(junit_report_xml_pretty) |
| 143 | } else { |
| 144 | throw e |
| 145 | } |
| 146 | } finally { |
| 147 | // TODO(ddmitriev): analyze the "def currentResult = currentBuild.result ?: 'SUCCESS'" |
| 148 | // and report appropriate data to TestRail |
| 149 | // TODO(ddmitriev): add checks for salt cluster |
| 150 | if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") { |
| 151 | shared.run_cmd("""\ |
| 152 | dos.py destroy ${ENV_NAME} |
| 153 | """) |
| 154 | } |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | } |
Dennis Dmitriev | 1f08b0c | 2019-05-27 17:03:53 +0300 | [diff] [blame] | 158 | } |
| 159 | } // timeout |