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