Skip to content

Commit 8df96a1

Browse files
committed
test/infamy: support [.='value'] in restconf transport
The xpath_to_uri() method did not properly handle XPath expressions that use [.='value'] syntax for selecting leaf-list items. Example types of XPath selection syntaxes: [key='value'] - for list items with named keys [.='value'] - for leaf-list items (current node selection) Example XPath requiring this fix: /infix-firewall:firewall/zone[name='untrusted']/interface[.='e2'] Must be converted to a RESTCONF URL: /infix-firewall:firewall/zone=untrusted/interface=e2 Without this fix, the [.='value'] pattern was incorrectly converted and caused "400 Bad Request" errors when attempting to delete any leaf-list value with this syntax via RESTCONF. Signed-off-by: Joachim Wiberg <[email protected]>
1 parent 9ff50e2 commit 8df96a1

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

test/infamy/restconf.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,19 @@ class Location:
2626

2727
def xpath_to_uri(xpath, extra=None):
2828
"""Convert xpath to HTTP URI"""
29-
# If the xpath has a
29+
# Handle [.='value'] syntax for leaf-list items
3030
pattern = r'\[(.*?)=["\'](.*?)["\']\]'
3131
matches = re.findall(pattern, xpath)
3232

33+
uri_path = xpath
3334
if matches:
3435
for key, value in matches:
35-
# replace [key=value] with =value
36-
uri_path = re.sub(rf'\[{re.escape(key)}=["\']{re.escape(value)}["\']\]', f'={value}', xpath)
37-
else:
38-
uri_path = xpath
36+
if key == '.':
37+
# For [.='value'], replace with =value
38+
uri_path = re.sub(rf'\[\.=["\']{re.escape(value)}["\']\]', f'={value}', uri_path)
39+
else:
40+
# For [key='value'], replace with =value
41+
uri_path = re.sub(rf'\[{re.escape(key)}=["\']{re.escape(value)}["\']\]', f'={value}', uri_path)
3942

4043
# Append extra if provided
4144
if extra is not None:

0 commit comments

Comments
 (0)