Bug 1428472

Summary: batch param compatibility is incorrect
Product: Red Hat Enterprise Linux 7 Reporter: Petr Vobornik <pvoborni>
Component: ipaAssignee: IPA Maintainers <ipa-maint>
Status: CLOSED ERRATA QA Contact: Nikhil Dehadrai <ndehadra>
Severity: urgent Docs Contact:
Priority: urgent    
Version: 7.3CC: ipa-qe, jcholast, jreznik, ksiddiqu, nsoman, pvoborni, rcritten, tscherf
Target Milestone: rcKeywords: ZStream
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: ipa-4.4.0-14.el7.7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1430674 (view as bug list) Environment:
Last Closed: 2017-08-01 09:44:33 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1430674    

Description Petr Vobornik 2017-03-02 16:15:02 UTC
The definition of the batch params all define methods as Str. It has never been a Str. It was defined as Any until recently when it was refined to Dict.

This causes the batch command in ipalib on 4.4 to fail to work because methods is not a Str (it doesn't even get far enough to make a request, it blows up validating the input).

Here is the output from the sample program:
Traceback (most recent call last):
  File "batch.py", line 10, in <module>
    res = api.Command.batch(batch)
  File "/usr/lib/python2.7/site-packages/ipalib/frontend.py", line 449, in __call__
    return self.__do_call(*args, **options)
  File "/usr/lib/python2.7/site-packages/ipalib/frontend.py", line 470, in __do_call
    params = self.convert(**params)
  File "/usr/lib/python2.7/site-packages/ipalib/frontend.py", line 671, in convert
    (k, self.params[k].convert(v)) for (k, v) in kw.items()
  File "/usr/lib/python2.7/site-packages/ipalib/frontend.py", line 671, in <genexpr>
    (k, self.params[k].convert(v)) for (k, v) in kw.items()
  File "/usr/lib/python2.7/site-packages/ipalib/parameters.py", line 831, in convert
    convert(v) for v in value if not _is_null(v)
  File "/usr/lib/python2.7/site-packages/ipalib/parameters.py", line 831, in <genexpr>
    convert(v) for v in value if not _is_null(v)
  File "/usr/lib/python2.7/site-packages/ipalib/parameters.py", line 1445, in _convert_scalar
    raise ConversionError(name=self.name, error=ugettext(self.type_error))
ipalib.errors.ConversionError: invalid 'methods': must be Unicode text



Reproducer (python script):

from ipalib import api
from ipalib import errors

api.bootstrap(context='cli')
api.finalize()
api.Backend.rpcclient.connect()

batch = [{u'params': [(u'test.example.com',), {u'force': u'True'}], u'method': u'host_add'}]

res = api.Command.batch(batch)


Expected result:

Commands are executed, command returns res and doesn't throw exception.

Comment 1 Petr Vobornik 2017-03-02 16:16:15 UTC
Upstream ticket:
https://pagure.io/freeipa/issue/6647

Comment 2 Petr Vobornik 2017-03-02 16:17:10 UTC
master:
    19060db1b8fa9d1d3e8f3ac3fcd1f387e9a39c94 compat: fix Any params in batch and dnsrecord

Comment 6 Jan Cholasta 2017-03-14 05:27:38 UTC
Fixed upstream
ipa-4-4:
https://pagure.io/freeipa/c/e3b49abfe7a8d9540d77ed355595d9e44a3bdd27

Comment 8 Nikhil Dehadrai 2017-05-09 11:16:38 UTC
IPA server version:  ipa-server-4.5.0-10.el7.x86_64

Verified the bug on the basis of following steps performed on IPA-server setup on pre4.4 (In my case RHEL 7.2.z) version and IPA-client on latest version (RHEL 7.4):

IPA MASTER:
============
[root@intel-sugarbay-do-01 ~]# rpm -qa ipa-server
ipa-server-4.2.0-15.el7_2.19.x86_64
[root@intel-sugarbay-do-01 ~]# ## THIS is IPA-SERVER
[root@intel-sugarbay-do-01 ~]# ipactl status
Directory Service: RUNNING
krb5kdc Service: RUNNING
kadmin Service: RUNNING
named Service: RUNNING
ipa_memcached Service: RUNNING
httpd Service: RUNNING
pki-tomcatd Service: RUNNING
ipa-otpd Service: RUNNING
ipa-dnskeysyncd Service: RUNNING
ipa: INFO: The ipactl command was successful
[root@intel-sugarbay-do-01 ~]# ipa host-find test.example.com
ipa: ERROR: did not receive Kerberos credentials
[root@intel-sugarbay-do-01 ~]# kinit admin
Password for admin: 
[root@intel-sugarbay-do-01 ~]# ipa host-find test.example.com
---------------
0 hosts matched
---------------
----------------------------
Number of entries returned 0
----------------------------



IPA-CLIENT:
=============
[root@cloud-qe-15 ~]# rpm -q ipa-client
ipa-client-4.5.0-10.el7.x86_64
[root@cloud-qe-15 ~]# kinit admin
Password for admin: 
[root@cloud-qe-15 ~]# ipa host-find test.example.com
---------------
0 hosts matched
---------------
----------------------------
Number of entries returned 0
----------------------------
[root@cloud-qe-15 ~]# cat test.py 
from ipalib import api
from ipalib import errors

api.bootstrap(context='cli')
api.finalize()
api.Backend.rpcclient.connect()

batch = [{u'params': [(u'test.example.com',), {u'force': u'True'}], u'method': u'host_add'}]

res = api.Command.batch(batch)
[root@cloud-qe-15 ~]# python test.py 
[root@cloud-qe-15 ~]# ipa host-find test.example.com
--------------
1 host matched
--------------
  Host name: test.example.com
  Principal name: host/test.example.com
  Password: False
  Keytab: False
  Managed by: test.example.com
----------------------------
Number of entries returned 1
----------------------------

IPA MASTER:
============
Now re-run "ipa host-find" on master:

[root@intel-sugarbay-do-01 ~]# ipa host-find test.example.com
--------------
1 host matched
--------------
  Host name: test.example.com
  Principal name: host/test.example.com
  Password: False
  Keytab: False
  Managed by: test.example.com
----------------------------
Number of entries returned 1
----------------------------

Thus on the basis of above steps, marking the status of bug to "VERIFIED"

Comment 9 errata-xmlrpc 2017-08-01 09:44:33 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2017:2304