salt/fix-for-errno-0-resolver-error-0-no-error-bsc-108758.patch
Bo Maryniuk 7966fde1ef Accepting request 626472 from home:mdinca:branches:systemsmanagement:saltstack
- Update to 2018.3.2
  See https://docs.saltstack.com/en/latest/topics/releases/2018.3.2.html
  for full changelog
- Added:
  * accounting-for-when-files-in-an-archive-contain-non-.patch
  * add-all_versions-parameter-to-include-all-installed-.patch
  * add-custom-suse-capabilities-as-grains.patch
  * add-engine-relaying-libvirt-events.patch
  * add-environment-variable-to-know-if-yum-is-invoked-f.patch
  * add-other-attribute-to-gecos-fields-to-avoid-inconsi.patch
  * align-suse-salt-master.service-limitnofiles-limit-wi.patch
  * avoid-incomprehensive-message-if-crashes.patch
  * fix-deprecation-warning-bsc-1095507.patch
  * fix-diffing-binary-files-in-file.get_diff-bsc-109839.patch
  * fix-unboundlocalerror-in-file.get_diff.patch
  * fix-zypper.list_pkgs-to-be-aligned-with-pkg-state.patch
  * prevent-zypper-from-parsing-repo-configuration-from-.patch
  * remove-old-hack-when-reporting-multiversion-packages.patch
  * show-recommendations-for-salt-ssh-cross-version-pyth.patch
- Modified:
  * activate-all-beacons-sources-config-pillar-grains.patch
  * add-saltssh-multi-version-support-across-python-inte.patch
  * avoid-excessive-syslogging-by-watchdog-cronjob-58.patch
  * do-not-override-jid-on-returners-only-sending-back-t.patch
  * enable-passing-a-unix_socket-for-mysql-returners-bsc.patch
  * fall-back-to-pymysql.patch
  * feat-add-grain-for-all-fqdns.patch
  * fix-bsc-1065792.patch
  * fix-decrease-loglevel-when-unable-to-resolve-addr.patch
  * fix-for-ec2-rate-limit-failures.patch

OBS-URL: https://build.opensuse.org/request/show/626472
OBS-URL: https://build.opensuse.org/package/show/systemsmanagement:saltstack/salt?expand=0&rev=127
2018-07-30 11:52:13 +00:00

82 lines
3.7 KiB
Diff

From 826194be2a036fee80d3ca546822023416ac3a7d Mon Sep 17 00:00:00 2001
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 ++++++++++++-------
tests/unit/grains/test_core.py | 22 ++++++++++++++++++++++
2 files changed, 34 insertions(+), 7 deletions(-)
diff --git a/salt/grains/core.py b/salt/grains/core.py
index c166a43d7c..dc472a6c0a 100644
--- a/salt/grains/core.py
+++ b/salt/grains/core.py
@@ -1898,16 +1898,21 @@ def fqdns():
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
index 616c62e658..dd7d5b06f8 100644
--- a/tests/unit/grains/test_core.py
+++ b/tests/unit/grains/test_core.py
@@ -877,3 +877,25 @@ SwapTotal: 4789244 kB'''
osdata = {'kernel': 'test', }
ret = core._virtual(osdata)
self.assertEqual(ret['virtual'], virt)
+
+ @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']))
--
2.13.7