← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~raharper/cloud-init:fix/sysconfig-distro-variant into cloud-init:master

 

Ryan Harper has proposed merging ~raharper/cloud-init:fix/sysconfig-distro-variant into cloud-init:master.

Commit message:
sysconfig: use distro variant to check if available
    
The sysconfig renderer used the distro name directly which mean
some variants of distros were not considered supported.  Fix this
by using util.system_info()['variant'] instead.  Fix the list of
KNOWN_DISTROS value for redhat -> rhel.
    
LP: #1843584


Requested reviews:
  cloud-init Commiters (cloud-init-dev)
Related bugs:
  Bug #1843584 in cloud-init: "cloudinit/net/sysconfig.py lacks support for openSUSE 15.x and Tumbleweed"
  https://bugs.launchpad.net/cloud-init/+bug/1843584

For more details, see:
https://code.launchpad.net/~raharper/cloud-init/+git/cloud-init/+merge/373277
-- 
Your team cloud-init Commiters is requested to review the proposed merge of ~raharper/cloud-init:fix/sysconfig-distro-variant into cloud-init:master.
diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
index be5dede..5140862 100644
--- a/cloudinit/net/sysconfig.py
+++ b/cloudinit/net/sysconfig.py
@@ -19,7 +19,7 @@ from .network_state import (
 LOG = logging.getLogger(__name__)
 NM_CFG_FILE = "/etc/NetworkManager/NetworkManager.conf"
 KNOWN_DISTROS = [
-    'opensuse', 'sles', 'suse', 'redhat', 'fedora', 'centos']
+    'opensuse', 'sles', 'suse', 'rhel', 'fedora', 'centos']
 
 
 def _make_header(sep='#'):
@@ -731,7 +731,7 @@ class Renderer(renderer.Renderer):
 def available(target=None):
     sysconfig = available_sysconfig(target=target)
     nm = available_nm(target=target)
-    return (util.get_linux_distro()[0] in KNOWN_DISTROS
+    return (util.system_info()['variant'] in KNOWN_DISTROS
             and any([nm, sysconfig]))
 
 
diff --git a/cloudinit/util.py b/cloudinit/util.py
index aa23b3f..6497578 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -2826,7 +2826,11 @@ def load_shell_content(content, add_empty=False, empty_val=None):
 
     data = {}
     for line in _shlex_split(content):
-        key, value = line.split("=", 1)
+        try:
+            key, value = line.split("=", 1)
+        except Exception as e:
+            print(e)
+            print("line:\n%s" % line)
         if not value:
             value = empty_val
         if add_empty or value:
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index e578992..a093cf1 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -4158,6 +4158,24 @@ class TestNetRenderers(CiTestCase):
         m_distro.return_value = ('opensuse', None, None)
         self.assertEqual('sysconfig', renderers.select(priority=None)[0])
 
+    @mock.patch("cloudinit.net.sysconfig.available_sysconfig")
+    @mock.patch("cloudinit.util.get_linux_distro")
+    def test_sysconfig_available_uses_variant_mapping(self, m_distro, m_avail):
+        m_avail.return_value = True
+        distro_values = [
+           ('opensuse', '', ''),
+           ('opensuse-leap', '', ''),
+           ('opensuse-tumbleweed', '', ''),
+           ('sles', '', ''),
+           ('centos', '', ''),
+           ('fedora', '', ''),
+           ('redhat', '', ''),
+        ]
+        for (distro_name, distro_version, flavor) in distro_values:
+            m_distro.return_value = (distro_name, distro_version, flavor)
+            result = sysconfig.available()
+            self.assertTrue(result)
+
 
 class TestGetInterfaces(CiTestCase):
     _data = {'bonds': ['bond1'],