Repository: Azure/WALinuxAgent (python)

Issue:
DHCP regression
[This commit](https://github.com/Azure/WALinuxAgent/commit/9bb5d40ad80177b49e397d871df2faded2d6e48d) added an exception when there is no interface found, resulting in the following logs:

```
'2018/04/23 02:55:05.255749 ERROR Event: name=WALinuxAgent, op=UnhandledError, message=Traceback (most recent call last):\n', 
'2018/04/23 02:57:01.471314 ERROR Event: name=WALinuxAgent, op=UnhandledError, message=Traceback (most recent call last):\n', 
'2018/04/23 02:58:57.619919 ERROR Event: name=WALinuxAgent, op=UnhandledError, message=Traceback (most recent call last):\n', 
'2018/04/23 03:00:53.930831 ERROR Event: name=WALinuxAgent, op=UnhandledError, message=Traceback (most recent call last):\n', 
'2018/04/23 03:02:50.577667 ERROR Event: name=WALinuxAgent, op=UnhandledError, message=Traceback (most recent call last):\n', 
'2018/04/23 03:04:46.782791 ERROR Event: name=WALinuxAgent, op=UnhandledError, message=Traceback (most recent call last):\n', 
'2018/04/23 03:06:42.903693 ERROR Event: name=WALinuxAgent, op=UnhandledError, message=Traceback (most recent call last):\n', 
'2018/04/23 03:08:39.078856 ERROR Event: name=WALinuxAgent, op=UnhandledError, message=Traceback (most recent call last):\n', 
'2018/04/23 03:10:35.215515 ERROR Event: name=WALinuxAgent, op=UnhandledError, message=Traceback (most recent call last):\n', 
'2018/04/23 03:12:31.405739 ERROR Event: name=WALinuxAgent, op=UnhandledError, message=Traceback (most recent call last):\n'
```

As there is nothing to be done about this we should remove the exception. 

Pull request description:
do not raise an exception if get_first_if fails
- fixes #1130 

Patch:
diff --git a/azurelinuxagent/common/osutil/default.py b/azurelinuxagent/common/osutil/default.py
index 0d637b54..d08daea1 100644
--- a/azurelinuxagent/common/osutil/default.py
+++ b/azurelinuxagent/common/osutil/default.py
@@ -662,12 +662,12 @@ class DefaultOSUtil(object):
 
     def get_mac_addr(self):
         """
-        Convienience function, returns mac addr bound to
+        Convenience function, returns mac addr bound to
         first non-loopback interface.
         """
-        ifname=''
-        while len(ifname) < 2 :
-            ifname=self.get_first_if()[0]
+        ifname = ''
+        while len(ifname) < 2:
+            ifname = self.get_first_if()[0]
         addr = self.get_if_mac(ifname)
         return textutil.hexstr_to_bytearray(addr)
 
@@ -737,16 +737,15 @@ class DefaultOSUtil(object):
         if primary in ifaces:
             return primary, ifaces[primary]
 
-        logger.warn(('Primary interface {0} not found in ifconf list'), primary)
+        logger.warn('Primary interface {0} not found in ifconf list', primary)
         for iface_name in ifaces.keys():
             if not self.is_loopback(iface_name):
                 if not self.disable_route_warning:
                     logger.info("Choosing non-primary {0}".format(iface_name))
                 return iface_name, ifaces[iface_name]
 
-        msg = 'No non-loopback interface found in ifconf list'
-        logger.warn(msg)
-        raise Exception(msg)
+        logger.warn('No non-loopback interface found in ifconf list')
+        return '', ''
 
 
     def get_primary_interface(self):
@@ -908,7 +907,10 @@ class DefaultOSUtil(object):
         return True
 
     def get_if_name(self):
-        return self.get_first_if()[0]
+        ifname = ''
+        while len(ifname) < 2:
+            ifname = self.get_first_if()[0]
+        return ifname
 
     def get_ip4_addr(self):
         return self.get_first_if()[1]


Test patch:
diff --git a/tests/common/osutil/test_default.py b/tests/common/osutil/test_default.py
index cbd01ee0..7db80271 100644
--- a/tests/common/osutil/test_default.py
+++ b/tests/common/osutil/test_default.py
@@ -124,7 +124,7 @@ class TestOSUtil(AgentTestCase):
         fake_ifaces = {'lo':'127.0.0.1'}
         with patch.object(osutil.DefaultOSUtil, 'get_primary_interface', return_value='bogus0'):
             with patch.object(osutil.DefaultOSUtil, '_get_all_interfaces', return_value=fake_ifaces):
-                self.assertRaises(Exception, osutil.DefaultOSUtil().get_first_if)
+                self.assertEqual(('', ''), osutil.DefaultOSUtil().get_first_if())
 
     def test_isloopback(self):
         self.assertTrue(osutil.DefaultOSUtil().is_loopback('lo'))