create_node() raises HTTP Error 400 Bad Request

Bug #1500898 reported by george
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Python Jenkins
Fix Released
Undecided
Dong Ma

Bug Description

after update to version 0.4.9 create_node() function raises error

>>> j.create_node(name="testest",numExecutors=1,nodeDescription='',remoteFS="/home/vagrant/jenkins")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\galexandrov\AppData\Local\Programs\Python\Python35\lib\site-packages\jenkins\__init__.py", line 1156, in create_node
    self._build_url(CREATE_NODE, params), b''))
  File "C:\Users\galexandrov\AppData\Local\Programs\Python\Python35\lib\site-packages\jenkins\__init__.py", line 341, in jenkins_open
    response = urlopen(req, timeout=self.timeout).read()
  File "C:\Users\galexandrov\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 162, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\galexandrov\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 471, in open
    response = meth(req, response)
  File "C:\Users\galexandrov\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 581, in http_response

    'http', request, response, code, msg, hdrs)
  File "C:\Users\galexandrov\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 509, in error
    return self._call_chain(*args)
  File "C:\Users\galexandrov\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 443, in _call_chain
    result = func(*args)
  File "C:\Users\galexandrov\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 589, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request

george (jack-pot-n)
summary: - create_node() raise HTTP Error 400 Bad Request
+ create_node() raises HTTP Error 400 Bad Request
description: updated
Revision history for this message
Alfredo Deza (cy-launchpad-deactivatedaccount) wrote :

We encountered this today using the latest (4.11) version.

The culprit is how the URL is parsed. Jenkins requires 3 queryargs: 'json', 'name', and 'type'. But the url part is getting created as a big dictionary which causes this (truncated for brevity):

    https://jenkins.ceph.com/computer/doCreateItem?{'json': ...

When it should really be:

    https://jenkins.ceph.com/computer/doCreateItem?json=...

This is caused by:

         self.jenkins_open(Request(
             self._build_url(CREATE_NODE, params), b''))

Where "params" is a big dictionary of options.

On previous versions where this worked it was actually:

        self.jenkins_open(Request(
            self.server + CREATE_NODE % urlencode(params)), b'')

Which correctly parses the query args and constructs the URL that Jenkins is expecting.

Dan Watkins (oddbloke)
Changed in python-jenkins:
status: New → Confirmed
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-jenkins (master)

Fix proposed to branch: master
Review: https://review.openstack.org/254644

Changed in python-jenkins:
assignee: nobody → Dong Ma (larainema)
status: Confirmed → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-jenkins (master)

Reviewed: https://review.openstack.org/254644
Committed: https://git.openstack.org/cgit/openstack/python-jenkins/commit/?id=302eb5dad6439842e076fead5bd76f20f615e6a8
Submitter: Jenkins
Branch: master

commit 302eb5dad6439842e076fead5bd76f20f615e6a8
Author: Dong Ma <email address hidden>
Date: Tue Dec 8 17:49:38 2015 +0800

    Fixed create_node() Error

    Fixed create_node() raises HTTP Error 400 Bad Request

    This issue caused by:
        self.jenkins_open(Request(
            self._build_url(CREATE_NODE, params), b''))
    The "params" dictionary of options isn't parsed correctly
    during _build_url funciton that Jenkins is expecting

    Fixed it use urlencode to parse the params and construct
    the URL

    Change-Id: I85fa43bc0b4ff1530133b862734e94aede9b44a5
    Closes-Bug: #1500898

Changed in python-jenkins:
status: In Progress → Fix Released
Revision history for this message
Ken Dreyer (Red Hat) (kdreyer-redhat) wrote :

For posterity, the first tagged version to contain that fix was python-jenkins 0.4.12.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.