Dzmitry Stremkouski | a9875d4 | 2020-07-06 16:45:36 +0200 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | * Cleanup OpenStack databases from stale records (archived records or records marked as deleted). |
| 4 | * Cleanup OpenStack service databases. |
| 5 | * |
| 6 | * Expected parameters: |
| 7 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API. |
| 8 | * SALT_MASTER_URL Full Salt API address [http://10.10.10.15:6969]. |
| 9 | * |
| 10 | **/ |
| 11 | |
| 12 | def common = new com.mirantis.mk.Common() |
| 13 | def salt = new com.mirantis.mk.Salt() |
| 14 | def python = new com.mirantis.mk.Python() |
| 15 | |
Oleksii Molchanov | 0cbc68d | 2021-09-07 14:43:03 +0300 | [diff] [blame] | 16 | def os_services = [ 'nova:controller', 'heat:server', 'cinder:controller', 'glance:server' ] |
Dzmitry Stremkouski | a9875d4 | 2020-07-06 16:45:36 +0200 | [diff] [blame] | 17 | |
| 18 | def slave_node = 'python' |
| 19 | |
| 20 | if (common.validInputParam('SLAVE_NODE')) { |
| 21 | slave_node = SLAVE_NODE |
| 22 | } |
| 23 | |
| 24 | def env = "pepperEnv" |
| 25 | timeout(time: 12, unit: 'HOURS') { |
| 26 | |
| 27 | node(slave_node) { |
| 28 | |
| 29 | stage('Setup virtualenv for Pepper') { |
| 30 | python.setupPepperVirtualenv(env, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 31 | } |
| 32 | |
| 33 | stage('Databases cleanup') { |
| 34 | |
| 35 | for (os_service in os_services) { |
| 36 | |
| 37 | formula = os_service.split(":")[0] |
| 38 | os_state = "${formula}.db.db_cleanup" |
| 39 | os_file = "/usr/share/salt-formulas/env/${formula}/db/db_cleanup.sls" |
| 40 | |
| 41 | if (salt.runSaltProcessStep(env, 'I@salt:master', 'file.file_exists', [os_file], null, true, 5)['return'][0].values()[0].toBoolean()) { |
| 42 | salt.enforceStateWithTest([saltId: env, target: "I@${os_service}:role:primary", state: [os_state]]) |
| 43 | } |
| 44 | |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | } |