Handle empty bridge case in OVSBridge.get_ports_attributes
Before this patch, get_ports_attributes would call
get_port_name_list. In the case of an empty bridge,
get_port_name_list would return an empty list and feed that
in to ovsdb.db_list, thereby returning all ports instead of
no ports.
Change-Id: I5a91028c59d71943b7cef86a94fa6ab1cc3d667c
Closes-Bug: #1499821
(cherry picked from commit 9c3e3a0fce
)
This commit is contained in:
parent
7c5e0b6112
commit
a43e35b4ce
|
@ -343,6 +343,8 @@ class OVSBridge(BaseOVS):
|
|||
check_error=True, log_errors=True,
|
||||
if_exists=False):
|
||||
port_names = ports or self.get_port_name_list()
|
||||
if not port_names:
|
||||
return []
|
||||
return (self.ovsdb.db_list(table, port_names, columns=columns,
|
||||
if_exists=if_exists).
|
||||
execute(check_error=check_error, log_errors=log_errors))
|
||||
|
|
|
@ -232,6 +232,17 @@ class OVSBridgeTestCase(OVSBridgeTestBase):
|
|||
expected = set([vif_ports[0].vif_id])
|
||||
self.assertEqual(expected, ports)
|
||||
|
||||
def test_get_vif_port_set_on_empty_bridge_returns_empty_set(self):
|
||||
# Create a port on self.br
|
||||
self.create_ovs_vif_port()
|
||||
|
||||
# Create another, empty bridge
|
||||
br_2 = self.useFixture(net_helpers.OVSBridgeFixture()).bridge
|
||||
|
||||
# Assert that get_vif_port_set on an empty bridge returns an empty set,
|
||||
# and does not return the other bridge's ports.
|
||||
self.assertEqual(set(), br_2.get_vif_port_set())
|
||||
|
||||
def test_get_ports_attributes(self):
|
||||
port_names = [self.create_ovs_port()[0], self.create_ovs_port()[0]]
|
||||
db_ports = self.br.get_ports_attributes('Interface', columns=['name'])
|
||||
|
|
Loading…
Reference in New Issue