pycontribs / jenkinsapi

A Python API for accessing resources and configuring Hudson & Jenkins continuous-integration servers
http://pypi.python.org/pypi/jenkinsapi
MIT License
857 stars 485 forks source link

Issue with Jenkins slave with the name "Built-In Node" #816

Closed manowar689 closed 1 year ago

manowar689 commented 2 years ago
ISSUE TYPE
Jenkinsapi version: latest
Jenkins 2.319.1
SUMMARY

Issue with "Built-In Node" being called, suggest checking the url and file / replacing like so:

if "Built-In" in url: 
    url = url.replace("Built-In%20Node","(built-in)")
EXPECTED RESULTS
ACTUAL RESULTS
USEFUL INFORMATION
12:30:07  Traceback (most recent call last):
12:30:07    File "/var/lib/jenkins/.local/lib/python3.7/site-packages/jenkinsapi/nodes.py", line 77, in iteritems
12:30:07      yield nodename, self._make_node(nodename)
12:30:07    File "/var/lib/jenkins/.local/lib/python3.7/site-packages/jenkinsapi/nodes.py", line 65, in _make_node
12:30:07      return Node(self.jenkins, nodeurl, nodename, node_dict={})
12:30:07    File "/var/lib/jenkins/.local/lib/python3.7/site-packages/jenkinsapi/node.py", line 97, in __init__
12:30:07      JenkinsBase.__init__(self, baseurl, poll=poll)
12:30:07    File "/var/lib/jenkins/.local/lib/python3.7/site-packages/jenkinsapi/jenkinsbase.py", line 38, in __init__
12:30:07      self.poll()
12:30:07    File "/var/lib/jenkins/.local/lib/python3.7/site-packages/jenkinsapi/jenkinsbase.py", line 60, in poll
12:30:07      data = self._poll(tree=tree)
12:30:07    File "/var/lib/jenkins/.local/lib/python3.7/site-packages/jenkinsapi/jenkinsbase.py", line 70, in _poll
12:30:07      return self.get_data(url, tree=tree)
12:30:07    File "/var/lib/jenkins/.local/lib/python3.7/site-packages/jenkinsapi/jenkinsbase.py", line 84, in get_data
12:30:07      response.raise_for_status()
12:30:07    File "/var/lib/jenkins/.local/lib/python3.7/site-packages/requests/models.py", line 941, in raise_for_status
12:30:07      raise HTTPError(http_error_msg, response=self)
12:30:07  requests.exceptions.HTTPError: 
404 Client Error: Not Found for url: https://ops-jenkins-master.example.com/computer/Built-In%20Node/api/python

 this can be easily fixed by calling:
https://ops-jenkins-master.example.com/computer/(built-in)/api/python
as I have successfully tested this without issue
HarshalKondhalkar commented 1 year ago

Workaround:

File path: /usr/local/lib/python3.6/site-packages/jenkinsapi Inside the following path, nodes.py and node.py are the files which are supposed to be edited.

vi nodes.py Previous: def _make_node(self, nodename): """ Creates an instance of Node for the given nodename. This function assumes the returned node exists. """ if nodename.lower() == 'master': nodeurl = '%s/(%s)' % (self.baseurl, nodename) else: nodeurl = '%s/%s' % (self.baseurl, nodename) return Node(self.jenkins, nodeurl, nodename, node_dict={})

Changed: def _make_node(self, nodename): """ Creates an instance of Node for the given nodename. This function assumes the returned node exists. """ if nodename.lower() == 'built-in': nodeurl = '%s/(%s)' % (self.baseurl, nodename) else: nodeurl = '%s/%s' % (self.baseurl, nodename) return Node(self.jenkins, nodeurl, nodename, node_dict={})

vi node.py Previous: self.name = nodename self.jenkins = jenkins_obj if not baseurl: poll = False baseurl = '%s/computer/%s' % (self.jenkins.baseurl, self.name) JenkinsBase.init(self, baseurl, poll=poll) self.node_attributes = node_dict self._element_tree = None self._config = None

Changed: def init(self, jenkins_obj, baseurl, nodename, node_dict, poll=True): self.name = nodename self.jenkins = jenkins_obj if not baseurl: poll = False baseurl = '%s/computer/%s' % (self.jenkins.baseurl, self.name) if "built-in" in baseurl.lower(): self.name = "built-in" baseurl = '%s/computer/(%s)' % (self.jenkins.baseurl.lower(), self.name) JenkinsBase.init(self, baseurl, poll=poll) self.node_attributes = node_dict self._element_tree = None self._config = None

Here I have replaced hardcoded "master" and replaced with "built-in"(As per Jenkins Upgrade) Also added condition for built-in and customized the base url.

Thanks!

manowar689 commented 1 year ago

Hey HarshalKondhalkar, Thanks again for fixing my issue, the changes you have mentioned above are working, the admins of this package this should be added into the next release as it has solved my issue

lechat commented 1 year ago

This is now fixed in library code. I will do new release soon.