diff --git a/master/buildbot/worker/openstack.py b/master/buildbot/worker/openstack.py index ce0ec1af4..f4b7e4c1f 100644 --- a/master/buildbot/worker/openstack.py +++ b/master/buildbot/worker/openstack.py @@ -250,6 +250,15 @@ class OpenStackLatentWorker(CompatibleLatentWorkerMixin, nova_args = yield build.render(self.nova_args) 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: block_devices = [] for bd in self.block_devices: @@ -270,6 +279,8 @@ class OpenStackLatentWorker(CompatibleLatentWorkerMixin, return res def _start_instance(self, image_uuid, flavor_uuid, block_devices, nova_args, meta): + # ensure existing, potentially duplicated, workers are stopped + self._stop_all_instances() boot_args = [self.workername, image_uuid, flavor_uuid] boot_kwargs = dict( meta=meta, @@ -330,6 +341,14 @@ class OpenStackLatentWorker(CompatibleLatentWorkerMixin, self._stop_instance(instance, fast) return None + def _stop_all_instances(self): + instances = self.novaclient.servers.findall(name=self.name) + if not instance: + return + for instance in instances: + if instance.metadata.get("BUILDBOT:instance", "") == self.masterhash: + self._stop_instance(instance, True) + def _stop_instance(self, instance, fast): try: instance = self.novaclient.servers.get(instance.id)