blob: c68fe9eb2f0f4e37416cf287a445e01f4ae94dd5 [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'
25 def openstackEnv = "${env.WORKSPACE}/venv"
Jakub Josef4cb727e2017-04-19 16:44:47 +020026
Jakub Josefa63f9862018-01-11 17:58:38 +010027 stage('Install OpenStack env') {
28 openstack.setupOpenstackVirtualenv(openstackEnv, openstackVersion)
Jakub Josef4cb727e2017-04-19 16:44:47 +020029 }
Jakub Josef4cb727e2017-04-19 16:44:47 +020030
Jakub Josefa63f9862018-01-11 17:58:38 +010031 stage('Connect to OpenStack cloud') {
32 openstackCloud = openstack.createOpenstackEnv(OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS, OPENSTACK_API_PROJECT)
33 openstack.getKeystoneToken(openstackCloud, openstackEnv)
34 }
35
36 stage('Delete broken Heat stacks') {
37 // get failed stacks
38 def brokenStacks = []
39 brokenStacks.addAll(openstack.getStacksWithStatus(openstackCloud, "CREATE_FAILED", openstackEnv))
40 brokenStacks.addAll(openstack.getStacksWithStatus(openstackCloud, "DELETE_FAILED", openstackEnv))
41 for(int i=0;i<brokenStacks.size();i++){
42 common.infoMsg("Deleting Heat stack " + brokenStacks[i])
43 openstack.deleteHeatStack(openstackCloud, brokenStacks[i], openstackEnv)
44 }
45 }
46
47 }
Jakub Josef4cb727e2017-04-19 16:44:47 +020048}