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