From c38eeec85f0b556442b093e1b474143a113d2e78 Mon Sep 17 00:00:00 2001 From: Sandon Van Ness Date: Thu, 21 Nov 2013 14:19:44 -0800 Subject: [PATCH] Allow ability to use multi machine type deliminated by ,- \t. 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 --- teuthology/lock.py | 62 ++++++++++--------- teuthology/misc.py | 14 +++++ .../test/test_get_multi_machine_types.py | 32 ++++++++++ 3 files changed, 78 insertions(+), 30 deletions(-) create mode 100644 teuthology/test/test_get_multi_machine_types.py diff --git a/teuthology/lock.py b/teuthology/lock.py index ac1c44de96ceb..7fdde6feb9845 100644 --- a/teuthology/lock.py +++ b/teuthology/lock.py @@ -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 [] diff --git a/teuthology/misc.py b/teuthology/misc.py index 02de9dfd9ea2c..1183ec265b764 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -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 index 0000000000000..4cde05a626f90 --- /dev/null +++ b/teuthology/test/test_get_multi_machine_types.py @@ -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 + + -- 2.39.5