Jakub Josef | 4cb727e | 2017-04-19 16:44:47 +0200 | [diff] [blame] | 1 | /** |
| 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 Josef | f68c52a | 2017-04-20 17:47:37 +0200 | [diff] [blame] | 14 | common = new com.mirantis.mk.Common() |
Jakub Josef | 4cb727e | 2017-04-19 16:44:47 +0200 | [diff] [blame] | 15 | git = new com.mirantis.mk.Git() |
| 16 | openstack = new com.mirantis.mk.Openstack() |
| 17 | salt = new com.mirantis.mk.Salt() |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 18 | timeout(time: 12, unit: 'HOURS') { |
| 19 | node { |
Jakub Josef | 4cb727e | 2017-04-19 16:44:47 +0200 | [diff] [blame] | 20 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 21 | // connection objects |
| 22 | def openstackCloud |
| 23 | // value defaults |
| 24 | def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : 'liberty' |
Jakub Josef | 88aaf83 | 2018-01-18 16:18:28 +0100 | [diff] [blame] | 25 | def workspace = common.getWorkspace() |
| 26 | def openstackEnv = "${workspace}/venv" |
Jakub Josef | 4cb727e | 2017-04-19 16:44:47 +0200 | [diff] [blame] | 27 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 28 | stage('Install OpenStack env') { |
| 29 | openstack.setupOpenstackVirtualenv(openstackEnv, openstackVersion) |
Jakub Josef | 4cb727e | 2017-04-19 16:44:47 +0200 | [diff] [blame] | 30 | } |
Jakub Josef | 4cb727e | 2017-04-19 16:44:47 +0200 | [diff] [blame] | 31 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 32 | |
| 33 | stage('Delete broken Heat stacks') { |
Jakub Josef | 0fef0a9 | 2018-02-21 15:06:05 +0100 | [diff] [blame] | 34 | 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 Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
| 51 | } |
Jakub Josef | 4cb727e | 2017-04-19 16:44:47 +0200 | [diff] [blame] | 52 | } |