Skip to content

Commit

Permalink
Add method to update offline reason for a node. (pycontribs#613)
Browse files Browse the repository at this point in the history
* Add method to update offline reason for a node.

* fixed bugs and added test
  • Loading branch information
vaideesw authored and lechat committed Nov 10, 2018
1 parent 9874906 commit 2ecfd56
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
12 changes: 12 additions & 0 deletions jenkinsapi/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,18 @@ def toggle_temporarily_offline(self, message="requested from jenkinsapi"):
"The node state has not changed: temporarilyOffline = %s" %
state)

def update_offline_reason(self, reason):
"""
Update offline reason on a temporary offline clsuter
"""

if self.is_temporarily_offline():
url = self.baseurl + '/changeOfflineCause?offlineMessage=' + urlquote(reason)
self.jenkins.requester.post_and_confirm_status(url, data={})

def offline_reason(self):
return self._data['offlineCauseReason']

@property
def _et(self):
return self._get_config_element_tree()
Expand Down
23 changes: 23 additions & 0 deletions jenkinsapi_tests/systests/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,26 @@ def test_set_master_executors(jenkins):
assert node.get_num_executors() == 5

node.set_num_executors(2)


def test_offline_reason(jenkins):
node_name = random_string()
node_labels = 'LABEL1 LABEL2'
node_dict = {
'num_executors': 1,
'node_description': 'Test Node with Labels',
'remote_fs': '/tmp',
'labels': node_labels,
'exclusive': True
}
node = jenkins.nodes.create_node(node_name, node_dict)

node.toggle_temporarily_offline('test1')
node.poll()
assert node.offline_reason() == 'test1'

node.update_offline_reason('test2')
node.poll()
assert node.offline_reason() == 'test2'

del jenkins.nodes[node_name]

0 comments on commit 2ecfd56

Please sign in to comment.