Change in vdsm[master]: ifcfg: make removeNic cope with a missing ifcfg file

osvoboda at redhat.com osvoboda at redhat.com
Tue Sep 8 21:41:16 UTC 2015


Ondřej Svoboda has uploaded a new change for review.

Change subject: ifcfg: make removeNic cope with a missing ifcfg file
......................................................................

ifcfg: make removeNic cope with a missing ifcfg file

The file is only read to be able to write back the HWADDR property.
This information may already be available in ConfigWriter._backups,
but let's just patch around the obvious problem first.

Change-Id: Ica18b30d508224903e7dcb898d74ae8ec35d4a23
Signed-off-by: Ondřej Svoboda <osvoboda at redhat.com>
---
M vdsm/network/configurators/ifcfg.py
1 file changed, 16 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/93/45893/1

diff --git a/vdsm/network/configurators/ifcfg.py b/vdsm/network/configurators/ifcfg.py
index 161a3b2..6315b15 100644
--- a/vdsm/network/configurators/ifcfg.py
+++ b/vdsm/network/configurators/ifcfg.py
@@ -647,11 +647,24 @@
     def removeNic(self, nic):
         cf = netinfo.NET_CONF_PREF + nic
         self._backup(cf)
-        with open(cf) as nicFile:
-            hwlines = [line for line in nicFile if line.startswith('HWADDR=')]
+
+        try:
+            with open(cf) as nicFile:
+                # TODO: how about getting the MAC from netinfo.gethwaddr or
+                # self._backups instead?
+                hwlines = [line for line in nicFile if line.startswith(
+                    'HWADDR=')]
+        except IOError as e:
+            if e.errno == os.errno.ENOENT:
+                # TODO: does logging not work during network restoration?
+                logging.warning("%s didn't exist, HWADDR is unknown", cf)
+            else:
+                logging.exception("%s couldn't be read, HWADDR is unknown", cf)
+            hwlines = []
+
         l = [self.CONFFILE_HEADER + '\n', 'DEVICE=%s\n' % nic, 'ONBOOT=yes\n',
              'MTU=%s\n' % netinfo.DEFAULT_MTU] + hwlines
-        l += 'NM_CONTROLLED=no\n'
+        l += 'NM_CONTROLLED=no\n'  # TODO: why care?
         with open(cf, 'w') as nicFile:
             nicFile.writelines(l)
 


-- 
To view, visit https://gerrit.ovirt.org/45893
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ica18b30d508224903e7dcb898d74ae8ec35d4a23
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ondřej Svoboda <osvoboda at redhat.com>


More information about the vdsm-patches mailing list