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