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