From 84414544ded470cd270680c0900ea9dfb95b88da Mon Sep 17 00:00:00 2001 From: Roopa Prabhu Date: Sun, 15 May 2016 13:49:05 -0700 Subject: [PATCH 1/3] ifupdownaddons: iproute2: fix set_mtu api to return if --no-act (DRYRUN) is set Ticket: CM-10965 Reviewed By: julien Testing Done: Tested set mtu with dry run Signed-off-by: Roopa Prabhu --- ifupdownaddons/iproute2.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ifupdownaddons/iproute2.py b/ifupdownaddons/iproute2.py index cf15046..04c6900 100644 --- a/ifupdownaddons/iproute2.py +++ b/ifupdownaddons/iproute2.py @@ -419,8 +419,9 @@ class iproute2(utilsBase): self._cache_update([ifacename, 'hwaddress'], hwaddress) def link_set_mtu(self, ifacename, mtu): + if ifupdownflags.flags.DRYRUN: + return True if not mtu or not ifacename: return - with open('/sys/class/net/%s/mtu' % ifacename, 'w') as f: f.write(mtu) self._cache_update([ifacename, 'mtu'], mtu) From bf3eda91db96321b65f373da50f3b3a21fff98d1 Mon Sep 17 00:00:00 2001 From: Roopa Prabhu Date: Sun, 15 May 2016 13:28:10 -0700 Subject: [PATCH 2/3] addons: move some warns to errors and make sure all errors set the exit code correctly Ticket: CM-7168 Reviewed By: julien Testing Done: Tested ifupdown2 negative testcases and ran ifupdown2 smoke Signed-off-by: Roopa Prabhu --- addons/address.py | 4 +-- addons/addressvirtual.py | 10 ++++--- addons/bond.py | 7 +++-- addons/bridge.py | 57 ++++++++++++++++++++---------------- addons/bridgevlan.py | 4 +-- addons/dhcp.py | 2 +- addons/ethtool.py | 3 +- addons/mstpctl.py | 22 ++++++++------ addons/vrf.py | 51 +++++++++++++++++--------------- ifupdownaddons/modulebase.py | 5 ++-- 10 files changed, 91 insertions(+), 74 deletions(-) diff --git a/addons/address.py b/addons/address.py index c063103..1e1e601 100644 --- a/addons/address.py +++ b/addons/address.py @@ -182,7 +182,7 @@ class address(moduleBase): else: self.ipcmd.addr_add(ifaceobj.name, newaddrs[addr_index]) except Exception, e: - self.log_error(str(e)) + self.log_error(str(e), ifaceobj) def _inet_address_config(self, ifaceobj, ifaceobj_getfunc=None, force_reapply=False): @@ -319,7 +319,7 @@ class address(moduleBase): # Handle special things on a bridge self._process_bridge(ifaceobj, True) except Exception, e: - self.log_warn('%s: %s' %(ifaceobj.name, str(e))) + self.log_error('%s: %s' %(ifaceobj.name, str(e)), ifaceobj) pass if addr_method != "dhcp": diff --git a/addons/addressvirtual.py b/addons/addressvirtual.py index 54ab11a..ad0c50b 100644 --- a/addons/addressvirtual.py +++ b/addons/addressvirtual.py @@ -160,8 +160,9 @@ class addressvirtual(moduleBase): for av in address_virtual_list: av_attrs = av.split() if len(av_attrs) < 2: - self.logger.warn("%s: incorrect address-virtual attrs '%s'" - %(ifaceobj.name, av)) + self.log_error("%s: incorrect address-virtual attrs '%s'" + %(ifaceobj.name, av), ifaceobj, + raise_error=False) av_idx += 1 continue @@ -242,8 +243,9 @@ class addressvirtual(moduleBase): for av in address_virtual_list: av_attrs = av.split() if len(av_attrs) < 2: - self.logger.warn("%s: incorrect address-virtual attrs '%s'" - %(ifaceobj.name, av)) + self.log_error("%s: incorrect address-virtual attrs '%s'" + %(ifaceobj.name, av), ifaceobj, + raise_error=False) av_idx += 1 continue diff --git a/addons/bond.py b/addons/bond.py index 882f543..63d85d3 100644 --- a/addons/bond.py +++ b/addons/bond.py @@ -230,8 +230,9 @@ class bond(moduleBase): for slave in Set(slaves).difference(Set(runningslaves)): if (not ifupdownflags.flags.PERFMODE and not self.ipcmd.link_exists(slave)): - self.log_warn('%s: skipping slave %s, does not exist' - %(ifaceobj.name, slave)) + self.log_error('%s: skipping slave %s, does not exist' + %(ifaceobj.name, slave), ifaceobj, + raise_error=False) continue link_up = False if self.ipcmd.is_link_up(slave): @@ -274,7 +275,7 @@ class bond(moduleBase): if ifaceobj.addr_method == 'manual': rtnetlink_api.rtnl_api.link_set(ifaceobj.name, "up") except Exception, e: - self.log_error(str(e)) + self.log_error(str(e), ifaceobj) def _down(self, ifaceobj): try: diff --git a/addons/bridge.py b/addons/bridge.py index 78f1f2d..ac3686c 100644 --- a/addons/bridge.py +++ b/addons/bridge.py @@ -326,7 +326,7 @@ class bridge(moduleBase): for p in ports: self._enable_disable_ipv6(p, state) - def _pretty_print_add_ports_error(self, errstr, bridgename, bridgeports): + def _pretty_print_add_ports_error(self, errstr, bridgeifaceobj, bridgeports): """ pretty print bridge port add errors. since the commands are batched and the kernel only returns error codes, this function tries to interpret some error codes @@ -341,14 +341,14 @@ class bridge(moduleBase): ifattrs = bport.split('.') if vlanid: if (len(ifattrs) == 1 or ifattrs[1] != vlanid): - self.logger.error('%s: ' %bridgename + - 'net.bridge.bridge-allow-multiple-vlans not set, multiple vlans not allowed') + self.log_error('%s: ' %bridgeifaceobj.name + + 'net.bridge.bridge-allow-multiple-vlans not set, multiple vlans not allowed', bridgeifaceobj) break if len(ifattrs) == 2: vlanid = ifattrs[1] except: pass - self.logger.error(bridgename + ': ' + errstr) + self.log_error(bridgeifaceobj.name + ': ' + errstr, bridgeifaceobj) def _add_ports(self, ifaceobj): bridgeports = self._get_bridge_port_list(ifaceobj) @@ -378,8 +378,8 @@ class bridge(moduleBase): try: if (not ifupdownflags.flags.DRYRUN and not self.ipcmd.link_exists(bridgeport)): - self.log_warn('%s: bridge port %s does not exist' - %(ifaceobj.name, bridgeport)) + self.log_error('%s: bridge port %s does not exist' + %(ifaceobj.name, bridgeport), ifaceobj) err += 1 continue hwaddress = self.ipcmd.link_get_hwaddress(bridgeport) @@ -401,7 +401,7 @@ class bridge(moduleBase): try: self.ipcmd.batch_commit() except Exception, e: - self._pretty_print_add_ports_error(str(e), ifaceobj.name, + self._pretty_print_add_ports_error(str(e), ifaceobj, bridgeports) pass @@ -695,8 +695,9 @@ class bridge(moduleBase): continue portlist = self.parse_port_list(ifaceobj.name, attrval) if not portlist: - self.log_warn('%s: could not parse \'%s %s\'' - %(ifaceobj.name, attrname, attrval)) + self.log_error('%s: could not parse \'%s %s\'' + %(ifaceobj.name, attrname, attrval), ifaceobj, + raise_error=False) continue for p in portlist: try: @@ -705,21 +706,23 @@ class bridge(moduleBase): portattrs[port] = {} portattrs[port].update({dstattrname : val}) except Exception, e: - self.log_warn('%s: could not parse %s (%s)' - %(ifaceobj.name, attrname, str(e))) + self.log_error('%s: could not parse %s (%s)' + %(ifaceobj.name, attrname, str(e)), + ifaceobj, raise_error=False) for port, attrdict in portattrs.iteritems(): try: self.brctlcmd.set_bridgeport_attrs(ifaceobj.name, port, attrdict) except Exception, e: - self.log_warn('%s: %s' %(ifaceobj.name, str(e))) + self.log_error('%s: %s' %(ifaceobj.name, str(e)), ifaceobj, + raise_error=False) pass self._set_bridge_vidinfo_compat(ifaceobj) self._set_bridge_mcqv4src_compat(ifaceobj) self._process_bridge_maxwait(ifaceobj, self._get_bridge_port_list(ifaceobj)) except Exception, e: - self.log_warn(str(e)) + self.log_error(str(e), ifaceobj) def _check_vids(self, ifaceobj, vids): ret = True @@ -752,8 +755,9 @@ class bridge(moduleBase): else: self.ipcmd.bridge_vids_add(bportifaceobj.name, vids, isbridge) except Exception, e: - self.log_warn('%s: failed to set vid `%s` (%s)' - %(bportifaceobj.name, str(vids), str(e))) + self.log_error('%s: failed to set vid `%s` (%s)' + %(bportifaceobj.name, str(vids), str(e)), + bportifaceobj) def _apply_bridge_port_pvids(self, bportifaceobj, pvid, running_pvid): # Install pvids @@ -766,8 +770,8 @@ class bridge(moduleBase): else: self.ipcmd.bridge_port_pvid_add(bportifaceobj.name, pvid) except Exception, e: - self.log_warn('%s: failed to set pvid `%s` (%s)' - %(bportifaceobj.name, pvid, str(e))) + self.log_error('%s: failed to set pvid `%s` (%s)' + %(bportifaceobj.name, pvid, str(e)), bportifaceobj) def _apply_bridge_vids_and_pvid(self, bportifaceobj, vids, running_vids, pvid, running_pvid, isbridge): @@ -812,9 +816,10 @@ class bridge(moduleBase): # vid 100 102 vids_to_add.append(pvid_to_del) except Exception, e: - self.log_warn('%s: failed to process vids/pvids' - %bportifaceobj.name + ' vids = %s' %str(vids) + - 'pvid = %s ' %pvid + '(%s)' %str(e)) + self.log_error('%s: failed to process vids/pvids' + %bportifaceobj.name + ' vids = %s' %str(vids) + + 'pvid = %s ' %pvid + '(%s)' %str(e), + bportifaceobj, raise_error=False) try: if vids_to_del: self.ipcmd.bridge_vids_del(bportifaceobj.name, @@ -836,15 +841,17 @@ class bridge(moduleBase): self.ipcmd.bridge_vids_add(bportifaceobj.name, vids_to_add, isbridge) except Exception, e: - self.log_warn('%s: failed to set vid `%s` (%s)' - %(bportifaceobj.name, str(vids_to_add), str(e))) + self.log_error('%s: failed to set vid `%s` (%s)' + %(bportifaceobj.name, str(vids_to_add), str(e)), + bportifaceobj, raise_error=False) try: if pvid_to_add: self.ipcmd.bridge_port_pvid_add(bportifaceobj.name, pvid_to_add) except Exception, e: - self.log_warn('%s: failed to set pvid `%s` (%s)' - %(bportifaceobj.name, pvid_to_add, str(e))) + self.log_error('%s: failed to set pvid `%s` (%s)' + %(bportifaceobj.name, pvid_to_add, str(e)), + bportifaceobj) def _apply_bridge_vlan_aware_port_settings_all(self, bportifaceobj, bridge_vids=None, @@ -916,7 +923,7 @@ class bridge(moduleBase): self.brctlcmd.set_bridgeport_attrs(bridgename, bportifaceobj.name, portattrs) except Exception, e: - self.log_warn(str(e)) + self.log_error(str(e), bportifaceobj) def _apply_bridge_port_settings_all(self, ifaceobj, ifaceobj_getfunc=None): diff --git a/addons/bridgevlan.py b/addons/bridgevlan.py index ef40ef2..fe26196 100644 --- a/addons/bridgevlan.py +++ b/addons/bridgevlan.py @@ -58,8 +58,8 @@ class bridgevlan(moduleBase): (bridgename, vlan) = self._get_bridge_n_vlan(ifaceobj) vlanid = int(vlan, 10) except: - self.logger.warn('%s: bridge vlan interface name ' %ifaceobj.name + - 'does not correspond to format (eg. br0.100)') + self.log_error('%s: bridge vlan interface name ' %ifaceobj.name + + 'does not correspond to format (eg. br0.100)', ifaceobj) raise if not self.ipcmd.link_exists(bridgename): diff --git a/addons/dhcp.py b/addons/dhcp.py index 14988b9..62dbe78 100644 --- a/addons/dhcp.py +++ b/addons/dhcp.py @@ -68,7 +68,7 @@ class dhcp(moduleBase): self.dhclientcmd.start6(ifaceobj.name, wait=wait, cmd_prefix=dhclient_cmd_prefix) except Exception, e: - self.log_error(str(e)) + self.log_error(str(e), ifaceobj) def _down(self, ifaceobj): dhclient_cmd_prefix = None diff --git a/addons/ethtool.py b/addons/ethtool.py index 2617602..21faf39 100644 --- a/addons/ethtool.py +++ b/addons/ethtool.py @@ -116,8 +116,7 @@ class ethtool(moduleBase,utilsBase): cmd = 'ethtool -s %s %s' %(ifaceobj.name, cmd) self.exec_command(cmd) except Exception, e: - ifaceobj.status = ifaceStatus.ERROR - self.log_warn('%s: %s' %(ifaceobj.name, str(e))) + self.log_error('%s: %s' %(ifaceobj.name, str(e)), ifaceobj) else: pass diff --git a/addons/mstpctl.py b/addons/mstpctl.py index 63eae3e..7a640f8 100644 --- a/addons/mstpctl.py +++ b/addons/mstpctl.py @@ -263,7 +263,7 @@ class mstpctl(moduleBase): self.ipcmd.link_set(bridgeport, 'master', ifaceobj.name) self.ipcmd.addr_flush(bridgeport) except Exception, e: - self.log_error(str(e)) + self.log_error(str(e), ifaceobj) if err: self.log_error('error configuring bridge (missing ports)') @@ -299,6 +299,8 @@ class mstpctl(moduleBase): if default_val and jsonAttr: bridgeports = self._get_bridge_port_list(ifaceobj) for port in bridgeports: + if not self.brctlcmd.is_bridge_port(port): + continue running_val = self.mstpctlcmd.get_mstpctl_bridgeport_attr(ifaceobj.name, port, jsonAttr) if running_val != default_val: @@ -313,8 +315,8 @@ class mstpctl(moduleBase): portlist = self.parse_port_list(ifaceobj.name, config_val) if not portlist: - self.log_warn('%s: error parsing \'%s %s\'' - %(ifaceobj.name, attrname, config_val)) + self.log_error('%s: error parsing \'%s %s\'' + %(ifaceobj.name, attrname, config_val), ifaceobj) continue # there was a configured value so we need to parse it # and set the attribute for each port configured @@ -327,8 +329,9 @@ class mstpctl(moduleBase): self.mstpctlcmd.set_bridgeport_attr(ifaceobj.name, port, dstattrname, val, check) except Exception, e: - self.log_warn('%s: error setting %s (%s)' - %(ifaceobj.name, attrname, str(e))) + self.log_error('%s: error setting %s (%s)' + %(ifaceobj.name, attrname, str(e)), + ifaceobj, raise_error=False) except Exception, e: self.log_warn(str(e)) pass @@ -380,8 +383,9 @@ class mstpctl(moduleBase): ifaceobj.name, dstattrname, config_val, check) applied = True except Exception, e: - self.log_warn('%s: error setting %s (%s)' - %(ifaceobj.name, attrname, str(e))) + self.log_error('%s: error setting %s (%s)' + %(ifaceobj.name, attrname, str(e)), ifaceobj, + raise_error=False) return applied def _apply_bridge_port_settings_all(self, ifaceobj, @@ -478,7 +482,7 @@ class mstpctl(moduleBase): self._apply_bridge_port_settings_all(ifaceobj, ifaceobj_getfunc=ifaceobj_getfunc) except Exception, e: - self.log_error(str(e)) + self.log_error(str(e), ifaceobj) if porterr: raise Exception(porterrstr) @@ -494,7 +498,7 @@ class mstpctl(moduleBase): self._ports_enable_disable_ipv6(ports, '0') self.brctlcmd.delete_bridge(ifaceobj.name) except Exception, e: - self.log_error(str(e)) + self.log_error(str(e), ifaceobj) def _query_running_attrs(self, ifaceobjrunning): bridgeattrdict = {} diff --git a/addons/vrf.py b/addons/vrf.py index 3cf7e2c..e504d33 100644 --- a/addons/vrf.py +++ b/addons/vrf.py @@ -242,24 +242,24 @@ class vrf(moduleBase): return str(t) return None - def _iproute2_is_vrf_tableid_inuse(self, vrf_dev_name, table_id): + def _iproute2_is_vrf_tableid_inuse(self, vrfifaceobj, table_id): old_vrf_name = self.iproute2_vrf_map.get(int(table_id)) - if old_vrf_name and old_vrf_name != vrf_dev_name: + if old_vrf_name and old_vrf_name != vrfifaceobj.name: self.log_error('table id %s already assigned to vrf dev %s' - %(table_id, old_vrf_name)) + %(table_id, old_vrf_name), vrfifaceobj) - def _iproute2_vrf_table_entry_add(self, vrf_dev_name, table_id): + def _iproute2_vrf_table_entry_add(self, vrfifaceobj, table_id): old_vrf_name = self.iproute2_vrf_map.get(int(table_id)) if not old_vrf_name: - self.iproute2_vrf_map[int(table_id)] = vrf_dev_name + self.iproute2_vrf_map[int(table_id)] = vrfifaceobj.name if self.iproute2_vrf_map_fd: self.iproute2_vrf_map_fd.write('%s %s\n' - %(table_id, vrf_dev_name)) + %(table_id, vrfifaceobj.name)) self.iproute2_vrf_map_fd.flush() self.vrf_count += 1 return - if old_vrf_name != vrf_dev_name: + if old_vrf_name != vrfifaceobj.name: self.log_error('table id %d already assigned to vrf dev %s' %(table_id, old_vrf_name)) @@ -315,7 +315,7 @@ class vrf(moduleBase): vrf_table = self._get_avail_vrf_table_id() if not vrf_table: self.log_error('%s: unable to get an auto table id' - %mobj.name) + %mobj.name, ifaceobj) self.logger.info('%s: table id auto: selected table id %s\n' %(mobj.name, vrf_table)) try: @@ -366,9 +366,9 @@ class vrf(moduleBase): rtnetlink_api.rtnl_api.link_set(ifacename, "up") else: self.log_error('vrf %s not around, skipping vrf config' - %(vrfname)) + %(vrfname), ifaceobj) except Exception, e: - self.log_error('%s: %s' %(ifacename, str(e))) + self.log_error('%s: %s' %(ifacename, str(e)), ifaceobj) def _del_vrf_rules(self, vrf_dev_name, vrf_table): pref = 200 @@ -507,23 +507,25 @@ class vrf(moduleBase): if not self.ipcmd.link_exists(ifaceobj.name): if ifaceobj.name in self.system_reserved_rt_tables.values(): self.log_error('cannot use system reserved %s vrf names' - %( str(self.system_reserved_rt_tables.values()))) + %(str(self.system_reserved_rt_tables.values())), + ifaceobj) if self.vrf_count == self.vrf_max_count: self.log_error('%s: max vrf count %d hit...not ' 'creating vrf' %(ifaceobj.name, - self.vrf_count)) + self.vrf_count), ifaceobj) if vrf_table == 'auto': vrf_table = self._get_avail_vrf_table_id() if not vrf_table: self.log_error('%s: unable to get an auto table id' - %ifaceobj.name) + %ifaceobj.name, ifaceobj) self.logger.info('%s: table id auto: selected table id %s\n' %(ifaceobj.name, vrf_table)) else: - self._iproute2_is_vrf_tableid_inuse(ifaceobj.name, vrf_table) + self._iproute2_is_vrf_tableid_inuse(ifaceobj, vrf_table) if ifaceobj.name in self.system_reserved_rt_tables.keys(): self.log_error('cannot use system reserved %s table ids' - %(str(self.system_reserved_rt_tables.keys()))) + %(str(self.system_reserved_rt_tables.keys())), + ifaceobj) if not vrf_table.isdigit(): self.log_error('%s: vrf-table must be an integer or \'auto\'' @@ -537,21 +539,21 @@ class vrf(moduleBase): self.log_error('%s: vrf table id %s out of reserved range [%d,%d]' %(ifaceobj.name, vrf_table, self.vrf_table_id_start, - self.vrf_table_id_end)) + self.vrf_table_id_end), ifaceobj) try: self.ipcmd.link_create(ifaceobj.name, 'vrf', {'table' : '%s' %vrf_table}) except Exception, e: self.log_error('%s: create failed (%s)\n' - %(ifaceobj.name, str(e))) + %(ifaceobj.name, str(e)), ifaceobj) if vrf_table != 'auto': - self._iproute2_vrf_table_entry_add(ifaceobj.name, vrf_table) + self._iproute2_vrf_table_entry_add(ifaceobj, vrf_table) else: if vrf_table == 'auto': vrf_table = self._get_iproute2_vrf_table(ifaceobj.name) if not vrf_table: self.log_error('%s: unable to get vrf table id' - %ifaceobj.name) + %ifaceobj.name, ifaceobj) # if the device exists, check if table id is same vrfdev_attrs = self.ipcmd.link_get_linkinfo_attrs(ifaceobj.name) @@ -559,7 +561,8 @@ class vrf(moduleBase): running_table = vrfdev_attrs.get('table', None) if vrf_table != running_table: self.log_error('%s: cannot change vrf table id,running table id %s is different from config id %s' %(ifaceobj.name, - running_table, vrf_table)) + running_table, vrf_table), + ifaceobj) return vrf_table def _up_vrf_helper(self, ifaceobj, vrf_table): @@ -582,7 +585,7 @@ class vrf(moduleBase): try: vrf_table = self._create_vrf_dev(ifaceobj, vrf_table) except Exception, e: - self.log_error('%s: %s' %(ifaceobj.name, str(e))) + self.log_error('%s: %s' %(ifaceobj.name, str(e)), ifaceobj) try: self._add_vrf_rules(ifaceobj.name, vrf_table) @@ -592,7 +595,7 @@ class vrf(moduleBase): self._set_vrf_dev_processed_flag(ifaceobj) rtnetlink_api.rtnl_api.link_set(ifaceobj.name, "up") except Exception, e: - self.log_error('%s: %s' %(ifaceobj.name, str(e))) + self.log_error('%s: %s' %(ifaceobj.name, str(e)), ifaceobj) def _kill_ssh_connections(self, ifacename): try: @@ -685,7 +688,7 @@ class vrf(moduleBase): self._down_vrf_slave(ifaceobj.name, ifaceobj, master) except Exception, e: - self.log_error(str(e)) + self.log_error(str(e), ifaceobj) def _down_vrf_helper(self, ifaceobj, vrf_table): mode = "" @@ -770,7 +773,7 @@ class vrf(moduleBase): else: ifaceobjcurr.update_config_with_status('vrf', master, 0) except Exception, e: - self.log_warn(str(e)) + self.log_error(str(e), ifaceobjcurr) def _query_check_vrf_dev(self, ifaceobj, ifaceobjcurr, vrf_table): try: diff --git a/ifupdownaddons/modulebase.py b/ifupdownaddons/modulebase.py index 7236d35..f91879c 100644 --- a/ifupdownaddons/modulebase.py +++ b/ifupdownaddons/modulebase.py @@ -42,14 +42,15 @@ class moduleBase(object): ifaceobj.set_status(ifaceStatus.WARNING) pass - def log_error(self, str, ifaceobj=None): + def log_error(self, str, ifaceobj=None, raise_error=True): """ log an err if err str is not one of which we should ignore and raise an exception """ if not self.ignore_error(str): if self.logger.getEffectiveLevel() == logging.DEBUG: traceback.print_stack() if ifaceobj: ifaceobj.set_status(ifaceStatus.ERROR) - raise Exception(str) + if raise_error: + raise Exception(str) else: pass From 666c6141710beb479533640d483571b2aad31ee3 Mon Sep 17 00:00:00 2001 From: Roopa Prabhu Date: Sun, 15 May 2016 14:17:56 -0700 Subject: [PATCH 3/3] ifupdownmain: return proper error code on syntax check errors Ticket: CM-7168 Reviewed By: julien Testing Done: Tested ifupdown2 negative testcases and ran ifupdown2 smoke Signed-off-by: Roopa Prabhu --- ifupdown/ifupdownmain.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ifupdown/ifupdownmain.py b/ifupdown/ifupdownmain.py index 66e5093..bce13c8 100644 --- a/ifupdown/ifupdownmain.py +++ b/ifupdown/ifupdownmain.py @@ -1136,6 +1136,8 @@ class ifupdownMain(ifupdownBase): if syntaxcheck: if not iface_read_ret: raise Exception() + elif self._any_iface_errors(filtered_ifacenames): + raise Exception() return ret = None @@ -1592,6 +1594,16 @@ class ifupdownMain(ifupdownBase): else: self._reload_default(*args, **kargs) + def _any_iface_errors(self, ifacenames): + for i in ifacenames: + ifaceobjs = self.get_ifaceobjs(i) + if not ifaceobjs: continue + for ifaceobj in ifaceobjs: + if (ifaceobj.status == ifaceStatus.NOTFOUND or + ifaceobj.status == ifaceStatus.ERROR): + return True + return False + def _pretty_print_ordered_dict(self, prefix, argdict): outbuf = prefix + ' {\n' for k, vlist in argdict.items():