diff options
author | Christian Poessinger <christian@poessinger.com> | 2021-01-31 10:16:30 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2021-01-31 10:17:50 +0100 |
commit | af2a367f4fe2c631336d211d268fde2a1e7bf241 (patch) | |
tree | 9e856210997d3696494a023e0623144e238da5ea /smoketest/scripts | |
parent | 6c286fab17e812a4d9aeb45cc5b78066f9a132ab (diff) | |
download | vyos-1x-af2a367f4fe2c631336d211d268fde2a1e7bf241.tar.gz vyos-1x-af2a367f4fe2c631336d211d268fde2a1e7bf241.zip |
smoketest: vrf: verify interfaces can be bound/unbound
(cherry picked from commit 33e10ccc33e3b25dcdd3d4ee57bfdc4e2c331a6e)
Diffstat (limited to 'smoketest/scripts')
-rwxr-xr-x | smoketest/scripts/cli/test_vrf.py | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/smoketest/scripts/cli/test_vrf.py b/smoketest/scripts/cli/test_vrf.py index 5270e758a..749863476 100755 --- a/smoketest/scripts/cli/test_vrf.py +++ b/smoketest/scripts/cli/test_vrf.py @@ -21,14 +21,29 @@ from netifaces import interfaces from vyos.configsession import ConfigSession from vyos.configsession import ConfigSessionError +from vyos.ifconfig import Interface +from vyos.ifconfig import Section from vyos.util import read_file from vyos.validate import is_intf_addr_assigned -from vyos.ifconfig import Interface base_path = ['vrf'] vrfs = ['red', 'green', 'blue', 'foo-bar', 'baz_foo'] class VRFTest(unittest.TestCase): + _interfaces = [] + + @classmethod + def setUpClass(cls): + # we need to filter out VLAN interfaces identified by a dot (.) + # in their name - just in case! + if 'TEST_ETH' in os.environ: + tmp = os.environ['TEST_ETH'].split() + cls._interfaces = tmp + else: + for tmp in Section.interfaces('ethernet'): + if not '.' in tmp: + cls._interfaces.append(tmp) + def setUp(self): self.session = ConfigSession(os.getpid()) @@ -120,5 +135,26 @@ class VRFTest(unittest.TestCase): with self.assertRaises(ConfigSessionError): self.session.commit() + def test_vrf_assign_interface(self): + vrf = vrfs[0] + table = '5000' + self.session.set(['vrf', 'name', vrf, 'table', table]) + + for interface in self._interfaces: + section = Section.section(interface) + self.session.set(['interfaces', section, interface, 'vrf', vrf]) + + # commit changes + self.session.commit() + + # Verify & cleanup + for interface in self._interfaces: + # os.readlink resolves to: '../../../../../virtual/net/foovrf' + tmp = os.readlink(f'/sys/class/net/{interface}/master').split('/')[-1] + self.assertEqual(tmp, vrf) + # cleanup + section = Section.section(interface) + self.session.delete(['interfaces', section, interface, 'vrf']) + if __name__ == '__main__': unittest.main(verbosity=2, failfast=True) |