0

I'm having trouble using the tcms_api to communicate with the API to our Kiwi deployment.

  • My host: Windows 10
  • Our Kiwi host: Docker containers running on CentOS
  • Kiwi version: 7.3

Trying to execute this script (test_kiwi_api.py), taken from an example found somewhere online:

import tcms_api
rpc_client = tcms_api.TCMS().exec

for test_case in rpc_client.exec.TestCase.filter({'pk': 46490}):
    print(test_case)

After following the steps at tcms-api 5.3 package incompatible with Windows for changing to kerberos-sspi (and installing Kerberos for Windows and the kerberos-sspi python package), encountered this error:

C:\kiwi\api>.\test_kiwi_api.py

Traceback (most recent call last):
  File "C:\kiwi\api\test_kiwi_api.py", line 1, in <module>
    import tcms_api
  File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\site-packages\tcms_api\__init__.py", line 64, in <module>
    from .xmlrpc import TCMSXmlrpc, TCMSKerbXmlrpc
  File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\site-packages\tcms_api\xmlrpc.py", line 22, in <module>
    import kerberos as k
ModuleNotFoundError: No module named 'kerberos'

After editing xmlrpc.py directly so that it uses kerberos-sspi instead of kerberos

done by changing:

import kerberos

to:

try:
    import kerberos as k
except:
    import kerberos_sspi as k

... and changing later kerberos references to k references

Encountering this error:

C:\kiwi\api>.\test_kiwi_api.py

  File "C:\kiwi\api\test_kiwi_api.py", line 2, in <module>
    rpc_client = tcms_api.TCMS().exec
  File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\site-packages\tcms_api\__init__.py", line 99, in __init__
    TCMS._connection = TCMSKerbXmlrpc(config['tcms']['url']).server
  File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\site-packages\tcms_api\xmlrpc.py", line 142, in __init__
    self.server.Auth.login_krbv()
  File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\xmlrpc\client.py", line 1112, in __call__
    return self.__send(self.__name, args)
  File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\xmlrpc\client.py", line 1452, in __request
    verbose=self.__verbose
  File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\xmlrpc\client.py", line 1154, in request
    return self.single_request(host, handler, request_body, verbose)
  File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\xmlrpc\client.py", line 1166, in single_request
    http_conn = self.send_request(host, handler, request_body, verbose)
  File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\xmlrpc\client.py", line 1267, in send_request
    connection = self.make_connection(host)
  File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\site-packages\tcms_api\xmlrpc.py", line 79, in make_connection
    chost, self._extra_headers, x509 = self.get_host_info(host)
  File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\site-packages\tcms_api\xmlrpc.py", line 64, in get_host_info
    k.authGSSClientStep(context, "")
  File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\site-packages\kerberos_sspi.py", line 218, in authGSSClientStep
    err, sec_buffer = context["csa"].authorize(data)
  File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\site-packages\win32\lib\sspi.py", line 139, in authorize
    sec_buffer_out)
pywintypes.error: (-2146893053, 'InitializeSecurityContext', 'The specified target is unknown or unreachable')

I have looked into just writing a node.js API interface (since most dev here is done in node and it would be nice to have dev help if needed), but a little research shows that their kerberos package relies on Python, so I'm pretty sure I'd run into this problem there as well. If I could write that (node.js tcms_api interface) but connect using something other than kerberos, I'd try it, and share it if I can get it to work.

Edit: Here's my config file (which, on Windows, goes in C:\etc)

[tcms]
url = https://qaportal01.irvl.mymbnet.com/xml-rpc/
username = rfeldman
password = <not shown>
use_mod_kerb = False
  • If you could connect with something other than Kerberos maybe you don't need to do anything to change the existing API package?!? FTR we don't officially support kerberos on windows and the situation with actively maintained kerberos libraries is somewhat dire. The best option is a port to gss-api. On the other had the API is also exported via JSON-RPC which is a much simpler protocol, see the FE implementation at https://github.com/kiwitcms/Kiwi/blob/master/tcms/static/js/jsonrpc.js – Alexander Todorov Feb 05 '20 at 13:11
  • @AlexanderTodorov I don't want to connect with Kerberos. That just seems to be what this API package is trying to do, even when I set use_mod_kerb = False. I will look into the JSON approach, thanks. – R. Feldman Feb 05 '20 at 17:40
  • hmm, there must be a bug in how the kerberos component gets initialzied if you see failures even with use_mod_kerb = False. Can you post a link to a git (GitHub) repo which contains your changes so we can try inspecting what is going on there? Maybe the same issue exists on Linux but just because the kerberos dependency is available we don't see it. – Alexander Todorov Feb 06 '20 at 12:14
  • @AlexanderTodorov I've figured out how to use the JSON-RPC and I'll be using that for this integration. Sorry I can't work on this right now. When I'm able to work on this integration again, if I run into real trouble using JSON-RPC or developing the client for it, I'll re-examine the XML-RPC option and deal with that error then. Thanks again! – R. Feldman Feb 06 '20 at 18:14
  • @AlexanderTodorov Actually, the bug looks like it is on line 97 of the __init__.py file: if config['tcms'].get('use_mod_kerb', False):. That should be "True" because if the test passes, it uses kerberos. – R. Feldman Feb 06 '20 at 18:24

1 Answers1

0

Turns out this was an actual bug in how configuration was handled. Even when use_mod_kerb was set to False the value returned was of type string ("False") which Python always evaluated to True in a boolean context (any non-empty string is evaluated to True).

This has been fixed by converting the config value to a bool value before evaluating: https://github.com/kiwitcms/tcms-api/pull/11 and has been released in tcms-api version 6.7.1

Alexander Todorov
  • 2,167
  • 3
  • 14
  • 13