diff --git a/salt/modules/network.py b/salt/modules/network.py index 278f273a795d..665034c2aba4 100644 --- a/salt/modules/network.py +++ b/salt/modules/network.py @@ -1910,8 +1910,7 @@ def fqdns(): def _lookup_fqdn(ip): try: - name, aliaslist, addresslist = socket.gethostbyaddr(ip) - return [socket.getfqdn(name)] + [als for als in aliaslist if salt.utils.network.is_fqdn(als)] + return [socket.getfqdn(socket.gethostbyaddr(ip)[0])] except socket.herror as err: if err.errno in (0, HOST_NOT_FOUND, NO_DATA): # No FQDN for this IP address, so we don't need to know this all the time. diff --git a/tests/unit/grains/test_core.py b/tests/unit/grains/test_core.py index 69a8b3eb2b2c..4ccbae5e75be 100644 --- a/tests/unit/grains/test_core.py +++ b/tests/unit/grains/test_core.py @@ -1029,30 +1029,6 @@ def test_fqdns_return(self): assert len(fqdns['fqdns']) == len(ret['fqdns']) assert set(fqdns['fqdns']) == set(ret['fqdns']) - @skipIf(not salt.utils.platform.is_linux(), 'System is not Linux') - @patch.object(salt.utils.platform, '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_aliases(self): - ''' - FQDNs aliases - ''' - reverse_resolv_mock = [('foo.bar.baz', ["throwmeaway", "this.is.valid.alias"], ['1.2.3.4']), - ('rinzler.evil-corp.com', ["false-hostname", "badaliass"], ['5.6.7.8']), - ('foo.bar.baz', [], ['fe80::a8b2:93ff:fe00:0']), - ('bluesniff.foo.bar', ["alias.bluesniff.foo.bar"], ['fe80::a8b2:93ff:dead:beef'])] - with patch.dict(core.__salt__, {'network.fqdns': salt.modules.network.fqdns}): - with patch.object(socket, 'gethostbyaddr', side_effect=reverse_resolv_mock): - fqdns = core.fqdns() - assert "fqdns" in fqdns - for alias in ["this.is.valid.alias", "alias.bluesniff.foo.bar"]: - assert alias in fqdns["fqdns"] - - for alias in ["throwmeaway", "false-hostname", "badaliass"]: - assert alias not in fqdns["fqdns"] - def test_core_virtual(self): ''' test virtual grain with cmd virt-what