Page MenuHomeVyOS Platform

XML: Python default dictionary returns wrong dictionary level(s)
Closed, ResolvedPublicBUG

Description

While working on T2653 and transforming the MACsec interface into a get_config_dict() approach it was noticed that the default dictionary does not obey the given XML levels.

We have a default priority for the MACsec key agreement protocol of 255, when adding this into the XML and querying the result the level is not taken into account

diff --git c/interface-definitions/interfaces-macsec.xml.in i/interface-definitions/interfaces-macsec.xml.in
index 36605ab5..dfef387d 100644
--- c/interface-definitions/interfaces-macsec.xml.in
+++ i/interface-definitions/interfaces-macsec.xml.in
@@ -83,6 +83,7 @@
                         <validator name="numeric" argument="--range 0-255" />
                       </constraint>
                     </properties>
+                    <defaultValue>255</defaultValue>
                   </leafNode>
                 </children>
               </node>
>>> from vyos.xml import defaults
>>> from pprint import pprint
>>> base = ['interfaces', 'macsec']
>>> pprint(defaults(base))
{'security_mka_priority': '255'}

I'd rather expect the following dictionary representing the same level as get_config_dict():
{'security': {'mka': {'priority': '255'}}}

Details

Difficulty level
Unknown (require assessment)
Version
1.3-rolling-202006261635
Why the issue appeared?
Will be filled on close
Is it a breaking change?
Behavior change
Issue type
Internal change (not visible to end users)

Event Timeline

c-po triaged this task as High priority.
c-po created this task.

@cpo, you can change the defaults from True to False in the patch if this is what you want to do.

LGTM:

>>> pprint(defaults(base, flat=False))
{'security': {'mka': {'priority': '255'}}}

We should make this a default option, not much functions using it and also it makes no sense to be to use the "flattened" dict as it can't be merged with a dict from `get_config_dict()

(15:07) cpo lnx01:~/vyos-1x [current] # git grep "vyos.xml" src/
src/conf_mode/interfaces-macsec.py:from vyos.xml import defaults
src/conf_mode/service_console-server.py:from vyos.xml import defaults
src/conf_mode/ssh.py:from vyos.xml import defaults
erkin set Issue type to Internal change (not visible to end users).Aug 29 2021, 2:01 PM
erkin removed a subscriber: Active contributors.