summaryrefslogtreecommitdiffstats
path: root/sdnvpn/lib/utils.py
diff options
context:
space:
mode:
authortomsou <soth@intracom-telecom.com>2017-05-22 09:14:22 +0000
committertomsou <soth@intracom-telecom.com>2017-05-31 13:19:43 +0000
commitde80ee56c458b127be3497f3882bc1c962f42dfe (patch)
treec2c415ece2c7e6aabf7a0a59493485787142e6b1 /sdnvpn/lib/utils.py
parent9fb7fad2a9f83ddb7d0c1f61b2d5609352fb6f15 (diff)
Cleanup after testcase running
After every testcase running cleanup neutron and nova elements: - Allocated floating IPs (nova) - Created instances (nova) - Created images (nova) - Created router-subnet interfaces (neutron) - Created gateaway routers (neutron) - Created routers (neutron) - Created subnets (neutron) - Created networks (neutron) - Created bgpvpns (neutron) JIRA: SDNVPN-145 JIRA: SDNVPN-148 Change-Id: Id6df004bb9d0d394e2cf39692b624607167c9a6c Signed-off-by: tomsou <soth@intracom-telecom.com>
Diffstat (limited to 'sdnvpn/lib/utils.py')
-rw-r--r--sdnvpn/lib/utils.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/sdnvpn/lib/utils.py b/sdnvpn/lib/utils.py
index 3bac483..7e41d41 100644
--- a/sdnvpn/lib/utils.py
+++ b/sdnvpn/lib/utils.py
@@ -536,3 +536,79 @@ def detach_instance_from_ext_br(instance, compute_node):
sudo brctl delbr {bridge}
"""
compute_node.run_cmd(cmd.format(bridge=bridge))
+
+
+def cleanup_neutron(neutron_client, bgpvpn_ids, interfaces, subnet_ids,
+ router_ids, network_ids):
+
+ if len(bgpvpn_ids) != 0:
+ for bgpvpn_id in bgpvpn_ids:
+ os_utils.delete_bgpvpn(neutron_client, bgpvpn_id)
+
+ if len(interfaces) != 0:
+ for router_id, subnet_id in interfaces:
+ if not os_utils.remove_interface_router(neutron_client,
+ router_id, subnet_id):
+ logging.error('Fail to delete all interface routers. '
+ 'Interface router with id {} was not deleted.'.
+ format(router_id))
+
+ if len(router_ids) != 0:
+ for router_id in router_ids:
+ if not os_utils.remove_gateway_router(neutron_client, router_id):
+ logging.error('Fail to delete all gateway routers. '
+ 'Gateway router with id {} was not deleted.'.
+ format(router_id))
+
+ if len(subnet_ids) != 0:
+ for subnet_id in subnet_ids:
+ if not os_utils.delete_neutron_subnet(neutron_client, subnet_id):
+ logging.error('Fail to delete all subnets. '
+ 'Subnet with id {} was not deleted.'.
+ format(subnet_id))
+ return False
+
+ if len(router_ids) != 0:
+ for router_id in router_ids:
+ if not os_utils.delete_neutron_router(neutron_client, router_id):
+ logging.error('Fail to delete all routers. '
+ 'Router with id {} was not deleted.'.
+ format(router_id))
+ return False
+
+ if len(network_ids) != 0:
+ for network_id in network_ids:
+ if not os_utils.delete_neutron_net(neutron_client, network_id):
+ logging.error('Fail to delete all networks. '
+ 'Network with id {} was not deleted.'.
+ format(network_id))
+ return False
+ return True
+
+
+def cleanup_nova(nova_client, floatingip_ids, instance_ids, image_ids):
+
+ if len(floatingip_ids) != 0:
+ for floatingip_id in floatingip_ids:
+ if not os_utils.delete_floating_ip(nova_client, floatingip_id):
+ logging.error('Fail to delete all floating ips. '
+ 'Floating ip with id {} was not deleted.'.
+ format(floatingip_id))
+ return False
+
+ if len(instance_ids) != 0:
+ for instance_id in instance_ids:
+ if not os_utils.delete_instance(nova_client, instance_id):
+ logging.error('Fail to delete all instances. '
+ 'Instance with id {} was not deleted.'.
+ format(instance_id))
+ return False
+
+ if len(image_ids) != 0:
+ for image_id in image_ids:
+ if not os_utils.delete_glance_image(nova_client, image_id):
+ logging.error('Fail to delete all images. '
+ 'Image with id {} was not deleted.'.
+ format(image_id))
+ return False
+ return True