diff options
author | Ben Nemec <bnemec@redhat.com> | 2015-01-08 17:58:40 +0000 |
---|---|---|
committer | Ben Nemec <bnemec@redhat.com> | 2015-01-08 18:04:35 +0000 |
commit | 208988b0e935836c76042d6f42829ec23135049b (patch) | |
tree | 5f337a7e9079acdbe1cfe6234a914b141bd6ebc0 /oslo_utils/tests/test_netutils.py | |
parent | 6e0b86164b955a7930cd39dd3c12574f25f1a14e (diff) | |
download | oslo-utils-208988b0e935836c76042d6f42829ec23135049b.tar.gz |
Return LOCALHOST if no default interface1.2.1
If no default interface is available in netutils._get_my_ipv4_address(),
return LOCALHOST immediately. Without this change, an UnboundLocalError
exception will be raised instead.
Co-Authored-By: Ruby Loo <rloo@yahoo-inc.com>
Change-Id: I098450c32ef8ad467298c845dd0122da3e3cda3e
Closes-Bug: #1405217
Closes-Bug: #1408701
Diffstat (limited to 'oslo_utils/tests/test_netutils.py')
-rw-r--r-- | oslo_utils/tests/test_netutils.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/oslo_utils/tests/test_netutils.py b/oslo_utils/tests/test_netutils.py index 790104f..7e1b545 100644 --- a/oslo_utils/tests/test_netutils.py +++ b/oslo_utils/tests/test_netutils.py @@ -222,3 +222,12 @@ class NetworkUtilsTest(test_base.BaseTestCase): ifaddr.return_value = {} addr = netutils._get_my_ipv4_address() self.assertEqual('127.0.0.1', addr) + + @mock.patch('netifaces.gateways') + @mock.patch('netifaces.ifaddresses') + def test_get_my_ipv4_address_without_default_interface( + self, ifaddr, gateways): + gateways.return_value = {} + addr = netutils._get_my_ipv4_address() + self.assertEqual('127.0.0.1', addr) + self.assertFalse(ifaddr.called) |