[2.0a1] python3-maas-client API 2.0 seems to no longer use op but MAASClient.post requires it and incorectly passes it along
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MAAS |
Fix Released
|
Critical
|
Unassigned |
Bug Description
Testing bleeding edge python3-maas-client API 2.0 with Xenial and python3
The client from both ppa:maas/next and ppa:~maas-
Note: Even to get to this point I needed to work around LP Bug#1555392
MAASClient post requires that op be set. However, every op option I tried led to HTTP Error 400: BAD REQUEST. It would seem the 2.0 API no longer uses an op however put incorrectly pushes op down to the request.
In my testing I am trying to create a new dnsresource using the 2.0 API.
Traceback (most recent call last):
File "hooks/test.py", line 81, in <module>
test_maas()
File "hooks/test.py", line 65, in test_maas
dns.
File "hooks/test.py", line 49, in create_dnsresource
address_
File "/home/
resp = self.driver.
File "/home/
fqdn=fqdn, ip_address=
File "/home/
response = self.client.
File "/usr/lib/
url, method="POST", headers=headers, data=body)
File "/usr/lib/
res = urllib.
File "/usr/lib/
return opener.open(url, data, timeout)
File "/usr/lib/
response = meth(req, response)
File "/usr/lib/
'http', request, response, code, msg, hdrs)
File "/usr/lib/
return self._call_
File "/usr/lib/
result = func(*args)
File "/usr/lib/
raise HTTPError(
urllib.
Quick and dirty fix (likely not the correct one:
--- /usr/lib/
+++ maas_client.py 2016-03-09 16:35:25.922925474 -0800
@@ -231,14 +231,15 @@
return self.dispatcher
url, method="GET", headers=headers)
- def post(self, path, op, as_json=False, **kwargs):
+ def post(self, path, op=None, as_json=False, **kwargs):
:param as_json: Instead of POSTing the content as multipart/form-data
POST it as application/json
:return: The result of the dispatch_query call on the dispatcher.
"""
- kwargs['op'] = op
+ if op:
+ kwargs['op'] = op
url, headers, body = self._formulate
path, kwargs, as_json=as_json)
return self.dispatcher
Related branches
- Gavin Panella (community): Approve
- Blake Rouse (community): Approve
-
Diff: 12 lines (+1/-1)1 file modifiedsrc/apiclient/maas_client.py (+1/-1)
Changed in maas: | |
importance: | Undecided → Critical |
milestone: | none → 2.0.0 |
summary: |
- python3-maas-client API 2.0 seems to no longer use op but + [2.0a1] python3-maas-client API 2.0 seems to no longer use op but MAASClient.post requires it and incorectly passes it along |
Changed in maas: | |
status: | New → Fix Committed |
Changed in maas: | |
status: | Fix Committed → Fix Released |
I am afraid this bug is still an issue using python3-maas-client 2.0.0~alpha3+ bzr4809- 0ubuntu1~ xenial1.
Attempting to create a dnsresource with post:
With post request not specifying an op code:
Traceback (most recent call last): maas_dns. py", line 149, in <module> maas_dns. py", line 131, in telco_ha_dns obj.create_ dnsresource( ) maas_dns. py", line 44, in create_dnsresource thedac/ dev/hacluster/ ocf/maas/ maasclient/ __init_ _.py", line 78, create_ dnsresource( fqdn, ip_address, address_ttl) thedac/ dev/hacluster/ ocf/maas/ maasclient/ apidriver. py", line ttl=address_ ttl) thedac/ dev/hacluster/ ocf/maas/ maasclient/ apidriver. py", line 89, post(path, op, **kwargs) python3/ dist-packages/ apiclient/ maas_client. py", line 242, in python3/ dist-packages/ apiclient/ maas_client. py", line 212, in python3/ dist-packages/ apiclient/ utils.py" , line 42, in python3/ dist-packages/ apiclient/ utils.py" , line 42, in python3. 5/urllib/ parse.py" , line 728, in quote_plus python3. 5/urllib/ parse.py" , line 712, in quote bytes(string, safe) python3. 5/urllib/ parse.py" , line 737, in quote_from_bytes "quote_ from_bytes( ) expected bytes")
File "ocf/maas/
telco_ha_dns()
File "ocf/maas/
dns_
File "ocf/maas/
self.ttl)
File "/home/
in create_dnsresource
resp = self.driver.
File "/home/
166, in create_dnsresource
address_
File "/home/
in _post
response = self.client.
File "/usr/lib/
post
path, kwargs, as_json=as_json)
File "/usr/lib/
_formulate_change
url += '?' + urlencode([('op', op)])
File "/usr/lib/
urlencode
for name, value in data)
File "/usr/lib/
<genexpr>
for name, value in data)
File "/usr/lib/
string = quote(string, safe + space, encoding, errors)
File "/usr/lib/
return quote_from_
File "/usr/lib/
raise TypeError(
TypeError: quote_from_bytes() expected bytes
If I explicitly set the op code to op=bytes('update', encoding='utf-8') and
working around LP Bug#1555392 it returns 400 Bad Request:
Traceback (most recent call last): maas_dns. py", line 149, in <module> maas_dns. py", line 131, in telco_ha_dns obj.create_ dnsresource( ) maas_dns. py", line 44, in create_dnsresource thedac/ dev/hacluster/ ocf/maas/ maasclient/ __init_ _.py", line 78, create_ dnsresource( fqdn, ip_address, address_ttl) thedac/ dev/hacluster/ ocf/maas/ maasclient/ apidriver. py", line ttl=address_ ttl) thedac/ dev/hacluster/ ocf/maas/ maasclient/ apidriver. py", line 89, post(path, op, **kwargs) python3/ dist-packages/ apiclient/ maas_client. py", line 245, in python3/ dist-packages/ apiclient/ maas_client. py", line 109, in request. urlopen( req) python3. 5/urllib/ request. py", line 162, in urlopen python3. 5/urllib/ request. py", line 471, in open python3. 5/urllib/ request. py", line 581, in ht...
File "ocf/maas/
telco_ha_dns()
File "ocf/maas/
dns_
File "ocf/maas/
self.ttl)
File "/home/
in create_dnsresource
resp = self.driver.
File "/home/
166, in create_dnsresource
address_
File "/home/
in _post
response = self.client.
File "/usr/lib/
post
url, method="POST", headers=headers, data=body)
File "/usr/lib/
dispatch_query
res = urllib.
File "/usr/lib/
return opener.open(url, data, timeout)
File "/usr/lib/
response = meth(req, response)
File "/usr/lib/