summaryrefslogtreecommitdiff
path: root/scripts/cli/test_interfaces_pppoe.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-06-28 20:22:13 +0200
committerChristian Poessinger <christian@poessinger.com>2020-06-28 20:22:48 +0200
commit256f5bc1bd1bf80e323d7d7db5ba3c9b7d3463a1 (patch)
tree63493d955b725f3f7f1636a81add30e7d038e8f0 /scripts/cli/test_interfaces_pppoe.py
parent4ad5cd436f1082ef5416c03a54730e710cc4441c (diff)
downloadvyos-1x-256f5bc1bd1bf80e323d7d7db5ba3c9b7d3463a1.tar.gz
vyos-1x-256f5bc1bd1bf80e323d7d7db5ba3c9b7d3463a1.zip
interfaces: pppoe: add DHCPv6-PD testcase
Diffstat (limited to 'scripts/cli/test_interfaces_pppoe.py')
-rwxr-xr-xscripts/cli/test_interfaces_pppoe.py92
1 files changed, 76 insertions, 16 deletions
diff --git a/scripts/cli/test_interfaces_pppoe.py b/scripts/cli/test_interfaces_pppoe.py
index 9a9a1512c..0ad50a2bc 100755
--- a/scripts/cli/test_interfaces_pppoe.py
+++ b/scripts/cli/test_interfaces_pppoe.py
@@ -23,6 +23,7 @@ from vyos.configsession import ConfigSession, ConfigSessionError
from vyos.util import read_file
config_file = '/etc/ppp/peers/{}'
+dhcp6c_config_file = '/run/dhcp6c/dhcp6c.{}.conf'
base_path = ['interfaces', 'pppoe']
def get_config_value(interface, key):
@@ -32,10 +33,20 @@ def get_config_value(interface, key):
return list(line.split())
return []
+def get_dhcp6c_config_value(interface, key):
+ tmp = read_file(dhcp6c_config_file.format(interface))
+ tmp = re.findall(r'\n?{}\s+(.*)'.format(key), tmp)
+
+ out = []
+ for item in tmp:
+ out.append(item.replace(';',''))
+ return out
+
class PPPoEInterfaceTest(unittest.TestCase):
def setUp(self):
self.session = ConfigSession(os.getpid())
- self._interfaces = ['pppoe0', 'pppoe1', 'pppoe2']
+ self._interfaces = ['pppoe0', 'pppoe50']
+ self._source_interface = 'eth0'
def tearDown(self):
self.session.delete(base_path)
@@ -44,24 +55,21 @@ class PPPoEInterfaceTest(unittest.TestCase):
def test_pppoe_1(self):
""" Check if PPPoE dialer can be configured and runs """
- # ensure source-interface is available
- source_interface = 'eth0'
- self.session.set(['interfaces', 'ethernet', source_interface])
-
for interface in self._interfaces:
user = 'VyOS-user-' + interface
passwd = 'VyOS-passwd-' + interface
+ mtu = '1400'
self.session.set(base_path + [interface, 'authentication', 'user', user])
self.session.set(base_path + [interface, 'authentication', 'password', passwd])
self.session.set(base_path + [interface, 'default-route', 'auto'])
- self.session.set(base_path + [interface, 'mtu', '1400'])
+ self.session.set(base_path + [interface, 'mtu', mtu])
self.session.set(base_path + [interface, 'no-peer-dns'])
# check validate() - a source-interface is required
with self.assertRaises(ConfigSessionError):
self.session.commit()
- self.session.set(base_path + [interface, 'source-interface', 'eth0'])
+ self.session.set(base_path + [interface, 'source-interface', self._source_interface])
# commit changes
self.session.commit()
@@ -71,15 +79,14 @@ class PPPoEInterfaceTest(unittest.TestCase):
user = 'VyOS-user-' + interface
password = 'VyOS-passwd-' + interface
- cur_mtu = get_config_value(interface, 'mtu')[1]
- cur_user = get_config_value(interface, 'user')[1].replace('"', '')
- cur_password = get_config_value(interface, 'password')[1].replace('"', '')
- cur_ifname = get_config_value(interface, 'ifname')[1]
-
- self.assertTrue(cur_mtu == '1400')
- self.assertTrue(cur_user == user)
- self.assertTrue(cur_password == password)
- self.assertTrue(cur_ifname == interface)
+ tmp = get_config_value(interface, 'mtu')[1]
+ self.assertTrue(tmp in mtu)
+ tmp = get_config_value(interface, 'user')[1].replace('"', '')
+ self.assertTrue(tmp in user)
+ tmp = get_config_value(interface, 'password')[1].replace('"', '')
+ self.assertTrue(tmp in password)
+ tmp = get_config_value(interface, 'ifname')[1]
+ self.assertTrue(tmp in interface)
# Check if ppp process is running in the interface in question
running = False
@@ -90,5 +97,58 @@ class PPPoEInterfaceTest(unittest.TestCase):
self.assertTrue(running)
+ def test_pppoe_dhcpv6pd(self):
+ """ Check if PPPoE dialer can be configured and runs """
+ address = '1'
+ sla_id = '0'
+ sla_len = '8'
+ for interface in self._interfaces:
+ self.session.set(base_path + [interface, 'authentication', 'user', 'vyos'])
+ self.session.set(base_path + [interface, 'authentication', 'password', 'vyos'])
+ self.session.set(base_path + [interface, 'default-route', 'none'])
+ self.session.set(base_path + [interface, 'no-peer-dns'])
+ self.session.set(base_path + [interface, 'source-interface', self._source_interface])
+
+ # prefix delegation stuff
+ dhcpv6_pd_base = base_path + [interface, 'dhcpv6-options', 'prefix-delegation']
+ self.session.set(dhcpv6_pd_base + ['length', '56'])
+ self.session.set(dhcpv6_pd_base + ['interface', self._source_interface, 'address', address])
+ self.session.set(dhcpv6_pd_base + ['interface', self._source_interface, 'sla-id', sla_id])
+ self.session.set(dhcpv6_pd_base + ['interface', self._source_interface, 'sla-len', sla_len])
+
+ # commit changes
+ self.session.commit()
+
+ # verify "normal" PPPoE value - 1492 is default MTU
+ tmp = get_config_value(interface, 'mtu')[1]
+ self.assertTrue(tmp in '1492')
+ tmp = get_config_value(interface, 'user')[1].replace('"', '')
+ self.assertTrue(tmp in 'vyos')
+ tmp = get_config_value(interface, 'password')[1].replace('"', '')
+ self.assertTrue(tmp in 'vyos')
+
+ # verify DHCPv6 prefix delegation
+ # will return: ['delegation', '::/56 infinity;']
+ tmp = get_dhcp6c_config_value(interface, 'prefix')[1].split()[0] # mind the whitespace
+ self.assertTrue(tmp in '::/56')
+ tmp = get_dhcp6c_config_value(interface, 'prefix-interface')[0].split()[0]
+ self.assertTrue(tmp in self._source_interface)
+ tmp = get_dhcp6c_config_value(interface, 'ifid')[0]
+ self.assertTrue(tmp in address)
+ tmp = get_dhcp6c_config_value(interface, 'sla-id')[0]
+ self.assertTrue(tmp in sla_id)
+ tmp = get_dhcp6c_config_value(interface, 'sla-len')[0]
+ self.assertTrue(tmp in sla_len)
+
+ # Check if ppp process is running in the interface in question
+ running = False
+ for p in process_iter():
+ if "pppd" in p.name():
+ running = True
+ self.assertTrue(running)
+
+ # We can not check if wide-dhcpv6 process is running as it is started
+ # after the PPP interface gets a link to the ISP
+
if __name__ == '__main__':
unittest.main()