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