Test dig options for salt.utils.dns.lookup

This commit is contained in:
Ty Hahn 2019-02-03 13:30:26 +00:00
parent a05305dce3
commit a00d708441
No known key found for this signature in database
GPG key ID: A0C48B7A57D4BB12
2 changed files with 9 additions and 1 deletions

View file

@ -45,6 +45,7 @@ try:
except ImportError:
HAS_DNSPYTHON = False
HAS_DIG = salt.utils.path.which('dig') is not None
DIG_OPTIONS = '+search +fail +noall +answer +noclass +nottl'
HAS_DRILL = salt.utils.path.which('drill') is not None
HAS_HOST = salt.utils.path.which('host') is not None
HAS_NSLOOKUP = salt.utils.path.which('nslookup') is not None
@ -229,7 +230,7 @@ def _lookup_dig(name, rdtype, timeout=None, servers=None, secure=None):
:param servers: [] of servers to use
:return: [] of records or False if error
'''
cmd = 'dig +search +fail +noall +answer +noclass +nottl -t {0} '.format(rdtype)
cmd = 'dig {0} -t {1} '.format(DIG_OPTIONS, rdtype)
if servers:
cmd += ''.join(['@{0} '.format(srv) for srv in servers])
if timeout is not None:

View file

@ -14,6 +14,7 @@ from salt.utils.odict import OrderedDict
import salt.utils.dns
from salt.utils.dns import _to_port, _tree, _weighted_order, _data2rec, _data2rec_group
from salt.utils.dns import _lookup_gai, _lookup_dig, _lookup_drill, _lookup_host, _lookup_nslookup
import salt.modules.cmdmod
# Testing
from tests.support.unit import skipIf, TestCase
@ -277,6 +278,12 @@ class DNSlookupsCase(TestCase):
msg='Error parsing DNSSEC\'d {0} returns'.format(rec_t)
)
@skipIf(not salt.utils.dns.HAS_DIG, 'dig is not available')
def test_dig_options(self):
cmd = 'dig {0}'.format(salt.utils.dns.DIG_OPTIONS)
cmd = salt.modules.cmdmod.retcode(cmd, python_shell=False, output_loglevel='quiet')
self.assertEqual(cmd, 0)
def test_dig(self):
wrong_type = {'retcode': 0, 'stderr': ';; Warning, ignoring invalid type ABC'}