Skip to content

Commit d454059

Browse files
author
Staging script
committed
Staging PR 2876
1 parent f5b81c0 commit d454059

File tree

2 files changed

+108
-4
lines changed

2 files changed

+108
-4
lines changed

kernelci/api/helper.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,18 @@ def should_create_node(self, rules, node, parent=None):
391391
def _fsanitize_node_fields(self, node, field_name):
392392
"""
393393
Sanitize node fields to escape curly braces
394+
We need to walk over multiple levels of the node dict to find the field
395+
and escape the curly braces.
394396
"""
395-
if field_name in node:
396-
# double each found bracket to escape it
397-
node[field_name] = node[field_name].replace('}', '}}')
398-
node[field_name] = node[field_name].replace('{', '{{')
397+
if isinstance(node, dict):
398+
for k, val in node.items():
399+
if k == field_name and isinstance(val, str):
400+
node[k] = val.replace('}', '}}').replace('{', '{{')
401+
else:
402+
self._fsanitize_node_fields(val, field_name)
403+
elif isinstance(node, list):
404+
for item in node:
405+
self._fsanitize_node_fields(item, field_name)
399406
return node
400407

401408
def create_job_node(self, job_config, input_node,

tests/api/test_apihelper.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# SPDX-License-Identifier: LGPL-2.1-or-later
2+
#
3+
# Copyright (C) 2025 Collabora Limited
4+
# Author: Denys Fedoryshchenko <[email protected]>
5+
6+
# pylint: disable=C0301
7+
8+
""" Test the APIHelper class """
9+
10+
from kernelci.api.helper import APIHelper
11+
import kernelci.api
12+
13+
14+
def test_apihelper():
15+
"""
16+
Test the APIHelper class
17+
(i know i should not be testing private methods, but this is it for now)
18+
"""
19+
node = {
20+
"id": "6823c3bafef071f536b6ec3c",
21+
"kind": "checkout",
22+
"name": "checkout",
23+
"path": ["checkout"],
24+
"group": None,
25+
"parent": None,
26+
"state": "done",
27+
"result": "pass",
28+
"artifacts": {
29+
"tarball": "https://files.kernelci.org/linux-mainline-master-v6.15-rc6-52-g9f35e33144ae5.tar.gz" # noqa: E501
30+
},
31+
"data": {
32+
"kernel_revision": {
33+
"tree": "mainline",
34+
"url": "https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git",
35+
"branch": "master",
36+
"commit": "9f35e33144ae5377d6a8de86dd3bd4d995c6ac65",
37+
"describe": "v6.15-rc6-52-g9f35e33144ae5",
38+
"version": {
39+
"version": 6,
40+
"patchlevel": 15,
41+
"extra": "-rc6-52-g9f35e33144ae5",
42+
},
43+
"commit_tags": [],
44+
"commit_message": (
45+
"x86/its: Fix build errors when CONFIG_MODULES=n\n\n"
46+
"Fix several build errors when CONFIG_MODULES=n, including the following:\n\n"
47+
"../arch/x86/kernel/alternative.c:195:25: error: incomplete definition of type 'struct module'\n" # noqa: E501
48+
" 195 | for (int i = 0; i < mod->its_num_pages; i++) {\n\n"
49+
'Fixes: 872df34d7c51 ("x86/its: Use dynamic thunks for indirect branches")\n'
50+
51+
"Signed-off-by: Eric Biggers \n"
52+
"Acked-by: Dave Hansen \n"
53+
"Tested-by: Steven Rostedt (Google) \n"
54+
"Reviewed-by: Alexandre Chartre \n"
55+
"Signed-off-by: Linus Torvalds "
56+
),
57+
"tip_of_branch": True,
58+
},
59+
"architecture_filter": ["x86_64", "arm64", "arm"],
60+
},
61+
"debug": {},
62+
"jobfilter": None,
63+
"platform_filter": [],
64+
"created": "2025-05-13T22:12:10.336000",
65+
"updated": "2025-05-13T22:26:20.157000",
66+
"timeout": "2025-05-13T23:12:10.327000",
67+
"holdoff": "2025-05-13T22:25:56.224000",
68+
"owner": "production",
69+
"submitter": "service:pipeline",
70+
"treeid": "c1c7b00a59158432a35f2458f745bfbf142bf513801766850c30f65fdb86d5ab",
71+
"user_groups": [],
72+
"processed_by_kcidb_bridge": True,
73+
}
74+
75+
configs = kernelci.config.load("tests/configs/api-configs.yaml")
76+
api_config = configs["api"]["docker-host"]
77+
testcfg = kernelci.api.get_api(api_config)
78+
apihelper = APIHelper(testcfg)
79+
node = apihelper._fsanitize_node_fields(node, "commit_message") # pylint: disable=protected-access # noqa: E501
80+
# Test that the _fsanitize_fsanitize_node_fields method returns a dictionary
81+
assert isinstance(node, dict)
82+
# test that commit message doesnt contain single curly braces
83+
# they should be replaced with double curly braces
84+
val = node["data"]["kernel_revision"]["commit_message"]
85+
assert val == (
86+
"x86/its: Fix build errors when CONFIG_MODULES=n\n\n"
87+
"Fix several build errors when CONFIG_MODULES=n, including the following:\n\n"
88+
"../arch/x86/kernel/alternative.c:195:25: error: incomplete definition of type 'struct module'\n" # noqa: E501
89+
" 195 | for (int i = 0; i < mod->its_num_pages; i++) {{\n\n"
90+
'Fixes: 872df34d7c51 ("x86/its: Use dynamic thunks for indirect branches")\n'
91+
92+
"Signed-off-by: Eric Biggers \n"
93+
"Acked-by: Dave Hansen \n"
94+
"Tested-by: Steven Rostedt (Google) \n"
95+
"Reviewed-by: Alexandre Chartre \n"
96+
"Signed-off-by: Linus Torvalds "
97+
)

0 commit comments

Comments
 (0)