Files
mikrotik-olsr/tests/test_container.py
T
feedc0de 22cf76deaf
Check source / check (push) Successful in 16s
Build OLSR container / image (push) Failing after 8m35s
Build NPK and multiarch container releases with native next-hop groundwork
2026-11-19 08:44:02 +01:00

55 lines
2.2 KiB
Python

import importlib.util
from pathlib import Path
import unittest
ROOT = Path(__file__).resolve().parents[1]
def module(name, file):
spec = importlib.util.spec_from_file_location(name, ROOT / 'container' / file)
result = importlib.util.module_from_spec(spec)
spec.loader.exec_module(result)
return result
start = module('container_start', 'start.py')
filters = module('container_filter', 'routeros-filter.py')
class ContainerRouting(unittest.TestCase):
def env(self):
return dict(OLSR_NODE_IP='10.12.4.173', BGP_LOCAL_IP='172.31.255.2',
BGP_PEER_IP='172.31.255.1')
def test_two_links_keep_identity(self):
env = self.env()
env['OLSR_LINKS'] = '[{"interface":"mesh4","address":"10.12.4.173","id":4},{"interface":"mesh5","address":"10.12.5.173","id":5}]'
olsr, bird = start.configuration(env)
self.assertIn('Interface "mesh4"', olsr)
self.assertIn('Interface "mesh5"', olsr)
self.assertIn('ifname = "mesh4" then bgp_community.add((64514, 4))', bird)
self.assertIn('ifname = "mesh5" then bgp_community.add((64514, 5))', bird)
self.assertNotIn('next hop self', bird)
self.assertIn('bgp_next_hop = gw', bird)
rule = filters.rule([(4, 'vlan4'), (5, 'ether2')], ['10.0.0.0/8'])
self.assertIn('set gw-interface vlan4', rule)
self.assertIn('set gw-interface ether2', rule)
self.assertTrue(rule.endswith('reject;'))
def test_ambiguous_links_rejected(self):
env = self.env()
env['OLSR_LINKS'] = '[{"interface":"a","address":"10.1.1.1","id":1},{"interface":"b","address":"10.1.1.2","id":1}]'
with self.assertRaises(ValueError):
start.configuration(env)
def test_no_default_or_injected_interface(self):
for links, prefixes in [([(1, 'vlan4')], ['0.0.0.0/0']),
([(1, 'vlan4; accept;')], ['10.0.0.0/8'])]:
with self.assertRaises(ValueError):
filters.rule(links, prefixes)
def test_hna_stays_blocked(self):
env = dict(self.env(), OLSR_HNA='10.1.2.0/24')
with self.assertRaises(ValueError):
start.configuration(env)