2018-07-30 13:52:13 +02:00
|
|
|
From 826194be2a036fee80d3ca546822023416ac3a7d Mon Sep 17 00:00:00 2001
|
2018-04-30 14:06:44 +02:00
|
|
|
From: Bo Maryniuk <bo@suse.de>
|
|
|
|
Date: Wed, 21 Mar 2018 11:10:23 +0100
|
|
|
|
Subject: [PATCH] Fix for [Errno 0] Resolver Error 0 (no error)
|
|
|
|
(bsc#1087581)
|
|
|
|
|
|
|
|
* Lintfix: PEP8 ident
|
|
|
|
* Use proper levels of the error handling, use proper log formatting.
|
|
|
|
* Fix unit test for reversed fqdns return data
|
|
|
|
---
|
|
|
|
salt/grains/core.py | 19 ++++++++++++-------
|
2018-07-30 13:52:13 +02:00
|
|
|
tests/unit/grains/test_core.py | 22 ++++++++++++++++++++++
|
|
|
|
2 files changed, 34 insertions(+), 7 deletions(-)
|
2018-04-30 14:06:44 +02:00
|
|
|
|
|
|
|
diff --git a/salt/grains/core.py b/salt/grains/core.py
|
2018-07-30 13:52:13 +02:00
|
|
|
index c166a43d7c..dc472a6c0a 100644
|
2018-04-30 14:06:44 +02:00
|
|
|
--- a/salt/grains/core.py
|
|
|
|
+++ b/salt/grains/core.py
|
2018-07-30 13:52:13 +02:00
|
|
|
@@ -1898,16 +1898,21 @@ def fqdns():
|
2018-04-30 14:06:44 +02:00
|
|
|
fqdns = set()
|
|
|
|
|
|
|
|
addresses = salt.utils.network.ip_addrs(include_loopback=False,
|
|
|
|
- interface_data=_INTERFACES)
|
|
|
|
+ interface_data=_INTERFACES)
|
|
|
|
addresses.extend(salt.utils.network.ip_addrs6(include_loopback=False,
|
|
|
|
- interface_data=_INTERFACES))
|
|
|
|
-
|
|
|
|
+ interface_data=_INTERFACES))
|
|
|
|
+ err_message = 'Exception during resolving address: %s'
|
|
|
|
for ip in addresses:
|
|
|
|
try:
|
|
|
|
- fqdns.add(socket.gethostbyaddr(ip)[0])
|
|
|
|
- except (socket.error, socket.herror,
|
|
|
|
- socket.gaierror, socket.timeout) as e:
|
|
|
|
- log.info("Exception during resolving address: " + str(e))
|
|
|
|
+ fqdns.add(socket.getfqdn(socket.gethostbyaddr(ip)[0]))
|
|
|
|
+ except socket.herror as err:
|
|
|
|
+ if err.errno == 0:
|
|
|
|
+ # No FQDN for this IP address, so we don't need to know this all the time.
|
|
|
|
+ log.debug("Unable to resolve address %s: %s", ip, err)
|
|
|
|
+ else:
|
|
|
|
+ log.error(err_message, err)
|
|
|
|
+ except (socket.error, socket.gaierror, socket.timeout) as err:
|
|
|
|
+ log.error(err_message, err)
|
|
|
|
|
|
|
|
grains['fqdns'] = list(fqdns)
|
|
|
|
return grains
|
|
|
|
diff --git a/tests/unit/grains/test_core.py b/tests/unit/grains/test_core.py
|
2018-07-30 13:52:13 +02:00
|
|
|
index 616c62e658..dd7d5b06f8 100644
|
2018-04-30 14:06:44 +02:00
|
|
|
--- a/tests/unit/grains/test_core.py
|
|
|
|
+++ b/tests/unit/grains/test_core.py
|
2018-07-30 13:52:13 +02:00
|
|
|
@@ -877,3 +877,25 @@ SwapTotal: 4789244 kB'''
|
|
|
|
osdata = {'kernel': 'test', }
|
|
|
|
ret = core._virtual(osdata)
|
|
|
|
self.assertEqual(ret['virtual'], virt)
|
2018-04-30 14:06:44 +02:00
|
|
|
+
|
|
|
|
+ @skipIf(not salt.utils.platform.is_linux(), 'System is not Linux')
|
|
|
|
+ @patch.object(salt.utils, 'is_windows', MagicMock(return_value=False))
|
|
|
|
+ @patch('salt.utils.network.ip_addrs', MagicMock(return_value=['1.2.3.4', '5.6.7.8']))
|
|
|
|
+ @patch('salt.utils.network.ip_addrs6',
|
|
|
|
+ MagicMock(return_value=['fe80::a8b2:93ff:fe00:0', 'fe80::a8b2:93ff:dead:beef']))
|
|
|
|
+ @patch('salt.utils.network.socket.getfqdn', MagicMock(side_effect=lambda v: v)) # Just pass-through
|
|
|
|
+ def test_fqdns_return(self):
|
|
|
|
+ '''
|
|
|
|
+ test the return for a dns grain. test for issue:
|
|
|
|
+ https://github.com/saltstack/salt/issues/41230
|
|
|
|
+ '''
|
|
|
|
+ reverse_resolv_mock = [('foo.bar.baz', [], ['1.2.3.4']),
|
|
|
|
+ ('rinzler.evil-corp.com', [], ['5.6.7.8']),
|
|
|
|
+ ('foo.bar.baz', [], ['fe80::a8b2:93ff:fe00:0']),
|
|
|
|
+ ('bluesniff.foo.bar', [], ['fe80::a8b2:93ff:dead:beef'])]
|
|
|
|
+ ret = {'fqdns': ['bluesniff.foo.bar', 'foo.bar.baz', 'rinzler.evil-corp.com']}
|
|
|
|
+ with patch.object(socket, 'gethostbyaddr', side_effect=reverse_resolv_mock):
|
|
|
|
+ fqdns = core.fqdns()
|
|
|
|
+ self.assertIn('fqdns', fqdns)
|
|
|
|
+ self.assertEqual(len(fqdns['fqdns']), len(ret['fqdns']))
|
|
|
|
+ self.assertEqual(set(fqdns['fqdns']), set(ret['fqdns']))
|
|
|
|
--
|
2018-07-30 13:52:13 +02:00
|
|
|
2.13.7
|
2018-04-30 14:06:44 +02:00
|
|
|
|
|
|
|
|