Merge ~raharper/cloud-init:fix/ubuntu-network-manager-sysconfig into cloud-init:master

Proposed by Ryan Harper on 2019-03-15
Status: Merged
Approved by: Ryan Harper on 2019-04-22
Approved revision: e6ad72c2447e5ff9462a435958aa8b9d7123dd04
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~raharper/cloud-init:fix/ubuntu-network-manager-sysconfig
Merge into: cloud-init:master
Diff against target: 70 lines (+39/-2)
2 files modified
cloudinit/net/sysconfig.py (+4/-2)
tests/unittests/test_net.py (+35/-0)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve on 2019-04-22
Dan Watkins 2019-03-15 Approve on 2019-04-11
Review via email: mp+364598@code.launchpad.net

Commit message

net/sysconfig: only indicate available on known sysconfig distros

Restrict the sysconfig renderer availabily to known distros.
Ubuntu/Debian systems may include network-manager but they do
not have support for reading sysconfig network output; that is
enabled via a Network-Manager plugin: ifcfg-rh which is not
available in Ubuntu/Debian.

LP: #1819994

To post a comment you must log in.

PASSED: Continuous integration, rev:f3cddcea4275d636c9fb5649bc76bf95a3ef3b5f
https://jenkins.ubuntu.com/server/job/cloud-init-ci/641/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/641/rebuild

review: Approve (continuous-integration)
Dan Watkins (oddbloke) :
review: Needs Information
Ryan Harper (raharper) wrote :

I forgot to submit a comment from the original review, hopefully this will show up now.

Dan Watkins (oddbloke) :
review: Approve
e6ad72c... by Ryan Harper on 2019-04-22

Drop parens, unneeded.

PASSED: Continuous integration, rev:e6ad72c2447e5ff9462a435958aa8b9d7123dd04
https://jenkins.ubuntu.com/server/job/cloud-init-ci/687/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/687/rebuild

review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
2index 0998392..a47da0a 100644
3--- a/cloudinit/net/sysconfig.py
4+++ b/cloudinit/net/sysconfig.py
5@@ -18,6 +18,8 @@ from .network_state import (
6
7 LOG = logging.getLogger(__name__)
8 NM_CFG_FILE = "/etc/NetworkManager/NetworkManager.conf"
9+KNOWN_DISTROS = [
10+ 'opensuse', 'sles', 'suse', 'redhat', 'fedora', 'centos']
11
12
13 def _make_header(sep='#'):
14@@ -717,8 +719,8 @@ class Renderer(renderer.Renderer):
15 def available(target=None):
16 sysconfig = available_sysconfig(target=target)
17 nm = available_nm(target=target)
18-
19- return any([nm, sysconfig])
20+ return (util.get_linux_distro()[0] in KNOWN_DISTROS
21+ and any([nm, sysconfig]))
22
23
24 def available_sysconfig(target=None):
25diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
26index ca6ef97..9db0156 100644
27--- a/tests/unittests/test_net.py
28+++ b/tests/unittests/test_net.py
29@@ -3829,6 +3829,41 @@ class TestNetRenderers(CiTestCase):
30 self.assertRaises(net.RendererNotFoundError, renderers.select,
31 priority=['sysconfig', 'eni'])
32
33+ @mock.patch("cloudinit.net.renderers.netplan.available")
34+ @mock.patch("cloudinit.net.renderers.sysconfig.available_sysconfig")
35+ @mock.patch("cloudinit.net.renderers.sysconfig.available_nm")
36+ @mock.patch("cloudinit.net.renderers.eni.available")
37+ @mock.patch("cloudinit.net.renderers.sysconfig.util.get_linux_distro")
38+ def test_sysconfig_selected_on_sysconfig_enabled_distros(self, m_distro,
39+ m_eni, m_sys_nm,
40+ m_sys_scfg,
41+ m_netplan):
42+ """sysconfig only selected on specific distros (rhel/sles)."""
43+
44+ # Ubuntu with Network-Manager installed
45+ m_eni.return_value = False # no ifupdown (ifquery)
46+ m_sys_scfg.return_value = False # no sysconfig/ifup/ifdown
47+ m_sys_nm.return_value = True # network-manager is installed
48+ m_netplan.return_value = True # netplan is installed
49+ m_distro.return_value = ('ubuntu', None, None)
50+ self.assertEqual('netplan', renderers.select(priority=None)[0])
51+
52+ # Centos with Network-Manager installed
53+ m_eni.return_value = False # no ifupdown (ifquery)
54+ m_sys_scfg.return_value = False # no sysconfig/ifup/ifdown
55+ m_sys_nm.return_value = True # network-manager is installed
56+ m_netplan.return_value = False # netplan is not installed
57+ m_distro.return_value = ('centos', None, None)
58+ self.assertEqual('sysconfig', renderers.select(priority=None)[0])
59+
60+ # OpenSuse with Network-Manager installed
61+ m_eni.return_value = False # no ifupdown (ifquery)
62+ m_sys_scfg.return_value = False # no sysconfig/ifup/ifdown
63+ m_sys_nm.return_value = True # network-manager is installed
64+ m_netplan.return_value = False # netplan is not installed
65+ m_distro.return_value = ('opensuse', None, None)
66+ self.assertEqual('sysconfig', renderers.select(priority=None)[0])
67+
68
69 class TestGetInterfaces(CiTestCase):
70 _data = {'bonds': ['bond1'],

Subscribers

People subscribed via source and target branches