diff options
| author | Christian Breunig <christian@breunig.cc> | 2026-09-10 17:26:11 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-09-10 17:26:11 +0200 |
| commit | 148dd2b2f5ac5f0cd3671650aa11100fc293b588 (patch) | |
| tree | cbcfc483d4699314b411ebb99448363051aab0c0 /src | |
| parent | b656e77a1c9a206edf35c361f4fcb1940cd5be91 (diff) | |
| parent | aa3f1c548198a1110d67385f19ccc910c5c48be8 (diff) | |
| download | vyos-1x-148dd2b2f5ac5f0cd3671650aa11100fc293b588.tar.gz vyos-1x-148dd2b2f5ac5f0cd3671650aa11100fc293b588.zip | |
Merge pull request #5454 from c-po/bond-fix-add-member
bond: T9269: keep the bond MAC when appending a member interface
Diffstat (limited to 'src')
| -rw-r--r-- | src/tests/test_configdict.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/tests/test_configdict.py b/src/tests/test_configdict.py new file mode 100644 index 000000000..5e1aba7c0 --- /dev/null +++ b/src/tests/test_configdict.py @@ -0,0 +1,70 @@ +# Copyright (C) VyOS Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +from unittest import TestCase +from unittest.mock import patch + +from vyos.configdict import leaf_node_changed + + +class TestLeafNodeChanged(TestCase): + """leaf_node_changed() reports the old value(s) of an altered leaf node. + + get_value_diff() reads the JSON rendering of the config tree, where a + multi node holding a single value is a plain string and only becomes a + list once it holds several values. A caller deleting whatever comes back + must therefore never see a value that is still configured. + """ + + def _changed(self, new, old): + # leaf_node_changed() imports get_config_diff() at call time + with patch('vyos.configdiff.get_config_diff') as get_diff: + get_diff.return_value.get_value_diff.return_value = (new, old) + return leaf_node_changed(None, ['some', 'path']) + + def test_unchanged(self): + self.assertIsNone(self._changed('eth1', 'eth1')) + self.assertIsNone(self._changed(['eth1', 'eth2'], ['eth1', 'eth2'])) + + def test_value_replaced(self): + self.assertEqual(self._changed('eth2', 'eth1'), ['eth1']) + + def test_value_deleted(self): + self.assertEqual(self._changed(None, 'eth1'), ['eth1']) + self.assertEqual(self._changed(None, ['eth1', 'eth2']), ['eth1', 'eth2']) + + def test_value_added(self): + self.assertEqual(self._changed('eth1', None), []) + + def test_valueless_node(self): + self.assertTrue(self._changed(None, {})) + self.assertTrue(self._changed({}, None)) + + def test_appended_to_single_valued_multi_node(self): + # T9269: the single configured value renders as a string while the two + # configured values render as a list. Nothing was removed here - adding + # a second bond member used to release the first one because this + # returned ['eth1'] + self.assertEqual(self._changed(['eth1', 'eth2'], 'eth1'), []) + + def test_appended_to_multi_valued_multi_node(self): + self.assertEqual(self._changed(['eth1', 'eth2', 'eth3'], ['eth1', 'eth2']), []) + + def test_replaced_in_multi_node(self): + self.assertEqual(self._changed(['eth2', 'eth3'], 'eth1'), ['eth1']) + self.assertEqual(self._changed(['eth1', 'eth3'], ['eth1', 'eth2']), ['eth2']) + + def test_shrunk_to_single_value(self): + # and the reverse representation change: list back to plain string + self.assertEqual(self._changed('eth1', ['eth1', 'eth2']), ['eth2']) |
