use general deploy cleanup job
Use deploy-stack-cleanup instead of deploy-stack-cleanup since this job
can clean aws stacks as well.
Change-Id: I39e47b5145b95651e19fddc893292a0f66e4eb69
diff --git a/cleanup-pipeline.groovy b/cleanup-pipeline.groovy
index 8b04990..4b67213 100644
--- a/cleanup-pipeline.groovy
+++ b/cleanup-pipeline.groovy
@@ -2,41 +2,71 @@
*
* Delete heat stack pipeline
*
- * Expected parameters:
- * OPENSTACK_API_URL OpenStack API address
- * OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API
- * OPENSTACK_API_PROJECT OpenStack project to connect to
- * OPENSTACK_API_CLIENT Versions of OpenStack python clients
- * OPENSTACK_API_VERSION Version of the OpenStack API (2/3)
- * HEAT_STACK_NAME Heat stack name
+ * General
+ * STACK_NAME Heat stack name
+ * STACK_TYPE Type of the stack (heat, aws)
*
+ * Heat parameters:
+ * OPENSTACK_API_URL OpenStack API address
+ * OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API
+ * OPENSTACK_API_PROJECT OpenStack project to connect to
+ * OPENSTACK_API_CLIENT Versions of OpenStack python clients
+ * OPENSTACK_API_VERSION Version of the OpenStack API (2/3)
+ *
+ * AWS parameters:
+ * AWS_API_CREDENTIALS Credentials id AWS EC2 API
+ * AWS_DEFAULT_REGION EC2 region
*/
+
common = new com.mirantis.mk.Common()
git = new com.mirantis.mk.Git()
openstack = new com.mirantis.mk.Openstack()
+aws = new com.mirantis.mk.Aws()
salt = new com.mirantis.mk.Salt()
node {
- // connection objects
- def openstackCloud
+ def venv_path = "${env.WORKSPACE}/venv"
+ def env_vars
- // value defaults
- def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : 'liberty'
- def openstackEnv = "${env.WORKSPACE}/venv"
-
- stage('Install OpenStack env') {
- openstack.setupOpenstackVirtualenv(openstackEnv, openstackVersion)
+ // default STACK_TYPE is heat
+ if (!env.getEnvironment().containsKey("STACK_TYPE") || STACK_TYPE == '') {
+ STACK_TYPE = 'heat'
}
- stage('Connect to OpenStack cloud') {
- openstackCloud = openstack.createOpenstackEnv(OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS, OPENSTACK_API_PROJECT)
- openstack.getKeystoneToken(openstackCloud, openstackEnv)
+ stage('Install environment') {
+ if (STACK_TYPE == 'heat') {
+
+ def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : 'liberty'
+ openstack.setupOpenstackVirtualenv(venv_path, openstackVersion)
+
+ } else if (STACK_TYPE == 'aws') {
+
+ env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
+ aws.setupVirtualEnv(venv_path)
+
+ } else {
+ throw new Exception('Stack type is not supported')
+ }
+
}
- stage('Delete Heat stack') {
- common.infoMsg("Deleting Heat Stack " + HEAT_STACK_NAME)
- openstack.deleteHeatStack(openstackCloud, HEAT_STACK_NAME, openstackEnv)
+ stage('Delete stack') {
+ if (STACK_TYPE == 'heat') {
+ def openstackCloud = openstack.createOpenstackEnv(OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS, OPENSTACK_API_PROJECT)
+ openstack.getKeystoneToken(openstackCloud, venv_path)
+
+ common.infoMsg("Deleting Heat Stack " + STACK_NAME)
+ openstack.deleteHeatStack(openstackCloud, STACK_NAME, venv_path)
+ } else if (STACK_TYPE == 'aws') {
+
+ aws.deteteStack(venv_path, env_vars, STACK_NAME)
+ aws.waitForStatus(venv_path, evn_vars, STACK_NAME, 'DELETE_COMPLETE', ['DELETE_FAILED'])
+
+ } else {
+ throw new Exception('Stack type is not supported')
+ }
+
}
}