Oleksii Zhurba | 90b6fa9 | 2019-03-26 13:14:21 -0500 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | * Launch CVP Tempest verification of the cloud |
| 4 | * |
| 5 | * Expected parameters: |
| 6 | |
| 7 | * SALT_MASTER_URL URL of Salt master |
| 8 | * SALT_MASTER_CREDENTIALS Credentials that are used in this Jenkins for accessing Salt master (usually "salt") |
| 9 | * SERVICE_NODE Node, where runtest formula and some other states will be executed |
| 10 | * VERBOSE Show salt output in Jenkins console |
| 11 | * DEBUG_MODE Remove or keep container after the test |
| 12 | * STOP_ON_ERROR Stop pipeline if error during salt run occurs |
| 13 | * GENERATE_CONFIG Run runtest formula / generate Tempest config |
| 14 | * SKIP_LIST_PATH Path to skip list (not in use right now) |
| 15 | * TEST_IMAGE Docker image link to use for running container with testing tools. |
| 16 | * TARGET_NODE Node to run container with Tempest/Rally |
| 17 | * PREPARE_RESOURCES Prepare Openstack resources before test run |
| 18 | * TEMPEST_TEST_PATTERN Tests to run |
| 19 | * TEMPEST_ENDPOINT_TYPE Type of OS endpoint to use during test run (not in use right now) |
| 20 | * concurrency Number of threads to use for Tempest test run |
| 21 | * remote_artifacts_dir Folder to use for artifacts on remote node |
Oleksii Zhurba | baa42c9 | 2019-05-29 16:08:40 -0500 | [diff] [blame] | 22 | * runtest_tempest_cfg_dir Folder to use to generate and store tempest.conf |
| 23 | * runtest_tempest_cfg_name Tempest config name |
Oleksii Zhurba | 90b6fa9 | 2019-03-26 13:14:21 -0500 | [diff] [blame] | 24 | * report_prefix Some prefix to put to report name |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | |
| 29 | common = new com.mirantis.mk.Common() |
| 30 | salt = new com.mirantis.mk.Salt() |
| 31 | validate = new com.mirantis.mcp.Validate() |
| 32 | |
| 33 | def saltMaster |
| 34 | extraYamlContext = env.getProperty('EXTRA_PARAMS') |
| 35 | if (extraYamlContext) { |
| 36 | common.mergeEnv(env, extraYamlContext) } |
| 37 | def SALT_MASTER_CREDENTIALS=(env.SALT_MASTER_CREDENTIALS) ?: 'salt' |
Oleksii Zhurba | f66b0e0 | 2019-04-15 15:57:42 -0500 | [diff] [blame] | 38 | def VERBOSE = (env.VERBOSE) ? env.VERBOSE.toBoolean() : true |
Oleksii Zhurba | 90b6fa9 | 2019-03-26 13:14:21 -0500 | [diff] [blame] | 39 | def DEBUG_MODE = (env.DEBUG_MODE) ?: false |
Oleksii Zhurba | f66b0e0 | 2019-04-15 15:57:42 -0500 | [diff] [blame] | 40 | def STOP_ON_ERROR = (env.STOP_ON_ERROR) ? env.STOP_ON_ERROR.toBoolean() : false |
Oleksii Zhurba | 90b6fa9 | 2019-03-26 13:14:21 -0500 | [diff] [blame] | 41 | def GENERATE_CONFIG = (env.GENERATE_CONFIG) ?: true |
Oleksii Zhurba | baa42c9 | 2019-05-29 16:08:40 -0500 | [diff] [blame] | 42 | // do not change unless you know what you're doing |
Oleksii Zhurba | 90b6fa9 | 2019-03-26 13:14:21 -0500 | [diff] [blame] | 43 | def remote_artifacts_dir = (env.remote_artifacts_dir) ?: '/root/test/' |
| 44 | def report_prefix = (env.report_prefix) ?: '' |
| 45 | def args = '' |
Oleksii Zhurba | baa42c9 | 2019-05-29 16:08:40 -0500 | [diff] [blame] | 46 | def mounts = [:] |
Oleksii Zhurba | 90b6fa9 | 2019-03-26 13:14:21 -0500 | [diff] [blame] | 47 | node() { |
Oleksii Zhurba | baa42c9 | 2019-05-29 16:08:40 -0500 | [diff] [blame] | 48 | stage('Initialization') { |
| 49 | deleteDir() |
| 50 | saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 51 | container_name = "${env.JOB_NAME}" |
| 52 | cluster_name=salt.getPillar(saltMaster, 'I@salt:master', '_param:cluster_name')['return'][0].values()[0] |
| 53 | os_version=salt.getPillar(saltMaster, 'I@salt:master', '_param:openstack_version')['return'][0].values()[0] |
| 54 | if (!os_version) { |
| 55 | throw new Exception("Openstack is not found on this env. Exiting") |
Oleksii Zhurba | 90b6fa9 | 2019-03-26 13:14:21 -0500 | [diff] [blame] | 56 | } |
Oleksii Zhurba | baa42c9 | 2019-05-29 16:08:40 -0500 | [diff] [blame] | 57 | TEST_IMAGE = (env.TEST_IMAGE) ?: "docker-prod-virtual.docker.mirantis.net/mirantis/cicd/ci-tempest:${os_version}" |
| 58 | runtest_node = salt.runSaltProcessStep(saltMaster, 'I@runtest:*', 'test.ping')['return'][0] |
| 59 | if (runtest_node.values()[0]) { |
| 60 | // Let's use Service node that was defined in reclass. If several nodes are defined |
| 61 | // we will use the first from salt output |
| 62 | common.infoMsg("Service node ${runtest_node.keySet()[0]} is defined in reclass") |
| 63 | SERVICE_NODE = runtest_node.keySet()[0] |
Oleksii Zhurba | 90b6fa9 | 2019-03-26 13:14:21 -0500 | [diff] [blame] | 64 | } |
Oleksii Zhurba | baa42c9 | 2019-05-29 16:08:40 -0500 | [diff] [blame] | 65 | else { |
| 66 | throw new Exception("Runtest config is not found in reclass. Please create runtest.yml and include it " + |
| 67 | "into reclass. Check documentation for more details") |
| 68 | } |
| 69 | common.infoMsg('Refreshing pillars on service node') |
| 70 | salt.runSaltProcessStep(saltMaster, SERVICE_NODE, 'saltutil.refresh_pillar', [], null, VERBOSE) |
| 71 | // default node is cid01 (preferably) or cfg01 |
| 72 | default_node=salt.getPillar(saltMaster, 'I@salt:master', '_param:cicd_control_node01_hostname')['return'][0].values()[0] ?: 'cfg01' |
| 73 | // fetch tempest_test_target from runtest.yaml, otherwise fallback to default_node |
| 74 | tempest_node=salt.getPillar(saltMaster, SERVICE_NODE, '_param:tempest_test_target')['return'][0].values()[0] ?: default_node+'*' |
| 75 | // TARGET_NODE will always override any settings above |
| 76 | TARGET_NODE = (env.TARGET_NODE) ?: tempest_node |
Oleksii Zhurba | 712b05a | 2019-07-17 12:29:49 -0500 | [diff] [blame] | 77 | // default is /root/test/ |
| 78 | runtest_tempest_cfg_dir = (env.runtest_tempest_cfg_dir) ?: salt.getPillar(saltMaster, SERVICE_NODE, '_param:runtest_tempest_cfg_dir')['return'][0].values()[0] |
| 79 | // default is tempest_generated.conf |
| 80 | runtest_tempest_cfg_name = (env.runtest_tempest_cfg_name) ?: salt.getPillar(saltMaster, SERVICE_NODE, '_param:runtest_tempest_cfg_name')['return'][0].values()[0] |
| 81 | common.infoMsg("runtest_tempest_cfg is ${runtest_tempest_cfg_dir}/${runtest_tempest_cfg_name}") |
Oleksii Zhurba | baa42c9 | 2019-05-29 16:08:40 -0500 | [diff] [blame] | 82 | } |
| 83 | stage('Preparing resources') { |
| 84 | if ( PREPARE_RESOURCES.toBoolean() ) { |
| 85 | common.infoMsg('Running salt.minion state on service node') |
| 86 | salt.enforceState(saltMaster, SERVICE_NODE, ['salt.minion'], VERBOSE, STOP_ON_ERROR, null, false, 300, 2, true, [], 60) |
| 87 | common.infoMsg('Running keystone.client on service node') |
| 88 | salt.enforceState(saltMaster, SERVICE_NODE, 'keystone.client', VERBOSE, STOP_ON_ERROR) |
| 89 | common.infoMsg('Running glance.client on service node') |
| 90 | salt.enforceState(saltMaster, SERVICE_NODE, 'glance.client', VERBOSE, STOP_ON_ERROR) |
| 91 | common.infoMsg('Running nova.client on service node') |
| 92 | salt.enforceState(saltMaster, SERVICE_NODE, 'nova.client', VERBOSE, STOP_ON_ERROR) |
| 93 | } |
| 94 | else { |
| 95 | common.infoMsg('Skipping resources preparation') |
| 96 | } |
| 97 | } |
| 98 | stage('Generate config') { |
| 99 | if ( GENERATE_CONFIG.toBoolean() ) { |
Oleksii Zhurba | baa42c9 | 2019-05-29 16:08:40 -0500 | [diff] [blame] | 100 | salt.runSaltProcessStep(saltMaster, SERVICE_NODE, 'file.remove', ["${runtest_tempest_cfg_dir}"]) |
| 101 | salt.runSaltProcessStep(saltMaster, SERVICE_NODE, 'file.mkdir', ["${runtest_tempest_cfg_dir}"]) |
| 102 | fullnodename = salt.getMinions(saltMaster, SERVICE_NODE).get(0) |
| 103 | if (TARGET_NODE != tempest_node) { |
| 104 | common.infoMsg("TARGET_NODE is defined in Jenkins") |
| 105 | def params_to_update = ['tempest_test_target': "${TARGET_NODE}"] |
| 106 | common.infoMsg("Overriding default ${tempest_node} value of tempest_test_target parameter") |
| 107 | result = salt.runSaltCommand(saltMaster, 'local', ['expression': SERVICE_NODE, 'type': 'compound'], 'reclass.node_update', |
| 108 | null, null, ['name': fullnodename, 'parameters': ['tempest_test_target': "${TARGET_NODE}"]]) |
| 109 | salt.checkResult(result) |
| 110 | } |
| 111 | common.infoMsg("TARGET_NODE is ${TARGET_NODE}") |
| 112 | salt.runSaltProcessStep(saltMaster, TARGET_NODE, 'file.remove', ["${remote_artifacts_dir}"]) |
| 113 | salt.runSaltProcessStep(saltMaster, TARGET_NODE, 'file.mkdir', ["${remote_artifacts_dir}"]) |
| 114 | // runtest state hangs if tempest_test_target is cfg01* |
| 115 | // let's run runtest.generate_tempest_config only for this case |
| 116 | if (TARGET_NODE == 'cfg01*') { |
| 117 | common.warningMsg("It is not recommended to run Tempest container on cfg node, but.. proceeding") |
| 118 | salt.enforceState(saltMaster, SERVICE_NODE, 'runtest.generate_tempest_config', VERBOSE, STOP_ON_ERROR) |
| 119 | } else { |
Oleksii Zhurba | 90b6fa9 | 2019-03-26 13:14:21 -0500 | [diff] [blame] | 120 | salt.enforceState(saltMaster, SERVICE_NODE, 'runtest', VERBOSE, STOP_ON_ERROR) |
Oleksii Zhurba | 90b6fa9 | 2019-03-26 13:14:21 -0500 | [diff] [blame] | 121 | } |
Oleksii Zhurba | baa42c9 | 2019-05-29 16:08:40 -0500 | [diff] [blame] | 122 | // we need to refresh pillars on target node after runtest state |
| 123 | salt.runSaltProcessStep(saltMaster, TARGET_NODE, 'saltutil.refresh_pillar', [], null, VERBOSE) |
| 124 | if (TARGET_NODE != tempest_node) { |
| 125 | common.infoMsg("Reverting tempest_test_target parameter") |
| 126 | result = salt.runSaltCommand(saltMaster, 'local', ['expression': SERVICE_NODE, 'type': 'compound'], 'reclass.node_update', |
| 127 | null, null, ['name': fullnodename, 'parameters': ['tempest_test_target': "${tempest_node}"]]) |
| 128 | } |
| 129 | SKIP_LIST_PATH = (env.SKIP_LIST_PATH) ?: salt.getPillar(saltMaster, SERVICE_NODE, '_param:tempest_skip_list_path')['return'][0].values()[0] |
| 130 | if (SKIP_LIST_PATH) { |
Oleksii Zhurba | f03497f | 2019-07-17 15:02:44 -0500 | [diff] [blame] | 131 | mounts = ["${runtest_tempest_cfg_dir}/skip.list": "/var/lib/tempest/skiplists/skip.list"] |
Oleksii Zhurba | baa42c9 | 2019-05-29 16:08:40 -0500 | [diff] [blame] | 132 | salt.cmdRun(saltMaster, SERVICE_NODE, "salt-cp ${TARGET_NODE} ${SKIP_LIST_PATH} ${runtest_tempest_cfg_dir}/skip.list") |
Oleksii Zhurba | 90b6fa9 | 2019-03-26 13:14:21 -0500 | [diff] [blame] | 133 | } |
| 134 | } |
Oleksii Zhurba | baa42c9 | 2019-05-29 16:08:40 -0500 | [diff] [blame] | 135 | else { |
| 136 | common.infoMsg('Skipping Tempest config generation') |
| 137 | salt.cmdRun(saltMaster, TARGET_NODE, "rm -rf ${remote_artifacts_dir}/reports") |
| 138 | } |
| 139 | } |
Oleksii Zhurba | 90b6fa9 | 2019-03-26 13:14:21 -0500 | [diff] [blame] | 140 | |
Oleksii Zhurba | baa42c9 | 2019-05-29 16:08:40 -0500 | [diff] [blame] | 141 | try{ |
Oleksii Zhurba | 90b6fa9 | 2019-03-26 13:14:21 -0500 | [diff] [blame] | 142 | stage('Run Tempest tests') { |
Oleksii Zhurba | baa42c9 | 2019-05-29 16:08:40 -0500 | [diff] [blame] | 143 | mounts = mounts + ["${runtest_tempest_cfg_dir}/${runtest_tempest_cfg_name}": "/etc/tempest/tempest.conf"] |
Oleksii Zhurba | c5987cb | 2019-04-23 21:47:57 -0500 | [diff] [blame] | 144 | validate.runContainer(master: saltMaster, target: TARGET_NODE, dockerImageLink: TEST_IMAGE, |
Oleksii Zhurba | b7593dc | 2019-05-13 12:29:55 -0500 | [diff] [blame] | 145 | mounts: mounts, name: container_name) |
Oleksii Zhurba | 90b6fa9 | 2019-03-26 13:14:21 -0500 | [diff] [blame] | 146 | report_prefix += 'tempest_' |
| 147 | if (env.concurrency) { |
| 148 | args += ' -w ' + env.concurrency |
| 149 | } |
| 150 | if (TEMPEST_TEST_PATTERN == 'set=smoke') { |
| 151 | args += ' -s ' |
| 152 | report_prefix += 'smoke' |
| 153 | } |
| 154 | else { |
| 155 | if (TEMPEST_TEST_PATTERN != 'set=full') { |
| 156 | args += " -r ${TEMPEST_TEST_PATTERN} " |
Oleksii Zhurba | baa42c9 | 2019-05-29 16:08:40 -0500 | [diff] [blame] | 157 | report_prefix += 'custom' |
Oleksii Zhurba | 90b6fa9 | 2019-03-26 13:14:21 -0500 | [diff] [blame] | 158 | } |
| 159 | } |
Oleksii Zhurba | b7593dc | 2019-05-13 12:29:55 -0500 | [diff] [blame] | 160 | salt.cmdRun(saltMaster, TARGET_NODE, "docker exec -e ARGS=\'${args}\' ${container_name} /bin/bash -c 'run-tempest'") |
Oleksii Zhurba | 90b6fa9 | 2019-03-26 13:14:21 -0500 | [diff] [blame] | 161 | } |
| 162 | stage('Collect results') { |
| 163 | report_prefix += "_report_${env.BUILD_NUMBER}" |
| 164 | // will be removed after changing runtest-formula logic |
| 165 | salt.cmdRun(saltMaster, TARGET_NODE, "mkdir -p ${remote_artifacts_dir}/reports; mv ${remote_artifacts_dir}/report_* ${remote_artifacts_dir}/reports") |
| 166 | validate.addFiles(saltMaster, TARGET_NODE, "${remote_artifacts_dir}/reports", '') |
| 167 | sh "mv report_*.xml ${report_prefix}.xml" |
| 168 | sh "mv report_*.log ${report_prefix}.log" |
| 169 | archiveArtifacts artifacts: "${report_prefix}.*" |
| 170 | junit "${report_prefix}.xml" |
| 171 | } |
Oleksii Zhurba | 90b6fa9 | 2019-03-26 13:14:21 -0500 | [diff] [blame] | 172 | } finally { |
Oleksii Zhurba | 8b23cb3 | 2019-07-17 12:19:09 -0500 | [diff] [blame] | 173 | if ( ! DEBUG_MODE.toBoolean() ) { |
Oleksii Zhurba | b7593dc | 2019-05-13 12:29:55 -0500 | [diff] [blame] | 174 | validate.runCleanup(saltMaster, TARGET_NODE, container_name) |
Oleksii Zhurba | 90b6fa9 | 2019-03-26 13:14:21 -0500 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | } |