From 8f9b156acc639599c37cd3424c76641c5e04726b Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Tue, 20 Nov 2018 17:51:23 +1100 Subject: [PATCH] Add NetworkManager distro plugin support On Fedora 29+, the network.service scripts have been moved into a separate deprecated package. NetworkManager is the supported interface for configuring networks. We have ignored NM for a long time, but we are now running out of options. Luckily we can support this fairly easily with the ifcfg-rh disto plugin that NM provides. Using this, the existing /etc/sysconfig/network-scripts files are used by NM. The only slight difference to the config files is that we need to tell NM it's ok to use it by removing NM_CONTROLLED=no. We also need to update the .service file which needs to call glean with the flag to enable NM, and doesn't need to call ifup. We have found that local-fs.target seems to be the best place to run this so it's nice and early. This is plumbed through from simple-init in DIB (I4d76e88ce25e5675fd5ef48924acd09915a62a4b) which will call glean-install with the new --use-nm flag if DIB_SIMPLE_INIT_NETWORKMANAGER is set. Since all Centos and Feodora are using NetworkManager by default, there is an argument that we should just switch to this and not bother with a flag. However, since NM brings in new libraries and possibly other changes to the base system, it's very possible we will either want to revert the change temporarily or perhaps even run parallel with and without. In these cases we can simply flip the variable in DIB and rebuild rather than having to revert code and do new glean releases. Longer term (say, around time we bring up CentOS 8), I see this becoming the default. Other platforms have distro plugins for NM to read their "legacy" configuration files too in the same way as here. This is left as future work. NetworkManager enabled build and boot for Centos and Fedora is tested in I640838c68a05f3b22683c1e90279725a77678526 Change-Id: I3d379d35e7b000f32c3f6cc197c8aaafebc683fb --- README.rst | 51 +++++++++++++++---- glean/cmd.py | 11 +++- glean/init/glean-nm@.service | 21 ++++++++ glean/init/nm-no-resolv-handling.conf | 2 + glean/install.py | 16 +++++- .../tests/fixtures/test/hp.centos.network.out | 6 +-- .../tests/fixtures/test/hp.fedora.network.out | 6 +-- .../tests/fixtures/test/hp.redhat.network.out | 6 +-- .../fixtures/test/liberty.centos.network.out | 24 ++++----- .../fixtures/test/liberty.fedora.network.out | 24 ++++----- .../fixtures/test/liberty.redhat.network.out | 24 ++++----- .../fixtures/test/nokey.centos.network.out | 6 +-- .../fixtures/test/nokey.fedora.network.out | 6 +-- .../fixtures/test/nokey.redhat.network.out | 6 +-- .../fixtures/test/ovh.centos.network.out | 2 +- .../fixtures/test/ovh.fedora.network.out | 2 +- .../fixtures/test/ovh.redhat.network.out | 2 +- .../fixtures/test/rax-iad.centos.network.out | 4 +- .../fixtures/test/rax-iad.fedora.network.out | 4 +- .../fixtures/test/rax-iad.redhat.network.out | 4 +- .../fixtures/test/rax.centos.network.out | 6 +-- .../fixtures/test/rax.fedora.network.out | 6 +-- .../fixtures/test/rax.redhat.network.out | 6 +-- glean/tests/test_glean.py | 19 ++++++- 24 files changed, 176 insertions(+), 88 deletions(-) create mode 100644 glean/init/glean-nm@.service create mode 100644 glean/init/nm-no-resolv-handling.conf diff --git a/README.rst b/README.rst index e4b8d19..ec7b943 100644 --- a/README.rst +++ b/README.rst @@ -41,29 +41,58 @@ It will also handle `authorized_keys` and host-name info provided from How does glean do this? +++++++++++++++++++++++ +Glean determines the network configuration environment for the running +platform and configures the interfaces appropriately. + systemd environment =================== -glean install will add a `udev` rules file (`99-glean.rules`) that -triggers on any network device being added. This will run the -`glean@.service` systemd template for the interface specified. +On platforms where systemd is detected `glean-install` will add a +`udev` rules file (`99-glean.rules`) that triggers on any network +device being added. This will run the `glean@.service` systemd +template for the interface specified. This systemd unit firstly determines if there is already a `/etc/sysconfig/network/` configuration for the interface; if so, the interface is considered configured and skipped. -If not, glean is started with the interface specified. The -configuration drive is probed to see if network configuration for the -interface is available. If so, it will be added, otherwise the -interface will configured for DHCP. +If not, glean is started with the interface that triggered this event +specified as an argument. The configuration drive is probed to see if +network configuration for the interface is available. If so, it will +be added, otherwise the interface will configured for DHCP. .. note :: - glean uses the network init scripts service ``network.service`` on - RedHat platforms (or the equivalent on other platforms). You should - ensure this service is enabled and other tools such as - NetworkManager are disabled for correct operation. + By default glean provides configuration for the network init + scripts service ``network.service`` on RedHat platforms (or the + equivalent on other platforms). You should ensure this service is + enabled and other tools such as NetworkManager are disabled for + correct operation in this mode. Note on Fedora 29 onwards, this is + in a separate package `network-scripts` and is considered + deprecated. + Alternatively, to use NetworkManager with the `ifcfg-rh` plugin + with to manage the interfaces, call `glean-install` with the + `--use-nm` flag. In this case, ensure NetworkManager is installed. + This will trigger glean to write out configuration files that are + suitable for use with NetworkManager and use a slightly different + service file that doesn't trigger legacy tools like `ifup`. + + +networkd +======== + +`networkd` support is implemented as a separate distribution type. +Currently it is only supported on Gentoo, and will be automatically +selected by `glean-install`. It will similarly install a systemd +service file or openrc config file (both are supported on Gentoo) and +udev rules to call glean. + +Other platforms +=============== + +`upstart` and `sysv` environments are also supported. These will have +init scripts installed to run glean at boot. How do I use glean? ------------------- diff --git a/glean/cmd.py b/glean/cmd.py index 04e3356..a030ec7 100644 --- a/glean/cmd.py +++ b/glean/cmd.py @@ -104,7 +104,9 @@ def _network_config(args): "DEVICE={name}", "BOOTPROTO={bootproto}", "HWADDR={hwaddr}"]) - footer = "\n".join(["ONBOOT=yes", "NM_CONTROLLED=no", + footer = "\n".join(["ONBOOT=yes", + "NM_CONTROLLED=%s" % + ("yes" if args.use_nm else "no"), "TYPE=Ethernet"]) + "\n" network_config = { @@ -182,7 +184,6 @@ def _write_rh_interface(name, interface, args): hwaddr=interface['mac_address'], ip_address=interface['ip_address'], netmask=interface['netmask'], - ) results += _set_rh_vlan(name, interface, distro) # set_rh_bonding takes results as argument so we need to assign @@ -1416,6 +1417,10 @@ def main(argv=None): parser.add_argument( '--skip-network', dest='skip', action='store_true', help="Do not write network info") + parser.add_argument( + '--use-nm', dest='use_nm', action='store_true', + help=('Use NetworkManager instead of legacy' + 'configuration scripts to manage interfaces')) parser.add_argument( '--skip-dns', dest='skip_dns', action='store_true', help='Do not write dns info') @@ -1431,6 +1436,8 @@ def main(argv=None): log.debug("Starting glean") log.debug("Detected distro : %s" % args.distro) + log.debug("Configuring %s NetworkManager" % + "with" if args.use_nm else "without") with systemlock.Lock('/tmp/glean.lock'): if args.ssh: diff --git a/glean/init/glean-nm@.service b/glean/init/glean-nm@.service new file mode 100644 index 0000000..83605a9 --- /dev/null +++ b/glean/init/glean-nm@.service @@ -0,0 +1,21 @@ +[Unit] +Description=Glean for interface %I with NetworkManager +Wants=local-fs.target +After=local-fs.target + +# Red Hat +ConditionPathExists=!/etc/sysconfig/network-scripts/ifcfg-%I +# SuSE +ConditionPathExists=!/etc/sysconfig/network/ifcfg-%I + +[Service] +Type=oneshot +User=root +Environment="ARGS=--interface %I" +ExecStart=%%GLEANSH_PATH%%/glean.sh --use-nm --debug $ARGS +RemainAfterExit=true + +StandardOutput=journal+console + +[Install] +WantedBy=multi-user.target diff --git a/glean/init/nm-no-resolv-handling.conf b/glean/init/nm-no-resolv-handling.conf new file mode 100644 index 0000000..5cd1587 --- /dev/null +++ b/glean/init/nm-no-resolv-handling.conf @@ -0,0 +1,2 @@ +[main] +dns=none \ No newline at end of file diff --git a/glean/install.py b/glean/install.py index 8d9aaaa..d0bb8a2 100755 --- a/glean/install.py +++ b/glean/install.py @@ -81,6 +81,8 @@ def main(): parser = argparse.ArgumentParser( description='Install glean init components') + parser.add_argument("-n", "--use-nm", help="Use NetworkManager", + action="store_true") parser.add_argument("-q", "--quiet", help="Be very quiet", action="store_true") @@ -118,8 +120,14 @@ def main(): replacements={'GLEANSH_PATH': p}) subprocess.call(['systemctl', 'enable', 'glean.service']) else: + log.info("Installing %s NetworkManager support" % + "with" if args.use_nm else "without") + if args.use_nm: + service_file = 'glean-nm@.service' + else: + service_file = 'glean@.service' install( - 'glean@.service', + service_file, '/usr/lib/systemd/system/glean@.service', mode='0644', replacements={'GLEANSH_PATH': p}) @@ -127,6 +135,12 @@ def main(): 'glean-udev.rules', '/etc/udev/rules.d/99-glean.rules', mode='0644') + if args.use_nm: + # glean handles resolv.conf, so this turns off nm touching + # it + install('nm-no-resolv-handling.conf', + '/etc/NetworkManager/conf.d/nm-no-resolv-handling.conf', + mode='0644') elif os.path.exists('/etc/init'): log.info("Installing upstart services") install('glean.conf', '/etc/init/glean.conf') diff --git a/glean/tests/fixtures/test/hp.centos.network.out b/glean/tests/fixtures/test/hp.centos.network.out index 95ba049..2aa9770 100644 --- a/glean/tests/fixtures/test/hp.centos.network.out +++ b/glean/tests/fixtures/test/hp.centos.network.out @@ -4,7 +4,7 @@ DEVICE=eth0 BOOTPROTO=dhcp HWADDR=bc:76:4e:01:62:86 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/ifcfg-eth1 # Automatically generated, do not edit @@ -12,7 +12,7 @@ DEVICE=eth1 BOOTPROTO=dhcp HWADDR=bc:76:4e:05:7b:06 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/ifcfg-eth3 # Automatically generated, do not edit @@ -20,5 +20,5 @@ DEVICE=eth3 BOOTPROTO=dhcp HWADDR=bc:76:4e:12:a4:bb ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet diff --git a/glean/tests/fixtures/test/hp.fedora.network.out b/glean/tests/fixtures/test/hp.fedora.network.out index 95ba049..2aa9770 100644 --- a/glean/tests/fixtures/test/hp.fedora.network.out +++ b/glean/tests/fixtures/test/hp.fedora.network.out @@ -4,7 +4,7 @@ DEVICE=eth0 BOOTPROTO=dhcp HWADDR=bc:76:4e:01:62:86 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/ifcfg-eth1 # Automatically generated, do not edit @@ -12,7 +12,7 @@ DEVICE=eth1 BOOTPROTO=dhcp HWADDR=bc:76:4e:05:7b:06 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/ifcfg-eth3 # Automatically generated, do not edit @@ -20,5 +20,5 @@ DEVICE=eth3 BOOTPROTO=dhcp HWADDR=bc:76:4e:12:a4:bb ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet diff --git a/glean/tests/fixtures/test/hp.redhat.network.out b/glean/tests/fixtures/test/hp.redhat.network.out index 95ba049..2aa9770 100644 --- a/glean/tests/fixtures/test/hp.redhat.network.out +++ b/glean/tests/fixtures/test/hp.redhat.network.out @@ -4,7 +4,7 @@ DEVICE=eth0 BOOTPROTO=dhcp HWADDR=bc:76:4e:01:62:86 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/ifcfg-eth1 # Automatically generated, do not edit @@ -12,7 +12,7 @@ DEVICE=eth1 BOOTPROTO=dhcp HWADDR=bc:76:4e:05:7b:06 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/ifcfg-eth3 # Automatically generated, do not edit @@ -20,5 +20,5 @@ DEVICE=eth3 BOOTPROTO=dhcp HWADDR=bc:76:4e:12:a4:bb ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet diff --git a/glean/tests/fixtures/test/liberty.centos.network.out b/glean/tests/fixtures/test/liberty.centos.network.out index a2ba8d7..e5307cc 100644 --- a/glean/tests/fixtures/test/liberty.centos.network.out +++ b/glean/tests/fixtures/test/liberty.centos.network.out @@ -9,7 +9,7 @@ HWADDR=bc:76:4e:01:62:86 IPADDR=23.253.229.154 NETMASK=255.255.255.0 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% DEFROUTE=yes GATEWAY=23.253.229.1 ### Write /etc/sysconfig/network-scripts/ifcfg-eth1 @@ -20,14 +20,14 @@ HWADDR=bc:76:4e:05:7b:06 IPADDR=10.208.169.118 NETMASK=255.255.224.0 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% ### Write /etc/sysconfig/network-scripts/ifcfg-eth3 # Automatically generated, do not edit DEVICE=eth3 BOOTPROTO=dhcp HWADDR=bc:76:4e:12:a4:bb ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/ifcfg-eth4.25 # Automatically generated, do not edit @@ -35,7 +35,7 @@ DEVICE=eth4.25 BOOTPROTO=dhcp HWADDR=bc:76:4e:12:a4:bc ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet VLAN=yes ### Write /etc/sysconfig/network-scripts/ifcfg-eth4.26 @@ -44,7 +44,7 @@ DEVICE=eth4.26 BOOTPROTO=dhcp HWADDR=bc:76:4e:12:a4:bd ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet VLAN=yes ### Write /etc/sysconfig/network-scripts/route-eth1 @@ -60,7 +60,7 @@ DEVICE=eth5 BOOTPROTO=none HWADDR=bc:76:4e:05:7b:13 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet SLAVE=yes MASTER=bond0 @@ -70,7 +70,7 @@ DEVICE=eth6 BOOTPROTO=none HWADDR=bc:76:4e:05:7b:14 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet SLAVE=yes MASTER=bond0 @@ -80,7 +80,7 @@ DEVICE=bond0 BOOTPROTO=dhcp HWADDR=bc:76:4e:05:7b:13 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/ifcfg-eth7 # Automatically generated, do not edit @@ -88,7 +88,7 @@ DEVICE=eth7 BOOTPROTO=none HWADDR=bc:76:4e:05:7b:15 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet SLAVE=yes MASTER=bond1 @@ -98,7 +98,7 @@ DEVICE=eth8 BOOTPROTO=none HWADDR=bc:76:4e:05:7b:16 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet SLAVE=yes MASTER=bond1 @@ -108,7 +108,7 @@ DEVICE=bond1 BOOTPROTO=none HWADDR=bc:76:4e:05:7b:15 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/ifcfg-bond1.27 # Automatically generated, do not edit @@ -116,6 +116,6 @@ DEVICE=bond1.27 BOOTPROTO=dhcp HWADDR=bc:76:4e:12:a4:be ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet VLAN=yes diff --git a/glean/tests/fixtures/test/liberty.fedora.network.out b/glean/tests/fixtures/test/liberty.fedora.network.out index 069bf76..efd9a71 100644 --- a/glean/tests/fixtures/test/liberty.fedora.network.out +++ b/glean/tests/fixtures/test/liberty.fedora.network.out @@ -9,7 +9,7 @@ HWADDR=bc:76:4e:01:62:86 IPADDR=23.253.229.154 NETMASK=255.255.255.0 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% DEFROUTE=yes GATEWAY=23.253.229.1 ### Write /etc/sysconfig/network-scripts/ifcfg-eth1 @@ -20,14 +20,14 @@ HWADDR=bc:76:4e:05:7b:06 IPADDR=10.208.169.118 NETMASK=255.255.224.0 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% ### Write /etc/sysconfig/network-scripts/ifcfg-eth3 # Automatically generated, do not edit DEVICE=eth3 BOOTPROTO=dhcp HWADDR=bc:76:4e:12:a4:bb ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/ifcfg-eth4.25 # Automatically generated, do not edit @@ -35,7 +35,7 @@ DEVICE=eth4.25 BOOTPROTO=dhcp HWADDR=bc:76:4e:12:a4:bc ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet VLAN=yes ### Write /etc/sysconfig/network-scripts/ifcfg-eth4.26 @@ -44,7 +44,7 @@ DEVICE=eth4.26 BOOTPROTO=dhcp HWADDR=bc:76:4e:12:a4:bd ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet VLAN=yes ### Write /etc/sysconfig/network-scripts/ifcfg-eth5 @@ -53,7 +53,7 @@ DEVICE=eth5 BOOTPROTO=none HWADDR=bc:76:4e:05:7b:13 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet SLAVE=yes MASTER=bond0 @@ -63,7 +63,7 @@ DEVICE=eth6 BOOTPROTO=none HWADDR=bc:76:4e:05:7b:14 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet SLAVE=yes MASTER=bond0 @@ -73,7 +73,7 @@ DEVICE=bond0 BOOTPROTO=dhcp HWADDR=bc:76:4e:05:7b:13 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/ifcfg-eth7 # Automatically generated, do not edit @@ -81,7 +81,7 @@ DEVICE=eth7 BOOTPROTO=none HWADDR=bc:76:4e:05:7b:15 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet SLAVE=yes MASTER=bond1 @@ -91,7 +91,7 @@ DEVICE=eth8 BOOTPROTO=none HWADDR=bc:76:4e:05:7b:16 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet SLAVE=yes MASTER=bond1 @@ -101,7 +101,7 @@ DEVICE=bond1 BOOTPROTO=none HWADDR=bc:76:4e:05:7b:15 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/ifcfg-bond1.27 # Automatically generated, do not edit @@ -109,7 +109,7 @@ DEVICE=bond1.27 BOOTPROTO=dhcp HWADDR=bc:76:4e:12:a4:be ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet VLAN=yes ### Write /etc/sysconfig/network-scripts/route-eth1 diff --git a/glean/tests/fixtures/test/liberty.redhat.network.out b/glean/tests/fixtures/test/liberty.redhat.network.out index a2ba8d7..e5307cc 100644 --- a/glean/tests/fixtures/test/liberty.redhat.network.out +++ b/glean/tests/fixtures/test/liberty.redhat.network.out @@ -9,7 +9,7 @@ HWADDR=bc:76:4e:01:62:86 IPADDR=23.253.229.154 NETMASK=255.255.255.0 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% DEFROUTE=yes GATEWAY=23.253.229.1 ### Write /etc/sysconfig/network-scripts/ifcfg-eth1 @@ -20,14 +20,14 @@ HWADDR=bc:76:4e:05:7b:06 IPADDR=10.208.169.118 NETMASK=255.255.224.0 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% ### Write /etc/sysconfig/network-scripts/ifcfg-eth3 # Automatically generated, do not edit DEVICE=eth3 BOOTPROTO=dhcp HWADDR=bc:76:4e:12:a4:bb ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/ifcfg-eth4.25 # Automatically generated, do not edit @@ -35,7 +35,7 @@ DEVICE=eth4.25 BOOTPROTO=dhcp HWADDR=bc:76:4e:12:a4:bc ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet VLAN=yes ### Write /etc/sysconfig/network-scripts/ifcfg-eth4.26 @@ -44,7 +44,7 @@ DEVICE=eth4.26 BOOTPROTO=dhcp HWADDR=bc:76:4e:12:a4:bd ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet VLAN=yes ### Write /etc/sysconfig/network-scripts/route-eth1 @@ -60,7 +60,7 @@ DEVICE=eth5 BOOTPROTO=none HWADDR=bc:76:4e:05:7b:13 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet SLAVE=yes MASTER=bond0 @@ -70,7 +70,7 @@ DEVICE=eth6 BOOTPROTO=none HWADDR=bc:76:4e:05:7b:14 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet SLAVE=yes MASTER=bond0 @@ -80,7 +80,7 @@ DEVICE=bond0 BOOTPROTO=dhcp HWADDR=bc:76:4e:05:7b:13 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/ifcfg-eth7 # Automatically generated, do not edit @@ -88,7 +88,7 @@ DEVICE=eth7 BOOTPROTO=none HWADDR=bc:76:4e:05:7b:15 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet SLAVE=yes MASTER=bond1 @@ -98,7 +98,7 @@ DEVICE=eth8 BOOTPROTO=none HWADDR=bc:76:4e:05:7b:16 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet SLAVE=yes MASTER=bond1 @@ -108,7 +108,7 @@ DEVICE=bond1 BOOTPROTO=none HWADDR=bc:76:4e:05:7b:15 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/ifcfg-bond1.27 # Automatically generated, do not edit @@ -116,6 +116,6 @@ DEVICE=bond1.27 BOOTPROTO=dhcp HWADDR=bc:76:4e:12:a4:be ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet VLAN=yes diff --git a/glean/tests/fixtures/test/nokey.centos.network.out b/glean/tests/fixtures/test/nokey.centos.network.out index 95ba049..2aa9770 100644 --- a/glean/tests/fixtures/test/nokey.centos.network.out +++ b/glean/tests/fixtures/test/nokey.centos.network.out @@ -4,7 +4,7 @@ DEVICE=eth0 BOOTPROTO=dhcp HWADDR=bc:76:4e:01:62:86 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/ifcfg-eth1 # Automatically generated, do not edit @@ -12,7 +12,7 @@ DEVICE=eth1 BOOTPROTO=dhcp HWADDR=bc:76:4e:05:7b:06 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/ifcfg-eth3 # Automatically generated, do not edit @@ -20,5 +20,5 @@ DEVICE=eth3 BOOTPROTO=dhcp HWADDR=bc:76:4e:12:a4:bb ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet diff --git a/glean/tests/fixtures/test/nokey.fedora.network.out b/glean/tests/fixtures/test/nokey.fedora.network.out index 95ba049..2aa9770 100644 --- a/glean/tests/fixtures/test/nokey.fedora.network.out +++ b/glean/tests/fixtures/test/nokey.fedora.network.out @@ -4,7 +4,7 @@ DEVICE=eth0 BOOTPROTO=dhcp HWADDR=bc:76:4e:01:62:86 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/ifcfg-eth1 # Automatically generated, do not edit @@ -12,7 +12,7 @@ DEVICE=eth1 BOOTPROTO=dhcp HWADDR=bc:76:4e:05:7b:06 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/ifcfg-eth3 # Automatically generated, do not edit @@ -20,5 +20,5 @@ DEVICE=eth3 BOOTPROTO=dhcp HWADDR=bc:76:4e:12:a4:bb ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet diff --git a/glean/tests/fixtures/test/nokey.redhat.network.out b/glean/tests/fixtures/test/nokey.redhat.network.out index 95ba049..2aa9770 100644 --- a/glean/tests/fixtures/test/nokey.redhat.network.out +++ b/glean/tests/fixtures/test/nokey.redhat.network.out @@ -4,7 +4,7 @@ DEVICE=eth0 BOOTPROTO=dhcp HWADDR=bc:76:4e:01:62:86 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/ifcfg-eth1 # Automatically generated, do not edit @@ -12,7 +12,7 @@ DEVICE=eth1 BOOTPROTO=dhcp HWADDR=bc:76:4e:05:7b:06 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/ifcfg-eth3 # Automatically generated, do not edit @@ -20,5 +20,5 @@ DEVICE=eth3 BOOTPROTO=dhcp HWADDR=bc:76:4e:12:a4:bb ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet diff --git a/glean/tests/fixtures/test/ovh.centos.network.out b/glean/tests/fixtures/test/ovh.centos.network.out index e872b03..24f375a 100644 --- a/glean/tests/fixtures/test/ovh.centos.network.out +++ b/glean/tests/fixtures/test/ovh.centos.network.out @@ -4,5 +4,5 @@ DEVICE=eth0 BOOTPROTO=dhcp HWADDR=fa:16:3e:c8:65:a0 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet diff --git a/glean/tests/fixtures/test/ovh.fedora.network.out b/glean/tests/fixtures/test/ovh.fedora.network.out index e872b03..24f375a 100644 --- a/glean/tests/fixtures/test/ovh.fedora.network.out +++ b/glean/tests/fixtures/test/ovh.fedora.network.out @@ -4,5 +4,5 @@ DEVICE=eth0 BOOTPROTO=dhcp HWADDR=fa:16:3e:c8:65:a0 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet diff --git a/glean/tests/fixtures/test/ovh.redhat.network.out b/glean/tests/fixtures/test/ovh.redhat.network.out index e872b03..24f375a 100644 --- a/glean/tests/fixtures/test/ovh.redhat.network.out +++ b/glean/tests/fixtures/test/ovh.redhat.network.out @@ -4,5 +4,5 @@ DEVICE=eth0 BOOTPROTO=dhcp HWADDR=fa:16:3e:c8:65:a0 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet diff --git a/glean/tests/fixtures/test/rax-iad.centos.network.out b/glean/tests/fixtures/test/rax-iad.centos.network.out index efbdf48..48ec2c5 100644 --- a/glean/tests/fixtures/test/rax-iad.centos.network.out +++ b/glean/tests/fixtures/test/rax-iad.centos.network.out @@ -9,7 +9,7 @@ HWADDR=bc:76:4e:20:d7:2f IPADDR=146.20.110.113 NETMASK=255.255.255.0 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% DEFROUTE=yes GATEWAY=146.20.110.1 ### Write /etc/sysconfig/network-scripts/ifcfg-eth1 @@ -20,7 +20,7 @@ HWADDR=bc:76:4e:20:d7:33 IPADDR=10.210.32.174 NETMASK=255.255.224.0 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% ### Write /etc/sysconfig/network-scripts/route-eth1 ADDRESS0=10.176.0.0 NETMASK0=255.240.0.0 diff --git a/glean/tests/fixtures/test/rax-iad.fedora.network.out b/glean/tests/fixtures/test/rax-iad.fedora.network.out index efbdf48..48ec2c5 100644 --- a/glean/tests/fixtures/test/rax-iad.fedora.network.out +++ b/glean/tests/fixtures/test/rax-iad.fedora.network.out @@ -9,7 +9,7 @@ HWADDR=bc:76:4e:20:d7:2f IPADDR=146.20.110.113 NETMASK=255.255.255.0 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% DEFROUTE=yes GATEWAY=146.20.110.1 ### Write /etc/sysconfig/network-scripts/ifcfg-eth1 @@ -20,7 +20,7 @@ HWADDR=bc:76:4e:20:d7:33 IPADDR=10.210.32.174 NETMASK=255.255.224.0 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% ### Write /etc/sysconfig/network-scripts/route-eth1 ADDRESS0=10.176.0.0 NETMASK0=255.240.0.0 diff --git a/glean/tests/fixtures/test/rax-iad.redhat.network.out b/glean/tests/fixtures/test/rax-iad.redhat.network.out index efbdf48..48ec2c5 100644 --- a/glean/tests/fixtures/test/rax-iad.redhat.network.out +++ b/glean/tests/fixtures/test/rax-iad.redhat.network.out @@ -9,7 +9,7 @@ HWADDR=bc:76:4e:20:d7:2f IPADDR=146.20.110.113 NETMASK=255.255.255.0 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% DEFROUTE=yes GATEWAY=146.20.110.1 ### Write /etc/sysconfig/network-scripts/ifcfg-eth1 @@ -20,7 +20,7 @@ HWADDR=bc:76:4e:20:d7:33 IPADDR=10.210.32.174 NETMASK=255.255.224.0 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% ### Write /etc/sysconfig/network-scripts/route-eth1 ADDRESS0=10.176.0.0 NETMASK0=255.240.0.0 diff --git a/glean/tests/fixtures/test/rax.centos.network.out b/glean/tests/fixtures/test/rax.centos.network.out index b15f9e1..62b16d4 100644 --- a/glean/tests/fixtures/test/rax.centos.network.out +++ b/glean/tests/fixtures/test/rax.centos.network.out @@ -9,7 +9,7 @@ HWADDR=bc:76:4e:01:62:86 IPADDR=23.253.229.154 NETMASK=255.255.255.0 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% DEFROUTE=yes GATEWAY=23.253.229.1 ### Write /etc/sysconfig/network-scripts/ifcfg-eth1 @@ -20,14 +20,14 @@ HWADDR=bc:76:4e:05:7b:06 IPADDR=10.208.169.118 NETMASK=255.255.224.0 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% ### Write /etc/sysconfig/network-scripts/ifcfg-eth3 # Automatically generated, do not edit DEVICE=eth3 BOOTPROTO=dhcp HWADDR=bc:76:4e:12:a4:bb ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/route-eth1 ADDRESS0=10.176.0.0 diff --git a/glean/tests/fixtures/test/rax.fedora.network.out b/glean/tests/fixtures/test/rax.fedora.network.out index b15f9e1..62b16d4 100644 --- a/glean/tests/fixtures/test/rax.fedora.network.out +++ b/glean/tests/fixtures/test/rax.fedora.network.out @@ -9,7 +9,7 @@ HWADDR=bc:76:4e:01:62:86 IPADDR=23.253.229.154 NETMASK=255.255.255.0 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% DEFROUTE=yes GATEWAY=23.253.229.1 ### Write /etc/sysconfig/network-scripts/ifcfg-eth1 @@ -20,14 +20,14 @@ HWADDR=bc:76:4e:05:7b:06 IPADDR=10.208.169.118 NETMASK=255.255.224.0 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% ### Write /etc/sysconfig/network-scripts/ifcfg-eth3 # Automatically generated, do not edit DEVICE=eth3 BOOTPROTO=dhcp HWADDR=bc:76:4e:12:a4:bb ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/route-eth1 ADDRESS0=10.176.0.0 diff --git a/glean/tests/fixtures/test/rax.redhat.network.out b/glean/tests/fixtures/test/rax.redhat.network.out index b15f9e1..62b16d4 100644 --- a/glean/tests/fixtures/test/rax.redhat.network.out +++ b/glean/tests/fixtures/test/rax.redhat.network.out @@ -9,7 +9,7 @@ HWADDR=bc:76:4e:01:62:86 IPADDR=23.253.229.154 NETMASK=255.255.255.0 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% DEFROUTE=yes GATEWAY=23.253.229.1 ### Write /etc/sysconfig/network-scripts/ifcfg-eth1 @@ -20,14 +20,14 @@ HWADDR=bc:76:4e:05:7b:06 IPADDR=10.208.169.118 NETMASK=255.255.224.0 ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% ### Write /etc/sysconfig/network-scripts/ifcfg-eth3 # Automatically generated, do not edit DEVICE=eth3 BOOTPROTO=dhcp HWADDR=bc:76:4e:12:a4:bb ONBOOT=yes -NM_CONTROLLED=no +%NM_CONTROLLED% TYPE=Ethernet ### Write /etc/sysconfig/network-scripts/route-eth1 ADDRESS0=10.176.0.0 diff --git a/glean/tests/test_glean.py b/glean/tests/test_glean.py index c25b60e..9edeb9d 100644 --- a/glean/tests/test_glean.py +++ b/glean/tests/test_glean.py @@ -157,7 +157,8 @@ class TestGlean(base.BaseTestCase): mock_os_symlink, mock_os_unlink, mock_call, - skip_dns=False): + skip_dns=False, + use_nm=False): """Main test function :param distro: distro to return from "distro.linux_distribution()" @@ -165,6 +166,7 @@ class TestGlean(base.BaseTestCase): out files :param interface: --interface argument; None for no argument :param skip_dns: --skip-dns argument; False for no argument + :param use_nm: --use-nm argument; False for no argument """ # These functions are watching the path and faking results @@ -189,6 +191,8 @@ class TestGlean(base.BaseTestCase): argv.append('--interface=%s' % interface) if skip_dns: argv.append('--skip-dns') + if use_nm: + argv.append('--use-nm') cmd.main(argv) @@ -197,7 +201,13 @@ class TestGlean(base.BaseTestCase): # Generate a list of (dest, content) into write_blocks to assert write_blocks = [] - lines = open(output_path).readlines() + lines = [] + with open(output_path) as f: + for line in f: + if line == '%NM_CONTROLLED%\n': + line = 'NM_CONTROLLED=%s\n' % \ + ("yes" if use_nm else "no") + lines.append(line) write_dest = None write_content = None for line in lines: @@ -267,3 +277,8 @@ class TestGlean(base.BaseTestCase): with mock.patch('glean.systemlock.Lock'): self._assert_distro_provider( self.distro, self.style, None, skip_dns=True) + + def test_glean_nm(self): + with mock.patch('glean.systemlock.Lock'): + self._assert_distro_provider( + self.distro, self.style, 'eth0', use_nm=True)