← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~smoser/cloud-init:cleanup/drop-dead-write-network-methods into cloud-init:master

 

Scott Moser has proposed merging ~smoser/cloud-init:cleanup/drop-dead-write-network-methods into cloud-init:master.

Commit message:
Remove dead-code _write_network distro implementations.

Any distro that has a '_write_nework_config' method should no
longer get their _write_network called at all.  So lets drop
that code and raise a RuntimeError any time we got there.

Replace the one caller of 'apply_network' (legacy openstack path)
with a call to apply_network_config after converting the ENI to
network config.

Requested reviews:
  cloud-init commiters (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/354962

see commit message
-- 
Your team cloud-init commiters is requested to review the proposed merge of ~smoser/cloud-init:cleanup/drop-dead-write-network-methods into cloud-init:master.
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index b8a48e8..ac150be 100644
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -74,11 +74,10 @@ class Distro(object):
     def install_packages(self, pkglist):
         raise NotImplementedError()
 
-    @abc.abstractmethod
     def _write_network(self, settings):
-        # In the future use the http://fedorahosted.org/netcf/
-        # to write this blob out in a distro format
-        raise NotImplementedError()
+        raise RuntimeError(
+            "Legacy function '_write_network' was called in distro '%s'.\n"
+            "_write_network_config needs implementation.\n" % self.name)
 
     def _write_network_config(self, settings):
         raise NotImplementedError()
diff --git a/cloudinit/distros/debian.py b/cloudinit/distros/debian.py
index 33cc0bf..d517fb8 100644
--- a/cloudinit/distros/debian.py
+++ b/cloudinit/distros/debian.py
@@ -109,11 +109,6 @@ class Distro(distros.Distro):
         self.update_package_sources()
         self.package_command('install', pkgs=pkglist)
 
-    def _write_network(self, settings):
-        # this is a legacy method, it will always write eni
-        util.write_file(self.network_conf_fn["eni"], settings)
-        return ['all']
-
     def _write_network_config(self, netconfig):
         _maybe_remove_legacy_eth0()
         return self._supported_write_network_config(netconfig)
diff --git a/cloudinit/distros/opensuse.py b/cloudinit/distros/opensuse.py
index 1fe896a..9341162 100644
--- a/cloudinit/distros/opensuse.py
+++ b/cloudinit/distros/opensuse.py
@@ -172,52 +172,6 @@ class Distro(distros.Distro):
             conf.set_hostname(hostname)
             util.write_file(out_fn, str(conf), 0o644)
 
-    def _write_network(self, settings):
-        # Convert debian settings to ifcfg format
-        entries = net_util.translate_network(settings)
-        LOG.debug("Translated ubuntu style network settings %s into %s",
-                  settings, entries)
-        # Make the intermediate format as the suse format...
-        nameservers = []
-        searchservers = []
-        dev_names = entries.keys()
-        for (dev, info) in entries.items():
-            net_fn = self.network_script_tpl % (dev)
-            route_fn = self.route_conf_tpl % (dev)
-            mode = None
-            if info.get('auto', None):
-                mode = 'auto'
-            else:
-                mode = 'manual'
-            bootproto = info.get('bootproto', None)
-            gateway = info.get('gateway', None)
-            net_cfg = {
-                'BOOTPROTO': bootproto,
-                'BROADCAST': info.get('broadcast'),
-                'GATEWAY': gateway,
-                'IPADDR': info.get('address'),
-                'LLADDR': info.get('hwaddress'),
-                'NETMASK': info.get('netmask'),
-                'STARTMODE': mode,
-                'USERCONTROL': 'no'
-            }
-            if dev != 'lo':
-                net_cfg['ETHTOOL_OPTIONS'] = ''
-            else:
-                net_cfg['FIREWALL'] = 'no'
-            rhutil.update_sysconfig_file(net_fn, net_cfg, True)
-            if gateway and bootproto == 'static':
-                default_route = 'default    %s' % gateway
-                util.write_file(route_fn, default_route, 0o644)
-            if 'dns-nameservers' in info:
-                nameservers.extend(info['dns-nameservers'])
-            if 'dns-search' in info:
-                searchservers.extend(info['dns-search'])
-        if nameservers or searchservers:
-            rhutil.update_resolve_conf_file(self.resolve_conf_fn,
-                                            nameservers, searchservers)
-        return dev_names
-
     def _write_network_config(self, netconfig):
         return self._supported_write_network_config(netconfig)
 
diff --git a/cloudinit/distros/rhel.py b/cloudinit/distros/rhel.py
index ff51343..b36fd84 100644
--- a/cloudinit/distros/rhel.py
+++ b/cloudinit/distros/rhel.py
@@ -65,54 +65,6 @@ class Distro(distros.Distro):
     def _write_network_config(self, netconfig):
         return self._supported_write_network_config(netconfig)
 
-    def _write_network(self, settings):
-        # TODO(harlowja) fix this... since this is the ubuntu format
-        entries = net_util.translate_network(settings)
-        LOG.debug("Translated ubuntu style network settings %s into %s",
-                  settings, entries)
-        # Make the intermediate format as the rhel format...
-        nameservers = []
-        searchservers = []
-        dev_names = entries.keys()
-        use_ipv6 = False
-        for (dev, info) in entries.items():
-            net_fn = self.network_script_tpl % (dev)
-            net_cfg = {
-                'DEVICE': dev,
-                'NETMASK': info.get('netmask'),
-                'IPADDR': info.get('address'),
-                'BOOTPROTO': info.get('bootproto'),
-                'GATEWAY': info.get('gateway'),
-                'BROADCAST': info.get('broadcast'),
-                'MACADDR': info.get('hwaddress'),
-                'ONBOOT': _make_sysconfig_bool(info.get('auto')),
-            }
-            if info.get('inet6'):
-                use_ipv6 = True
-                net_cfg.update({
-                    'IPV6INIT': _make_sysconfig_bool(True),
-                    'IPV6ADDR': info.get('ipv6').get('address'),
-                    'IPV6_DEFAULTGW': info.get('ipv6').get('gateway'),
-                })
-            rhel_util.update_sysconfig_file(net_fn, net_cfg)
-            if 'dns-nameservers' in info:
-                nameservers.extend(info['dns-nameservers'])
-            if 'dns-search' in info:
-                searchservers.extend(info['dns-search'])
-        if nameservers or searchservers:
-            rhel_util.update_resolve_conf_file(self.resolve_conf_fn,
-                                               nameservers, searchservers)
-        if dev_names:
-            net_cfg = {
-                'NETWORKING': _make_sysconfig_bool(True),
-            }
-            # If IPv6 interface present, enable ipv6 networking
-            if use_ipv6:
-                net_cfg['NETWORKING_IPV6'] = _make_sysconfig_bool(True)
-                net_cfg['IPV6_AUTOCONF'] = _make_sysconfig_bool(False)
-            rhel_util.update_sysconfig_file(self.network_conf_fn, net_cfg)
-        return dev_names
-
     def apply_locale(self, locale, out_fn=None):
         if self.uses_systemd():
             if not out_fn:
diff --git a/cloudinit/sources/DataSourceConfigDrive.py b/cloudinit/sources/DataSourceConfigDrive.py
index 4cb2897..664dc4b 100644
--- a/cloudinit/sources/DataSourceConfigDrive.py
+++ b/cloudinit/sources/DataSourceConfigDrive.py
@@ -196,7 +196,7 @@ def on_first_boot(data, distro=None, network=True):
         net_conf = data.get("network_config", '')
         if net_conf and distro:
             LOG.warning("Updating network interfaces from config drive")
-            distro.apply_network(net_conf)
+            distro.apply_network_config(eni.convert_eni_data(net_conf))
     write_injected_files(data.get('files'))
 
 
diff --git a/tests/unittests/test_distros/test_netconfig.py b/tests/unittests/test_distros/test_netconfig.py
index 740fb76..8d3e7ff 100644
--- a/tests/unittests/test_distros/test_netconfig.py
+++ b/tests/unittests/test_distros/test_netconfig.py
@@ -328,16 +328,6 @@ class TestNetCfgDistroUbuntuEni(TestNetCfgDistroBase):
             self.assertEqual(expected, results[cfgpath])
             self.assertEqual(0o644, get_mode(cfgpath, tmpd))
 
-    def test_simple_write_ub(self):
-        expected_cfgs = {
-            self.eni_path(): BASE_NET_CFG,
-        }
-
-        # ub_distro.apply_network(BASE_NET_CFG, False)
-        self._apply_and_verify_eni(self.distro.apply_network,
-                                   BASE_NET_CFG,
-                                   expected_cfgs=expected_cfgs.copy())
-
     def test_apply_network_config_eni_ub(self):
         expected_cfgs = {
             self.eni_path(): V1_NET_CFG_OUTPUT,
@@ -428,35 +418,6 @@ class TestNetCfgDistroRedhat(TestNetCfgDistroBase):
             self.assertCfgEquals(expected, results[cfgpath])
             self.assertEqual(0o644, get_mode(cfgpath, tmpd))
 
-    def test_simple_write_rh(self):
-        expected_cfgs = {
-            self.ifcfg_path('lo'): dedent("""\
-                DEVICE="lo"
-                ONBOOT=yes
-                """),
-            self.ifcfg_path('eth0'): dedent("""\
-                DEVICE="eth0"
-                BOOTPROTO="static"
-                NETMASK="255.255.255.0"
-                IPADDR="192.168.1.5"
-                ONBOOT=yes
-                GATEWAY="192.168.1.254"
-                BROADCAST="192.168.1.0"
-                """),
-            self.ifcfg_path('eth1'): dedent("""\
-                DEVICE="eth1"
-                BOOTPROTO="dhcp"
-                ONBOOT=yes
-                """),
-            self.control_path(): dedent("""\
-                NETWORKING=yes
-                """),
-        }
-        # rh_distro.apply_network(BASE_NET_CFG, False)
-        self._apply_and_verify(self.distro.apply_network,
-                               BASE_NET_CFG,
-                               expected_cfgs=expected_cfgs.copy())
-
     def test_apply_network_config_rh(self):
         expected_cfgs = {
             self.ifcfg_path('eth0'): dedent("""\
@@ -488,47 +449,6 @@ class TestNetCfgDistroRedhat(TestNetCfgDistroBase):
                                V1_NET_CFG,
                                expected_cfgs=expected_cfgs.copy())
 
-    def test_write_ipv6_rhel(self):
-        expected_cfgs = {
-            self.ifcfg_path('lo'): dedent("""\
-                DEVICE="lo"
-                ONBOOT=yes
-                """),
-            self.ifcfg_path('eth0'): dedent("""\
-                DEVICE="eth0"
-                BOOTPROTO="static"
-                NETMASK="255.255.255.0"
-                IPADDR="192.168.1.5"
-                ONBOOT=yes
-                GATEWAY="192.168.1.254"
-                BROADCAST="192.168.1.0"
-                IPV6INIT=yes
-                IPV6ADDR="2607:f0d0:1002:0011::2"
-                IPV6_DEFAULTGW="2607:f0d0:1002:0011::1"
-                """),
-            self.ifcfg_path('eth1'): dedent("""\
-                DEVICE="eth1"
-                BOOTPROTO="static"
-                NETMASK="255.255.255.0"
-                IPADDR="192.168.1.6"
-                ONBOOT=no
-                GATEWAY="192.168.1.254"
-                BROADCAST="192.168.1.0"
-                IPV6INIT=yes
-                IPV6ADDR="2607:f0d0:1002:0011::3"
-                IPV6_DEFAULTGW="2607:f0d0:1002:0011::1"
-                """),
-            self.control_path(): dedent("""\
-                NETWORKING=yes
-                NETWORKING_IPV6=yes
-                IPV6_AUTOCONF=no
-                """),
-        }
-        # rh_distro.apply_network(BASE_NET_CFG_IPV6, False)
-        self._apply_and_verify(self.distro.apply_network,
-                               BASE_NET_CFG_IPV6,
-                               expected_cfgs=expected_cfgs.copy())
-
     def test_apply_network_config_ipv6_rh(self):
         expected_cfgs = {
             self.ifcfg_path('eth0'): dedent("""\
@@ -588,37 +508,6 @@ class TestNetCfgDistroOpensuse(TestNetCfgDistroBase):
             self.assertCfgEquals(expected, results[cfgpath])
             self.assertEqual(0o644, get_mode(cfgpath, tmpd))
 
-    def test_simple_write_opensuse(self):
-        """Opensuse network rendering writes appropriate sysconfig files."""
-        expected_cfgs = {
-            self.ifcfg_path('lo'): dedent('''
-                STARTMODE="auto"
-                USERCONTROL="no"
-                FIREWALL="no"
-                '''),
-            self.ifcfg_path('eth0'): dedent('''
-                BOOTPROTO="static"
-                BROADCAST="192.168.1.0"
-                GATEWAY="192.168.1.254"
-                IPADDR="192.168.1.5"
-                NETMASK="255.255.255.0"
-                STARTMODE="auto"
-                USERCONTROL="no"
-                ETHTOOL_OPTIONS=""
-                '''),
-            self.ifcfg_path('eth1'): dedent('''
-                BOOTPROTO="dhcp"
-                STARTMODE="auto"
-                USERCONTROL="no"
-                ETHTOOL_OPTIONS=""
-                ''')
-        }
-
-        # distro.apply_network(BASE_NET_CFG, False)
-        self._apply_and_verify(self.distro.apply_network,
-                               BASE_NET_CFG,
-                               expected_cfgs=expected_cfgs.copy())
-
     def test_apply_network_config_opensuse(self):
         """Opensuse uses apply_network_config and renders sysconfig"""
         expected_cfgs = {

Follow ups