blob: 135f9d566a005be676de153974d07500781580dd [file] [log] [blame]
Dennis Dmitrievb3b37492018-07-08 21:23:00 +03001/**
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
27common = new com.mirantis.mk.Common()
28shared = new com.mirantis.system_qa.SharedPipeline()
29
30if (! env.PARENT_NODE_NAME) {
31 error "'PARENT_NODE_NAME' must be set from the parent deployment job!"
32}
33
34node ("${PARENT_NODE_NAME}") {
35 if (! fileExists("${PARENT_WORKSPACE}")) {
36 error "'PARENT_WORKSPACE' contains path to non-existing directory ${PARENT_WORKSPACE} on the node '${PARENT_NODE_NAME}'."
37 }
38 dir("${PARENT_WORKSPACE}") {
39 try {
40 stage("Cleanup: erase ${ENV_NAME} and remove config drive") {
41 println "Remove environment ${ENV_NAME}"
42 shared.run_cmd("""\
43 dos.py erase ${ENV_NAME} || true
44 """)
45 println "Remove config drive ISO"
46 shared.run_cmd("""\
47 rm /home/jenkins/images/${CFG01_CONFIG_IMAGE_NAME} || true
48 """)
49 }
50
51 stage("Create an environment ${ENV_NAME} in disabled state") {
52 // deploy_hardware.xml
53 shared.run_cmd("""\
54 export ENV_NAME=${ENV_NAME}
55 export LAB_CONFIG_NAME=${LAB_CONFIG_NAME}
56 export MANAGER=devops
57 export PYTHONIOENCODING=UTF-8
58 export REPOSITORY_SUITE=${MCP_VERSION}
59 export TEST_GROUP=test_create_environment
60 py.test -vvv -s -p no:django -p no:ipdb --junit-xml=deploy_hardware.xml -k \${TEST_GROUP}
61 """)
62 }
63
64 stage("Generate the model") {
65 shared.generate_cookied_model()
66 }
67
68 stage("Generate config drive ISO") {
69 shared.generate_configdrive_iso()
70 }
71
72 stage("Upload generated config drive ISO into volume on cfg01 node") {
73 shared.run_cmd("""\
Dennis Dmitriev06fac232018-07-19 13:20:53 +030074 # Get SALT_MASTER_HOSTNAME to determine the volume name
75 . ./tcp_tests/utils/env_salt
76 virsh vol-upload ${ENV_NAME}_\${SALT_MASTER_HOSTNAME}_config /home/jenkins/images/${CFG01_CONFIG_IMAGE_NAME} --pool default
77 virsh pool-refresh --pool default
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030078 """)
79 }
80
81 stage("Run the 'underlay' and 'salt-deployed' fixtures to bootstrap salt cluster") {
82 // deploy_salt.xml
83 shared.run_cmd("""\
84 export ENV_NAME=${ENV_NAME}
85 export LAB_CONFIG_NAME=${LAB_CONFIG_NAME}
86 export MANAGER=devops
87 export SHUTDOWN_ENV_ON_TEARDOWN=false
88 export BOOTSTRAP_TIMEOUT=900
89 export PYTHONIOENCODING=UTF-8
90 export REPOSITORY_SUITE=${MCP_VERSION}
91 export TEST_GROUP=test_bootstrap_salt
92 py.test -vvv -s -p no:django -p no:ipdb --junit-xml=deploy_salt.xml -k \${TEST_GROUP}
93 sleep 60 # wait for jenkins to start and IO calm down
94 """)
95 }
96
97 } catch (e) {
98 common.printMsg("Job failed", "red")
99 throw e
100 } finally {
101 // TODO(ddmitriev): analyze the "def currentResult = currentBuild.result ?: 'SUCCESS'"
102 // and report appropriate data to TestRail
103 // TODO(ddmitriev): add checks for salt cluster
104 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") {
105 shared.run_cmd("""\
106 dos.py destroy ${ENV_NAME}
107 """)
108 }
109 }
110 }
111}