Change the label of devstack nodes on use.

Instead of disconnecting then node, change the label to
"devstack-used", which is a label we will never use for a job.
That way the node will not be re-used, but we don't get a warning
in the job console output about the node going offline.

Also, make sure the nodes are created for exclusive use
(tied jobs only).

Change-Id: Ib162d78baee17452cec13c150235f3584737d3c3
This commit is contained in:
James E. Blair 2012-06-21 22:51:43 +00:00 committed by Gerrit Code Review
parent 05a70c24ef
commit 848dbdcfdd
3 changed files with 26 additions and 1 deletions

View File

@ -29,11 +29,13 @@ import myjenkins
import vmdatabase
import utils
import novaclient
import re
NODE_NAME = sys.argv[1]
DEVSTACK_GATE_SECURE_CONFIG = os.environ.get('DEVSTACK_GATE_SECURE_CONFIG',
os.path.expanduser('~/devstack-gate-secure.conf'))
LABEL_RE = re.compile(r'<label>.*</label>')
def main():
db = vmdatabase.VMDatabase()
@ -51,7 +53,9 @@ def main():
if machine.jenkins_name:
if jenkins.node_exists(machine.jenkins_name):
jenkins.disable_node(machine.jenkins_name, "Devstack build started")
config = jenkins.get_node_config(machine.jenkins_name)
config = LABEL_RE.sub('<label>devstack-used</label>', config)
jenkins.reconfig_node(machine.jenkins_name, config)
if __name__ == '__main__':

View File

@ -91,6 +91,7 @@ def create_jenkins_node(jenkins, machine):
nodeDescription='Dynamic single use %s slave for devstack' % machine.base_image.name,
remoteFS='/home/jenkins',
labels='%sdevstack-%s' % (DEVSTACK_GATE_PREFIX, machine.base_image.name),
exclusive=True,
launcher='hudson.plugins.sshslaves.SSHLauncher',
launcher_params = {'port': 22, 'username': 'jenkins',
'privatekey': '/var/lib/jenkins/.ssh/id_rsa',

View File

@ -5,6 +5,7 @@ import urllib2
from jenkins import JenkinsException, NODE_TYPE, CREATE_NODE
TOGGLE_OFFLINE = '/computer/%(name)s/toggleOffline?offlineMessage=%(msg)s'
CONFIG_NODE = '/computer/%(name)s/config.xml'
class Jenkins(jenkins.Jenkins):
def disable_node(self, name, msg=''):
@ -34,6 +35,25 @@ class Jenkins(jenkins.Jenkins):
msg = ''
self.jenkins_open(urllib2.Request(self.server + TOGGLE_OFFLINE%locals()))
def get_node_config(self, name):
'''
Get the configuration for a node.
:param name: Jenkins node name, ``str``
'''
get_config_url = self.server + CONFIG_NODE%locals()
return self.jenkins_open(urllib2.Request(get_config_url))
def reconfig_node(self, name, config_xml):
'''
Change the configuration for an existing node.
:param name: Jenkins node name, ``str``
:param config_xml: New XML configuration, ``str``
'''
headers = {'Content-Type': 'text/xml'}
reconfig_url = self.server + CONFIG_NODE%locals()
self.jenkins_open(urllib2.Request(reconfig_url, config_xml, headers))
def create_node(self, name, numExecutors=2, nodeDescription=None,
remoteFS='/var/lib/jenkins', labels=None, exclusive=False,