Skip to content

Commit b6df26f

Browse files
committed
T7121: add test_commit wrapper and test script
1 parent 21d960b commit b6df26f

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

python/vyos/configtree.py

+13
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,19 @@ def show_commit_data(active_tree, proposed_tree, libpath=LIBPATH):
539539
return res.decode()
540540

541541

542+
def test_commit(active_tree, proposed_tree, libpath=LIBPATH):
543+
if not (
544+
isinstance(active_tree, ConfigTree) and isinstance(proposed_tree, ConfigTree)
545+
):
546+
raise TypeError('Arguments must be instances of ConfigTree')
547+
548+
__lib = cdll.LoadLibrary(libpath)
549+
__test_commit = __lib.test_commit
550+
__test_commit.argtypes = [c_void_p, c_void_p]
551+
552+
__test_commit(active_tree._get_config(), proposed_tree._get_config())
553+
554+
542555
def reference_tree_to_json(from_dir, to_file, internal_cache='', libpath=LIBPATH):
543556
try:
544557
__lib = cdll.LoadLibrary(libpath)

src/helpers/test_commit.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright (C) 2025 VyOS maintainers and contributors
4+
#
5+
# This program is free software; you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License version 2 or later as
7+
# published by the Free Software Foundation.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
#
17+
#
18+
# This script is used to test execution of the commit algorithm by vyos-commitd
19+
20+
from pathlib import Path
21+
from argparse import ArgumentParser
22+
from datetime import datetime
23+
24+
from vyos.configtree import ConfigTree
25+
from vyos.configtree import test_commit
26+
27+
28+
parser = ArgumentParser(
29+
description='Execute commit priority queue'
30+
)
31+
parser.add_argument(
32+
'--active-config', help='Path to the active configuration file', required=True
33+
)
34+
parser.add_argument(
35+
'--proposed-config', help='Path to the proposed configuration file', required=True
36+
)
37+
args = parser.parse_args()
38+
39+
active_arg = args.active_config
40+
proposed_arg = args.proposed_config
41+
42+
active = ConfigTree(Path(active_arg).read_text())
43+
proposed = ConfigTree(Path(proposed_arg).read_text())
44+
45+
46+
time_begin_commit = datetime.now()
47+
test_commit(active, proposed)
48+
time_end_commit = datetime.now()
49+
print(f'commit time: {time_end_commit - time_begin_commit}')

0 commit comments

Comments
 (0)