Skip to content

Commit

Permalink
Do not add aliases to fqdns grains
Browse files Browse the repository at this point in the history
  • Loading branch information
meaksh committed Sep 6, 2019
1 parent b6c93d2 commit 331eda0
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 26 deletions.
3 changes: 1 addition & 2 deletions salt/modules/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 0 additions & 24 deletions tests/unit/grains/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 331eda0

Please sign in to comment.