]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Improve os-release parsing
authorZack Cerza <zack.cerza@inktank.com>
Thu, 18 Sep 2014 19:43:22 +0000 (13:43 -0600)
committerZack Cerza <zack.cerza@inktank.com>
Thu, 18 Sep 2014 19:43:22 +0000 (13:43 -0600)
Signed-off-by: Zack Cerza <zack.cerza@inktank.com>
teuthology/orchestra/remote.py
teuthology/orchestra/test/test_remote.py

index 12cead96ba45d4e8df0770610ae0d4b4e0e69c16..de9c25352b2a3123dd4b7a10af8ea696a04e5a3e 100644 (file)
@@ -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 ''
index 4305005fb3535d5f581a12be784b79ffdd6d73b2..cca5bc33007209c60244e209746131ff9484e279 100644 (file)
@@ -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'