From ac8458dac8224b6bd921982bf6e248827c872660 Mon Sep 17 00:00:00 2001 From: Markos Chandras Date: Tue, 5 Jun 2018 15:24:02 +0100 Subject: [PATCH] glean: Fix SUSE support for bridges and vlan configurations. We need to check the /etc/sysconfig/network/ifcfg-* files for bridges and vlans similar to regular interfaces. Moreover, the existing code for checking whether the host is a SUSE distribution did not work for newer releases (openSUSE Leap 15 is being reported as 'opensuse-leap' and Tumbleweed is being reported as 'opensuse-tumbleweed') so we need to refactor it a bit to actually check whether the string 'suse' exists in the distro variable to simplify things. Finally, the systemd service was missing the check for the SUSE network files so we add that as well. systemd should apply a logical AND in these conditionals so it should work fine on both Red Hat and SUSE distros. Change-Id: Ic5c6745dbe0077089ecaa1dd8f9b4949ac80efae --- glean/cmd.py | 25 ++++++++++++++++++------- glean/init/glean@.service | 1 + 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/glean/cmd.py b/glean/cmd.py index d87011c..0adf8d9 100644 --- a/glean/cmd.py +++ b/glean/cmd.py @@ -59,15 +59,17 @@ def safe_open(*args, **kwargs): subprocess.call([SELINUX_RESTORECON, path]) -def _exists_rh_interface(name): - file_to_check = '/etc/sysconfig/network-scripts/ifcfg-{name}'.format( +def _exists_rh_interface(name, distro): + file_to_check = _network_files(distro)['ifcfg'] + '-{name}'.format( name=name ) return os.path.exists(file_to_check) def _is_suse(distro): - return distro in ('suse', 'opensuse') + # 'distro could be any of suse, opensuse, + # opensuse-leap, opensuse-tumbleweed + return 'suse' in distro def _network_files(distro): @@ -298,7 +300,7 @@ def write_redhat_interfaces(interfaces, sys_interfaces, distro): _write_rh_manual(interface_name, interface, distro)) for mac, iname in sorted( sys_interfaces.items(), key=lambda x: x[1]): - if _exists_rh_interface(iname): + if _exists_rh_interface(iname, distro): # This interface already has a config file, move on log.debug("%s already has config file, skipping" % iname) continue @@ -1049,7 +1051,8 @@ def write_static_network_info( if args.distro in ('debian', 'ubuntu'): files_to_write.update( write_debian_interfaces(interfaces, sys_interfaces)) - elif args.distro in ('redhat', 'centos', 'fedora', 'suse', 'opensuse'): + elif args.distro in ('redhat', 'centos', 'fedora') or \ + _is_suse(args.distro): files_to_write.update( write_redhat_interfaces(interfaces, sys_interfaces, args.distro)) elif args.distro in 'gentoo': @@ -1134,10 +1137,14 @@ def is_interface_vlan(iface, distro): file_name = '/etc/network/interfaces.d/%s.cfg' % iface if os.path.exists(file_name): return 'vlan-raw-device' in open(file_name).read() - elif distro in ('redhat', 'centos', 'fedora', 'suse', 'opensuse'): + elif distro in ('redhat', 'centos', 'fedora'): file_name = '/etc/sysconfig/network-scripts/ifcfg-%s' % iface if os.path.exists(file_name): return 'VLAN=YES' in open(file_name).read() + elif _is_suse(distro): + file_name = '/etc/sysconfig/network/ifcfg-%s' % iface + if os.path.exists(file_name): + return 'ETHERDEVICE' in open(file_name).read() elif distro in ('gentoo'): file_name = '/etc/conf.d/net.%s' % iface if os.path.exists(file_name): @@ -1151,10 +1158,14 @@ def is_interface_bridge(iface, distro): file_name = '/etc/network/interfaces.d/%s.cfg' % iface if os.path.exists(file_name): return 'bridge_ports' in open(file_name).read().lower() - elif distro in ('redhat', 'centos', 'fedora', 'suse', 'opensuse'): + elif distro in ('redhat', 'centos', 'fedora'): file_name = '/etc/sysconfig/network-scripts/ifcfg-%s' % iface if os.path.exists(file_name): return 'type=bridge' in open(file_name).read().lower() + elif _is_suse(distro): + file_name = '/etc/sysconfig/network/ifcfg-%s' % iface + if os.path.exists(file_name): + return 'bridge=yes' in open(file_name).read().lower() elif distro in ('gentoo'): file_name = '/etc/conf.d/net.%s' % iface if os.path.exists(file_name): diff --git a/glean/init/glean@.service b/glean/init/glean@.service index 376a177..93ab529 100644 --- a/glean/init/glean@.service +++ b/glean/init/glean@.service @@ -5,6 +5,7 @@ Before=network-pre.target Wants=network-pre.target ConditionPathExists=!/etc/sysconfig/network-scripts/ifcfg-%I +ConditionPathExists=!/etc/sysconfig/network/ifcfg-%I [Service] Type=oneshot