From: Sandon Van Ness Date: Thu, 25 Jul 2013 21:45:02 +0000 (-0700) Subject: Added get_distro() to misc.py X-Git-Tag: 1.1.0~2042^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=810cca1daf3ff2fc83106e776f46e059811bb28a;p=teuthology.git 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 --- diff --git a/teuthology/lock.py b/teuthology/lock.py index 1db09b2850..3c378274fd 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 cef9b7d7b8..264963afa2 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 474c102af3..713272fa4e 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 0000000000..3ade547e05 --- /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'