mirror of
https://github.com/clearlinux/WALinuxAgent.git
synced 2026-09-03 20:31:31 +00:00
do not try encode None, always return a string from get_primary_interface (#287)
This commit is contained in:
@@ -500,6 +500,10 @@ class DefaultOSUtil(object):
|
||||
if primary is None or metric < primary_metric:
|
||||
primary = iface
|
||||
primary_metric = metric
|
||||
|
||||
if primary is None:
|
||||
primary = ''
|
||||
|
||||
logger.info('primary interface is [{0}]'.format(primary))
|
||||
return primary
|
||||
|
||||
|
||||
@@ -106,6 +106,17 @@ class TestOSUtil(AgentTestCase):
|
||||
self.assertFalse(osutil.DefaultOSUtil().is_primary_interface('nflg'))
|
||||
self.assertFalse(osutil.DefaultOSUtil().is_primary_interface('invalid'))
|
||||
|
||||
def test_no_primary_does_not_throw(self):
|
||||
with patch.object(osutil.DefaultOSUtil, 'get_primary_interface') \
|
||||
as patch_primary:
|
||||
exception = False
|
||||
patch_primary.return_value = ''
|
||||
try:
|
||||
osutil.DefaultOSUtil().get_first_if()[0]
|
||||
except Exception as e:
|
||||
exception = True
|
||||
self.assertFalse(exception)
|
||||
|
||||
def test_dhcp_lease_default(self):
|
||||
self.assertTrue(osutil.DefaultOSUtil().get_dhcp_lease_endpoint() is None)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user