Modify

Opened 2 years ago

Last modified 4 weeks ago

#10905 new defect

Hudson 3.0.0 no longer supports /api/python interface

Reported by: c.jones@… Owned by: roadrunner
Priority: normal Component: HudsonTracPlugin
Severity: major Keywords:
Cc: rjollos Trac Release: 0.11

Description (last modified by rjollos)

The HudsonTracPlugin requires that hudson makes available the API for python on the URL /api/python at the moment, however now that Eclipse have taken on hudson, and version 3.0.0 has been released, the python API is no longer supported. Once hudson is upgraded to version 3.0.0 you get this error in the TRAC timeline:

Trac Error

Hudson Builds event provider (HudsonTracPlugin) failed:
IOError: Error getting build info from 
'http://myserver:8080/job/jobname/api/python?
tree=builds[building,timestamp,duration,result,description,url,
fullDisplayName,changeSet[items[revision,id,user,author[fullName]]],
culprits[fullName],actions[causes[userName]]]': 
HTTPError: HTTP Error 404: Not Found. 
This most likely means you configured a wrong job_url, username, or password.

See discussion here, that explains the python interface is no longer supported: http://www.eclipse.org/forums/index.php/t/457665/

Apparently though, the api is almost identical to the JSON interface anyway, so perhaps HudsonTracPlugin can be fairly easily modified to point to /api/json instead?

Attachments (1)

hudsontracplugin.diff (2.2 KB) - added by Cinc 4 weeks ago.
Patch to get ththe plugin to work with Hudson 3.2.x. Note that the path in this file must be corrected properly before applying. Sorry for this inconvenience.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 2 years ago by rjollos

  • Description modified (diff)

comment:2 follow-up: Changed 20 months ago by tcfenstermaker

Without this fix, this plug-in is completely broken (and in fact it breaks the timeline feature in Trac as noted in the bug and thus is actually disruptive). So, made a fix for this myself, replacing the python API with the one for JSON, and also replacing the code used to handle the HTTP calls with the requests library (from python-requests.org). It works fine for my Hudson installation but it probably needs more testing against other configurations of Hudson and Jenkins. Also, since this is my first time writing python, I could use a little coaching in how to make sure I bundle it correctly so it knows the requests library is now a dependency.

Can someone help me with those two items? Then I could give this code to whoever runs this project and have them update it as the next release.

Last edited 20 months ago by tcfenstermaker (previous) (diff)

comment:3 in reply to: ↑ 2 Changed 20 months ago by rjollos

Replying to tcfenstermaker:

[...] Also, since this is my first time writing python, I could use a little coaching in how to make sure I bundle it correctly so it knows the requests library is now a dependency.

You'll just need to add an entry in install_requires. Here is an example, and the relevant documentation for setuptools.

Can someone help me with those two items? Then I could give this code to whoever runs this project and have them update it as the next release.

It will probably be easiest if you just attach the code to this ticket, or give us a link to a fork of the code in GitHub, BitBucket, etc...

comment:4 Changed 20 months ago by tcfenstermaker

Thanks for the help rjollos; I'll try to get to this this week. I'll probably just attach the code to the ticket, as it's only one module. I just need to clean it up a bit.

comment:5 Changed 4 weeks ago by Cinc

I created a patch to get the plugin to work with Trac 0.12.3 and Hudson 3.2.x:

  • Trac/Plugins/HudsonTrac/HudsonTrac-0.5-py2.7.egg/HudsonTrac/HudsonTracPlugin.py

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    1515import urllib2
    1616import base64
    1717from datetime import datetime
     18import json
    1819
    1920from genshi.builder import tag
    2021from trac.core import *
     
    2930    from trac.timeline.api import ITimelineEventProvider
    3031except ImportError:
    3132    from trac.Timeline import ITimelineEventProvider
    32 try:
    33     from ast import literal_eval
    34 except ImportError:
    35     def literal_eval(str):
    36         return eval(str, {"__builtins__":None}, {"True":True, "False":False})
    3733
     34
    3835class HudsonTracPlugin(Component):
    3936    """
    4037    Display Hudson results in the timeline and an entry in the main navigation
     
    105102        api_url = unicode_quote(self.job_url, '/%:@')
    106103        if api_url and api_url[-1] != '/':
    107104            api_url += '/'
    108         api_url += 'api/python'
     105        api_url += 'api/json'
    109106
    110107        # set up http authentication
    111108        if self.username and self.api_token:
     
    172169                cset = resp.info().getparam('charset') or 'ISO-8859-1'
    173170
    174171                ct   = resp.info().gettype()
    175                 if ct != 'text/x-python':
     172                if ct != 'application/javascript':
    176173                    local_exc = True
    177174                    raise IOError(
    178175                        "Error getting build info from '%s': returned document "
    179                         "has unexpected type '%s' (expected 'text/x-python'). "
     176                        "has unexpected type '%s' (expected 'application/javascript'). "
    180177                        "The returned text is:\n%s" %
    181178                        (self.info_url, ct, unicode(resp.read(), cset)))
    182179
    183                 info = literal_eval(resp.read())
     180                info = json.loads(resp.read())
    184181
    185182                return info, cset
    186183            except Exception:

Note that the revisions are our internal SVN revisions and the path must be adapted properly because the plugin was imported into our private tree.

Sorry for this inconvenience.

Changed 4 weeks ago by Cinc

Patch to get ththe plugin to work with Hudson 3.2.x. Note that the path in this file must be corrected properly before applying. Sorry for this inconvenience.

comment:6 Changed 4 weeks ago by rjollos

  • Cc rjollos added

Add Comment

Modify Ticket

Action
as new The owner will remain roadrunner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.