Oleg Basov | c478c2d | 2019-01-23 02:38:09 +0100 | [diff] [blame^] | 1 | /** |
| 2 | * |
| 3 | * Launch CVP Shaker network tests |
| 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 | * IMAGE Docker image link to use for running container with Shaker. |
| 10 | * SHAKER_PARAMS Yaml context which contains parameters for running Shaker |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | /* |
| 15 | SHAKER_PARAMS yaml example: |
| 16 | --- |
| 17 | SHAKER_SERVER_ENDPOINT: '10.13.0.15:5999' |
| 18 | SHAKER_SCENARIOS: 'scenarios/essential' |
| 19 | SKIP_LIST: '' |
| 20 | image_builder: |
| 21 | - SHAKER_FLAVOR_DISK=4 |
| 22 | - SHAKER_FLAVOR_RAM=512 |
| 23 | - SHAKER_FLAVOR_VCPUS=1 |
| 24 | - SHAKER_IMAGE_BUILDER_MODE='dib' |
| 25 | shaker: |
| 26 | - SHAKER_AGENT_JOIN_TIMEOUT=300 |
| 27 | - SHAKER_AGENT_LOSS_TIMEOUT=120 |
| 28 | - SCENARIO_AVAILABILITY_ZONE='nova,internal' |
| 29 | - SCENARIO_COMPUTE_NODES=2 |
| 30 | - SHAKER_EXTERNAL_NET='public' |
| 31 | |
| 32 | Where: |
| 33 | "SHAKER_SERVER_ENDPOINT" - Address for Shaker server connections (host:port). Should be accessible |
| 34 | from tenant's VM network (usually equals to public address of cicd node) |
| 35 | "SHAKER_SCENARIOS" - Path to shaker scenarios in the cvp-shaker docker image |
| 36 | (can be directory or specific file). Main categories are |
| 37 | scenarios/essential/l2 |
| 38 | scenarios/essential/l3 |
| 39 | scenarios/additional/cross_az |
| 40 | scenarios/additional/external |
| 41 | scenarios/additional/qos |
| 42 | "SKIP_LIST" - Comma-separated list of Shaker scenarios to skip, directories or files inside scenarios/ |
| 43 | of cvp-shaker, e.g. "dense_l2.yaml,full_l2.yaml,l3" |
| 44 | "image_builder" - shaker-image-builder env variables |
| 45 | SHAKER_FLAVOR_DISK=4 |
| 46 | SHAKER_FLAVOR_RAM=512 |
| 47 | SHAKER_FLAVOR_VCPUS=1 |
| 48 | SHAKER_IMAGE_BUILDER_MODE='dib' |
| 49 | "shaker" - main shaker runner env variables |
| 50 | SHAKER_AGENT_JOIN_TIMEOUT=300 |
| 51 | SHAKER_AGENT_LOSS_TIMEOUT=120 |
| 52 | SCENARIO_AVAILABILITY_ZONE='nova,internal' |
| 53 | SCENARIO_COMPUTE_NODES=2 |
| 54 | SHAKER_EXTERNAL_NET='public' |
| 55 | For the more detailed description of the last two categories please refer to the shaker documentation |
| 56 | https://pyshaker.readthedocs.io/en/latest/tools.html |
| 57 | */ |
| 58 | |
| 59 | common = new com.mirantis.mk.Common() |
| 60 | salt = new com.mirantis.mk.Salt() |
| 61 | validate = new com.mirantis.mcp.Validate() |
| 62 | salt_testing = new com.mirantis.mk.SaltModelTesting() |
| 63 | |
| 64 | |
| 65 | def IMAGE = (env.getProperty('IMAGE')) ?: 'docker-prod-local.docker.mirantis.net/mirantis/cvp/cvp-shaker:proposed' |
| 66 | def SLAVE_NODE = (env.getProperty('SLAVE_NODE')) ?: 'docker' |
| 67 | def SHAKER_PARAMS = readYaml(text: env.getProperty('SHAKER_PARAMS')) ?: [:] |
| 68 | def artifacts_dir = 'validation_artifacts' |
| 69 | def configRun = [:] |
| 70 | |
| 71 | node (SLAVE_NODE) { |
| 72 | try{ |
| 73 | stage('Initialization') { |
| 74 | def workdir = '/opt/shaker/' |
| 75 | def container_artifacts = '/artifacts' |
| 76 | def html_file = "${container_artifacts}/shaker-report.html" |
| 77 | def log_file = "${container_artifacts}/shaker.log" |
| 78 | def cmd_shaker_args = "--debug --cleanup-on-error " + |
| 79 | "--log-file ${log_file} --report ${html_file}" |
| 80 | |
| 81 | sh "mkdir -p ${artifacts_dir}" |
| 82 | |
| 83 | // Get Openstack credentials |
| 84 | def saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 85 | keystone_creds = validate._get_keystone_creds_v3(saltMaster) |
| 86 | if (!keystone_creds) { |
| 87 | keystone_creds = validate._get_keystone_creds_v2(saltMaster) |
| 88 | } |
| 89 | |
| 90 | // Get shaker env variables |
| 91 | def general_params = [ |
| 92 | SHAKER_SERVER_ENDPOINT: (SHAKER_PARAMS.get('SHAKER_SERVER_ENDPOINT')), |
| 93 | SHAKER_SCENARIOS: (SHAKER_PARAMS.get('SHAKER_SCENARIOS')) ?: 'scenarios/essential', |
| 94 | SKIP_LIST: (SHAKER_PARAMS.get('SKIP_LIST')) |
| 95 | ] |
| 96 | if (! general_params['SHAKER_SERVER_ENDPOINT']) { |
| 97 | throw new Exception("SHAKER_SERVER_ENDPOINT address was not set in the SHAKER_PARAMS") |
| 98 | } |
| 99 | def builder_vars = SHAKER_PARAMS.get("image_builder") ?: [ |
| 100 | "SHAKER_FLAVOR_DISK=4", |
| 101 | "SHAKER_FLAVOR_RAM=512", |
| 102 | "SHAKER_FLAVOR_VCPUS=1" |
| 103 | ] |
| 104 | def shaker_vars = SHAKER_PARAMS.get("shaker") ?: [] |
| 105 | def env_vars_list = general_params.collect{ "${it.key}=${it.value}" } |
| 106 | env_vars_list = env_vars_list + keystone_creds + builder_vars + shaker_vars |
| 107 | |
| 108 | // Get shaker scenarios cmd |
| 109 | def scen_cmd = validate.bundle_up_scenarios( |
| 110 | workdir + |
| 111 | general_params['SHAKER_SCENARIOS'].replaceAll("^/+", ""), |
| 112 | general_params['SKIP_LIST'] |
| 113 | ) |
| 114 | |
| 115 | // Define docker commands |
| 116 | def commands = [ |
| 117 | '001_build_image': "shaker-image-builder --debug", |
| 118 | '002_run_shaker': scen_cmd + "-print0" + |
| 119 | "|paste -zsd ',' - " + |
| 120 | "|xargs --null " + |
| 121 | "shaker ${cmd_shaker_args} --scenario " |
| 122 | ] |
| 123 | def commands_list = commands.collectEntries{ [ (it.key) : { sh("${it.value}") } ] } |
| 124 | |
| 125 | configRun = [ |
| 126 | 'image': IMAGE, |
| 127 | 'baseRepoPreConfig': false, |
| 128 | 'dockerMaxCpus': 2, |
| 129 | // suppress sudo resolve warnings |
| 130 | // which break image build |
| 131 | 'dockerHostname': 'localhost', |
| 132 | 'dockerExtraOpts': [ |
| 133 | "--network=host", |
| 134 | "--privileged", |
| 135 | "-v ${env.WORKSPACE}/${artifacts_dir}/:${container_artifacts}" |
| 136 | ], |
| 137 | 'envOpts' : env_vars_list, |
| 138 | 'runCommands' : commands_list |
| 139 | ] |
| 140 | } |
| 141 | |
| 142 | stage('Run Shaker tests') { |
| 143 | salt_testing.setupDockerAndTest(configRun) |
| 144 | } |
| 145 | |
| 146 | stage('Collect results') { |
| 147 | archiveArtifacts artifacts: "${artifacts_dir}/*" |
| 148 | } |
| 149 | |
| 150 | } catch (Throwable e) { |
| 151 | // If there was an error or exception thrown, the build failed |
| 152 | currentBuild.result = "FAILURE" |
| 153 | throw e |
| 154 | } finally { |
| 155 | sh "rm -rf ${artifacts_dir}" |
| 156 | } |
| 157 | } |