Make sure key pair is removed
If stack wasn't removed by the same user which has created it,
nova key pair won't be removed, so need to make sure that no
key pair with the same name exists before creating the stack.
Change-Id: If39658cf93587cbff710632cb3d6bab8fd4277dd
Related-Prod: https://mirantis.jira.com/browse/PROD-21733
diff --git a/cloud-deploy-pipeline.groovy b/cloud-deploy-pipeline.groovy
index 1eecbc0..a4ed1d6 100644
--- a/cloud-deploy-pipeline.groovy
+++ b/cloud-deploy-pipeline.groovy
@@ -224,6 +224,17 @@
envParams.put('cfg_saltversion', SALT_VERSION)
}
+ // If stack wasn't removed by the same user which has created it,
+ // nova key pair won't be removed, so need to make sure that no
+ // key pair with the same name exists before creating the stack.
+ if (openstack.getKeyPair(openstackCloud, STACK_NAME, venv)){
+ try {
+ openstack.deleteKeyPair(openstackCloud, STACK_NAME, venv)
+ } catch (Exception e) {
+ common.errorMsg("Key pair failed to remove with error ${e.message}")
+ }
+ }
+
openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
}