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