Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group functions filter out tail match results #103

Open
dmulyalin opened this issue Apr 14, 2023 · 2 comments
Open

Group functions filter out tail match results #103

dmulyalin opened this issue Apr 14, 2023 · 2 comments

Comments

@dmulyalin
Copy link
Owner

When having this template and data:

data = """
interface Gig123
 description foo
 mtu 1234
 ipv4 address 1.2.3.4 255.255.255.0
 arp timeout 123
 mac-address 123.123.1
!
interface Gig321
 description foo
 mtu 4321
 ipv4 address 1.2.3.5 255.255.255.0
 arp-timeout 4321
 mac-address 123.123.2
!
"""
template = """
<group name="interfaces*" contains="name">
interface {{ name }}
 description {{ description | re(".*") }}
 mtu {{ mtu | to_int }}
 mac-address {{ mac_address }}
 arp timeout {{ arp_timeout }}
 
 <group name="ipv4*" method="table">
 ipv4 address {{ ip | _exact_ }} {{ mask }}
 </group>
 
!{{ _end_ }}
</group>
"""

Parsing gives these results:

[[{'interfaces': [{'description': 'foo',
                   'ipv4': [{'ip': '1.2.3.4', 'mask': '255.255.255.0'}],
                   'mtu': 1234,
                   'name': 'Gig123'},
                  {'description': 'foo',
                   'ipv4': [{'ip': '1.2.3.5', 'mask': '255.255.255.0'}],
                   'mtu': 4321,
                   'name': 'Gig321'}]}]]

this is due to the fact that mac_address matched after ipv4 group matched, and by the time we process mac_address match group functions results does not have name attribute in them. Removing contains="name" produces expected result:

[[{'interfaces': [{'arp_timeout': '123',
                   'description': 'foo',
                   'ipv4': [{'ip': '1.2.3.4', 'mask': '255.255.255.0'}],
                   'mac_address': '123.123.1',
                   'mtu': 1234,
                   'name': 'Gig123'},
                  {'description': 'foo',
                   'ipv4': [{'ip': '1.2.3.5', 'mask': '255.255.255.0'}],
                   'mac_address': '123.123.2',
                   'mtu': 4321,
                   'name': 'Gig321'}]}]]
@dmulyalin
Copy link
Owner Author

Introduced fix in latest commit, fix logic is weak but simplest to fix this issue, better approach required to collect parsing results in general but will require significant code refactoring.

dmulyalin added a commit that referenced this issue Apr 14, 2023
dmulyalin added a commit that referenced this issue Apr 23, 2023
…lts processing logic to try and reconstruct full group results for marco functions processing, this still has flaw that would not work for the case when tail match results are part of group path. bump to 0.9.4
@ffhan
Copy link

ffhan commented Jun 28, 2023

@dmulyalin first of all thank you so much for this project, it is amazing.

Unfortunately, this bug is still not fixed even in version 0.9.5.
I can provide the minimal example to reproduce if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants