Files
devstack-gate/myjenkins.py
James E. Blair f32f06b50b Make devstack nodes jenkins slaves.
Add them as nodes with the tag "devstack-IMAGE" where IMAGE is, eg,
oneiric, with a single executor.  Change the reap job to delete
these jenkins nodes.  Change the delete script to simply mark them
for deletion.  It should then be called by a new job that is a
post-build step for the devstack gate job.  Another new job should
be called as the first build step in the devstack gate, and it should
invoke devstack-vm-inprogress.py to disable the node that the job
just started running on.  In this manner, we end up with single-use
jenkins slaves.

Change the gate script to expect to be run the host itself, so it
no longer needs to ssh and scp/rsync files around.

Add a new script, devstack-vm-gate-wrap.sh, which assists running
the gate job on a separate devstack host, as is currently done,
to test it out without requiring the full Jenkins infrastructure.

Change-Id: I28902918406670163d32ae7c2a644055233dc1fa
2012-05-22 01:36:08 +00:00

94 lines
3.2 KiB
Python

import jenkins
import json
import urllib
import urllib2
from jenkins import JenkinsException, NODE_TYPE, CREATE_NODE
TOGGLE_OFFLINE = '/computer/%(name)s/toggleOffline?offlineMessage=%(msg)s'
class Jenkins(jenkins.Jenkins):
def disable_node(self, name, msg=''):
'''
Disable a node
@param name: Jenkins node name
@type name: str
@param msg: Offline message
@type msg: str
'''
info = self.get_node_info(name)
if info['offline']:
return
self.jenkins_open(urllib2.Request(self.server + TOGGLE_OFFLINE%locals()))
def enable_node(self, name):
'''
Enable a node
@param name: Jenkins node name
@type name: str
'''
info = self.get_node_info(name)
if not info['offline']:
return
msg = ''
self.jenkins_open(urllib2.Request(self.server + TOGGLE_OFFLINE%locals()))
def create_node(self, name, numExecutors=2, nodeDescription=None,
remoteFS='/var/lib/jenkins', labels=None, exclusive=False,
launcher='hudson.slaves.JNLPLauncher', launcher_params={}):
'''
@param name: name of node to create
@type name: str
@param numExecutors: number of executors for node
@type numExecutors: int
@param nodeDescription: Description of node
@type nodeDescription: str
@param remoteFS: Remote filesystem location to use
@type remoteFS: str
@param labels: Labels to associate with node
@type labels: str
@param exclusive: Use this node for tied jobs only
@type exclusive: boolean
@param launcher: The launch method for the slave
@type launcher: str
@param launcher_params: Additional parameters for the launcher
@type launcher_params: dict
'''
if self.node_exists(name):
raise JenkinsException('node[%s] already exists'%(name))
mode = 'NORMAL'
if exclusive:
mode = 'EXCLUSIVE'
#hudson.plugins.sshslaves.SSHLauncher
#hudson.slaves.CommandLauncher
#hudson.os.windows.ManagedWindowsServiceLauncher
launcher_params['stapler-class'] = launcher
inner_params = {
'name' : name,
'nodeDescription' : nodeDescription,
'numExecutors' : numExecutors,
'remoteFS' : remoteFS,
'labelString' : labels,
'mode' : mode,
'type' : NODE_TYPE,
'retentionStrategy' : { 'stapler-class' : 'hudson.slaves.RetentionStrategy$Always' },
'nodeProperties' : { 'stapler-class-bag' : 'true' },
'launcher' : launcher_params
}
params = {
'name' : name,
'type' : NODE_TYPE,
'json' : json.dumps(inner_params)
}
self.jenkins_open(urllib2.Request(self.server + CREATE_NODE%urllib.urlencode(params)))
if not self.node_exists(name):
raise JenkinsException('create[%s] failed'%(name))