Skip to content

Commit

Permalink
Show an error when *_bridge_ports is not a list
Browse files Browse the repository at this point in the history
Closes-Bug: #2020378
Change-Id: I000ae473bb759e19b48ecefdbf5d5dc19c833088
Signed-off-by: Maksim Malchuk <[email protected]>
(cherry picked from commit 9b58320)
  • Loading branch information
mmalchuk committed May 24, 2023
1 parent cad9830 commit 8fb45c0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion kayobe/plugins/filter/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,11 @@ def net_libvirt_network_name(context, name, inventory_hostname=None):

@jinja2.contextfilter
def net_bridge_ports(context, name, inventory_hostname=None):
return net_attr(context, name, 'bridge_ports', inventory_hostname)
ports = net_attr(context, name, 'bridge_ports', inventory_hostname)
if ports and not isinstance(ports, list):
raise errors.AnsibleFilterError("Bridge ports for network '%s' should"
" be a list", name)
return ports


net_bond_mode = _make_attr_filter('bond_mode')
Expand Down
6 changes: 6 additions & 0 deletions kayobe/tests/unit/plugins/filter/test_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import jinja2

from ansible import errors
from kayobe.plugins.filter import networks


Expand Down Expand Up @@ -197,3 +198,8 @@ def test_get_ovs_veths_bridge_vlan_multiple_mtu(self):
}
]
self.assertEqual(expected, veths)

def test_ensure_bridge_ports_is_list(self):
self._update_context({"net3_bridge_ports": "ens3"})
self.assertRaises(errors.AnsibleFilterError, networks.net_bridge_ports,
self.context, "net3")

0 comments on commit 8fb45c0

Please sign in to comment.