Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | * Launch heat/cloudformation stack |
| 4 | * |
| 5 | * Expected parameters: |
| 6 | * STACK_NAME Infrastructure stack name |
| 7 | * STACK_TEMPLATE Stack HOT/CFN template |
| 8 | * STACK_TYPE Deploy OpenStack/AWS [heat/aws] |
| 9 | * |
| 10 | * STACK_TEMPLATE_URL URL to git repo with stack templates |
| 11 | * STACK_TEMPLATE_CREDENTIALS Credentials to the templates repo |
| 12 | * STACK_TEMPLATE_BRANCH Stack templates repo branch |
| 13 | * |
| 14 | * STACK_DELETE Delete stack when finished (bool) |
| 15 | * STACK_REUSE Reuse existing stack (don't create one) |
| 16 | * STACK_INSTALL What should be installed (k8s, openstack, ...) |
| 17 | * STACK_TEST Run tests (bool) |
| 18 | * STACK_CLEANUP_JOB Name of job for deleting stack |
| 19 | * |
Tomáš Kukrál | 74f9286 | 2017-06-05 19:18:43 +0200 | [diff] [blame] | 20 | * STACK_COMPUTE_COUNT Number of compute nodes to launch |
| 21 | * |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 22 | * AWS_STACK_REGION CloudFormation AWS region |
| 23 | * AWS_API_CREDENTIALS AWS Access key ID with AWS secret access key |
Tomáš Kukrál | 7a8a4fa | 2017-05-25 14:54:24 +0200 | [diff] [blame] | 24 | * AWS_SSH_KEY AWS key pair name (used for SSH access) |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 25 | * |
| 26 | * HEAT_STACK_ENVIRONMENT Heat stack environmental parameters |
| 27 | * HEAT_STACK_ZONE Heat stack availability zone |
| 28 | * HEAT_STACK_PUBLIC_NET Heat stack floating IP pool |
| 29 | * OPENSTACK_API_URL OpenStack API address |
| 30 | * OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API |
| 31 | * OPENSTACK_API_PROJECT OpenStack project to connect to |
| 32 | * OPENSTACK_API_CLIENT Versions of OpenStack python clients |
| 33 | * OPENSTACK_API_VERSION Version of the OpenStack API (2/3) |
| 34 | * |
| 35 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API |
| 36 | * SALT_MASTER_URL URL of Salt master |
| 37 | * |
| 38 | * K8S_API_SERVER Kubernetes API address |
| 39 | * K8S_CONFORMANCE_IMAGE Path to docker image with conformance e2e tests |
Matthew Mosesohn | 1393344 | 2017-07-04 21:20:08 +0300 | [diff] [blame^] | 40 | * SALT_OVERRIDES YAML with overrides for Salt deployment |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 41 | * |
| 42 | * TEMPEST_IMAGE_LINK Tempest image link |
| 43 | * |
| 44 | */ |
| 45 | common = new com.mirantis.mk.Common() |
| 46 | git = new com.mirantis.mk.Git() |
| 47 | openstack = new com.mirantis.mk.Openstack() |
Tomáš Kukrál | 7a8a4fa | 2017-05-25 14:54:24 +0200 | [diff] [blame] | 48 | aws = new com.mirantis.mk.Aws() |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 49 | orchestrate = new com.mirantis.mk.Orchestrate() |
| 50 | salt = new com.mirantis.mk.Salt() |
| 51 | test = new com.mirantis.mk.Test() |
| 52 | |
| 53 | _MAX_PERMITTED_STACKS = 2 |
| 54 | overwriteFile = "/srv/salt/reclass/classes/cluster/override.yml" |
| 55 | |
Tomáš Kukrál | 31414a2 | 2017-06-09 14:17:53 +0200 | [diff] [blame] | 56 | def saltMaster |
Tomáš Kukrál | bc4be25 | 2017-06-06 11:28:40 +0200 | [diff] [blame] | 57 | |
Tomáš Kukrál | b19bdda | 2017-06-13 17:09:43 +0200 | [diff] [blame] | 58 | if (STACK_TYPE == 'aws') { |
Tomáš Kukrál | 0ecd76a | 2017-06-13 17:28:09 +0200 | [diff] [blame] | 59 | venv_path = 'aws_venv' |
| 60 | env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION) |
Tomáš Kukrál | b19bdda | 2017-06-13 17:09:43 +0200 | [diff] [blame] | 61 | } |
| 62 | |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 63 | timestamps { |
| 64 | node { |
| 65 | try { |
| 66 | // |
| 67 | // Prepare machines |
| 68 | // |
| 69 | stage ('Create infrastructure') { |
| 70 | |
| 71 | if (STACK_TYPE == 'heat') { |
| 72 | // value defaults |
| 73 | def openstackCloud |
| 74 | def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : 'liberty' |
| 75 | def openstackEnv = "${env.WORKSPACE}/venv" |
| 76 | |
| 77 | if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') { |
| 78 | error("If you want to reuse existing stack you need to provide it's name") |
| 79 | } |
| 80 | |
| 81 | if (STACK_REUSE.toBoolean() == false) { |
| 82 | // Don't allow to set custom heat stack name |
| 83 | wrap([$class: 'BuildUser']) { |
| 84 | if (env.BUILD_USER_ID) { |
| 85 | STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}" |
| 86 | } else { |
| 87 | STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}" |
| 88 | } |
| 89 | currentBuild.description = STACK_NAME |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | // set description |
| 94 | currentBuild.description = "${STACK_NAME}" |
| 95 | |
| 96 | // get templates |
| 97 | git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS) |
| 98 | |
| 99 | // create openstack env |
| 100 | openstack.setupOpenstackVirtualenv(openstackEnv, openstackVersion) |
| 101 | openstackCloud = openstack.createOpenstackEnv(OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS, OPENSTACK_API_PROJECT) |
| 102 | openstack.getKeystoneToken(openstackCloud, openstackEnv) |
| 103 | // |
| 104 | // Verify possibility of create stack for given user and stack type |
| 105 | // |
| 106 | wrap([$class: 'BuildUser']) { |
| 107 | if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) { |
| 108 | def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}", openstackEnv) |
| 109 | if(existingStacks.size() >= _MAX_PERMITTED_STACKS){ |
| 110 | STACK_DELETE = "false" |
| 111 | throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}") |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | // launch stack |
| 116 | if (STACK_REUSE.toBoolean() == false) { |
| 117 | stage('Launch new Heat stack') { |
| 118 | // create stack |
| 119 | envParams = [ |
| 120 | 'instance_zone': HEAT_STACK_ZONE, |
| 121 | 'public_net': HEAT_STACK_PUBLIC_NET |
| 122 | ] |
Ales Komarek | e0999ae | 2017-06-27 11:26:10 +0200 | [diff] [blame] | 123 | openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, openstackEnv, false) |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
| 127 | // get SALT_MASTER_URL |
| 128 | saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', openstackEnv) |
Tomáš Kukrál | 7a8a4fa | 2017-05-25 14:54:24 +0200 | [diff] [blame] | 129 | currentBuild.description = "${STACK_NAME} ${saltMasterHost}" |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 130 | |
| 131 | SALT_MASTER_URL = "http://${saltMasterHost}:6969" |
Tomáš Kukrál | 7a8a4fa | 2017-05-25 14:54:24 +0200 | [diff] [blame] | 132 | } else if (STACK_TYPE == 'aws') { |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 133 | |
Tomáš Kukrál | 7a8a4fa | 2017-05-25 14:54:24 +0200 | [diff] [blame] | 134 | |
| 135 | if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') { |
| 136 | error("If you want to reuse existing stack you need to provide it's name") |
| 137 | } |
| 138 | |
| 139 | if (STACK_REUSE.toBoolean() == false) { |
| 140 | // Don't allow to set custom stack name |
| 141 | wrap([$class: 'BuildUser']) { |
| 142 | if (env.BUILD_USER_ID) { |
| 143 | STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}" |
| 144 | } else { |
| 145 | STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}" |
| 146 | } |
Tomáš Kukrál | 7a8a4fa | 2017-05-25 14:54:24 +0200 | [diff] [blame] | 147 | } |
Tomáš Kukrál | dbf8ca8 | 2017-05-25 15:13:20 +0200 | [diff] [blame] | 148 | |
| 149 | // no underscore in STACK_NAME |
| 150 | STACK_NAME = STACK_NAME.replaceAll('_', '-') |
Tomáš Kukrál | 7a8a4fa | 2017-05-25 14:54:24 +0200 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | // set description |
Tomáš Kukrál | dbf8ca8 | 2017-05-25 15:13:20 +0200 | [diff] [blame] | 154 | currentBuild.description = STACK_NAME |
Tomáš Kukrál | 7a8a4fa | 2017-05-25 14:54:24 +0200 | [diff] [blame] | 155 | |
Tomáš Kukrál | 7a8a4fa | 2017-05-25 14:54:24 +0200 | [diff] [blame] | 156 | if (STACK_REUSE.toBoolean() == false) { |
| 157 | // get templates |
| 158 | git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS) |
| 159 | |
| 160 | // setup environment |
| 161 | aws.setupVirtualEnv(venv_path) |
| 162 | |
| 163 | // start stack |
Tomáš Kukrál | ad79d32 | 2017-06-05 15:40:14 +0200 | [diff] [blame] | 164 | def stack_params = [ |
| 165 | "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY, |
| 166 | "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT |
| 167 | ] |
Tomáš Kukrál | dbb5840 | 2017-06-02 07:08:53 +0200 | [diff] [blame] | 168 | def template_file = 'cfn/' + STACK_TEMPLATE + '.yml' |
Tomáš Kukrál | d4c0fed | 2017-06-01 17:20:11 +0200 | [diff] [blame] | 169 | aws.createStack(venv_path, env_vars, template_file, STACK_NAME, stack_params) |
Tomáš Kukrál | 7a8a4fa | 2017-05-25 14:54:24 +0200 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | // wait for stack to be ready |
| 173 | aws.waitForStatus(venv_path, env_vars, STACK_NAME, 'CREATE_COMPLETE') |
| 174 | |
| 175 | // get outputs |
| 176 | saltMasterHost = aws.getOutputs(venv_path, env_vars, STACK_NAME, 'SaltMasterIP') |
| 177 | currentBuild.description = "${STACK_NAME} ${saltMasterHost}" |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 178 | SALT_MASTER_URL = "http://${saltMasterHost}:6969" |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 179 | |
Tomáš Kukrál | 7a8a4fa | 2017-05-25 14:54:24 +0200 | [diff] [blame] | 180 | } else { |
| 181 | throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported") |
| 182 | } |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 183 | |
Tomáš Kukrál | 2070764 | 2017-06-09 13:35:13 +0200 | [diff] [blame] | 184 | // Connect to Salt master |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 185 | saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 186 | } |
| 187 | |
Matthew Mosesohn | 1393344 | 2017-07-04 21:20:08 +0300 | [diff] [blame^] | 188 | // Set up override params |
| 189 | if (env.getEnvironment().containsKey('SALT_OVERRIDES')) { |
| 190 | stage('Set Salt overrides') { |
| 191 | salt.setSaltOverrides(saltMaster, SALT_OVERRIDES) |
| 192 | } |
| 193 | } |
| 194 | |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 195 | // |
| 196 | // Install |
| 197 | // |
| 198 | |
| 199 | if (common.checkContains('STACK_INSTALL', 'core')) { |
| 200 | stage('Install core infrastructure') { |
| 201 | orchestrate.installFoundationInfra(saltMaster) |
| 202 | |
| 203 | if (common.checkContains('STACK_INSTALL', 'kvm')) { |
| 204 | orchestrate.installInfraKvm(saltMaster) |
| 205 | orchestrate.installFoundationInfra(saltMaster) |
| 206 | } |
| 207 | |
| 208 | orchestrate.validateFoundationInfra(saltMaster) |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | // install k8s |
| 213 | if (common.checkContains('STACK_INSTALL', 'k8s')) { |
| 214 | stage('Install Kubernetes infra') { |
Tomáš Kukrál | b19bdda | 2017-06-13 17:09:43 +0200 | [diff] [blame] | 215 | // configure kubernetes_control_address - save loadbalancer |
| 216 | def kubernetes_control_address = aws.getOutputs(venv_path, env_vars, STACK_NAME, 'ControlLoadBalancer') |
| 217 | print(kubernetes_control_address) |
Tomáš Kukrál | c466261 | 2017-06-14 13:46:29 +0200 | [diff] [blame] | 218 | salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_control_address', kubernetes_control_address], null, true) |
Tomáš Kukrál | b19bdda | 2017-06-13 17:09:43 +0200 | [diff] [blame] | 219 | |
Tomáš Kukrál | 4898be3 | 2017-06-19 09:54:15 +0200 | [diff] [blame] | 220 | // ensure certificates are generated properly |
| 221 | salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_pillar', [], null, true) |
| 222 | salt.enforceState(saltMaster, '*', ['salt.minion.cert'], true) |
| 223 | |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 224 | orchestrate.installKubernetesInfra(saltMaster) |
| 225 | } |
| 226 | |
| 227 | stage('Install Kubernetes control') { |
| 228 | |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 229 | orchestrate.installKubernetesControl(saltMaster) |
Tomáš Kukrál | 74f9286 | 2017-06-05 19:18:43 +0200 | [diff] [blame] | 230 | |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 231 | } |
| 232 | |
Tomáš Kukrál | 74f9286 | 2017-06-05 19:18:43 +0200 | [diff] [blame] | 233 | stage('Scale Kubernetes computes') { |
Tomáš Kukrál | b9a7d6f | 2017-06-07 14:05:31 +0200 | [diff] [blame] | 234 | if (STACK_COMPUTE_COUNT > 0) { |
| 235 | if (STACK_TYPE == 'aws') { |
Tomáš Kukrál | fa0c745 | 2017-06-06 11:44:11 +0200 | [diff] [blame] | 236 | |
Tomáš Kukrál | b9a7d6f | 2017-06-07 14:05:31 +0200 | [diff] [blame] | 237 | // get stack info |
| 238 | def scaling_group = aws.getOutputs(venv_path, env_vars, STACK_NAME, 'ComputesScalingGroup') |
Tomáš Kukrál | 74f9286 | 2017-06-05 19:18:43 +0200 | [diff] [blame] | 239 | |
Tomáš Kukrál | b9a7d6f | 2017-06-07 14:05:31 +0200 | [diff] [blame] | 240 | //update autoscaling group |
| 241 | aws.updateAutoscalingGroup(venv_path, env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT]) |
Tomáš Kukrál | 8130a56 | 2017-06-06 11:09:22 +0200 | [diff] [blame] | 242 | |
Tomáš Kukrál | b9a7d6f | 2017-06-07 14:05:31 +0200 | [diff] [blame] | 243 | // wait for computes to boot up |
Tomáš Kukrál | edc1d8d | 2017-06-09 13:44:13 +0200 | [diff] [blame] | 244 | aws.waitForAutoscalingInstances(venv_path, env_vars, scaling_group) |
Tomáš Kukrál | f31a591 | 2017-06-13 15:47:25 +0200 | [diff] [blame] | 245 | sleep(60) |
Tomáš Kukrál | b9a7d6f | 2017-06-07 14:05:31 +0200 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | orchestrate.installKubernetesCompute(saltMaster) |
Tomáš Kukrál | 74f9286 | 2017-06-05 19:18:43 +0200 | [diff] [blame] | 249 | } |
Tomáš Kukrál | 74f9286 | 2017-06-05 19:18:43 +0200 | [diff] [blame] | 250 | } |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 251 | |
| 252 | if (common.checkContains('STACK_INSTALL', 'contrail')) { |
Tomáš Kukrál | 391df0d | 2017-06-13 10:37:02 +0200 | [diff] [blame] | 253 | stage('Install Contrail for Kubernetes') { |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 254 | orchestrate.installContrailNetwork(saltMaster) |
| 255 | orchestrate.installContrailCompute(saltMaster) |
| 256 | } |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | // install openstack |
| 261 | if (common.checkContains('STACK_INSTALL', 'openstack')) { |
| 262 | // install Infra and control, tests, ... |
| 263 | |
| 264 | stage('Install OpenStack infra') { |
| 265 | orchestrate.installOpenstackInfra(saltMaster) |
| 266 | } |
| 267 | |
| 268 | stage('Install OpenStack control') { |
| 269 | orchestrate.installOpenstackControl(saltMaster) |
| 270 | } |
| 271 | |
| 272 | stage('Install OpenStack network') { |
| 273 | |
| 274 | if (common.checkContains('STACK_INSTALL', 'contrail')) { |
| 275 | orchestrate.installContrailNetwork(saltMaster) |
| 276 | } else if (common.checkContains('STACK_INSTALL', 'ovs')) { |
| 277 | orchestrate.installOpenstackNetwork(saltMaster) |
| 278 | } |
| 279 | |
| 280 | salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list']) |
| 281 | salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list']) |
| 282 | } |
| 283 | |
| 284 | stage('Install OpenStack compute') { |
| 285 | orchestrate.installOpenstackCompute(saltMaster) |
| 286 | |
| 287 | if (common.checkContains('STACK_INSTALL', 'contrail')) { |
| 288 | orchestrate.installContrailCompute(saltMaster) |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | } |
| 293 | |
| 294 | |
| 295 | if (common.checkContains('STACK_INSTALL', 'stacklight')) { |
| 296 | stage('Install StackLight') { |
| 297 | orchestrate.installStacklightControl(saltMaster) |
| 298 | orchestrate.installStacklightClient(saltMaster) |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | // |
| 303 | // Test |
| 304 | // |
| 305 | def artifacts_dir = '_artifacts/' |
| 306 | |
| 307 | if (common.checkContains('STACK_TEST', 'k8s')) { |
| 308 | stage('Run k8s bootstrap tests') { |
| 309 | def image = 'tomkukral/k8s-scripts' |
| 310 | def output_file = image.replaceAll('/', '-') + '.output' |
| 311 | |
| 312 | // run image |
| 313 | test.runConformanceTests(saltMaster, K8S_API_SERVER, image) |
| 314 | |
| 315 | // collect output |
| 316 | sh "mkdir -p ${artifacts_dir}" |
| 317 | file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file) |
| 318 | writeFile file: "${artifacts_dir}${output_file}", text: file_content |
| 319 | sh "cat ${artifacts_dir}${output_file}" |
| 320 | |
| 321 | // collect artifacts |
| 322 | archiveArtifacts artifacts: "${artifacts_dir}${output_file}" |
| 323 | } |
| 324 | |
| 325 | stage('Run k8s conformance e2e tests') { |
| 326 | //test.runConformanceTests(saltMaster, K8S_API_SERVER, K8S_CONFORMANCE_IMAGE) |
| 327 | |
| 328 | def image = K8S_CONFORMANCE_IMAGE |
| 329 | def output_file = image.replaceAll('/', '-') + '.output' |
| 330 | |
| 331 | // run image |
| 332 | test.runConformanceTests(saltMaster, K8S_API_SERVER, image) |
| 333 | |
| 334 | // collect output |
| 335 | sh "mkdir -p ${artifacts_dir}" |
| 336 | file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file) |
| 337 | writeFile file: "${artifacts_dir}${output_file}", text: file_content |
| 338 | sh "cat ${artifacts_dir}${output_file}" |
| 339 | |
| 340 | // collect artifacts |
| 341 | archiveArtifacts artifacts: "${artifacts_dir}${output_file}" |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | if (common.checkContains('STACK_TEST', 'openstack')) { |
| 346 | stage('Run deployment tests') { |
| 347 | test.runTempestTests(saltMaster, TEMPEST_IMAGE_LINK) |
| 348 | } |
| 349 | |
| 350 | stage('Copy test results to config node') { |
| 351 | test.copyTempestResults(saltMaster) |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | stage('Finalize') { |
| 356 | if (STACK_INSTALL != '') { |
| 357 | try { |
| 358 | salt.runSaltProcessStep(saltMaster, '*', 'state.apply', [], null, true) |
| 359 | } catch (Exception e) { |
| 360 | common.warningMsg('State apply failed but we should continue to run') |
| 361 | } |
| 362 | } |
| 363 | } |
| 364 | } catch (Throwable e) { |
| 365 | currentBuild.result = 'FAILURE' |
| 366 | throw e |
| 367 | } finally { |
| 368 | |
| 369 | |
| 370 | // |
| 371 | // Clean |
| 372 | // |
| 373 | |
Tomáš Kukrál | 439c62e | 2017-06-02 11:42:36 +0200 | [diff] [blame] | 374 | if (STACK_NAME && STACK_NAME != '') { |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 375 | // send notification |
| 376 | common.sendNotification(currentBuild.result, STACK_NAME, ["slack"]) |
Tomáš Kukrál | 439c62e | 2017-06-02 11:42:36 +0200 | [diff] [blame] | 377 | } |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 378 | |
Tomáš Kukrál | 439c62e | 2017-06-02 11:42:36 +0200 | [diff] [blame] | 379 | if (STACK_DELETE.toBoolean() == true) { |
| 380 | stage('Trigger cleanup job') { |
| 381 | common.errorMsg('Stack cleanup job triggered') |
| 382 | build(job: STACK_CLEANUP_JOB, parameters: [ |
| 383 | [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME], |
| 384 | [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE] |
| 385 | ]) |
| 386 | } |
| 387 | } else { |
| 388 | if (currentBuild.result == 'FAILURE') { |
| 389 | common.errorMsg("Deploy job FAILED and was not deleted. Please fix the problem and delete stack on you own.") |
| 390 | if (SALT_MASTER_URL) { |
| 391 | common.errorMsg("Salt master URL: ${SALT_MASTER_URL}") |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 392 | } |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | } |
| 397 | } |