PaloAltoNetworks / PaloAltoNetworks/pan-os-python
Use of TemplateVariable for 'Group ID' causes an error due to it being converted to an int() during parse_xml
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 400
- Forks
- 199
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
I attempt Template.refreshall(pano) which fails because a Template is making use of a 'Group ID' template value of '$groupID'. pan-os-python attempts to convert the value to int() during parse_xml.
Expected behavior
I would expect a condition of str(elm.text) if elm.text.startswith('$') else int(elm.text)
Current behavior
Traceback (most recent call last):
File "<pyshell#157>", line 1, in <module>
Template.refreshall(pano)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/panos/base.py", line 1338, in refreshall
instances = class_instance.refreshall_from_xml(obj)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/panos/base.py", line 1404, in refreshall_from_xml
instance._refresh_children(xml=obj)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/panos/base.py", line 1038, in _refresh_children
l = child.refreshall_from_xml(childroot)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/panos/base.py", line 1389, in refreshall_from_xml
instance.parse_xml(obj)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/panos/base.py", line 2789, in parse_xml
var_path.parse_xml(xml, settings, possibilities)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/panos/base.py", line 3223, in parse_xml
self.parse_value_from_xml_last_tag(e, settings, attr)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/panos/base.py", line 3306, in parse_value_from_xml_last_tag
settings[self.param] = int(elm.text)
ValueError: invalid literal for int() with base 10: '$groupID'
Possible solution
Use of a conditional statement such as settings[self.param] = str(elm.text) if elm.text.startswith('$') else int(elm.text)
Steps to reproduce
- Define a template variable for $groupID
- Assign the $groupID to Template>Device>High Availability>Setup>Group ID
Template.refreshall(pano)from a pan-os-python script
Screenshots
Context
Your Environment
- Version used:
- pan-os-python 1.11.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in panos/base.py at parse_value_from_xml_last_tag, reached through Template.refreshall and parse_xml. Reproduce the failure by assigning $groupID to Template > Device > High Availability > Setup > Group ID and running Template.refreshall(pano). Done means refreshall no longer raises ValueError when that template variable is parsed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100