"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "buildbot/worker/openstack.py" between
buildbot-3.0.2.tar.gz and buildbot-3.1.0.tar.gz

About: Buildbot is a continuous integration testing framework (Python-based). It supports also automation of complex build systems, application deployment, and management of sophisticated software-release processes.

openstack.py  (buildbot-3.0.2):openstack.py  (buildbot-3.1.0)
skipping to change at line 17 skipping to change at line 17
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details. # details.
# #
# You should have received a copy of the GNU General Public License along with # 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 # this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# #
# Portions Copyright Buildbot Team Members # Portions Copyright Buildbot Team Members
# Portions Copyright 2013 Cray Inc. # Portions Copyright 2013 Cray Inc.
import hashlib
import math import math
import time import time
from twisted.internet import defer from twisted.internet import defer
from twisted.internet import threads from twisted.internet import threads
from twisted.python import log from twisted.python import log
from buildbot import config from buildbot import config
from buildbot.interfaces import LatentWorkerFailedToSubstantiate from buildbot.interfaces import LatentWorkerFailedToSubstantiate
from buildbot.util import unicode2bytes
from buildbot.util.latent import CompatibleLatentWorkerMixin from buildbot.util.latent import CompatibleLatentWorkerMixin
from buildbot.worker import AbstractLatentWorker from buildbot.worker import AbstractLatentWorker
try: try:
from keystoneauth1 import loading from keystoneauth1 import loading
from keystoneauth1 import session from keystoneauth1 import session
from novaclient import client from novaclient import client
from novaclient.exceptions import NotFound from novaclient.exceptions import NotFound
_hush_pyflakes = [client] _hush_pyflakes = [client]
except ImportError: except ImportError:
skipping to change at line 146 skipping to change at line 148
self.novaclient.client.region_name = region self.novaclient.client.region_name = region
if block_devices is not None: if block_devices is not None:
self.block_devices = [ self.block_devices = [
self._parseBlockDevice(bd) for bd in block_devices] self._parseBlockDevice(bd) for bd in block_devices]
else: else:
self.block_devices = None self.block_devices = None
self.image = image self.image = image
self.meta = meta self.meta = meta
self.nova_args = nova_args if nova_args is not None else {} self.nova_args = nova_args if nova_args is not None else {}
masterName = unicode2bytes(self.master.name)
self.masterhash = hashlib.sha1(masterName).hexdigest()[:6]
def _constructClient(self, client_version, auth_args): def _constructClient(self, client_version, auth_args):
"""Return a novaclient from the given args.""" """Return a novaclient from the given args."""
auth_plugin = auth_args.pop('auth_type', 'password') auth_plugin = auth_args.pop('auth_type', 'password')
loader = loading.get_plugin_loader(auth_plugin) loader = loading.get_plugin_loader(auth_plugin)
auth = loader.load_from_options(**auth_args) auth = loader.load_from_options(**auth_args)
sess = session.Session(auth=auth) sess = session.Session(auth=auth)
skipping to change at line 250 skipping to change at line 254
flavor_uuid = flavor.id flavor_uuid = flavor.id
return flavor_uuid return flavor_uuid
@defer.inlineCallbacks @defer.inlineCallbacks
def renderWorkerProps(self, build): def renderWorkerProps(self, build):
image = yield self._getImage(build) image = yield self._getImage(build)
flavor = yield self._getFlavor(build) flavor = yield self._getFlavor(build)
nova_args = yield build.render(self.nova_args) nova_args = yield build.render(self.nova_args)
meta = yield build.render(self.meta) meta = yield build.render(self.meta)
worker_meta = {
'BUILDBOT:instance': self.masterhash,
}
if meta is None:
meta = worker_meta
else:
meta.update(worker_meta)
if self.block_devices is not None: if self.block_devices is not None:
block_devices = [] block_devices = []
for bd in self.block_devices: for bd in self.block_devices:
rendered_block_device = yield self._renderBlockDevice(bd, build) rendered_block_device = yield self._renderBlockDevice(bd, build)
block_devices.append(rendered_block_device) block_devices.append(rendered_block_device)
else: else:
block_devices = None block_devices = None
return (image, flavor, block_devices, nova_args, meta) return (image, flavor, block_devices, nova_args, meta)
@defer.inlineCallbacks @defer.inlineCallbacks
def start_instance(self, build): def start_instance(self, build):
if self.instance is not None: if self.instance is not None:
raise ValueError('instance active') raise ValueError('instance active')
image, flavor, block_devices, nova_args, meta = yield self.renderWorkerP ropsOnStart(build) image, flavor, block_devices, nova_args, meta = yield self.renderWorkerP ropsOnStart(build)
res = yield threads.deferToThread(self._start_instance, image, flavor, res = yield threads.deferToThread(self._start_instance, image, flavor,
block_devices, nova_args, meta) block_devices, nova_args, meta)
return res return res
def _start_instance(self, image_uuid, flavor_uuid, block_devices, nova_args, meta): def _start_instance(self, image_uuid, flavor_uuid, block_devices, nova_args, meta):
# ensure existing, potentially duplicated, workers are stopped
self._stop_instance(None, True)
# then try to start new one
boot_args = [self.workername, image_uuid, flavor_uuid] boot_args = [self.workername, image_uuid, flavor_uuid]
boot_kwargs = dict( boot_kwargs = dict(
meta=meta, meta=meta,
block_device_mapping_v2=block_devices, block_device_mapping_v2=block_devices,
**nova_args) **nova_args)
instance = self.novaclient.servers.create(*boot_args, **boot_kwargs) instance = self.novaclient.servers.create(*boot_args, **boot_kwargs)
# There is an issue when using sessions that the status is not # There is an issue when using sessions that the status is not
# available on the first try. Trying again will work fine. Fetch the # available on the first try. Trying again will work fine. Fetch the
# instance to avoid that. # instance to avoid that.
try: try:
skipping to change at line 319 skipping to change at line 336
seconds = duration % 60 seconds = duration % 60
log.msg('{} {} instance {} ({}) started in about {} minutes {} secon ds'.format( log.msg('{} {} instance {} ({}) started in about {} minutes {} secon ds'.format(
self.__class__.__name__, self.workername, instance.id, insta nce.name, minutes, self.__class__.__name__, self.workername, instance.id, insta nce.name, minutes,
seconds)) seconds))
return [instance.id, image_uuid, return [instance.id, image_uuid,
'%02d:%02d:%02d' % (minutes // 60, minutes % 60, seconds)] '%02d:%02d:%02d' % (minutes // 60, minutes % 60, seconds)]
else: else:
self.failed_to_start(instance.id, instance.status) self.failed_to_start(instance.id, instance.status)
def stop_instance(self, fast=False): 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 instance = self.instance
self.instance = None self.instance = None
self.resetWorkerPropsOnStop() self.resetWorkerPropsOnStop()
self._stop_instance(instance, fast) self._stop_instance(instance, fast)
return None
def _stop_instance(self, instance, fast): def _stop_instance(self, instance_param, fast):
instances = []
try: try:
instance = self.novaclient.servers.get(instance.id) if instance_param is None:
filter_f = lambda instance: \
instance.metadata.get("BUILDBOT:instance", "") == self.m
asterhash
instances = list(filter(filter_f, self.novaclient.servers.findal
l(name=self.name)))
else:
instances = [self.novaclient.servers.get(instance_param.id)]
except NotFound: except NotFound:
# If can't find the instance, then it's already gone. # If can't find the instance, then it's already gone.
log.msg('{} {} instance {} ({}) already terminated'.format(self.__cl ass__.__name__, log.msg('{} {} instance {} ({}) already terminated'.format(self.__cl ass__.__name__,
self.work self.work
ername, instance.id, ername,
instance. instance_
name)) param.id,
return instance_
if instance.status not in (DELETED, UNKNOWN): param.name))
instance.delete() for instance in instances:
log.msg('{} {} terminating instance {} ({})'.format(self.__class__._ if instance.status not in (DELETED, UNKNOWN):
_name__, instance.delete()
self.workername, log.msg('{} {} terminating instance {} ({})'.format(self.__class
instance.id, __.__name__,
instance.name)) self.workern
ame, instance.id,
instance.nam
e))
 End of changes. 10 change blocks. 
8 lines changed or deleted 27 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)