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