From 810cca1daf3ff2fc83106e776f46e059811bb28a Mon Sep 17 00:00:00 2001 From: Sandon Van Ness Date: Thu, 25 Jul 2013 14:45:02 -0700 Subject: [PATCH] Added get_distro() to misc.py Since getting the ostype is used multiple places I made a function for it and modified the existing code to use said function. I also added tests for the function. Signed-off-by: Sandon Van Ness --- teuthology/lock.py | 9 ++------- teuthology/misc.py | 10 ++++++++++ teuthology/run.py | 8 ++------ teuthology/test/test_get_distro.py | 29 +++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 13 deletions(-) create mode 100644 teuthology/test/test_get_distro.py diff --git a/teuthology/lock.py b/teuthology/lock.py index 1db09b285027f..3c378274fd6ec 100644 --- a/teuthology/lock.py +++ b/teuthology/lock.py @@ -537,13 +537,8 @@ def create_if_vm(ctx, machine_name): phys_host = status_info['vpshost'] if not phys_host: return False - try: - os_type = ctx.config['os_type'] - except KeyError: - try: - os_type = ctx.os_type - except AttributeError: - os_type = 'ubuntu' + from teuthology.misc import get_distro + os_type = get_distro(ctx) os_version = dict( ubuntu="12.04", fedora="18", diff --git a/teuthology/misc.py b/teuthology/misc.py index cef9b7d7b8478..264963afa24d5 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -867,3 +867,13 @@ def stop_daemons_of_type(ctx, type_): log.exception('Saw exception from %s.%s', daemon.role, daemon.id_) if exc_info != (None, None, None): raise exc_info[0], exc_info[1], exc_info[2] + +def get_distro(ctx): + try: + os_type = ctx.config.get('os_type', ctx.os_type) + except AttributeError: + os_type = 'ubuntu' + try: + return ctx.config['downburst'].get('distro', os_type) + except KeyError: + return os_type diff --git a/teuthology/run.py b/teuthology/run.py index 474c102af3d44..713272fa4e40c 100644 --- a/teuthology/run.py +++ b/teuthology/run.py @@ -166,12 +166,8 @@ def main(): {'internal.vm_setup': None}, ]) if 'kernel' in ctx.config: - try: - distro = ctx.config['downburst'].get('distro') - if distro is None: - distro = 'ubuntu' - except: - distro = 'ubuntu' + from teuthology.misc import get_distro + distro = get_distro(ctx) if distro == 'ubuntu': init_tasks.append({'kernel': ctx.config['kernel']}) init_tasks.extend([ diff --git a/teuthology/test/test_get_distro.py b/teuthology/test/test_get_distro.py new file mode 100644 index 0000000000000..3ade547e05864 --- /dev/null +++ b/teuthology/test/test_get_distro.py @@ -0,0 +1,29 @@ +from .. import misc as teuthology + +class Mock: pass + +class TestGetDistro(object): + + def setup(self): + self.fake_ctx = Mock() + self.fake_ctx.config = {} + self.fake_ctx.os_type = 'ubuntu' + + def test_default_distro(self): + distro = teuthology.get_distro(self.fake_ctx) + assert distro == 'ubuntu' + + def test_argument(self): + self.fake_ctx.os_type = 'centos' + distro = teuthology.get_distro(self.fake_ctx) + assert distro == 'centos' + + def test_teuth_config(self): + self.fake_ctx.config = {'os_type': 'fedora'} + distro = teuthology.get_distro(self.fake_ctx) + assert distro == 'fedora' + + def test_teuth_config_downburst(self): + self.fake_ctx.config = {'downburst' : {'distro': 'sles'}} + distro = teuthology.get_distro(self.fake_ctx) + assert distro == 'sles' -- 2.39.5