Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 1 | /** |
| 2 | * |
Tomáš Kukrál | 0d00dd2 | 2017-07-27 14:28:36 +0200 | [diff] [blame] | 3 | * Launch stack and work with it |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 4 | * |
| 5 | * Expected parameters: |
| 6 | * STACK_NAME Infrastructure stack name |
Tomáš Kukrál | 4691f68 | 2017-07-27 16:36:12 +0200 | [diff] [blame] | 7 | * STACK_TEMPLATE File with stack template |
| 8 | * STACK_TYPE Deploy OpenStack/AWS [heat/aws], use 'physical' if no stack should be started |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 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) |
Tomáš Kukrál | 4691f68 | 2017-07-27 16:36:12 +0200 | [diff] [blame] | 15 | * STACK_REUSE Reuse existing stack (don't create one, only read outputs) |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 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) |
Tomáš Kukrál | 5c2ec13 | 2017-07-26 09:57:27 +0200 | [diff] [blame] | 34 | |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 35 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API |
Tomáš Kukrál | 4691f68 | 2017-07-27 16:36:12 +0200 | [diff] [blame] | 36 | * required for STACK_TYPE=physical |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 37 | * SALT_MASTER_URL URL of Salt master |
Tomáš Kukrál | 5c2ec13 | 2017-07-26 09:57:27 +0200 | [diff] [blame] | 38 | |
| 39 | * Test settings: |
| 40 | * TEST_K8S_API_SERVER Kubernetes API address |
| 41 | * TEST_K8S_CONFORMANCE_IMAGE Path to docker image with conformance e2e tests |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 42 | * |
Tomáš Kukrál | 5c2ec13 | 2017-07-26 09:57:27 +0200 | [diff] [blame] | 43 | * TEST_DOCKER_INSTALL Install docker on the target if true |
| 44 | * TEST_TEMPEST_IMAGE Tempest image link |
| 45 | * TEST_TEMPEST_PATTERN If not false, run tests matched to pattern only |
| 46 | * TEST_TEMPEST_TARGET Salt target for tempest node |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 47 | * |
Tomáš Kukrál | 5c2ec13 | 2017-07-26 09:57:27 +0200 | [diff] [blame] | 48 | * optional parameters for overwriting soft params |
| 49 | * SALT_OVERRIDES YAML with overrides for Salt deployment |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 50 | * |
| 51 | */ |
Tomáš Kukrál | 3a17dd6 | 2017-07-27 18:24:16 +0200 | [diff] [blame] | 52 | |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 53 | common = new com.mirantis.mk.Common() |
| 54 | git = new com.mirantis.mk.Git() |
| 55 | openstack = new com.mirantis.mk.Openstack() |
Tomáš Kukrál | 7a8a4fa | 2017-05-25 14:54:24 +0200 | [diff] [blame] | 56 | aws = new com.mirantis.mk.Aws() |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 57 | orchestrate = new com.mirantis.mk.Orchestrate() |
| 58 | salt = new com.mirantis.mk.Salt() |
| 59 | test = new com.mirantis.mk.Test() |
| 60 | |
| 61 | _MAX_PERMITTED_STACKS = 2 |
| 62 | overwriteFile = "/srv/salt/reclass/classes/cluster/override.yml" |
| 63 | |
Tomáš Kukrál | a1d86b8 | 2017-07-10 17:24:01 +0200 | [diff] [blame] | 64 | // Define global variables |
Tomáš Kukrál | 31414a2 | 2017-06-09 14:17:53 +0200 | [diff] [blame] | 65 | def saltMaster |
Tomáš Kukrál | a1d86b8 | 2017-07-10 17:24:01 +0200 | [diff] [blame] | 66 | def venv |
Tomáš Kukrál | bc4be25 | 2017-06-06 11:28:40 +0200 | [diff] [blame] | 67 | |
Tomáš Kukrál | b19bdda | 2017-06-13 17:09:43 +0200 | [diff] [blame] | 68 | if (STACK_TYPE == 'aws') { |
Tomáš Kukrál | a1d86b8 | 2017-07-10 17:24:01 +0200 | [diff] [blame] | 69 | def aws_env_vars |
Tomáš Kukrál | b19bdda | 2017-06-13 17:09:43 +0200 | [diff] [blame] | 70 | } |
| 71 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 72 | node("python") { |
| 73 | try { |
| 74 | // Set build-specific variables |
| 75 | venv = "${env.WORKSPACE}/venv" |
Tomáš Kukrál | a1d86b8 | 2017-07-10 17:24:01 +0200 | [diff] [blame] | 76 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 77 | // |
| 78 | // Prepare machines |
| 79 | // |
| 80 | stage ('Create infrastructure') { |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 81 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 82 | if (STACK_TYPE == 'heat') { |
| 83 | // value defaults |
| 84 | def openstackCloud |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 85 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 86 | if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') { |
| 87 | error("If you want to reuse existing stack you need to provide it's name") |
| 88 | } |
| 89 | |
| 90 | if (STACK_REUSE.toBoolean() == false) { |
| 91 | // Don't allow to set custom heat stack name |
| 92 | wrap([$class: 'BuildUser']) { |
| 93 | if (env.BUILD_USER_ID) { |
| 94 | STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}" |
| 95 | } else { |
| 96 | STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}" |
| 97 | } |
| 98 | currentBuild.description = STACK_NAME |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 99 | } |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 100 | } |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 101 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 102 | // set description |
| 103 | currentBuild.description = "${STACK_NAME}" |
| 104 | |
| 105 | // get templates |
| 106 | git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS) |
| 107 | |
| 108 | // create openstack env |
| 109 | openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT) |
| 110 | openstackCloud = openstack.createOpenstackEnv( |
| 111 | OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS, |
| 112 | OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN, |
| 113 | OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN, |
| 114 | OPENSTACK_API_VERSION) |
| 115 | openstack.getKeystoneToken(openstackCloud, venv) |
| 116 | // |
| 117 | // Verify possibility of create stack for given user and stack type |
| 118 | // |
| 119 | wrap([$class: 'BuildUser']) { |
| 120 | if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) { |
| 121 | def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}", venv) |
| 122 | if(existingStacks.size() >= _MAX_PERMITTED_STACKS){ |
| 123 | STACK_DELETE = "false" |
| 124 | throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}") |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | // launch stack |
| 129 | if (STACK_REUSE.toBoolean() == false) { |
| 130 | stage('Launch new Heat stack') { |
| 131 | envParams = [ |
| 132 | 'cluster_zone': HEAT_STACK_ZONE, |
| 133 | 'cluster_public_net': HEAT_STACK_PUBLIC_NET |
| 134 | ] |
| 135 | |
| 136 | // set reclass repo in heat env |
| 137 | try { |
| 138 | envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH) |
| 139 | envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS) |
| 140 | } catch (MissingPropertyException e) { |
| 141 | common.infoMsg("Property STACK_RECLASS_BRANCH or STACK_RECLASS_ADDRESS not found! Using default values from template.") |
| 142 | } |
| 143 | |
Tomáš Kukrál | 10d019e | 2017-08-03 12:23:06 +0200 | [diff] [blame] | 144 | def legacy_env = false; |
| 145 | if (STACK_TEMPLATE.startsWith('virtual_') && !STACK_TEMPLATE.contains('aio')) { |
| 146 | legacy_env = true; |
| 147 | } |
| 148 | |
| 149 | openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, legacy_env) |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | |
| 153 | // get SALT_MASTER_URL |
| 154 | saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv) |
| 155 | currentBuild.description = "${STACK_NAME} ${saltMasterHost}" |
| 156 | |
| 157 | SALT_MASTER_URL = "http://${saltMasterHost}:6969" |
| 158 | |
| 159 | } else if (STACK_TYPE == 'aws') { |
| 160 | |
| 161 | // setup environment |
| 162 | aws.setupVirtualEnv(venv) |
| 163 | |
| 164 | // set aws_env_vars |
| 165 | aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION) |
| 166 | |
| 167 | if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') { |
| 168 | error("If you want to reuse existing stack you need to provide it's name") |
| 169 | } |
| 170 | |
| 171 | if (STACK_REUSE.toBoolean() == false) { |
| 172 | // Don't allow to set custom stack name |
| 173 | wrap([$class: 'BuildUser']) { |
| 174 | if (env.BUILD_USER_ID) { |
| 175 | STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}" |
| 176 | } else { |
| 177 | STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}" |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 178 | } |
| 179 | } |
| 180 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 181 | // no underscore in STACK_NAME |
| 182 | STACK_NAME = STACK_NAME.replaceAll('_', '-') |
| 183 | } |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 184 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 185 | // set description |
| 186 | currentBuild.description = STACK_NAME |
| 187 | |
| 188 | if (STACK_REUSE.toBoolean() == false) { |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 189 | // get templates |
| 190 | git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS) |
| 191 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 192 | // start stack |
| 193 | def stack_params = [ |
| 194 | "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY, |
| 195 | "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT |
| 196 | ] |
| 197 | def template_file = 'cfn/' + STACK_TEMPLATE + '.yml' |
| 198 | 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] | 199 | } |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 200 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 201 | // wait for stack to be ready |
| 202 | aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE') |
| 203 | |
| 204 | // get outputs |
| 205 | saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP') |
| 206 | currentBuild.description = "${STACK_NAME} ${saltMasterHost}" |
| 207 | SALT_MASTER_URL = "http://${saltMasterHost}:6969" |
| 208 | |
| 209 | } else if (STACK_TYPE != 'physical') { |
| 210 | throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported") |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 211 | } |
| 212 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 213 | // Connect to Salt master |
| 214 | saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 215 | } |
Tomáš Kukrál | 4691f68 | 2017-07-27 16:36:12 +0200 | [diff] [blame] | 216 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 217 | |
| 218 | // Set up override params |
Jakub Josef | eb15f0b | 2017-08-03 18:22:06 +0200 | [diff] [blame] | 219 | if (common.validInputParam('SALT_OVERRIDES')) { |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 220 | stage('Set Salt overrides') { |
| 221 | salt.setSaltOverrides(saltMaster, SALT_OVERRIDES) |
Tomáš Kukrál | 4691f68 | 2017-07-27 16:36:12 +0200 | [diff] [blame] | 222 | } |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 223 | } |
Tomáš Kukrál | 4691f68 | 2017-07-27 16:36:12 +0200 | [diff] [blame] | 224 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 225 | // |
| 226 | // Install |
| 227 | // |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 228 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 229 | if (common.checkContains('STACK_INSTALL', 'core')) { |
| 230 | stage('Install core infrastructure') { |
| 231 | orchestrate.installFoundationInfra(saltMaster) |
| 232 | |
| 233 | if (common.checkContains('STACK_INSTALL', 'kvm')) { |
| 234 | orchestrate.installInfraKvm(saltMaster) |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 235 | orchestrate.installFoundationInfra(saltMaster) |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 236 | } |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 237 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 238 | orchestrate.validateFoundationInfra(saltMaster) |
| 239 | } |
| 240 | } |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 241 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 242 | // install k8s |
| 243 | if (common.checkContains('STACK_INSTALL', 'k8s')) { |
| 244 | |
| 245 | stage('Install Kubernetes infra') { |
| 246 | if (STACK_TYPE == 'aws') { |
| 247 | // configure kubernetes_control_address - save loadbalancer |
| 248 | def kubernetes_control_address = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ControlLoadBalancer') |
| 249 | print(kubernetes_control_address) |
| 250 | salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_control_address', kubernetes_control_address], null, true) |
| 251 | } |
| 252 | |
| 253 | // ensure certificates are generated properly |
| 254 | salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_pillar', [], null, true) |
| 255 | salt.enforceState(saltMaster, '*', ['salt.minion.cert'], true) |
| 256 | |
| 257 | orchestrate.installKubernetesInfra(saltMaster) |
| 258 | } |
| 259 | |
| 260 | if (common.checkContains('STACK_INSTALL', 'contrail')) { |
| 261 | stage('Install Contrail for Kubernetes') { |
| 262 | orchestrate.installContrailNetwork(saltMaster) |
| 263 | orchestrate.installContrailCompute(saltMaster) |
| 264 | orchestrate.installKubernetesContrailCompute(saltMaster) |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 268 | stage('Install Kubernetes control') { |
vrovachev | 7be1e96 | 2017-07-05 13:28:26 +0400 | [diff] [blame] | 269 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 270 | orchestrate.installKubernetesControl(saltMaster) |
| 271 | } |
| 272 | |
| 273 | stage('Scale Kubernetes computes') { |
| 274 | if (STACK_COMPUTE_COUNT > 0) { |
Tomáš Kukrál | 39c96cd | 2017-07-11 10:14:13 +0200 | [diff] [blame] | 275 | if (STACK_TYPE == 'aws') { |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 276 | // get stack info |
| 277 | def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup') |
| 278 | |
| 279 | //update autoscaling group |
| 280 | aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT]) |
| 281 | |
| 282 | // wait for computes to boot up |
| 283 | aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group) |
| 284 | sleep(60) |
Tomáš Kukrál | 39c96cd | 2017-07-11 10:14:13 +0200 | [diff] [blame] | 285 | } |
Tomáš Kukrál | 4691f68 | 2017-07-27 16:36:12 +0200 | [diff] [blame] | 286 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 287 | orchestrate.installKubernetesCompute(saltMaster) |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 288 | } |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | |
| 292 | // install openstack |
| 293 | if (common.checkContains('STACK_INSTALL', 'openstack')) { |
| 294 | // install Infra and control, tests, ... |
| 295 | |
| 296 | stage('Install OpenStack infra') { |
| 297 | orchestrate.installOpenstackInfra(saltMaster) |
| 298 | } |
| 299 | |
| 300 | stage('Install OpenStack control') { |
| 301 | orchestrate.installOpenstackControl(saltMaster) |
| 302 | } |
| 303 | |
| 304 | stage('Install OpenStack network') { |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 305 | |
vrovachev | 7be1e96 | 2017-07-05 13:28:26 +0400 | [diff] [blame] | 306 | if (common.checkContains('STACK_INSTALL', 'contrail')) { |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 307 | orchestrate.installContrailNetwork(saltMaster) |
| 308 | } else if (common.checkContains('STACK_INSTALL', 'ovs')) { |
| 309 | orchestrate.installOpenstackNetwork(saltMaster) |
vrovachev | 7be1e96 | 2017-07-05 13:28:26 +0400 | [diff] [blame] | 310 | } |
| 311 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 312 | salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list']) |
| 313 | salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list']) |
| 314 | } |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 315 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 316 | if (salt.testTarget(saltMaster, 'I@ironic:conductor')){ |
| 317 | stage('Install OpenStack Ironic conductor') { |
| 318 | orchestrate.installIronicConductor(saltMaster) |
Tomáš Kukrál | 74f9286 | 2017-06-05 19:18:43 +0200 | [diff] [blame] | 319 | } |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 320 | } |
| 321 | |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 322 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 323 | stage('Install OpenStack compute') { |
| 324 | orchestrate.installOpenstackCompute(saltMaster) |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 325 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 326 | if (common.checkContains('STACK_INSTALL', 'contrail')) { |
| 327 | orchestrate.installContrailCompute(saltMaster) |
Martin Polreich | 4697110 | 2017-07-11 12:56:40 +0200 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | |
| 334 | if (common.checkContains('STACK_INSTALL', 'sl-legacy')) { |
| 335 | stage('Install StackLight v1') { |
| 336 | orchestrate.installStacklightv1Control(saltMaster) |
| 337 | orchestrate.installStacklightv1Client(saltMaster) |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | if (common.checkContains('STACK_INSTALL', 'stacklight')) { |
| 342 | stage('Install StackLight') { |
| 343 | orchestrate.installDockerSwarm(saltMaster) |
| 344 | orchestrate.installStacklight(saltMaster) |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | // |
| 349 | // Test |
| 350 | // |
| 351 | def artifacts_dir = '_artifacts/' |
| 352 | |
| 353 | if (common.checkContains('STACK_TEST', 'k8s')) { |
| 354 | stage('Run k8s bootstrap tests') { |
| 355 | def image = 'tomkukral/k8s-scripts' |
| 356 | def output_file = image.replaceAll('/', '-') + '.output' |
| 357 | |
| 358 | // run image |
| 359 | test.runConformanceTests(saltMaster, TEST_K8S_API_SERVER, image) |
| 360 | |
| 361 | // collect output |
| 362 | sh "mkdir -p ${artifacts_dir}" |
| 363 | file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file) |
| 364 | writeFile file: "${artifacts_dir}${output_file}", text: file_content |
| 365 | sh "cat ${artifacts_dir}${output_file}" |
| 366 | |
| 367 | // collect artifacts |
| 368 | archiveArtifacts artifacts: "${artifacts_dir}${output_file}" |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 369 | } |
| 370 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 371 | stage('Run k8s conformance e2e tests') { |
| 372 | def image = K8S_CONFORMANCE_IMAGE |
| 373 | def output_file = image.replaceAll('/', '-') + '.output' |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 374 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 375 | // run image |
| 376 | test.runConformanceTests(saltMaster, TEST_K8S_API_SERVER, image) |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 377 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 378 | // collect output |
| 379 | sh "mkdir -p ${artifacts_dir}" |
| 380 | file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file) |
| 381 | writeFile file: "${artifacts_dir}${output_file}", text: file_content |
| 382 | sh "cat ${artifacts_dir}${output_file}" |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 383 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 384 | // collect artifacts |
| 385 | archiveArtifacts artifacts: "${artifacts_dir}${output_file}" |
| 386 | } |
| 387 | } |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 388 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 389 | if (common.checkContains('STACK_TEST', 'openstack')) { |
| 390 | if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) { |
| 391 | test.install_docker(saltMaster, TEST_TEMPEST_TARGET) |
| 392 | } |
| 393 | stage('Run OpenStack tests') { |
| 394 | test.runTempestTests(saltMaster, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN) |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 395 | } |
| 396 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 397 | stage('Copy Tempest results to config node') { |
| 398 | test.copyTempestResults(saltMaster, TEST_TEMPEST_TARGET) |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 399 | } |
Vasyl Saienko | ff24e58 | 2017-08-04 10:04:33 +0300 | [diff] [blame^] | 400 | |
| 401 | stage('Archive rally artifacts') { |
| 402 | test.archiveRallyArtifacts(saltMaster, TEST_TEMPEST_TARGET) |
| 403 | } |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 404 | } |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 405 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 406 | if (common.checkContains('STACK_INSTALL', 'finalize')) { |
| 407 | stage('Finalize') { |
| 408 | salt.runSaltProcessStep(saltMaster, '*', 'state.apply', [], null, true) |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 409 | } |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 410 | } |
Tomáš Kukrál | 53224c2 | 2017-07-26 10:53:20 +0200 | [diff] [blame] | 411 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 412 | } catch (Throwable e) { |
| 413 | currentBuild.result = 'FAILURE' |
| 414 | throw e |
| 415 | } finally { |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 416 | |
| 417 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 418 | // |
| 419 | // Clean |
| 420 | // |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 421 | |
Jakub Josef | eb15f0b | 2017-08-03 18:22:06 +0200 | [diff] [blame] | 422 | if (common.validInputParam('STACK_NAME')) { |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 423 | // send notification |
| 424 | common.sendNotification(currentBuild.result, STACK_NAME, ["slack"]) |
| 425 | } |
| 426 | |
Jakub Josef | eb15f0b | 2017-08-03 18:22:06 +0200 | [diff] [blame] | 427 | if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) { |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 428 | stage('Trigger cleanup job') { |
| 429 | common.errorMsg('Stack cleanup job triggered') |
| 430 | build(job: STACK_CLEANUP_JOB, parameters: [ |
| 431 | [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME], |
| 432 | [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE], |
| 433 | [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL], |
| 434 | [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS], |
| 435 | [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT], |
| 436 | [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN], |
| 437 | [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID], |
| 438 | [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN], |
| 439 | [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT], |
| 440 | [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION] |
| 441 | ]) |
Tomáš Kukrál | 439c62e | 2017-06-02 11:42:36 +0200 | [diff] [blame] | 442 | } |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 443 | } else { |
| 444 | if (currentBuild.result == 'FAILURE') { |
| 445 | common.errorMsg("Deploy job FAILED and was not deleted. Please fix the problem and delete stack on you own.") |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 446 | |
Jakub Josef | eb15f0b | 2017-08-03 18:22:06 +0200 | [diff] [blame] | 447 | if (common.validInputParam('SALT_MASTER_URL')) { |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 448 | common.errorMsg("Salt master URL: ${SALT_MASTER_URL}") |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 449 | } |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | } |