From c282e4e00fff73fcc2092ecff5881ab109871651 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Tue, 30 Jan 2018 15:27:22 -0600 Subject: [PATCH] Replace LooseVersion comparison with int/float comparison. Fixes #35435 (#35519) --- lib/ansible/modules/system/hostname.py | 13 ++++++++----- test/sanity/import/skip.txt | 1 - 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/ansible/modules/system/hostname.py b/lib/ansible/modules/system/hostname.py index 590acb89d5..1c15b0ed8c 100644 --- a/lib/ansible/modules/system/hostname.py +++ b/lib/ansible/modules/system/hostname.py @@ -39,7 +39,6 @@ EXAMPLES = ''' import os import socket import traceback -from distutils.version import LooseVersion from ansible.module_utils.basic import ( AnsibleModule, @@ -567,10 +566,14 @@ class FedoraHostname(Hostname): class SLESHostname(Hostname): platform = 'Linux' distribution = 'Suse linux enterprise server ' - distribution_version = get_distribution_version() - if distribution_version and LooseVersion("10") <= LooseVersion(distribution_version) <= LooseVersion("12"): - strategy_class = SLESStrategy - else: + try: + distribution_version = get_distribution_version() + # cast to float may raise ValueError on non SLES, we use float for a little more safety over int + if distribution_version and 10 <= float(distribution_version) <= 12: + strategy_class = SLESStrategy + else: + raise ValueError() + except ValueError: strategy_class = UnimplementedStrategy diff --git a/test/sanity/import/skip.txt b/test/sanity/import/skip.txt index ec5991261e..790a9f1f53 100644 --- a/test/sanity/import/skip.txt +++ b/test/sanity/import/skip.txt @@ -5,4 +5,3 @@ lib/ansible/modules/cloud/webfaction/webfaction_domain.py lib/ansible/modules/cloud/webfaction/webfaction_mailbox.py lib/ansible/modules/cloud/webfaction/webfaction_site.py lib/ansible/modules/packaging/os/yum_repository.py -lib/ansible/modules/system/hostname.py