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