Simplified Router's interfaces removal

This commit is contained in:
Florent Flament
2014-02-21 12:57:12 +00:00
parent 5bdbc3edc6
commit 22914da240
2 changed files with 10 additions and 19 deletions

View File

@@ -289,23 +289,19 @@ class NeutronRouters(NeutronResources):
class NeutronInterfaces(NeutronResources):
def list(self):
def get_ports(router):
# Only considering "router_interface" ports (not gateways)
ports = [port for port in
self.client.list_ports(device_id=router['id'])['ports']
# Only considering "router_interface" ports
# (not gateways, neither unbound ports)
all_ports = [port for port in self.client.list_ports()['ports']
if port["device_owner"] == "network:router_interface"]
return [{'router_id': router['id'], 'interface_id': port['id']}
for port in ports ]
interfaces = [get_ports(rout) for rout in self.list_routers()]
return itertools.chain(*interfaces)
return filter(self._owned_resource, all_ports)
def delete(self, interface):
super(NeutronInterfaces, self).delete(interface)
self.client.remove_interface_router(interface['router_id'],
{'port_id':interface['interface_id']})
self.client.remove_interface_router(interface['device_id'],
{'port_id':interface['id']})
def resource_str(self, interface):
return "interfaces {} (id)".format(interface['interface_id'])
return "interfaces {} (id)".format(interface['id'])
class NeutronPorts(NeutronResources):

View File

@@ -261,6 +261,8 @@ class TestNeutronRouters(TestNeutronBase):
class TestNeutronInterfaces(TestNeutronBase):
IDS = client_fixtures.PORTS_IDS
def stub_list(self):
self.stub_list_routers()
self.stub_url('GET', parts=['v2.0', "ports.json?device_id={}".format(client_fixtures.ROUTERS_IDS[0])],
@@ -278,15 +280,8 @@ class TestNeutronInterfaces(TestNeutronBase):
super(TestNeutronInterfaces, self).setUp()
self.resources = ospurge.NeutronInterfaces(self.session)
# Special case there, interfaces ids can be accessed through
# port['interface_id']['id']
@httpretty.activate
def test_list(self):
self.stub_auth()
self.stub_list()
ids = [port['interface_id'] for port in self.resources.list()]
# Converting lists to sets, because order of element may have change
self.assertEqual(set(ids), set(client_fixtures.PORTS_IDS))
self._test_list()
def test_delete(self):
self._test_delete()