Skip to content

Commit

Permalink
Merge pull request #1356 from anarkiwi/master
Browse files Browse the repository at this point in the history
Catch missing route config.
  • Loading branch information
anarkiwi committed Dec 4, 2017
2 parents 314052f + 426ec72 commit 438b7a4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
21 changes: 12 additions & 9 deletions faucet/vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,18 @@ def check_config(self):
assert self.bgp_neighbor_as

if self.routes:
self.routes = [route['route'] for route in self.routes]
for route in self.routes:
try:
ip_gw = ipaddress.ip_address(btos(route['ip_gw']))
ip_dst = ipaddress.ip_network(btos(route['ip_dst']))
except (ValueError, AttributeError, TypeError) as err:
assert False, 'Invalid IP address in route: %s' % err
assert ip_gw.version == ip_dst.version
self.dyn_routes_by_ipv[ip_gw.version][ip_dst] = ip_gw
try:
self.routes = [route['route'] for route in self.routes]
for route in self.routes:
try:
ip_gw = ipaddress.ip_address(btos(route['ip_gw']))
ip_dst = ipaddress.ip_network(btos(route['ip_dst']))
except (ValueError, AttributeError, TypeError) as err:
assert False, 'Invalid IP address in route: %s' % err
assert ip_gw.version == ip_dst.version
self.dyn_routes_by_ipv[ip_gw.version][ip_dst] = ip_gw
except KeyError:
assert False, 'missing route config'

@staticmethod
def vid_valid(vid):
Expand Down
21 changes: 20 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def test_port_range_valid_config(self):
dp = dps[0]
self.assertEqual(len(dp.ports), 8)
self.assertTrue(all([p.permanent_learn for p in dp.ports.values() if p.number < 9]))
self.assertTrue(all([p.max_hosts==2 for p in dp.ports.values() if p.number > 1]))
self.assertTrue(all([p.max_hosts == 2 for p in dp.ports.values() if p.number > 1]))
self.assertTrue(dp.ports[1].max_hosts == 4)
self.assertEqual(dp.ports[1].description, "video conf")

Expand Down Expand Up @@ -713,11 +713,30 @@ def test_invalid_char(self):
def test_perm_denied(self):

def unreadable():
"""Make config unreadable."""
os.chmod(self.conf_file_name(), 0)

config = ''
self.check_config_failure(config, cp.dp_parser, before_function=unreadable)

def test_missing_route_config(self):
config = """
vlans:
office:
vid: 100
routes:
- route:
ip_dst: '192.168.0.0/24'
dps:
sw1:
dp_id: 0x1
interfaces:
1:
native_vlan: office
"""

self.check_config_failure(config, cp.dp_parser)


if __name__ == "__main__":
unittest.main()

0 comments on commit 438b7a4

Please sign in to comment.