summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2025-03-16 21:10:07 -0500
committerJohn Estabrook <jestabro@vyos.io>2025-03-16 23:55:12 -0500
commitb6df26f89df776bb63e79203c06744f9bed65c72 (patch)
tree71d834f122886bf9d4ac887749aa425dfc8bf012
parent21d960b34da2cd8b98be1ff59c416e434c31b1e1 (diff)
downloadvyos-1x-b6df26f89df776bb63e79203c06744f9bed65c72.tar.gz
vyos-1x-b6df26f89df776bb63e79203c06744f9bed65c72.zip
T7121: add test_commit wrapper and test script
-rw-r--r--python/vyos/configtree.py13
-rwxr-xr-xsrc/helpers/test_commit.py49
2 files changed, 62 insertions, 0 deletions
diff --git a/python/vyos/configtree.py b/python/vyos/configtree.py
index c1db0782b..83954327c 100644
--- a/python/vyos/configtree.py
+++ b/python/vyos/configtree.py
@@ -539,6 +539,19 @@ def show_commit_data(active_tree, proposed_tree, libpath=LIBPATH):
return res.decode()
+def test_commit(active_tree, proposed_tree, libpath=LIBPATH):
+ if not (
+ isinstance(active_tree, ConfigTree) and isinstance(proposed_tree, ConfigTree)
+ ):
+ raise TypeError('Arguments must be instances of ConfigTree')
+
+ __lib = cdll.LoadLibrary(libpath)
+ __test_commit = __lib.test_commit
+ __test_commit.argtypes = [c_void_p, c_void_p]
+
+ __test_commit(active_tree._get_config(), proposed_tree._get_config())
+
+
def reference_tree_to_json(from_dir, to_file, internal_cache='', libpath=LIBPATH):
try:
__lib = cdll.LoadLibrary(libpath)
diff --git a/src/helpers/test_commit.py b/src/helpers/test_commit.py
new file mode 100755
index 000000000..00a413687
--- /dev/null
+++ b/src/helpers/test_commit.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) 2025 VyOS maintainers and contributors
+#
+# 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/>.
+#
+#
+# This script is used to test execution of the commit algorithm by vyos-commitd
+
+from pathlib import Path
+from argparse import ArgumentParser
+from datetime import datetime
+
+from vyos.configtree import ConfigTree
+from vyos.configtree import test_commit
+
+
+parser = ArgumentParser(
+ description='Execute commit priority queue'
+)
+parser.add_argument(
+ '--active-config', help='Path to the active configuration file', required=True
+)
+parser.add_argument(
+ '--proposed-config', help='Path to the proposed configuration file', required=True
+)
+args = parser.parse_args()
+
+active_arg = args.active_config
+proposed_arg = args.proposed_config
+
+active = ConfigTree(Path(active_arg).read_text())
+proposed = ConfigTree(Path(proposed_arg).read_text())
+
+
+time_begin_commit = datetime.now()
+test_commit(active, proposed)
+time_end_commit = datetime.now()
+print(f'commit time: {time_end_commit - time_begin_commit}')