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