]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Locking changes needed for libcloud
authorZack Cerza <zack@redhat.com>
Wed, 4 Jan 2017 17:22:44 +0000 (10:22 -0700)
committerZack Cerza <zack@redhat.com>
Fri, 24 Feb 2017 16:03:33 +0000 (09:03 -0700)
Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/lock.py
teuthology/provision/__init__.py
teuthology/provision/test/test_downburst.py

index 846c2ceefcbb8b938858cd39ede6697e73f1afaf..ebe7827f79e8d737a01e42a3c341b0ea99812770 100644 (file)
@@ -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.',
index a2ae82894b018003858a0b2ac31dcc43521cfed7..cfc4038fb2e80ffab7e23276b4ba2e269000ba75 100644 (file)
@@ -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)
index ecbf400b10011e9d0cf1490c923e69d87ae1fd91..53d8e54c5f943857503f81cb0dfc39104c6b3663 100644 (file)
@@ -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