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 |
| 16 | * TCP_QA_REFS Reference to the tcp-qa change on review.gerrithub.io, like refs/changes/46/418546/41 |
| 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 |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | @Library('tcp-qa')_ |
| 26 | |
Dennis Dmitriev | 4780016 | 2018-10-31 11:57:02 +0200 | [diff] [blame] | 27 | import groovy.xml.XmlUtil |
| 28 | |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 29 | common = new com.mirantis.mk.Common() |
| 30 | shared = new com.mirantis.system_qa.SharedPipeline() |
| 31 | |
| 32 | if (! env.PARENT_NODE_NAME) { |
| 33 | error "'PARENT_NODE_NAME' must be set from the parent deployment job!" |
| 34 | } |
| 35 | |
Dennis Dmitriev | 201a35e | 2018-08-06 01:37:05 +0300 | [diff] [blame] | 36 | currentBuild.description = "${PARENT_NODE_NAME}:${ENV_NAME}" |
| 37 | |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 38 | node ("${PARENT_NODE_NAME}") { |
| 39 | if (! fileExists("${PARENT_WORKSPACE}")) { |
| 40 | error "'PARENT_WORKSPACE' contains path to non-existing directory ${PARENT_WORKSPACE} on the node '${PARENT_NODE_NAME}'." |
| 41 | } |
| 42 | dir("${PARENT_WORKSPACE}") { |
Dennis Dmitriev | efe5c0b | 2018-10-24 20:35:26 +0300 | [diff] [blame] | 43 | stage("Cleanup: erase ${ENV_NAME} and remove config drive") { |
| 44 | println "Remove environment ${ENV_NAME}" |
| 45 | shared.run_cmd("""\ |
| 46 | dos.py erase ${ENV_NAME} || true |
| 47 | """) |
| 48 | println "Remove config drive ISO" |
| 49 | shared.run_cmd("""\ |
| 50 | rm /home/jenkins/images/${CFG01_CONFIG_IMAGE_NAME} || true |
| 51 | """) |
| 52 | } |
| 53 | |
| 54 | if (env.TCP_QA_REFS) { |
| 55 | stage("Update working dir to patch ${TCP_QA_REFS}") { |
| 56 | shared.update_working_dir() |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | stage("Create an environment ${ENV_NAME} in disabled state") { |
| 61 | // deploy_hardware.xml |
| 62 | shared.run_cmd("""\ |
| 63 | export ENV_NAME=${ENV_NAME} |
| 64 | export LAB_CONFIG_NAME=${LAB_CONFIG_NAME} |
| 65 | export MANAGER=devops |
| 66 | export PYTHONIOENCODING=UTF-8 |
| 67 | export REPOSITORY_SUITE=${MCP_VERSION} |
| 68 | export TEST_GROUP=test_create_environment |
| 69 | py.test -vvv -s -p no:django -p no:ipdb --junit-xml=deploy_hardware.xml -k \${TEST_GROUP} |
| 70 | """) |
| 71 | } |
| 72 | |
| 73 | stage("Generate the model") { |
| 74 | shared.generate_cookied_model() |
| 75 | } |
| 76 | |
| 77 | stage("Generate config drive ISO") { |
| 78 | shared.generate_configdrive_iso() |
| 79 | } |
| 80 | |
| 81 | stage("Upload generated config drive ISO into volume on cfg01 node") { |
| 82 | shared.run_cmd("""\ |
| 83 | # Get SALT_MASTER_HOSTNAME to determine the volume name |
| 84 | . ./tcp_tests/utils/env_salt |
| 85 | virsh vol-upload ${ENV_NAME}_\${SALT_MASTER_HOSTNAME}_config /home/jenkins/images/${CFG01_CONFIG_IMAGE_NAME} --pool default |
| 86 | virsh pool-refresh --pool default |
| 87 | """) |
| 88 | } |
| 89 | |
Dennis Dmitriev | 4780016 | 2018-10-31 11:57:02 +0200 | [diff] [blame] | 90 | stage("Run the 'underlay' and 'salt-deployed' fixtures to bootstrap salt cluster") { |
| 91 | def xml_report_name = "deploy_salt.xml" |
| 92 | try { |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 93 | // deploy_salt.xml |
Dennis Dmitriev | 4780016 | 2018-10-31 11:57:02 +0200 | [diff] [blame] | 94 | shared.run_sh("""\ |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 95 | export ENV_NAME=${ENV_NAME} |
| 96 | export LAB_CONFIG_NAME=${LAB_CONFIG_NAME} |
| 97 | export MANAGER=devops |
| 98 | export SHUTDOWN_ENV_ON_TEARDOWN=false |
Dennis Dmitriev | 87c22d7 | 2018-11-09 17:18:00 +0200 | [diff] [blame] | 99 | export BOOTSTRAP_TIMEOUT=1800 |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 100 | export PYTHONIOENCODING=UTF-8 |
| 101 | export REPOSITORY_SUITE=${MCP_VERSION} |
| 102 | export TEST_GROUP=test_bootstrap_salt |
Dennis Dmitriev | 4780016 | 2018-10-31 11:57:02 +0200 | [diff] [blame] | 103 | 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] | 104 | """) |
Dennis Dmitriev | 44f6db2 | 2018-10-31 16:07:56 +0200 | [diff] [blame] | 105 | // Wait for jenkins to start and IO calm down |
| 106 | sleep(60) |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 107 | |
Dennis Dmitriev | 4780016 | 2018-10-31 11:57:02 +0200 | [diff] [blame] | 108 | } catch (e) { |
| 109 | common.printMsg("Saltstack cluster deploy is failed", "purple") |
| 110 | if (fileExists(xml_report_name)) { |
| 111 | shared.download_logs("deploy_salt") |
| 112 | def String junit_report_xml = readFile(xml_report_name) |
| 113 | def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml) |
| 114 | throw new Exception(junit_report_xml_pretty) |
| 115 | } else { |
| 116 | throw e |
| 117 | } |
| 118 | } finally { |
| 119 | // TODO(ddmitriev): analyze the "def currentResult = currentBuild.result ?: 'SUCCESS'" |
| 120 | // and report appropriate data to TestRail |
| 121 | // TODO(ddmitriev): add checks for salt cluster |
| 122 | if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") { |
| 123 | shared.run_cmd("""\ |
| 124 | dos.py destroy ${ENV_NAME} |
| 125 | """) |
| 126 | } |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | } |
| 130 | } |