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