From d4a632df5fa19b58bcc6e2d14349ee5f57299080 Mon Sep 17 00:00:00 2001 From: Sandon Van Ness Date: Fri, 25 Oct 2013 17:48:50 -0700 Subject: [PATCH] Support --os-version as argument. You can use --os-type as an argument when not running teuthology tests but instead just using teuthology-lock. This adds the ability to also use --os-version so you can specify the version of the distro without having to run an actual test with a yaml like you normally would have had to do setting os_version in the yaml. Signed-off-by: Sandon Van Ness --- scripts/lock.py | 7 +++- scripts/run.py | 5 +++ teuthology/lock.py | 20 +++------- teuthology/misc.py | 25 ++++++++++++ teuthology/test/test_get_distro_version.py | 46 ++++++++++++++++++++++ 5 files changed, 87 insertions(+), 16 deletions(-) create mode 100644 teuthology/test/test_get_distro_version.py diff --git a/scripts/lock.py b/scripts/lock.py index 0751fc4f225cb..f94021bf09750 100644 --- a/scripts/lock.py +++ b/scripts/lock.py @@ -149,7 +149,12 @@ def parse_args(): parser.add_argument( '--os-type', default='ubuntu', - help='virtual machine type', + help='OS type (distro)', + ) + parser.add_argument( + '--os-version', + default=None, + help='OS (distro) version such as "12.10"', ) return parser.parse_args() diff --git a/scripts/run.py b/scripts/run.py index a1767e4d8f462..5eee377216904 100644 --- a/scripts/run.py +++ b/scripts/run.py @@ -53,6 +53,11 @@ def parse_args(): default='ubuntu', help='Distro/OS of machine to run test on.', ) + parser.add_argument( + '--os-version', + default=None, + help='Distro/OS version of machine to run test on.', + ) parser.add_argument( '--block', action='store_true', diff --git a/teuthology/lock.py b/teuthology/lock.py index de39f8c63a217..ac1c44de96ceb 100644 --- a/teuthology/lock.py +++ b/teuthology/lock.py @@ -14,6 +14,8 @@ import teuthology from .config import config from . import lockstatus as ls from . import misc +from teuthology.misc import get_distro +from teuthology.misc import get_distro_version log = logging.getLogger(__name__) @@ -436,17 +438,9 @@ def create_if_vm(ctx, machine_name): phys_host = status_info['vpshost'] if not phys_host: return False - from teuthology.misc import get_distro os_type = get_distro(ctx) - default_os_version = dict( - ubuntu="12.04", - fedora="18", - centos="6.4", - opensuse="12.2", - sles="11-sp2", - rhel="6.3", - debian='6.0' - ) + os_version = get_distro_version(ctx) + createMe = decanonicalize_hostname(machine_name) with tempfile.NamedTemporaryFile() as tmp: try: @@ -455,11 +449,7 @@ def create_if_vm(ctx, machine_name): lcnfg = {} distro = lcnfg.get('distro', os_type.lower()) - try: - distroversion = ctx.config.get( - 'os_version', default_os_version[distro]) - except AttributeError: - distroversion = default_os_version[distro] + distroversion = lcnfg.get('distroversion', os_version) file_info = {} file_info['disk-size'] = lcnfg.get('disk-size', '30G') diff --git a/teuthology/misc.py b/teuthology/misc.py index 9892fe3189530..5fe5bfe733a15 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -921,3 +921,28 @@ def get_distro(ctx): return os_type except AttributeError: return ctx.os_type + +def get_distro_version(ctx): + default_os_version = dict( + ubuntu="12.04", + fedora="18", + centos="6.4", + opensuse="12.2", + sles="11-sp2", + rhel="6.4", + debian='7.0' + ) + distro = get_distro(ctx) + try: + os_version = ctx.config.get('os_version', ctx.os_version) + except AttributeError: + os_version = default_os_version[distro] + try: + return ctx.config['downburst'].get('distroversion', os_type) + except KeyError: + return os_version + except AttributeError: + if ctx.os_version is not None: + return ctx.os_version + return os_version + diff --git a/teuthology/test/test_get_distro_version.py b/teuthology/test/test_get_distro_version.py new file mode 100644 index 0000000000000..17dc6cf9a7ba9 --- /dev/null +++ b/teuthology/test/test_get_distro_version.py @@ -0,0 +1,46 @@ +from .. import misc as teuthology + +class Mock: pass + +class TestGetDistroVersion(object): + + def setup(self): + self.fake_ctx = Mock() + self.fake_ctx.config = {} + self.fake_ctx.os_version = '13.04' + self.fake_ctx_noarg = Mock() + self.fake_ctx_noarg.config = {} + + def test_default_distro_version(self): + distroversion = teuthology.get_distro_version(self.fake_ctx) + assert distroversion == '13.04' + + def test_argument_version(self): + self.fake_ctx.os_version = '13.04' + distroversion = teuthology.get_distro_version(self.fake_ctx) + assert distroversion == '13.04' + + def test_teuth_config_version(self): + self.fake_ctx.config = {'os_version': '13.04'} + distroversion = teuthology.get_distro_version(self.fake_ctx) + assert distroversion == '13.04' + + def test_teuth_config_downburst_version(self): + self.fake_ctx.config = {'downburst' : {'distroversion': '13.04'}} + distroversion = teuthology.get_distro_version(self.fake_ctx) + assert distroversion == '13.04' + + def test_default_distro_noarg_version(self): + distroversion = teuthology.get_distro_version(self.fake_ctx_noarg) + #Default distro is ubuntu, default version of ubuntu is 012.04 + assert distroversion == '12.04' + + def test_teuth_config_noarg_version(self): + self.fake_ctx_noarg.config = {'os_version': '13.04'} + distroversion = teuthology.get_distro_version(self.fake_ctx_noarg) + assert distroversion == '13.04' + + def test_teuth_config_downburst_noarg_version(self): + self.fake_ctx_noarg.config = {'downburst' : {'distroversion': '13.04'}} + distroversion = teuthology.get_distro_version(self.fake_ctx_noarg) + assert distroversion == '13.04' -- 2.39.5