]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Added get_distro() to misc.py
authorSandon Van Ness <sandon@inktank.com>
Thu, 25 Jul 2013 21:45:02 +0000 (14:45 -0700)
committerSandon Van Ness <sandon@inktank.com>
Thu, 25 Jul 2013 21:45:02 +0000 (14:45 -0700)
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 <sandon@inktank.com>
teuthology/lock.py
teuthology/misc.py
teuthology/run.py
teuthology/test/test_get_distro.py [new file with mode: 0644]

index 1db09b285027f6d800702a2e98c909d3edb5bb19..3c378274fd6ece0ece21b5042b8a65f9739317c4 100644 (file)
@@ -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",
index cef9b7d7b8478056d70d03818bf371f19c6f40f8..264963afa24d5c6bfe9dcb2169de2e9c94dbff7e 100644 (file)
@@ -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
index 474c102af3d44026429768856193e0bdad2bfbb0..713272fa4e40c54e4ff2ad077753ed4115ea79a5 100644 (file)
@@ -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 (file)
index 0000000..3ade547
--- /dev/null
@@ -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'