]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Allow ability to use multi machine type deliminated by ,- \t.
authorSandon Van Ness <sandon@inktank.com>
Thu, 21 Nov 2013 22:19:44 +0000 (14:19 -0800)
committerSandon Van Ness <sandon@inktank.com>
Thu, 21 Nov 2013 22:19:44 +0000 (14:19 -0800)
I was originally attempting a more complicated locking mechanism
but I think its almost as good to just have it attempt the other
machine type if one.

Signed-off-by: Sandon Van Ness <sandon@inktank.com>
teuthology/lock.py
teuthology/misc.py
teuthology/test/test_get_multi_machine_types.py [new file with mode: 0644]

index ac1c44de96ceb499d5894c0b42ddd4557e48e811..7fdde6feb9845fdea70c2dfdc20ff64ba043bde0 100644 (file)
@@ -21,36 +21,38 @@ log = logging.getLogger(__name__)
 
 
 def lock_many(ctx, num, machinetype, user=None, description=None):
-    if user is None:
-        user = misc.get_user()
-    success, content, status = ls.send_request(
-        'POST',
-        config.lock_server,
-        urllib.urlencode(
-            dict(
-                user=user,
-                num=num,
-                machinetype=machinetype,
-                desc=description,
-            )))
-    if success:
-        machines = json.loads(content)
-        log.debug('locked {machines}'.format(
-            machines=', '.join(machines.keys())))
-        if ctx.machine_type == 'vps':
-            ok_machs = {}
-            for machine in machines:
-                if create_if_vm(ctx, machine):
-                    ok_machs[machine] = machines[machine]
-                else:
-                    log.error('Unable to create virtual machine: %s' % machine)
-                    unlock_one(ctx, machine)
-            return ok_machs
-        return machines
-    if status == 503:
-        log.error('Insufficient nodes available to lock %d nodes.', num)
-    else:
-        log.error('Could not lock %d nodes, reason: unknown.', num)
+    machinetypes = misc.get_multi_machine_types(machinetype)
+    for machinetype in machinetypes:
+        if user is None:
+            user = misc.get_user()
+        success, content, status = ls.send_request(
+            'POST',
+            config.lock_server,
+            urllib.urlencode(
+                dict(
+                    user=user,
+                    num=num,
+                    machinetype=machinetype,
+                    desc=description,
+                )))
+        if success:
+            machines = json.loads(content)
+            log.debug('locked {machines}'.format(
+                machines=', '.join(machines.keys())))
+            if machine_type == 'vps':
+                ok_machs = {}
+                for machine in machines:
+                    if create_if_vm(ctx, machine):
+                        ok_machs[machine] = machines[machine]
+                    else:
+                        log.error('Unable to create virtual machine: %s' % machine)
+                        unlock_one(ctx, machine)
+                return ok_machs
+            return machines
+        if status == 503:
+            log.error('Insufficient nodes available to lock %d %s nodes.', num,machinetype)
+        else:
+            log.error('Could not lock %d %s nodes, reason: unknown.', num, machinetype)
     return []
 
 
index 02de9dfd9ea2c2a31cee2176b321c5bce909aa84..1183ec265b764eb8a84f903d3a1b44fa1ff57b07 100644 (file)
@@ -943,3 +943,17 @@ def get_distro_version(ctx):
         return ctx.config['downburst'].get('distroversion', os_version)
     except (KeyError, AttributeError):
         return os_version
+
+def get_multi_machine_types(machinetype):
+    """
+    Converts machine type string to list based on common deliminators
+    """
+    machinetypes = []
+    machine_type_deliminator = ['-',' ',',','\t']
+    for deliminator in machine_type_deliminator:
+        if deliminator in machinetype:
+            machinetypes = machinetype.split(deliminator)
+            break
+    if not machinetypes:
+        machinetypes.append(machinetype)
+    return machinetypes
diff --git a/teuthology/test/test_get_multi_machine_types.py b/teuthology/test/test_get_multi_machine_types.py
new file mode 100644 (file)
index 0000000..4cde05a
--- /dev/null
@@ -0,0 +1,32 @@
+from .. import misc as teuthology
+
+class Mock: pass
+
+class TestGetMultiMachineTypes(object):
+
+    def test_space(self):
+        give = 'burnupi plana vps'
+        expect = ['burnupi','plana','vps']
+        assert teuthology.get_multi_machine_types(give) == expect
+
+    def test_tab(self):
+        give = 'burnupi        plana   vps'
+        expect = ['burnupi','plana','vps']
+        assert teuthology.get_multi_machine_types(give) == expect
+
+    def test_hiphen(self):
+        give = 'burnupi-plana-vps'
+        expect = ['burnupi','plana','vps']
+        assert teuthology.get_multi_machine_types(give) == expect
+
+    def test_comma(self):
+        give = 'burnupi,plana,vps'
+        expect = ['burnupi','plana','vps']
+        assert teuthology.get_multi_machine_types(give) == expect
+
+    def test_single(self):
+        give = 'burnupi'
+        expect = ['burnupi']
+        assert teuthology.get_multi_machine_types(give) == expect
+
+