PaloAltoNetworks / PaloAltoNetworks/pan-os-python
activate_feature_using_authorization_code returns nothing if successful and eventually times out the client
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 400
- Forks
- 199
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
When using the activate_feature_using_authorization_code method, nothing is returned. After the license is applied the FW goes for a reboot and the client disconnects with an http.client.RemoteDisconnected: Remote end closed connection without response
exception.
Expected behavior
Return anything, so we know if the license application was successful. It looks like the method checks for a status from the op call, so maybe return that status.
if result.attrib.get("status") != "success":
raise err.PanActivateFeatureAuthCodeError(
result.get("./msg/line").text, pan_device=self
)
Return the status if it was successful
if result.attrib.get("status") != "success":
raise err.PanActivateFeatureAuthCodeError(
result.get("./msg/line").text, pan_device=self
)
else:
return result.attrib.get("status")
Current behavior
Nothing is returned, and the client times out with an http.client error.
Traceback (most recent call last):
File "license.py", line 43, in <module>
main()
File "license.py", line 33, in main
fw.activate_feature_using_authorization_code(code)
File "/home/mbarry/.virtualenvs/azure-panos/lib/python3.8/site-packages/panos/base.py", line 5112, in activate_feature_using_authorization_code
result = self.op('request license fetch auth-code "{0}"'.format(code))
File "/home/mbarry/.virtualenvs/azure-panos/lib/python3.8/site-packages/panos/firewall.py", line 219, in op
return super(Firewall, self).op(
File "/home/mbarry/.virtualenvs/azure-panos/lib/python3.8/site-packages/panos/base.py", line 3822, in op
element = self.xapi.op(
File "/home/mbarry/.virtualenvs/azure-panos/lib/python3.8/site-packages/panos/base.py", line 3661, in method
super_method(self, *args, **kwargs)
File "/home/mbarry/.virtualenvs/azure-panos/lib/python3.8/site-packages/pan/xapi.py", line 951, in op
self.__type_op(cmd, vsys, extra_qs)
File "/home/mbarry/.virtualenvs/azure-panos/lib/python3.8/site-packages/pan/xapi.py", line 969, in __type_op
response = self.__api_request(query)
File "/home/mbarry/.virtualenvs/azure-panos/lib/python3.8/site-packages/pan/xapi.py", line 545, in __api_request
response = urlopen(**kwargs)
File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.8/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/usr/lib/python3.8/urllib/request.py", line 542, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
result = func(*args)
File "/usr/lib/python3.8/urllib/request.py", line 1369, in https_open
return self.do_open(http.client.HTTPSConnection, req,
File "/usr/lib/python3.8/urllib/request.py", line 1330, in do_open
r = h.getresponse()
File "/usr/lib/python3.8/http/client.py", line 1332, in getresponse
response.begin()
File "/usr/lib/python3.8/http/client.py", line 303, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.8/http/client.py", line 272, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response
Possible solution
Return result as mentioned above.
Steps to reproduce
- Start with an unlicensed vm-series firewall
- Issue authcode with activate_feature_using_authorization_code
- Whatch client connection timeout.
Context
We are trying to apply an auth code programmatically through a pipeline.
Your Environment
panos - 10.1.4
python - 3.8.2
os - ubuntu 20.04
pan-os-python: 1.6.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 activate_feature_using_authorization_code and follow its op call through panos/firewall.py and pan/xapi.py. Reproduce the authorization-code activation on an unlicensed VM-series firewall and verify that successful license application yields the expected status instead of an http.client.RemoteDisconnected exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100