From 3907233b51e721ea894f383b51e42118a2012d78 Mon Sep 17 00:00:00 2001
From: Christian Poessinger <christian@poessinger.com>
Date: Sun, 10 Jul 2022 22:27:29 +0200
Subject: smoketest: bond: add testcase for source-interface re-use

A bond member is not allowed to also be used as a source interface for
e.g. PPPoE or MACsec.

(cherry picked from commit 6fca4854aa2e950795ff0411abe4601f86bdeac0)
---
 smoketest/scripts/cli/test_interfaces_bonding.py | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

(limited to 'smoketest')

diff --git a/smoketest/scripts/cli/test_interfaces_bonding.py b/smoketest/scripts/cli/test_interfaces_bonding.py
index 9bb561275..a6e5ea59c 100755
--- a/smoketest/scripts/cli/test_interfaces_bonding.py
+++ b/smoketest/scripts/cli/test_interfaces_bonding.py
@@ -49,7 +49,7 @@ class BondingInterfaceTest(BasicInterfaceTest.TestCase):
                 if not '.' in tmp:
                     cls._members.append(tmp)
 
-        cls._options['bond0'] = []
+        cls._options = {'bond0' : []}
         for member in cls._members:
             cls._options['bond0'].append(f'member interface {member}')
         cls._interfaces = list(cls._options)
@@ -165,6 +165,26 @@ class BondingInterfaceTest(BasicInterfaceTest.TestCase):
 
         self.cli_commit()
 
+    def test_bonding_source_interface(self):
+        # Re-use member interface that is already a source-interface
+        bond = 'bond99'
+        pppoe = 'pppoe98756'
+        member = next(iter(self._members))
+
+        self.cli_set(self._base_path + [bond, 'member', 'interface', member])
+        self.cli_set(['interfaces', 'pppoe', pppoe, 'source-interface', member])
+
+        # check validate() - can not add interface to bond, it is the source-interface of ...
+        with self.assertRaises(ConfigSessionError):
+            self.cli_commit()
+
+        self.cli_delete(['interfaces', 'pppoe', pppoe])
+        self.cli_commit()
+
+        # verify config
+        slaves = read_file(f'/sys/class/net/{bond}/bonding/slaves').split()
+        self.assertIn(member, slaves)
+
     def test_bonding_uniq_member_description(self):
         ethernet_path = ['interfaces', 'ethernet']
         for interface in self._interfaces:
-- 
cgit v1.2.3