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 |
Vasyl Saienko | a81e931 | 2018-03-06 01:28:35 +0200 | [diff] [blame] | 21 | * STACK_CLUSTER_NAME The name of cluster model to use |
Jiri Broulik | 61b3e5d | 2017-12-19 15:42:30 +0100 | [diff] [blame] | 22 | * STATIC_MGMT_NETWORK Check if model contains static IP address definitions for all nodes |
Tomáš Kukrál | 74f9286 | 2017-06-05 19:18:43 +0200 | [diff] [blame] | 23 | * |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 24 | * AWS_STACK_REGION CloudFormation AWS region |
| 25 | * 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] | 26 | * AWS_SSH_KEY AWS key pair name (used for SSH access) |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 27 | * |
| 28 | * HEAT_STACK_ENVIRONMENT Heat stack environmental parameters |
| 29 | * HEAT_STACK_ZONE Heat stack availability zone |
| 30 | * HEAT_STACK_PUBLIC_NET Heat stack floating IP pool |
| 31 | * OPENSTACK_API_URL OpenStack API address |
| 32 | * OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API |
| 33 | * OPENSTACK_API_PROJECT OpenStack project to connect to |
| 34 | * OPENSTACK_API_CLIENT Versions of OpenStack python clients |
| 35 | * OPENSTACK_API_VERSION Version of the OpenStack API (2/3) |
Oleh Hryhorov | 9630a76 | 2017-10-24 14:33:25 +0300 | [diff] [blame] | 36 | * SLAVE_NODE Lable or node name where the job will be run |
Tomáš Kukrál | 5c2ec13 | 2017-07-26 09:57:27 +0200 | [diff] [blame] | 37 | |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 38 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API |
Tomáš Kukrál | 4691f68 | 2017-07-27 16:36:12 +0200 | [diff] [blame] | 39 | * required for STACK_TYPE=physical |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 40 | * SALT_MASTER_URL URL of Salt master |
Tomáš Kukrál | 5c2ec13 | 2017-07-26 09:57:27 +0200 | [diff] [blame] | 41 | |
Oleg Iurchenko | 9a8c3d7 | 2017-12-21 14:55:38 +0200 | [diff] [blame] | 42 | * BOOTSTRAP_EXTRA_REPO_PARAMS optional parameter to define a list of extra repos with parameters |
| 43 | * which have to be added during bootstrap. |
| 44 | * Format: repo 1, repo priority 1, repo pin 1; repo 2, repo priority 2, repo pin 2; |
| 45 | |
Oleh Hryhorov | 825b5be | 2018-06-13 13:01:53 +0300 | [diff] [blame] | 46 | * SALT_VERSION Version of Salt which is going to be installed i.e. 'stable 2016.3' or 'stable 2017.7' etc. |
| 47 | * |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 48 | * EXTRA_TARGET The value will be added to target nodes |
| 49 | * |
Tomáš Kukrál | 5c2ec13 | 2017-07-26 09:57:27 +0200 | [diff] [blame] | 50 | * Test settings: |
| 51 | * TEST_K8S_API_SERVER Kubernetes API address |
| 52 | * TEST_K8S_CONFORMANCE_IMAGE Path to docker image with conformance e2e tests |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 53 | * |
Tomáš Kukrál | 5c2ec13 | 2017-07-26 09:57:27 +0200 | [diff] [blame] | 54 | * TEST_DOCKER_INSTALL Install docker on the target if true |
| 55 | * TEST_TEMPEST_IMAGE Tempest image link |
| 56 | * TEST_TEMPEST_PATTERN If not false, run tests matched to pattern only |
| 57 | * TEST_TEMPEST_TARGET Salt target for tempest node |
ibumarskov | 637a215 | 2018-01-16 10:39:57 +0400 | [diff] [blame] | 58 | * TESTRAIL_REPORT Whether upload results to testrail or not |
| 59 | * TESTRAIL_REPORTER_IMAGE Docker image for testrail reporter |
| 60 | * TESTRAIL_QA_CREDENTIALS Credentials for upload to testrail |
| 61 | * TESTRAIL_MILESTONE Product version for tests |
| 62 | * TESTRAIL_PLAN Testrail test plan |
| 63 | * TESTRAIL_GROUP Testrail test group |
| 64 | * TESTRAIL_SUITE Testrail test suite |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 65 | * |
Tomáš Kukrál | 5c2ec13 | 2017-07-26 09:57:27 +0200 | [diff] [blame] | 66 | * optional parameters for overwriting soft params |
| 67 | * SALT_OVERRIDES YAML with overrides for Salt deployment |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 68 | * |
| 69 | */ |
Tomáš Kukrál | 3a17dd6 | 2017-07-27 18:24:16 +0200 | [diff] [blame] | 70 | |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 71 | common = new com.mirantis.mk.Common() |
| 72 | git = new com.mirantis.mk.Git() |
| 73 | openstack = new com.mirantis.mk.Openstack() |
Tomáš Kukrál | 7a8a4fa | 2017-05-25 14:54:24 +0200 | [diff] [blame] | 74 | aws = new com.mirantis.mk.Aws() |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 75 | orchestrate = new com.mirantis.mk.Orchestrate() |
Mykyta Karpin | e016d7e | 2017-10-09 13:35:20 +0300 | [diff] [blame] | 76 | python = new com.mirantis.mk.Python() |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 77 | salt = new com.mirantis.mk.Salt() |
| 78 | test = new com.mirantis.mk.Test() |
| 79 | |
| 80 | _MAX_PERMITTED_STACKS = 2 |
| 81 | overwriteFile = "/srv/salt/reclass/classes/cluster/override.yml" |
| 82 | |
Tomáš Kukrál | a1d86b8 | 2017-07-10 17:24:01 +0200 | [diff] [blame] | 83 | // Define global variables |
Tomáš Kukrál | a1d86b8 | 2017-07-10 17:24:01 +0200 | [diff] [blame] | 84 | def venv |
chnyda | 597fb03 | 2017-10-06 13:42:48 +0200 | [diff] [blame] | 85 | def venvPepper |
Tomáš Kukrál | 8e50d8e | 2017-09-01 17:40:53 +0200 | [diff] [blame] | 86 | def outputs = [:] |
Tomáš Kukrál | bc4be25 | 2017-06-06 11:28:40 +0200 | [diff] [blame] | 87 | |
chnyda | e14058a | 2017-08-29 15:07:48 +0200 | [diff] [blame] | 88 | def ipRegex = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}" |
| 89 | |
Tomáš Kukrál | b19bdda | 2017-06-13 17:09:43 +0200 | [diff] [blame] | 90 | if (STACK_TYPE == 'aws') { |
Tomáš Kukrál | a1d86b8 | 2017-07-10 17:24:01 +0200 | [diff] [blame] | 91 | def aws_env_vars |
Tomáš Kukrál | 8427ff5 | 2017-08-30 15:46:52 +0200 | [diff] [blame] | 92 | } else if (STACK_TYPE == 'heat') { |
| 93 | def envParams |
| 94 | def openstackCloud |
Tomáš Kukrál | b19bdda | 2017-06-13 17:09:43 +0200 | [diff] [blame] | 95 | } |
| 96 | |
Oleh Hryhorov | 9630a76 | 2017-10-24 14:33:25 +0300 | [diff] [blame] | 97 | def slave_node = 'python' |
| 98 | |
Oleh Hryhorov | 5446051 | 2017-10-26 18:45:36 +0300 | [diff] [blame] | 99 | if (common.validInputParam('SLAVE_NODE')) { |
Oleh Hryhorov | 9630a76 | 2017-10-24 14:33:25 +0300 | [diff] [blame] | 100 | slave_node = SLAVE_NODE |
| 101 | } |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 102 | |
| 103 | def extra_tgt = '' |
Stanislav Riazanov | f030258 | 2019-02-04 17:47:06 +0400 | [diff] [blame] | 104 | def extra_tgt_bckp = '' |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 105 | if (common.validInputParam('EXTRA_TARGET')) { |
| 106 | extra_tgt = "${EXTRA_TARGET}" |
| 107 | } |
| 108 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 109 | timeout(time: 12, unit: 'HOURS') { |
| 110 | node(slave_node) { |
| 111 | try { |
| 112 | // Set build-specific variables |
Jakub Josef | 88aaf83 | 2018-01-18 16:18:28 +0100 | [diff] [blame] | 113 | def workspace = common.getWorkspace() |
| 114 | venv = "${workspace}/venv" |
| 115 | venvPepper = "${workspace}/venvPepper" |
Jakub Josef | 052e77a | 2018-03-05 15:19:03 +0100 | [diff] [blame] | 116 | if(common.validInputParam("STACK_DELETE") && STACK_DELETE.toBoolean()){ |
| 117 | common.warningMsg("You running stack with STACK_DELETE option enabled, deployed stack will be removed at the end!") |
| 118 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 119 | // |
| 120 | // Prepare machines |
| 121 | // |
| 122 | stage ('Create infrastructure') { |
Tomáš Kukrál | a1d86b8 | 2017-07-10 17:24:01 +0200 | [diff] [blame] | 123 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 124 | outputs.put('stack_type', STACK_TYPE) |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 125 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 126 | if (STACK_TYPE == 'heat') { |
| 127 | // value defaults |
| 128 | envParams = [ |
| 129 | 'cluster_zone': HEAT_STACK_ZONE, |
| 130 | 'cluster_public_net': HEAT_STACK_PUBLIC_NET |
| 131 | ] |
Tomáš Kukrál | 8e50d8e | 2017-09-01 17:40:53 +0200 | [diff] [blame] | 132 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 133 | if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') { |
| 134 | error("If you want to reuse existing stack you need to provide it's name") |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 135 | } |
Tomáš Kukrál | 550364e | 2017-08-23 11:42:45 +0200 | [diff] [blame] | 136 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 137 | if (STACK_REUSE.toBoolean() == false) { |
Vasyl Saienko | 293fa3f | 2019-01-22 21:14:37 +0200 | [diff] [blame] | 138 | // TODO(vsaienko): remove stack creation from this pipeline to separate job |
| 139 | // Allow to set custom stack name but user-id will be added anyway |
| 140 | // This will fix issue with cleanup when job is aborted by jenkins and |
| 141 | // still guarantee stack count per user. |
| 142 | def stackNameSuffix = "${JOB_NAME}-${BUILD_NUMBER}" |
| 143 | if (STACK_NAME != ''){ |
| 144 | stackNameSuffix = STACK_NAME |
| 145 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 146 | wrap([$class: 'BuildUser']) { |
| 147 | if (env.BUILD_USER_ID) { |
Vasyl Saienko | 293fa3f | 2019-01-22 21:14:37 +0200 | [diff] [blame] | 148 | STACK_NAME = "${env.BUILD_USER_ID}-${stackNameSuffix}" |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 149 | } else { |
Vasyl Saienko | 293fa3f | 2019-01-22 21:14:37 +0200 | [diff] [blame] | 150 | STACK_NAME = "jenkins-${stackNameSuffix}" |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 151 | } |
| 152 | currentBuild.description = STACK_NAME |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 153 | } |
Inessa Vasilevskaya | 7fd23f2 | 2018-10-09 10:58:46 +0200 | [diff] [blame] | 154 | } else { |
| 155 | // In case name was copied with unicode zero-width space chars - |
| 156 | // remove them |
| 157 | STACK_NAME = STACK_NAME.trim().replaceAll("\\p{C}", "") |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 158 | } |
| 159 | |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 160 | // no underscore in STACK_NAME |
| 161 | STACK_NAME = STACK_NAME.replaceAll('_', '-') |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 162 | outputs.put('stack_name', STACK_NAME) |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 163 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 164 | // set description |
| 165 | currentBuild.description = "${STACK_NAME}" |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 166 | |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 167 | // get templates |
| 168 | git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS) |
| 169 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 170 | // create openstack env |
| 171 | openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT) |
Jakub Josef | 88aaf83 | 2018-01-18 16:18:28 +0100 | [diff] [blame] | 172 | openstackCloud = openstack.createOpenstackEnv(venv, |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 173 | OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS, |
| 174 | OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN, |
| 175 | OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN, |
| 176 | OPENSTACK_API_VERSION) |
| 177 | openstack.getKeystoneToken(openstackCloud, venv) |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 178 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 179 | // |
| 180 | // Verify possibility of create stack for given user and stack type |
| 181 | // |
| 182 | wrap([$class: 'BuildUser']) { |
| 183 | if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) { |
| 184 | def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}".replaceAll('_', '-'), venv) |
| 185 | if (existingStacks.size() >= _MAX_PERMITTED_STACKS) { |
| 186 | STACK_DELETE = "false" |
| 187 | throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}") |
| 188 | } |
| 189 | } |
Tomáš Kukrál | 8e50d8e | 2017-09-01 17:40:53 +0200 | [diff] [blame] | 190 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 191 | // launch stack |
| 192 | if (STACK_REUSE.toBoolean() == false) { |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 193 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 194 | // set reclass repo in heat env |
| 195 | try { |
| 196 | envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH) |
| 197 | envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS) |
| 198 | } catch (MissingPropertyException e) { |
| 199 | common.infoMsg("Property STACK_RECLASS_BRANCH or STACK_RECLASS_ADDRESS not found! Using default values from template.") |
Tomáš Kukrál | f83409d | 2017-11-08 20:56:57 +0100 | [diff] [blame] | 200 | } |
| 201 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 202 | // put formulas revision - stable, testing or nightly |
| 203 | if (common.validInputParam('FORMULA_PKG_REVISION')) { |
| 204 | common.infoMsg("Setting formulas revision to ${FORMULA_PKG_REVISION}") |
| 205 | envParams.put('cfg_formula_pkg_revision', FORMULA_PKG_REVISION) |
| 206 | } |
| 207 | |
| 208 | // put extra repo definitions |
| 209 | if (common.validInputParam('BOOTSTRAP_EXTRA_REPO_PARAMS')) { |
| 210 | common.infoMsg("Setting additional repo during bootstrap to ${BOOTSTRAP_EXTRA_REPO_PARAMS}") |
| 211 | envParams.put('cfg_bootstrap_extra_repo_params', BOOTSTRAP_EXTRA_REPO_PARAMS) |
| 212 | } |
| 213 | |
azvyagintsev | b8ddb49 | 2018-09-12 14:59:45 +0300 | [diff] [blame] | 214 | // put extra salt-formulas # FIXME: looks like some outdated logic. See #PROD-23127 |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 215 | if (common.validInputParam('EXTRA_FORMULAS')) { |
| 216 | common.infoMsg("Setting extra salt-formulas to ${EXTRA_FORMULAS}") |
| 217 | envParams.put('cfg_extra_formulas', EXTRA_FORMULAS) |
| 218 | } |
| 219 | |
Vasyl Saienko | a81e931 | 2018-03-06 01:28:35 +0200 | [diff] [blame] | 220 | // add cluster name if specified |
| 221 | if (common.validInputParam('STACK_CLUSTER_NAME')) { |
| 222 | common.infoMsg("Setting cluster_name to ${STACK_CLUSTER_NAME}") |
| 223 | envParams.put('cluster_name', STACK_CLUSTER_NAME) |
| 224 | } |
| 225 | |
Vasyl Saienko | 51139fd | 2018-04-20 12:01:50 +0300 | [diff] [blame] | 226 | if (common.validInputParam('STACK_COMPUTE_COUNT')) { |
| 227 | if (STACK_COMPUTE_COUNT.toInteger() > 0){ |
| 228 | common.infoMsg("Setting cluster_node_count to ${STACK_COMPUTE_COUNT}") |
| 229 | envParams.put('cluster_node_count', STACK_COMPUTE_COUNT) |
| 230 | } |
| 231 | } |
| 232 | |
Oleh Hryhorov | 825b5be | 2018-06-13 13:01:53 +0300 | [diff] [blame] | 233 | |
| 234 | if (common.validInputParam('SALT_VERSION')) { |
| 235 | common.infoMsg("Setting salt version to ${SALT_VERSION}") |
| 236 | envParams.put('cfg_saltversion', SALT_VERSION) |
| 237 | } |
| 238 | |
Mykyta Karpin | 35f7133 | 2018-07-27 11:54:51 +0300 | [diff] [blame] | 239 | // If stack wasn't removed by the same user which has created it, |
| 240 | // nova key pair won't be removed, so need to make sure that no |
| 241 | // key pair with the same name exists before creating the stack. |
| 242 | if (openstack.getKeyPair(openstackCloud, STACK_NAME, venv)){ |
| 243 | try { |
| 244 | openstack.deleteKeyPair(openstackCloud, STACK_NAME, venv) |
| 245 | } catch (Exception e) { |
| 246 | common.errorMsg("Key pair failed to remove with error ${e.message}") |
| 247 | } |
| 248 | } |
| 249 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 250 | openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv) |
| 251 | } |
| 252 | |
| 253 | // get SALT_MASTER_URL |
| 254 | saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv) |
| 255 | // check that saltMasterHost is valid |
| 256 | if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) { |
| 257 | common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}") |
| 258 | throw new Exception("saltMasterHost is not a valid ip") |
| 259 | } |
| 260 | |
| 261 | currentBuild.description = "${STACK_NAME} ${saltMasterHost}" |
| 262 | |
| 263 | SALT_MASTER_URL = "http://${saltMasterHost}:6969" |
| 264 | |
| 265 | } else if (STACK_TYPE == 'aws') { |
| 266 | |
| 267 | // setup environment |
| 268 | aws.setupVirtualEnv(venv) |
| 269 | |
| 270 | // set aws_env_vars |
| 271 | aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION) |
| 272 | |
| 273 | if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') { |
| 274 | error("If you want to reuse existing stack you need to provide it's name") |
| 275 | } |
| 276 | |
| 277 | if (STACK_REUSE.toBoolean() == false) { |
| 278 | // Don't allow to set custom stack name |
| 279 | wrap([$class: 'BuildUser']) { |
| 280 | if (env.BUILD_USER_ID) { |
| 281 | STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}" |
| 282 | } else { |
| 283 | STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}" |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | // no underscore in STACK_NAME |
| 288 | STACK_NAME = STACK_NAME.replaceAll('_', '-') |
| 289 | } |
| 290 | |
| 291 | // set description |
| 292 | currentBuild.description = STACK_NAME |
| 293 | outputs.put('stack_name', STACK_NAME) |
| 294 | |
| 295 | if (STACK_REUSE.toBoolean() == false) { |
| 296 | // get templates |
| 297 | git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS) |
| 298 | |
| 299 | // start stack |
| 300 | def stack_params = [ |
| 301 | "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY, |
| 302 | "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT |
| 303 | ] |
| 304 | def template_file = 'cfn/' + STACK_TEMPLATE + '.yml' |
| 305 | aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params) |
| 306 | } |
| 307 | |
| 308 | // wait for stack to be ready |
| 309 | aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE') |
| 310 | |
| 311 | // get outputs |
| 312 | saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP') |
| 313 | |
| 314 | // check that saltMasterHost is valid |
| 315 | if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) { |
| 316 | common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}") |
| 317 | throw new Exception("saltMasterHost is not a valid ip") |
| 318 | } |
| 319 | |
| 320 | currentBuild.description = "${STACK_NAME} ${saltMasterHost}" |
| 321 | SALT_MASTER_URL = "http://${saltMasterHost}:6969" |
| 322 | |
| 323 | } else if (STACK_TYPE != 'physical') { |
| 324 | throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported") |
| 325 | } |
| 326 | |
| 327 | outputs.put('salt_api', SALT_MASTER_URL) |
| 328 | |
| 329 | // Setup virtualenv for pepper |
| 330 | python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 331 | } |
| 332 | |
| 333 | |
| 334 | // Set up override params |
Oleh Hryhorov | c409d1e | 2019-02-27 16:57:09 +0200 | [diff] [blame] | 335 | if (common.validInputParam('SALT_OVERRIDES') && common.validInputParam('STACK_INSTALL')) { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 336 | stage('Set Salt overrides') { |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 337 | salt.setSaltOverrides(venvPepper, SALT_OVERRIDES, '/srv/salt/reclass', extra_tgt) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 338 | } |
| 339 | } |
| 340 | |
| 341 | // |
| 342 | // Install |
| 343 | // |
| 344 | |
| 345 | if (common.checkContains('STACK_INSTALL', 'core')) { |
| 346 | stage('Install core infrastructure') { |
| 347 | def staticMgmtNetwork = false |
| 348 | if (common.validInputParam('STATIC_MGMT_NETWORK')) { |
| 349 | staticMgmtNetwork = STATIC_MGMT_NETWORK.toBoolean() |
| 350 | } |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 351 | orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork, extra_tgt) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 352 | |
| 353 | if (common.checkContains('STACK_INSTALL', 'kvm')) { |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 354 | orchestrate.installInfraKvm(venvPepper, extra_tgt) |
Dzmitry Stremkouski | 16fb74f | 2018-07-10 02:01:34 +0200 | [diff] [blame] | 355 | orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork, extra_tgt) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 356 | } |
| 357 | |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 358 | orchestrate.validateFoundationInfra(venvPepper, extra_tgt) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | |
Oleksii Grudev | d3d5fad | 2018-06-29 16:25:35 +0300 | [diff] [blame] | 362 | stage('Install infra') { |
Stanislav Riazanov | f030258 | 2019-02-04 17:47:06 +0400 | [diff] [blame] | 363 | if (common.checkContains('STACK_INSTALL', 'core') || |
Oleksii Grudev | d3d5fad | 2018-06-29 16:25:35 +0300 | [diff] [blame] | 364 | common.checkContains('STACK_INSTALL', 'openstack') || |
Stanislav Riazanov | f030258 | 2019-02-04 17:47:06 +0400 | [diff] [blame] | 365 | common.checkContains('STACK_INSTALL', 'oss')) { |
| 366 | orchestrate.installInfra(venvPepper, extra_tgt) |
| 367 | } |
Oleksii Grudev | d3d5fad | 2018-06-29 16:25:35 +0300 | [diff] [blame] | 368 | } |
| 369 | |
Oleh Hryhorov | c409d1e | 2019-02-27 16:57:09 +0200 | [diff] [blame] | 370 | if (common.validInputParam('STACK_INSTALL')) { |
| 371 | stage('Install Orchestrated Apps'){ |
| 372 | orchestrate.OrchestrateApplications(venvPepper, "I@salt:master ${extra_tgt}", "orchestration.deploy.applications") |
| 373 | } |
Vasyl Saienko | 4c78fe1 | 2018-08-06 10:17:28 +0300 | [diff] [blame] | 374 | } |
| 375 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 376 | // install k8s |
| 377 | if (common.checkContains('STACK_INSTALL', 'k8s')) { |
Stanislav Riazanov | f030258 | 2019-02-04 17:47:06 +0400 | [diff] [blame] | 378 | extra_tgt_bckp = extra_tgt |
| 379 | extra_tgt = 'and not kdt* ' + extra_tgt_bckp |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 380 | stage('Install Kubernetes infra') { |
| 381 | if (STACK_TYPE == 'aws') { |
| 382 | // configure kubernetes_control_address - save loadbalancer |
| 383 | def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME) |
| 384 | common.prettyPrint(awsOutputs) |
| 385 | if (awsOutputs.containsKey('ControlLoadBalancer')) { |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 386 | salt.runSaltProcessStep(venvPepper, "I@salt:master ${extra_tgt}", 'reclass.cluster_meta_set', ['kubernetes_control_address', awsOutputs['ControlLoadBalancer']], null, true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 387 | outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer']) |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | // ensure certificates are generated properly |
Andrey Shestakov | f23ed00 | 2018-08-21 12:09:51 +0300 | [diff] [blame] | 392 | salt.runSaltProcessStep(venvPepper, "I@kubernetes:* ${extra_tgt}", 'saltutil.refresh_pillar', [], null, true) |
| 393 | salt.enforceState(venvPepper, "I@kubernetes:* ${extra_tgt}", ['salt.minion.cert'], true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | if (common.checkContains('STACK_INSTALL', 'contrail')) { |
Svimba | a554ea0 | 2018-06-06 18:45:23 +0200 | [diff] [blame] | 397 | stage('Install Contrail control') { |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 398 | orchestrate.installContrailNetwork(venvPepper, extra_tgt) |
Tomáš Kukrál | 39c96cd | 2017-07-11 10:14:13 +0200 | [diff] [blame] | 399 | } |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 400 | } |
Tomáš Kukrál | f83409d | 2017-11-08 20:56:57 +0100 | [diff] [blame] | 401 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 402 | stage('Install Kubernetes control') { |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 403 | orchestrate.installKubernetesControl(venvPepper, extra_tgt) |
Anton Samoylov | f8a65aa | 2019-01-23 20:22:26 +0400 | [diff] [blame] | 404 | if (common.checkContains('STACK_INSTALL', 'contrail')) { |
| 405 | orchestrate.checkContrailApiReadiness(venvPepper, extra_tgt) |
| 406 | } |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 407 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 408 | // collect artifacts (kubeconfig) |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 409 | writeFile(file: 'kubeconfig', text: salt.getFileContent(venvPepper, "I@kubernetes:master and *01* ${extra_tgt}", '/etc/kubernetes/admin-kube-config')) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 410 | archiveArtifacts(artifacts: 'kubeconfig') |
vrovachev | 7be1e96 | 2017-07-05 13:28:26 +0400 | [diff] [blame] | 411 | } |
| 412 | |
Svimba | a554ea0 | 2018-06-06 18:45:23 +0200 | [diff] [blame] | 413 | if (common.checkContains('STACK_INSTALL', 'contrail')) { |
| 414 | stage('Install Contrail compute') { |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 415 | orchestrate.installContrailCompute(venvPepper, extra_tgt) |
Svimba | a554ea0 | 2018-06-06 18:45:23 +0200 | [diff] [blame] | 416 | } |
| 417 | } |
| 418 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 419 | stage('Install Kubernetes computes') { |
| 420 | if (common.validInputParam('STACK_COMPUTE_COUNT')) { |
| 421 | if (STACK_COMPUTE_COUNT > 0) { |
| 422 | if (STACK_TYPE == 'aws') { |
| 423 | // get stack info |
| 424 | def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup') |
| 425 | |
| 426 | //update autoscaling group |
| 427 | aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT]) |
| 428 | |
| 429 | // wait for computes to boot up |
| 430 | aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group) |
| 431 | sleep(60) |
| 432 | |
| 433 | } else if (STACK_TYPE == 'heat') { |
| 434 | envParams.put('cluster_node_count', STACK_COMPUTE_COUNT) |
| 435 | |
| 436 | openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, "update") |
| 437 | sleep(60) |
| 438 | } |
| 439 | |
| 440 | } |
| 441 | } |
| 442 | |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 443 | orchestrate.installKubernetesCompute(venvPepper, extra_tgt) |
Svimba | a979f8f | 2018-09-26 11:24:49 +0200 | [diff] [blame] | 444 | // Setup kubernetes addons for opencontrail. More info in the definition of the func. |
| 445 | orchestrate.setupKubeAddonForContrail(venvPepper, extra_tgt) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 446 | } |
Vasyl Saienko | b8494f2 | 2019-03-05 10:56:29 +0200 | [diff] [blame^] | 447 | orchestrate.installKubernetesClient(venvPepper, extra_tgt) |
Stanislav Riazanov | f030258 | 2019-02-04 17:47:06 +0400 | [diff] [blame] | 448 | extra_tgt = extra_tgt_bckp |
| 449 | } |
| 450 | |
| 451 | // install kdt (drivetrain on k8s) cluster |
| 452 | if (common.checkContains('STACK_INSTALL', 'kdt')){ |
| 453 | extra_tgt_bckp = extra_tgt |
| 454 | extra_tgt = 'and kdt* ' + extra_tgt_bckp |
| 455 | stage('Install Kubernetes infra for kdt') { |
| 456 | // ensure certificates are generated properly |
| 457 | salt.runSaltProcessStep(venvPepper, "I@kubernetes:* ${extra_tgt}", 'saltutil.refresh_pillar', [], null, true) |
| 458 | salt.enforceState(venvPepper, "I@kubernetes:* ${extra_tgt}", ['salt.minion.cert'], true) |
| 459 | } |
| 460 | |
| 461 | stage('Install Kubernetes control for kdt') { |
| 462 | salt.enforceStateWithTest([saltId: venvPepper, target: "I@kubernetes:master ${extra_tgt}", state: 'kubernetes.master.kube-addons']) |
| 463 | orchestrate.installKubernetesControl(venvPepper, extra_tgt) |
| 464 | |
| 465 | // collect artifacts (kubeconfig) |
| 466 | writeFile(file: 'kubeconfig-kdt', text: salt.getFileContent(venvPepper, "I@kubernetes:master and *01* ${extra_tgt}", '/etc/kubernetes/admin-kube-config')) |
| 467 | archiveArtifacts(artifacts: 'kubeconfig-kdt') |
| 468 | } |
Vasyl Saienko | b8494f2 | 2019-03-05 10:56:29 +0200 | [diff] [blame^] | 469 | orchestrate.installKubernetesClient(venvPepper, extra_tgt) |
Stanislav Riazanov | f030258 | 2019-02-04 17:47:06 +0400 | [diff] [blame] | 470 | extra_tgt = extra_tgt_bckp |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 471 | } |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 472 | |
Mykyta Karpin | 5b7c260 | 2018-09-11 17:47:20 +0300 | [diff] [blame] | 473 | // install ceph |
| 474 | if (common.checkContains('STACK_INSTALL', 'ceph')) { |
| 475 | stage('Install Ceph MONs') { |
| 476 | orchestrate.installCephMon(venvPepper, "I@ceph:mon ${extra_tgt}", extra_tgt) |
| 477 | } |
| 478 | |
| 479 | stage('Install Ceph OSDs') { |
| 480 | orchestrate.installCephOsd(venvPepper, "I@ceph:osd ${extra_tgt}", true, extra_tgt) |
| 481 | } |
| 482 | |
| 483 | stage('Install Ceph clients') { |
| 484 | orchestrate.installCephClient(venvPepper, extra_tgt) |
| 485 | } |
| 486 | } |
| 487 | |
Vasyl Saienko | c562fc4 | 2018-12-15 22:19:28 +0200 | [diff] [blame] | 488 | // install docker swarm |
Oleh Hryhorov | c409d1e | 2019-02-27 16:57:09 +0200 | [diff] [blame] | 489 | if (common.validInputParam('STACK_INSTALL')) { |
| 490 | orchestrate.installDockerSwarm(venvPepper, extra_tgt) |
| 491 | } |
Vasyl Saienko | c562fc4 | 2018-12-15 22:19:28 +0200 | [diff] [blame] | 492 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 493 | // install openstack |
| 494 | if (common.checkContains('STACK_INSTALL', 'openstack')) { |
Oleksii Grudev | d3d5fad | 2018-06-29 16:25:35 +0300 | [diff] [blame] | 495 | // install control, tests, ... |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 496 | stage('Install OpenStack control') { |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 497 | orchestrate.installOpenstackControl(venvPepper, extra_tgt) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 498 | } |
| 499 | |
Oleg Iurchenko | 86f1a84 | 2018-02-13 22:18:28 +0200 | [diff] [blame] | 500 | // Workaround for PROD-17765 issue to prevent crashes of keystone.role_present state. |
| 501 | // More details: https://mirantis.jira.com/browse/PROD-17765 |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 502 | salt.runSaltProcessStep(venvPepper, "I@keystone:client ${extra_tgt}", 'service.restart', ['salt-minion']) |
| 503 | salt.minionsReachable(venvPepper, "I@salt:master and *01* ${extra_tgt}", 'I@keystone:client', null, 10, 6) |
Oleg Iurchenko | 86f1a84 | 2018-02-13 22:18:28 +0200 | [diff] [blame] | 504 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 505 | stage('Install OpenStack network') { |
| 506 | |
| 507 | if (common.checkContains('STACK_INSTALL', 'contrail')) { |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 508 | orchestrate.installContrailNetwork(venvPepper, extra_tgt) |
Anton Samoylov | f8a65aa | 2019-01-23 20:22:26 +0400 | [diff] [blame] | 509 | orchestrate.checkContrailApiReadiness(venvPepper, extra_tgt) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 510 | } else if (common.checkContains('STACK_INSTALL', 'ovs')) { |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 511 | orchestrate.installOpenstackNetwork(venvPepper, extra_tgt) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 512 | } |
| 513 | |
Petr Jediný | efd668f | 2018-05-24 14:44:08 +0200 | [diff] [blame] | 514 | // Wait for network to come up, 150s should be enough |
| 515 | common.retry(10, 15) { |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 516 | salt.cmdRun(venvPepper, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; openstack network list') |
Petr Jediný | efd668f | 2018-05-24 14:44:08 +0200 | [diff] [blame] | 517 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 518 | } |
| 519 | |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 520 | if (salt.testTarget(venvPepper, "I@ironic:conductor ${extra_tgt}")){ |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 521 | stage('Install OpenStack Ironic conductor') { |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 522 | orchestrate.installIronicConductor(venvPepper, extra_tgt) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 523 | } |
| 524 | } |
| 525 | |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 526 | if (salt.testTarget(venvPepper, "I@manila:share ${extra_tgt}")){ |
Vasyl Saienko | b800a0f | 2018-02-21 18:38:53 +0200 | [diff] [blame] | 527 | stage('Install OpenStack Manila data and share') { |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 528 | orchestrate.installManilaShare(venvPepper, extra_tgt) |
Vasyl Saienko | b800a0f | 2018-02-21 18:38:53 +0200 | [diff] [blame] | 529 | } |
| 530 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 531 | |
| 532 | stage('Install OpenStack compute') { |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 533 | orchestrate.installOpenstackCompute(venvPepper, extra_tgt) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 534 | |
| 535 | if (common.checkContains('STACK_INSTALL', 'contrail')) { |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 536 | orchestrate.installContrailCompute(venvPepper, extra_tgt) |
Inessa Vasilevskaya | 30cb731 | 2018-10-08 12:13:03 +0200 | [diff] [blame] | 537 | orchestrate.installBackup(venvPepper, 'contrail', extra_tgt) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | |
| 541 | } |
| 542 | |
Mykyta Karpin | 5b7c260 | 2018-09-11 17:47:20 +0300 | [diff] [blame] | 543 | // connect ceph |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 544 | if (common.checkContains('STACK_INSTALL', 'ceph')) { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 545 | |
| 546 | stage('Connect Ceph') { |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 547 | orchestrate.connectCeph(venvPepper, extra_tgt) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 548 | } |
| 549 | } |
| 550 | |
| 551 | if (common.checkContains('STACK_INSTALL', 'oss')) { |
| 552 | stage('Install Oss infra') { |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 553 | orchestrate.installOssInfra(venvPepper, extra_tgt) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | |
| 557 | if (common.checkContains('STACK_INSTALL', 'cicd')) { |
| 558 | stage('Install Cicd') { |
Stanislav Riazanov | f030258 | 2019-02-04 17:47:06 +0400 | [diff] [blame] | 559 | extra_tgt_bckp = extra_tgt |
| 560 | extra_tgt = 'and cid* ' + extra_tgt_bckp |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 561 | orchestrate.installInfra(venvPepper, extra_tgt) |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 562 | orchestrate.installCicd(venvPepper, extra_tgt) |
Stanislav Riazanov | f030258 | 2019-02-04 17:47:06 +0400 | [diff] [blame] | 563 | extra_tgt = extra_tgt_bckp |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | if (common.checkContains('STACK_INSTALL', 'kdt')) { |
| 568 | stage('Install Cicd on kdt') { |
| 569 | extra_tgt_bckp = extra_tgt |
| 570 | extra_tgt = 'and kdt* ' + extra_tgt_bckp |
| 571 | orchestrate.installInfra(venvPepper, extra_tgt) |
| 572 | orchestrate.installCicd(venvPepper, extra_tgt) |
| 573 | extra_tgt = extra_tgt_bckp |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 574 | } |
| 575 | } |
| 576 | |
| 577 | if (common.checkContains('STACK_INSTALL', 'sl-legacy')) { |
| 578 | stage('Install StackLight v1') { |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 579 | orchestrate.installStacklightv1Control(venvPepper, extra_tgt) |
| 580 | orchestrate.installStacklightv1Client(venvPepper, extra_tgt) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 581 | } |
| 582 | } |
| 583 | |
| 584 | if (common.checkContains('STACK_INSTALL', 'stacklight')) { |
| 585 | stage('Install StackLight') { |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 586 | orchestrate.installStacklight(venvPepper, extra_tgt) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 587 | } |
| 588 | } |
| 589 | |
| 590 | if (common.checkContains('STACK_INSTALL', 'oss')) { |
| 591 | stage('Install OSS') { |
| 592 | if (!common.checkContains('STACK_INSTALL', 'stacklight')) { |
| 593 | // In case if StackLightv2 enabled containers already started |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 594 | salt.enforceState(venvPepper, "I@docker:swarm:role:master and I@devops_portal:config ${extra_tgt}", 'docker.client', true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 595 | } |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 596 | orchestrate.installOss(venvPepper, extra_tgt) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | |
| 600 | // |
| 601 | // Test |
| 602 | // |
| 603 | def artifacts_dir = '_artifacts/' |
| 604 | |
| 605 | if (common.checkContains('STACK_TEST', 'k8s')) { |
| 606 | stage('Run k8s conformance e2e tests') { |
| 607 | def image = TEST_K8S_CONFORMANCE_IMAGE |
Victor Ryzhenkin | 723bd06 | 2018-12-11 17:09:06 +0400 | [diff] [blame] | 608 | def autodetect = AUTODETECT |
| 609 | def ctl_target = 'I@kubernetes:master' |
| 610 | firstTarget = salt.getFirstMinion(venvPepper, ctl_target) |
| 611 | def containerd_enabled = salt.getPillar( |
| 612 | venvPepper, firstTarget, "kubernetes:common:containerd:enabled" |
| 613 | )["return"][0].values()[0].toBoolean() |
| 614 | if (containerd_enabled) { |
| 615 | def config = ['master': venvPepper, |
| 616 | 'target': firstTarget, |
| 617 | 'junitResults': true, |
| 618 | 'autodetect': autodetect, |
| 619 | 'image': image] |
| 620 | test.executeConformance(config) |
| 621 | } else { |
| 622 | def output_file = image.replaceAll('/', '-') + '.output' |
| 623 | def target = "ctl01* ${extra_tgt}" |
| 624 | def conformance_output_file = 'conformance_test.tar' |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 625 | |
Victor Ryzhenkin | 723bd06 | 2018-12-11 17:09:06 +0400 | [diff] [blame] | 626 | // run image |
| 627 | test.runConformanceTests(venvPepper, target, TEST_K8S_API_SERVER, image) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 628 | |
Victor Ryzhenkin | 723bd06 | 2018-12-11 17:09:06 +0400 | [diff] [blame] | 629 | // collect output |
| 630 | sh "mkdir -p ${artifacts_dir}" |
| 631 | file_content = salt.getFileContent(venvPepper, target, '/tmp/' + output_file) |
| 632 | writeFile file: "${artifacts_dir}${output_file}", text: file_content |
| 633 | sh "cat ${artifacts_dir}${output_file}" |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 634 | |
Victor Ryzhenkin | 723bd06 | 2018-12-11 17:09:06 +0400 | [diff] [blame] | 635 | // collect artifacts |
| 636 | archiveArtifacts artifacts: "${artifacts_dir}${output_file}" |
vrovachev | ff3e72d | 2018-01-25 16:14:43 +0400 | [diff] [blame] | 637 | |
Victor Ryzhenkin | 723bd06 | 2018-12-11 17:09:06 +0400 | [diff] [blame] | 638 | // Copy test results |
| 639 | test.CopyConformanceResults(venvPepper, target, artifacts_dir, conformance_output_file) |
| 640 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 641 | } |
| 642 | } |
| 643 | |
| 644 | if (common.checkContains('STACK_TEST', 'openstack')) { |
| 645 | if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) { |
| 646 | test.install_docker(venvPepper, TEST_TEMPEST_TARGET) |
| 647 | } |
| 648 | stage('Run OpenStack tests') { |
| 649 | test.runTempestTests(venvPepper, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN) |
| 650 | } |
| 651 | |
| 652 | stage('Copy Tempest results to config node') { |
| 653 | test.copyTempestResults(venvPepper, TEST_TEMPEST_TARGET) |
| 654 | } |
| 655 | |
| 656 | stage('Archive rally artifacts') { |
| 657 | test.archiveRallyArtifacts(venvPepper, TEST_TEMPEST_TARGET) |
Tomáš Kukrál | 74f9286 | 2017-06-05 19:18:43 +0200 | [diff] [blame] | 658 | } |
ibumarskov | 637a215 | 2018-01-16 10:39:57 +0400 | [diff] [blame] | 659 | |
| 660 | if (common.validInputParam('TESTRAIL_REPORT') && TESTRAIL_REPORT.toBoolean()) { |
| 661 | stage('Upload test results to TestRail') { |
| 662 | def date = sh(script: 'date +%Y-%m-%d', returnStdout: true).trim() |
| 663 | def plan = TESTRAIL_PLAN ?: "[${TESTRAIL_MILESTONE}]System-Devcloud-${date}" |
| 664 | def group = TESTRAIL_GROUP ?: STACK_TEMPLATE |
| 665 | |
| 666 | salt.cmdRun(venvPepper, TEST_TEMPEST_TARGET, "cd /root/rally_reports && cp \$(ls -t *xml | head -n1) report.xml") |
| 667 | test.uploadResultsTestrail("/root/rally_reports/report.xml", |
| 668 | TESTRAIL_REPORTER_IMAGE, group, TESTRAIL_QA_CREDENTIALS, |
| 669 | plan, TESTRAIL_MILESTONE, TESTRAIL_SUITE) |
| 670 | } |
| 671 | } |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 672 | } |
| 673 | |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 674 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 675 | if (common.checkContains('STACK_TEST', 'ceph')) { |
| 676 | stage('Run infra tests') { |
| 677 | sleep(120) |
| 678 | 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/" |
| 679 | salt.cmdRun(venvPepper, 'I@salt:master', cmd, false) |
| 680 | writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper, 'I@salt:master', '/root/report.xml')) |
| 681 | junit(keepLongStdio: true, testResults: 'report.xml') |
Martin Polreich | 4697110 | 2017-07-11 12:56:40 +0200 | [diff] [blame] | 682 | } |
| 683 | } |
| 684 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 685 | if (common.checkContains('STACK_TEST', 'opencontrail')) { |
| 686 | stage('Run opencontrail tests') { |
| 687 | def opencontrail_tests_dir = "/opt/opencontrail_test/fuel-plugin-contrail/plugin_test/vapor/" |
| 688 | def report_dir = "/opt/opencontrail-test-report/" |
| 689 | def cmd = ". ${opencontrail_tests_dir}exports.sh && " + |
| 690 | "cd ${opencontrail_tests_dir} && " + |
| 691 | "py.test --junit-xml=${report_dir}report.xml" + |
| 692 | " --html=${report_dir}report.html -v vapor/tests/ -k 'not destructive' " |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 693 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 694 | salt.runSaltProcessStep(venvPepper, 'cfg*', 'saltutil.refresh_pillar', [], null, true) |
| 695 | salt.enforceState(venvPepper, 'I@opencontrail:test' , 'opencontrail.test' , true) |
Jiri Broulik | d01c42f | 2018-01-02 11:37:10 +0100 | [diff] [blame] | 696 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 697 | salt.cmdRun(venvPepper, 'I@opencontrail:test', cmd, false) |
| 698 | |
| 699 | writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper, |
| 700 | 'I@opencontrail:test', "${report_dir}report.xml")) |
| 701 | junit(keepLongStdio: true, testResults: 'report.xml') |
| 702 | } |
Jiri Broulik | d01c42f | 2018-01-02 11:37:10 +0100 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 706 | stage('Finalize') { |
| 707 | if (common.checkContains('STACK_INSTALL', 'finalize')) { |
Oleh Hryhorov | 2a63aa6 | 2018-06-22 17:26:41 +0300 | [diff] [blame] | 708 | def gluster_compound = "I@glusterfs:server ${extra_tgt}" |
| 709 | def salt_ca_compound = "I@salt:minion:ca:salt_master_ca ${extra_tgt}" |
Dzmitry Stremkouski | fa4c163 | 2018-03-21 17:55:39 +0100 | [diff] [blame] | 710 | // Enforce highstate asynchronous only on the nodes which are not glusterfs servers |
Dzmitry Stremkouski | 47a4512 | 2018-04-25 17:05:56 +0200 | [diff] [blame] | 711 | salt.enforceHighstate(venvPepper, '* and not ' + gluster_compound + ' and not ' + salt_ca_compound) |
Dzmitry Stremkouski | fa4c163 | 2018-03-21 17:55:39 +0100 | [diff] [blame] | 712 | // Iterate over nonempty set of gluster servers and apply highstates one by one |
| 713 | // TODO: switch to batch once salt 2017.7+ would be used |
Dzmitry Stremkouski | 47a4512 | 2018-04-25 17:05:56 +0200 | [diff] [blame] | 714 | def saltcaMinions = salt.getMinionsSorted(venvPepper, salt_ca_compound) |
| 715 | if ( !saltcaMinions.isEmpty() ) { |
| 716 | for ( target in saltcaMinions ) { |
| 717 | salt.enforceHighstate(venvPepper, target) |
| 718 | } |
| 719 | } |
Dzmitry Stremkouski | fa4c163 | 2018-03-21 17:55:39 +0100 | [diff] [blame] | 720 | def glusterMinions = salt.getMinionsSorted(venvPepper, gluster_compound) |
| 721 | if ( !glusterMinions.isEmpty() ) { |
| 722 | for ( target in glusterMinions ) { |
| 723 | salt.enforceHighstate(venvPepper, target) |
| 724 | } |
| 725 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | outputsPretty = common.prettify(outputs) |
| 729 | print(outputsPretty) |
| 730 | writeFile(file: 'outputs.json', text: outputsPretty) |
| 731 | archiveArtifacts(artifacts: 'outputs.json') |
Jiri Broulik | d01c42f | 2018-01-02 11:37:10 +0100 | [diff] [blame] | 732 | } |
| 733 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 734 | } catch (Throwable e) { |
| 735 | currentBuild.result = 'FAILURE' |
| 736 | throw e |
| 737 | } finally { |
Jiri Broulik | d01c42f | 2018-01-02 11:37:10 +0100 | [diff] [blame] | 738 | |
Mikhail Ivanov | 3deb79a | 2017-12-06 17:44:47 +0400 | [diff] [blame] | 739 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 740 | // |
| 741 | // Clean |
| 742 | // |
Ruslan Kamaldinov | 6514432 | 2017-08-02 15:16:55 +0400 | [diff] [blame] | 743 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 744 | if (common.validInputParam('STACK_NAME')) { |
| 745 | // send notification |
| 746 | common.sendNotification(currentBuild.result, STACK_NAME, ["slack"]) |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 747 | } |
| 748 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 749 | if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) { |
| 750 | stage('Trigger cleanup job') { |
| 751 | common.errorMsg('Stack cleanup job triggered') |
| 752 | build(job: STACK_CLEANUP_JOB, parameters: [ |
| 753 | [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME], |
| 754 | [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE], |
| 755 | [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL], |
| 756 | [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS], |
| 757 | [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT], |
| 758 | [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN], |
| 759 | [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID], |
| 760 | [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN], |
| 761 | [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT], |
| 762 | [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION] |
| 763 | ]) |
| 764 | } |
| 765 | } else { |
| 766 | if (currentBuild.result == 'FAILURE') { |
| 767 | common.errorMsg("Deploy job FAILED and was not deleted. Please fix the problem and delete stack on you own.") |
Vasyl Saienko | ff24e58 | 2017-08-04 10:04:33 +0300 | [diff] [blame] | 768 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 769 | if (common.validInputParam('SALT_MASTER_URL')) { |
| 770 | common.errorMsg("Salt master URL: ${SALT_MASTER_URL}") |
| 771 | } |
Ales Komarek | 2409740 | 2017-05-22 16:28:10 +0200 | [diff] [blame] | 772 | } |
| 773 | } |
| 774 | } |
| 775 | } |
| 776 | } |