Skip to content

Commit

Permalink
Merge branch 'master' into github_status
Browse files Browse the repository at this point in the history
  • Loading branch information
adiroiban committed Apr 6, 2013
2 parents 84827eb + 4c0e8e2 commit 53e7cbe
Show file tree
Hide file tree
Showing 132 changed files with 5,790 additions and 1,844 deletions.
1 change: 1 addition & 0 deletions MAINTAINERS.txt
Expand Up @@ -223,3 +223,4 @@ Committers
M: Marc-Antoine Ruel <maruel@chromium.org>
M: Marcus Lindblom <macke@yar.nu>
M: Tom Prince <tom.prince@ualberta.net> (irc:tomprince)
M: Pierre Tardy <tardyp@gmail.com>
52 changes: 31 additions & 21 deletions common/validate.sh
Expand Up @@ -16,7 +16,7 @@ if [ $# -eq 0 ]; then
echo "USAGE: common/validate.sh oldrev"
echo " This script will test a set of patches (oldrev..HEAD) for basic acceptability as a patch"
echo " Run it in an activated virtualenv with the current Buildbot installed, as well as"
echo " sphinx, pyflakes, mock, and coverage."
echo " sphinx, pyflakes, mock, and so on"
echo "To use a different directory for tests, pass TRIALTMP=/path as an env variable"
exit 1
fi
Expand All @@ -27,9 +27,15 @@ status() {
}

ok=true
problem_summary=""
not_ok() {
ok=false
echo "${RED}** ${*} **${NORM}"
problem_summary="$problem_summary"$'\n'"${RED}**${NORM} ${*}"
}

check_tabs() {
git diff "$REVRANGE" | grep -q $'+.*\t'
}

check_long_lines() {
Expand All @@ -38,14 +44,29 @@ check_long_lines() {
for f in $(git diff --name-only --stat "$REVRANGE" | grep '.py$'); do
# don't try to check removed files
[ ! -f "$f" ] && continue
if [ $(git diff "$REVRANGE" $f | grep -c '+.{80}') != 0 ]; then
if [ $(git diff "$REVRANGE" $f | grep -E -c '^\+.{80}') != 0 ]; then
echo " $f"
long_lines=true
fi
done
$long_lines
}

check_relnotes() {
if git diff --exit-code "$REVRANGE" master/docs/relnotes/index.rst >/dev/null 2>&1; then
return 1
else
return 0
fi
}

run_tests() {
if [ -n "${TRIALTMP}" ]; then
TEMP_DIRECTORY_OPT="--temp-directory ${TRIALTMP}"
fi
sandbox/bin/trial --reporter summary ${TEMP_DIRECTORY_OPT} ${TEST}
}

if ! git diff --no-ext-diff --quiet --exit-code; then
not_ok "changed files in working copy"
exit 1
Expand All @@ -54,29 +75,18 @@ fi
echo "${MAGENTA}Validating the following commits:${NORM}"
git log "$REVRANGE" --pretty=oneline || exit 1

status "running tests"
run_tests || not_ok "tests failed"

status "checking formatting"
git diff "$REVRANGE" | grep -q $'+.*\t' && not_ok "$REVRANGE adds tabs"
check_tabs && not_ok "$REVRANGE adds tabs"
check_long_lines && not_ok "$REVRANGE adds long lines"

status "running tests"
if [ -n "${TRIALTMP}" ]; then
echo rm -rf ${TRIALTMP}
TEMP_DIRECTORY_OPT="--temp-directory ${TRIAL_TMP}"
fi

coverage erase || exit 1
coverage run --rcfile=.coveragerc \
sandbox/bin/trial --reporter summary ${TEMP_DIRECTORY_OPT} ${TEST} \
|| not_ok "tests failed"
status "checking for release notes"
check_relnotes || not_ok "$REVRANGE does not add release notes"

status "running pyflakes"
make pyflakes || not_ok "failed pyflakes"

status "coverage report"
coverage report > covreport || exit 1
head -n2 covreport || exit 1
tail -n1 covreport || exit 1
rm covreport || exit 1
sandbox/bin/pyflakes master/buildbot slave/buildslave || not_ok "failed pyflakes"

status "building docs"
make -C master/docs VERSION=latest clean html || not_ok "docs failed"
Expand All @@ -86,6 +96,6 @@ if $ok; then
echo "${GREEN}GOOD!${NORM}"
exit 0
else
echo "${RED}NO GOOD!${NORM}"
echo "${RED}NO GOOD!${NORM}$problem_summary"
exit 1
fi
6 changes: 3 additions & 3 deletions master/buildbot/__init__.py
Expand Up @@ -30,14 +30,14 @@
version = f.read().strip()

except IOError:
from subprocess import Popen, PIPE, STDOUT
from subprocess import Popen, PIPE
import re

VERSION_MATCH = re.compile(r'\d+\.\d+\.\d+(\w|-)*')

try:
dir = os.path.dirname(os.path.abspath(__file__))
p = Popen(['git', 'describe', '--tags', '--always'], cwd=dir, stdout=PIPE, stderr=STDOUT)
dir = os.path.dirname(os.path.abspath(__file__))
p = Popen(['git', 'describe', '--tags', '--always'], cwd=dir, stdout=PIPE, stderr=PIPE)
out = p.communicate()[0]

if (not p.returncode) and out:
Expand Down
Expand Up @@ -18,7 +18,7 @@
from email.Message import Message
from email.Utils import formatdate
from zope.interface import implements
from twisted.python import log, failure
from twisted.python import log
from twisted.internet import defer, reactor
from twisted.application import service
from twisted.spread import pb
Expand Down Expand Up @@ -417,9 +417,9 @@ def _got_commands(commands):
state["slave_commands"] = commands
def _commands_unavailable(why):
# probably an old slave
log.msg("BuildSlave._commands_unavailable")
if why.check(AttributeError):
return
log.msg("BuildSlave.getCommands is unavailable - ignoring")
log.err(why)
d1.addCallbacks(_got_commands, _commands_unavailable)
return d1
Expand Down Expand Up @@ -932,11 +932,26 @@ def insubstantiate(self, fast=False):
yield d
self.insubstantiating = False

@defer.inlineCallbacks
def _soft_disconnect(self, fast=False):
if not self.build_wait_timeout < 0:
return AbstractBuildSlave.disconnect(self)
# a negative build_wait_timeout means the slave should never be shut
# down, so just disconnect.
if self.build_wait_timeout < 0:
yield AbstractBuildSlave.disconnect(self)
return

if self.missing_timer:
self.missing_timer.cancel()
self.missing_timer = None

if self.substantiation_deferred is not None:
log.msg("Weird: Got request to stop before started. Allowing "
"slave to start cleanly to avoid inconsistent state")
yield self.substantiation_deferred
self.substantiation_deferred = None
self.substantiation_build = None
log.msg("Substantiation complete, immediately terminating.")

d = AbstractBuildSlave.disconnect(self)
if self.slave is not None:
# this could be called when the slave needs to shut down, such as
# in BotMaster.removeSlave, *or* when a new slave requests a
Expand All @@ -947,24 +962,15 @@ def _soft_disconnect(self, fast=False):
# here, we just do what should be appropriate for the first case,
# and put our heads in the sand for the second, at least for now.
# The best solution to the odd situation is removing it as a
# possibilty: make the master in charge of connecting to the
# possibility: make the master in charge of connecting to the
# slave, rather than vice versa. TODO.
d = defer.DeferredList([d, self.insubstantiate(fast)])
yield defer.DeferredList([
AbstractBuildSlave.disconnect(self),
self.insubstantiate(fast)
], consumeErrors=True, fireOnOneErrback=True)
else:
if self.substantiation_deferred is not None:
# unlike the previous block, we don't expect this situation when
# ``attached`` calls ``disconnect``, only when we get a simple
# request to "go away".
d = self.substantiation_deferred
self.substantiation_deferred = None
self.substantiation_build = None
d.errback(failure.Failure(
RuntimeError("soft disconnect aborted substantiation")))
if self.missing_timer:
self.missing_timer.cancel()
self.missing_timer = None
self.stop_instance()
return d
yield AbstractBuildSlave.disconnect(self)
yield self.stop_instance(fast)

def disconnect(self):
# This returns a Deferred but we don't use it
Expand Down
183 changes: 183 additions & 0 deletions master/buildbot/buildslave/openstack.py
@@ -0,0 +1,183 @@
# This file is part of Buildbot. Buildbot is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Portions Copyright Buildbot Team Members
# Portions Copyright 2013 Cray Inc.

import time

from twisted.internet import defer, threads
from twisted.python import log

from buildbot.buildslave import AbstractLatentBuildSlave
from buildbot import config, interfaces

try:
import novaclient.exceptions as nce
from novaclient.v1_1 import client
_hush_pyflakes = [nce, client]
except ImportError:
nce = None
client = None


ACTIVE = 'ACTIVE'
BUILD = 'BUILD'
DELETED = 'DELETED'
UNKNOWN = 'UNKNOWN'

class OpenStackLatentBuildSlave(AbstractLatentBuildSlave):

instance = None
_poll_resolution = 5 # hook point for tests

def __init__(self, name, password,
flavor,
image,
os_username,
os_password,
os_tenant_name,
os_auth_url,
meta=None,
max_builds=None, notify_on_missing=[], missing_timeout=60*20,
build_wait_timeout=60*10, properties={}, locks=None):

if not client or not nce:
config.error("The python module 'novaclient' is needed "
"to use a OpenStackLatentBuildSlave")

AbstractLatentBuildSlave.__init__(
self, name, password, max_builds, notify_on_missing,
missing_timeout, build_wait_timeout, properties, locks)
self.flavor = flavor
self.image = image
self.os_username = os_username
self.os_password = os_password
self.os_tenant_name = os_tenant_name
self.os_auth_url = os_auth_url
self.meta = meta

def _getImage(self, os_client):
# If self.image is a callable, then pass it the list of images. The
# function should return the image's UUID to use.
if callable(self.image):
image_uuid = self.image(os_client.images.list())
else:
image_uuid = self.image
return image_uuid

def start_instance(self, build):
if self.instance is not None:
raise ValueError('instance active')
return threads.deferToThread(self._start_instance)

def _start_instance(self):
# Authenticate to OpenStack.
os_client = client.Client(self.os_username, self.os_password,
self.os_tenant_name, self.os_auth_url)
image_uuid = self._getImage(os_client)
flavor_id = self.flavor
boot_args = [self.slavename, image_uuid, flavor_id]
boot_kwargs = {}
if self.meta is not None:
boot_kwargs['meta'] = self.meta
self.instance = os_client.servers.create(*boot_args, **boot_kwargs)
log.msg('%s %s starting instance %s (image %s)' %
(self.__class__.__name__, self.slavename, self.instance.id,
image_uuid))
duration = 0
interval = self._poll_resolution
inst = self.instance
while inst.status == BUILD:
time.sleep(interval)
duration += interval
if duration % 60 == 0:
log.msg('%s %s has waited %d minutes for instance %s' %
(self.__class__.__name__, self.slavename, duration//60,
self.instance.id))
try:
inst = os_client.servers.get(self.instance.id)
except nce.NotFound:
log.msg('%s %s instance %s (%s) went missing' %
(self.__class__.__name__, self.slavename,
self.instance.id, self.instance.name))
raise interfaces.LatentBuildSlaveFailedToSubstantiate(
self.instance.id, self.instance.status)
if inst.status == ACTIVE:
minutes = duration//60
seconds = duration%60
log.msg('%s %s instance %s (%s) started '
'in about %d minutes %d seconds' %
(self.__class__.__name__, self.slavename,
self.instance.id, self.instance.name, minutes, seconds))
return [self.instance.id, image_uuid,
'%02d:%02d:%02d' % (minutes//60, minutes%60, seconds)]
else:
log.msg('%s %s failed to start instance %s (%s)' %
(self.__class__.__name__, self.slavename,
self.instance.id, inst.status))
raise interfaces.LatentBuildSlaveFailedToSubstantiate(
self.instance.id, self.instance.status)

def stop_instance(self, fast=False):
if self.instance is None:
# be gentle. Something may just be trying to alert us that an
# instance never attached, and it's because, somehow, we never
# started.
return defer.succeed(None)
instance = self.instance
self.instance = None
return threads.deferToThread(self._stop_instance, instance, fast)

def _stop_instance(self, instance, fast):
# Authenticate to OpenStack. This is needed since it seems the update
# method doesn't do a whole lot of updating right now.
os_client = client.Client(self.os_username, self.os_password,
self.os_tenant_name, self.os_auth_url)
# When the update method does work, replace the lines like below with
# instance.update().
try:
inst = os_client.servers.get(instance.id)
except nce.NotFound:
# If can't find the instance, then it's already gone.
log.msg('%s %s instance %s (%s) already terminated' %
(self.__class__.__name__, self.slavename, instance.id,
instance.name))
return
if inst.status not in (DELETED, UNKNOWN):
inst.delete()
log.msg('%s %s terminating instance %s (%s)' %
(self.__class__.__name__, self.slavename, instance.id,
instance.name))
duration = 0
interval = self._poll_resolution
if fast:
goal = (DELETED, UNKNOWN)
else:
goal = (DELETED,)
while inst.status not in goal:
time.sleep(interval)
duration += interval
if duration % 60 == 0:
log.msg(
'%s %s has waited %d minutes for instance %s to end' %
(self.__class__.__name__, self.slavename, duration//60,
instance.id))
try:
inst = os_client.servers.get(instance.id)
except nce.NotFound:
break
log.msg('%s %s instance %s %s '
'after about %d minutes %d seconds' %
(self.__class__.__name__, self.slavename,
instance.id, goal, duration//60, duration%60))

0 comments on commit 53e7cbe

Please sign in to comment.