summaryrefslogtreecommitdiff
path: root/smoketest/scripts/cli
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-01-31 10:16:30 +0100
committerChristian Poessinger <christian@poessinger.com>2021-01-31 10:16:30 +0100
commit33e10ccc33e3b25dcdd3d4ee57bfdc4e2c331a6e (patch)
tree5680ef91ff992fd3faeec36dca620883561fe06e /smoketest/scripts/cli
parentca202f30fc5fad4c2fd99064ad0eba2643e71a5f (diff)
downloadvyos-1x-33e10ccc33e3b25dcdd3d4ee57bfdc4e2c331a6e.tar.gz
vyos-1x-33e10ccc33e3b25dcdd3d4ee57bfdc4e2c331a6e.zip
smoketest: vrf: verify interfaces can be bound/unbound
Diffstat (limited to 'smoketest/scripts/cli')
-rwxr-xr-xsmoketest/scripts/cli/test_vrf.py38
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)