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