blob: 25f2e1240594859e6b3b417082c5668652e039b3 [file] [log] [blame]
Jakub Josef4cb727e2017-04-19 16:44:47 +02001/**
2 *
3 * Delete broken heat stacks pipeline (in CREATE_FAILED or DELETE_FAILED state)
4 *
5 * Expected parameters:
6 * OPENSTACK_API_URL OpenStack API address
7 * OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API
8 * OPENSTACK_API_PROJECT OpenStack project to connect to
9 * OPENSTACK_API_CLIENT Versions of OpenStack python clients
10 * OPENSTACK_API_VERSION Version of the OpenStack API (2/3)
11 *
12 *
13 */
Jakub Joseff68c52a2017-04-20 17:47:37 +020014common = new com.mirantis.mk.Common()
Jakub Josef4cb727e2017-04-19 16:44:47 +020015git = new com.mirantis.mk.Git()
16openstack = new com.mirantis.mk.Openstack()
17salt = new com.mirantis.mk.Salt()
Jakub Josefa63f9862018-01-11 17:58:38 +010018timeout(time: 12, unit: 'HOURS') {
19 node {
Jakub Josef4cb727e2017-04-19 16:44:47 +020020
Jakub Josefa63f9862018-01-11 17:58:38 +010021 // connection objects
22 def openstackCloud
23 // value defaults
24 def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : 'liberty'
Jakub Josef88aaf832018-01-18 16:18:28 +010025 def workspace = common.getWorkspace()
26 def openstackEnv = "${workspace}/venv"
Jakub Josef4cb727e2017-04-19 16:44:47 +020027
Jakub Josefa63f9862018-01-11 17:58:38 +010028 stage('Install OpenStack env') {
29 openstack.setupOpenstackVirtualenv(openstackEnv, openstackVersion)
Jakub Josef4cb727e2017-04-19 16:44:47 +020030 }
Jakub Josef4cb727e2017-04-19 16:44:47 +020031
Jakub Josefa63f9862018-01-11 17:58:38 +010032
33 stage('Delete broken Heat stacks') {
Jakub Josef0fef0a92018-02-21 15:06:05 +010034 def tenants = OPENSTACK_API_PROJECT.tokenize(",").collect{it.trim()}
35 for(tenant in tenants){
36 common.infoMsg("Cleaning broken heat stacks in tenant ${tenant}")
37 // connect to openstack
38 openstackCloud = openstack.createOpenstackEnv(openstackEnv, OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS, tenant)
39 openstack.getKeystoneToken(openstackCloud, openstackEnv)
40 // get failed stacks
41 def brokenStacks = []
42 brokenStacks.addAll(openstack.getStacksWithStatus(openstackCloud, "CREATE_FAILED", openstackEnv))
43 brokenStacks.addAll(openstack.getStacksWithStatus(openstackCloud, "DELETE_FAILED", openstackEnv))
44 for(int i=0;i<brokenStacks.size();i++){
45 common.infoMsg("Deleting Heat stack " + brokenStacks[i])
46 openstack.deleteHeatStack(openstackCloud, brokenStacks[i], openstackEnv)
47 }
Jakub Josefa63f9862018-01-11 17:58:38 +010048 }
49 }
50
51 }
Jakub Josef4cb727e2017-04-19 16:44:47 +020052}