From cf020e0a745e334158ab14b5eaf11a99a2b5f696 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Wed, 4 Jan 2017 10:22:44 -0700 Subject: [PATCH] Locking changes needed for libcloud Signed-off-by: Zack Cerza --- teuthology/lock.py | 10 +++++--- teuthology/provision/__init__.py | 27 +++++++++++++++++---- teuthology/provision/test/test_downburst.py | 23 ++++++++++++------ 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/teuthology/lock.py b/teuthology/lock.py index 846c2ceefc..ebe7827f79 100644 --- a/teuthology/lock.py +++ b/teuthology/lock.py @@ -429,9 +429,9 @@ def lock_many(ctx, num, machine_type, user=None, description=None, machine_type=machine_type, description=description, ) - # Only query for os_type/os_version if non-vps, since in that case we - # just create them. - if machine_type != 'vps': + # Only query for os_type/os_version if non-vps and non-libcloud, since + # in that case we just create them. + if machine_type not in ['vps'] + provision.cloud.get_types(): if os_type: data['os_type'] = os_type if os_version: @@ -449,7 +449,7 @@ def lock_many(ctx, num, machine_type, user=None, description=None, machine['ssh_pub_key'] for machine in response.json()} log.debug('locked {machines}'.format( machines=', '.join(machines.keys()))) - if machine_type == 'vps': + if machine_type in ['vps'] + provision.cloud.get_types(): ok_machs = {} for machine in machines: if provision.create_if_vm(ctx, machine): @@ -459,6 +459,8 @@ def lock_many(ctx, num, machine_type, user=None, description=None, machine) unlock_one(ctx, machine, user) return ok_machs + if machine_type in provision.cloud.get_types(): + machines = do_update_keys(machines.keys()) return machines elif response.status_code == 503: log.error('Insufficient nodes available to lock %d %s nodes.', diff --git a/teuthology/provision/__init__.py b/teuthology/provision/__init__.py index a2ae82894b..cfc4038fb2 100644 --- a/teuthology/provision/__init__.py +++ b/teuthology/provision/__init__.py @@ -5,6 +5,8 @@ from ..lockstatus import get_status from .downburst import Downburst from .openstack import ProvisionOpenStack +import cloud + log = logging.getLogger(__name__) @@ -19,10 +21,21 @@ def create_if_vm(ctx, machine_name, _downburst=None): status_info = _downburst.status else: status_info = get_status(machine_name) - if not status_info.get('is_vm', False): - return False + shortname = decanonicalize_hostname(machine_name) + machine_type = status_info['machine_type'] os_type = get_distro(ctx) os_version = get_distro_version(ctx) + if not status_info.get('is_vm', False): + return False + + if machine_type in cloud.get_types(): + return cloud.get_provisioner( + machine_type, + shortname, + os_type, + os_version, + conf=getattr(ctx, 'config', dict()), + ).create() has_config = hasattr(ctx, 'config') and ctx.config is not None if has_config and 'downburst' in ctx.config: @@ -63,9 +76,13 @@ def destroy_if_vm(ctx, machine_name, user=None, description=None, log.error(msg.format(node=machine_name, desc_arg=description, desc_lock=status_info['description'])) return False - if status_info.get('machine_type') == 'openstack': - return ProvisionOpenStack().destroy( - decanonicalize_hostname(machine_name)) + machine_type = status_info.get('machine_type') + shortname = decanonicalize_hostname(machine_name) + if machine_type == 'openstack': + return ProvisionOpenStack().destroy(shortname) + elif machine_type in cloud.get_types(): + return cloud.get_provisioner( + machine_type, shortname, None, None).destroy() dbrst = _downburst or Downburst(name=machine_name, os_type=None, os_version=None, status=status_info) diff --git a/teuthology/provision/test/test_downburst.py b/teuthology/provision/test/test_downburst.py index ecbf400b10..53d8e54c5f 100644 --- a/teuthology/provision/test/test_downburst.py +++ b/teuthology/provision/test/test_downburst.py @@ -13,6 +13,7 @@ class TestDownburst(object): self.status = dict( vm_host=dict(name='host999'), is_vm=True, + machine_type='mtype', ) def test_create_if_vm_success(self): @@ -20,7 +21,8 @@ class TestDownburst(object): ctx = self.ctx status = self.status - dbrst = provision.Downburst(name, ctx.os_type, ctx.os_version, status) + dbrst = provision.Downburst( + name, ctx.os_type, ctx.os_version, status) dbrst.executable = '/fake/path' dbrst.build_config = MagicMock(name='build_config') dbrst._run_create = MagicMock(name='_run_create') @@ -41,7 +43,8 @@ class TestDownburst(object): ctx = self.ctx status = self.status - dbrst = provision.Downburst(name, ctx.os_type, ctx.os_version, status) + dbrst = provision.Downburst( + name, ctx.os_type, ctx.os_version, status) dbrst.destroy = MagicMock(name='destroy') dbrst.destroy.return_value = True @@ -56,7 +59,8 @@ class TestDownburst(object): status = self.status status['locked_by'] = 'user@a' - dbrst = provision.Downburst(name, ctx.os_type, ctx.os_version, status) + dbrst = provision.Downburst( + name, ctx.os_type, ctx.os_version, status) dbrst.destroy = MagicMock(name='destroy', side_effect=RuntimeError) result = provision.destroy_if_vm(ctx, name, user='user@b', @@ -69,7 +73,8 @@ class TestDownburst(object): status = self.status status['description'] = 'desc_a' - dbrst = provision.Downburst(name, ctx.os_type, ctx.os_version, status) + dbrst = provision.Downburst( + name, ctx.os_type, ctx.os_version, status) dbrst.destroy = MagicMock(name='destroy') dbrst.destroy = MagicMock(name='destroy', side_effect=RuntimeError) @@ -77,22 +82,24 @@ class TestDownburst(object): _downburst=dbrst) assert result is False - @patch('teuthology.provision.downburst.downburst_executable') + @patch('teuthology.provision_executable') def test_create_fails_without_executable(self, m_exec): name = self.name ctx = self.ctx status = self.status m_exec.return_value = '' - dbrst = provision.Downburst(name, ctx.os_type, ctx.os_version, status) + dbrst = provision.Downburst( + name, ctx.os_type, ctx.os_version, status) result = dbrst.create() assert result is False - @patch('teuthology.provision.downburst.downburst_executable') + @patch('teuthology.provision_executable') def test_destroy_fails_without_executable(self, m_exec): name = self.name ctx = self.ctx status = self.status m_exec.return_value = '' - dbrst = provision.Downburst(name, ctx.os_type, ctx.os_version, status) + dbrst = provision.Downburst( + name, ctx.os_type, ctx.os_version, status) result = dbrst.destroy() assert result is False -- 2.39.5