Skip to content

Commit

Permalink
Merge "Fix cleaning up neutron resources"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Jul 24, 2014
2 parents b1692a0 + f00dd21 commit 7501233
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
33 changes: 15 additions & 18 deletions rally/benchmark/context/cleanup/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,35 +119,32 @@ def delete_keypairs(nova):


def delete_neutron_resources(neutron, project_uuid):
search_opts = {"tenant_id": project_uuid}
# Ports
for port in neutron.list_ports()["ports"]:
if port["tenant_id"] == project_uuid:

# Detach routers
for fip in port["fixed_ips"]:
neutron.remove_interface_router(
port["device_id"], {
"subnet_id": fip["subnet_id"]
})
for port in neutron.list_ports(**search_opts)["ports"]:
# Detach routers
if port["device_owner"] == "network:router_interface":
neutron.remove_interface_router(
port["device_id"], {
"port_id": port["id"]
})
else:
try:
neutron.delete_port(port["id"])
except neutron_exceptions.PortNotFoundClient:
# Port can be already auto-deleted, skip silently
pass
# Routers
for router in neutron.list_routers()["routers"]:
if router["tenant_id"] == project_uuid:
neutron.delete_router(router["id"])
for router in neutron.list_routers(**search_opts)["routers"]:
neutron.delete_router(router["id"])

# Subnets
for subnet in neutron.list_subnets()["subnets"]:
if subnet["tenant_id"] == project_uuid:
neutron.delete_subnet(subnet["id"])
for subnet in neutron.list_subnets(**search_opts)["subnets"]:
neutron.delete_subnet(subnet["id"])

# Networks
for network in neutron.list_networks()["networks"]:
if network["tenant_id"] == project_uuid:
neutron.delete_network(network["id"])
for network in neutron.list_networks(**search_opts)["networks"]:
neutron.delete_network(network["id"])


def delete_ceilometer_resources(ceilometer, project_uuid):
Expand Down
26 changes: 18 additions & 8 deletions tests/fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,12 @@ def __init__(self, **kwargs):
self.format = "json"
self.version = "2.0"

@staticmethod
def _filter(resource_list, search_opts):
return [res for res in resource_list
if all(res[field] == value
for field, value in search_opts.items())]

def add_interface_router(self, router_id, data):
subnet_id = data["subnet_id"]

Expand Down Expand Up @@ -766,17 +772,21 @@ def delete_subnet(self, subnet_id):
del self.__subnets[subnet_id]
return ""

def list_networks(self):
return {"networks": self.__networks.values()}
def list_networks(self, **search_opts):
nets = self._filter(self.__networks.values(), search_opts)
return {"networks": nets}

def list_ports(self):
return {"ports": self.__ports.values()}
def list_ports(self, **search_opts):
ports = self._filter(self.__ports.values(), search_opts)
return {"ports": ports}

def list_routers(self):
return {"routers": self.__routers.values()}
def list_routers(self, **search_opts):
routers = self._filter(self.__routers.values(), search_opts)
return {"routers": routers}

def list_subnets(self):
return {"subnets": self.__subnets.values()}
def list_subnets(self, **search_opts):
subnets = self._filter(self.__subnets.values(), search_opts)
return {"subnets": subnets}

def remove_interface_router(self, router_id, data):
subnet_id = data["subnet_id"]
Expand Down

0 comments on commit 7501233

Please sign in to comment.