From 3b241620d3b34b136be70abd9c5eff5c0ae34bf4 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Thu, 18 Sep 2014 13:43:22 -0600 Subject: [PATCH] Improve os-release parsing Signed-off-by: Zack Cerza --- teuthology/orchestra/remote.py | 4 ++-- teuthology/orchestra/test/test_remote.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/teuthology/orchestra/remote.py b/teuthology/orchestra/remote.py index 12cead96ba..de9c25352b 100644 --- a/teuthology/orchestra/remote.py +++ b/teuthology/orchestra/remote.py @@ -328,8 +328,8 @@ class OS(object): self.package_type = "rpm" def _get_value(self, name): - regex = name + '=(.+)' - match = re.search(regex, self._os_release_str) + regex = '^%s=(.+)' % name + match = re.search(regex, self._os_release_str, flags=re.M) if match: return match.groups()[0].strip('"\'') return '' diff --git a/teuthology/orchestra/test/test_remote.py b/teuthology/orchestra/test/test_remote.py index 4305005fb3..cca5bc3300 100644 --- a/teuthology/orchestra/test/test_remote.py +++ b/teuthology/orchestra/test/test_remote.py @@ -154,6 +154,18 @@ class TestDistribution(object): BUG_REPORT_URL="https://bugs.centos.org/" """) + str_debian = dedent(""" + PRETTY_NAME="Debian GNU/Linux 7 (wheezy)" + NAME="Debian GNU/Linux" + VERSION_ID="7" + VERSION="7 (wheezy)" + ID=debian + ANSI_COLOR="1;31" + HOME_URL="http://www.debian.org/" + SUPPORT_URL="http://www.debian.org/support/" + BUG_REPORT_URL="http://bugs.debian.org/" + """) + str_ubuntu = dedent(""" NAME="Ubuntu" VERSION="12.04.4 LTS, Precise Pangolin" @@ -191,6 +203,16 @@ class TestDistribution(object): assert os.version_id == '7' assert os.package_type == 'rpm' + def test_debian(self): + os = remote.OS(self.str_debian) + assert os.name == 'Debian GNU/Linux' + assert os.version == '7 (wheezy)' + assert os.id == 'debian' + assert os.id_like == '' + assert os.pretty_name == 'Debian GNU/Linux 7 (wheezy)' + assert os.version_id == '7' + assert os.package_type == 'deb' + def test_ubuntu(self): os = remote.OS(self.str_ubuntu) assert os.name == 'Ubuntu' -- 2.39.5