| |
@@ -0,0 +1,214 @@
|
| |
+ From 7a00a9d51d5af19edeccda4b7c50d07a57d2efd4 Mon Sep 17 00:00:00 2001
|
| |
+ From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
|
| |
+ Date: Tue, 14 Sep 2021 20:02:14 +0200
|
| |
+ Subject: [PATCH] Skip probe tests on empty resolv.conf
|
| |
+ MIME-Version: 1.0
|
| |
+ Content-Type: text/plain; charset=UTF-8
|
| |
+ Content-Transfer-Encoding: 8bit
|
| |
+
|
| |
+ Return different return code from probe in case no resolvers were found.
|
| |
+ Use that return code to detect this problem in tests and mark test case
|
| |
+ skipped instead of failed. Helps avoiding failures in networkless build
|
| |
+ environment in Fedora mock.
|
| |
+
|
| |
+ Signed-off-by: Petr Menšík <pemensik@redhat.com>
|
| |
+ PatchNumber: 3
|
| |
+ ---
|
| |
+ dnsviz/commands/probe.py | 7 ++++++-
|
| |
+ doc/man/dnsviz-probe.1 | 2 ++
|
| |
+ tests/test_dnsviz_probe_options.py | 7 +++++--
|
| |
+ tests/test_dnsviz_probe_run_offline.py | 27 +++++++++++++++++---------
|
| |
+ tests/test_dnsviz_probe_run_online.py | 16 ++++++++++-----
|
| |
+ 5 files changed, 42 insertions(+), 17 deletions(-)
|
| |
+
|
| |
+ diff --git a/dnsviz/commands/probe.py b/dnsviz/commands/probe.py
|
| |
+ index d317a45..5d90c93 100644
|
| |
+ --- a/dnsviz/commands/probe.py
|
| |
+ +++ b/dnsviz/commands/probe.py
|
| |
+ @@ -1451,7 +1451,7 @@ def build_helper(logger, cmd, subcmd):
|
| |
+ resolver = Resolver.from_file(RESOLV_CONF, StandardRecursiveQueryCD, transport_manager=tm)
|
| |
+ except ResolvConfError:
|
| |
+ sys.stderr.write('File %s not found or contains no nameserver entries.\n' % RESOLV_CONF)
|
| |
+ - sys.exit(1)
|
| |
+ + sys.exit(5)
|
| |
+
|
| |
+ arghelper = ArgHelper(resolver, logger)
|
| |
+ arghelper.build_parser('%s %s' % (cmd, subcmd))
|
| |
+ @@ -1481,6 +1481,11 @@ def main(argv):
|
| |
+ arghelper.serve_zones()
|
| |
+ except argparse.ArgumentTypeError as e:
|
| |
+ arghelper.parser.error(str(e))
|
| |
+ + except ResolvConfError as e:
|
| |
+ + arghelper.parser.print_usage(sys.stderr)
|
| |
+ + sys.stderr.write("%(prog)s: error: %(errmsg)s\n" % {
|
| |
+ + 'prog': arghelper.parser.prog, 'errmsg': str(e) })
|
| |
+ + sys.exit(5)
|
| |
+ except (ZoneFileServiceError, MissingExecutablesError) as e:
|
| |
+ s = str(e)
|
| |
+ if s:
|
| |
+ diff --git a/doc/man/dnsviz-probe.1 b/doc/man/dnsviz-probe.1
|
| |
+ index 71a9e7d..17c66da 100644
|
| |
+ --- a/doc/man/dnsviz-probe.1
|
| |
+ +++ b/doc/man/dnsviz-probe.1
|
| |
+ @@ -326,6 +326,8 @@ The network was unavailable for diagnostic queries.
|
| |
+ There was an error processing the input or saving the output.
|
| |
+ .IP 4
|
| |
+ Program execution was interrupted, or an unknown error occurred.
|
| |
+ +.IP 5
|
| |
+ +No recursive resolvers found in resolv.conf nor given on command line.
|
| |
+ .SH SEE ALSO
|
| |
+ .BR dnsviz(1),
|
| |
+ .BR dnsviz-grok(1),
|
| |
+ diff --git a/tests/test_dnsviz_probe_options.py b/tests/test_dnsviz_probe_options.py
|
| |
+ index 4519160..2f7140d 100644
|
| |
+ --- a/tests/test_dnsviz_probe_options.py
|
| |
+ +++ b/tests/test_dnsviz_probe_options.py
|
| |
+ @@ -13,7 +13,7 @@ import dns.name, dns.rdatatype, dns.rrset, dns.zone
|
| |
+
|
| |
+ from dnsviz.commands.probe import ZoneFileToServe, ArgHelper, DomainListArgHelper, StandardRecursiveQueryCD, WILDCARD_EXPLICIT_DELEGATION, AnalysisInputError, CustomQueryMixin
|
| |
+ from dnsviz import transport
|
| |
+ -from dnsviz.resolver import Resolver
|
| |
+ +from dnsviz.resolver import Resolver, ResolvConfError
|
| |
+ from dnsviz.ipaddr import IPAddr
|
| |
+
|
| |
+ DATA_DIR = os.path.dirname(__file__)
|
| |
+ @@ -24,7 +24,10 @@ EXAMPLE_AUTHORITATIVE = os.path.join(DATA_DIR, 'data', 'example-authoritative.js
|
| |
+ class DNSVizProbeOptionsTestCase(unittest.TestCase):
|
| |
+ def setUp(self):
|
| |
+ self.tm = transport.DNSQueryTransportManager()
|
| |
+ - self.resolver = Resolver.from_file('/etc/resolv.conf', StandardRecursiveQueryCD, transport_manager=self.tm)
|
| |
+ + try:
|
| |
+ + self.resolver = Resolver.from_file('/etc/resolv.conf', StandardRecursiveQueryCD, transport_manager=self.tm)
|
| |
+ + except ResolvConfError:
|
| |
+ + self.skipTest("No resolvers found")
|
| |
+ self.helper = DomainListArgHelper(self.resolver)
|
| |
+ self.logger = logging.getLogger()
|
| |
+ for handler in self.logger.handlers:
|
| |
+ diff --git a/tests/test_dnsviz_probe_run_offline.py b/tests/test_dnsviz_probe_run_offline.py
|
| |
+ index b0705d3..068e6bf 100644
|
| |
+ --- a/tests/test_dnsviz_probe_run_offline.py
|
| |
+ +++ b/tests/test_dnsviz_probe_run_offline.py
|
| |
+ @@ -42,19 +42,27 @@ class DNSProbeRunOfflineTestCase(unittest.TestCase):
|
| |
+ os.remove(self.output.name)
|
| |
+ subprocess.check_call(['rm', '-rf', self.run_cwd])
|
| |
+
|
| |
+ + def assertReturnCode(self, retcode):
|
| |
+ + if retcode == 5:
|
| |
+ + self.skipTest("No resolvers available")
|
| |
+ + else:
|
| |
+ + self.assertEqual(retcode, 0)
|
| |
+ +
|
| |
+ +
|
| |
+ def test_dnsviz_probe_input(self):
|
| |
+ with io.open(self.output.name, 'wb') as fh_out:
|
| |
+ with gzip.open(EXAMPLE_AUTHORITATIVE) as fh_in:
|
| |
+ p = subprocess.Popen([self.dnsviz_bin, 'probe', '-d', '0', '-r', '-', 'example.com'], stdin=subprocess.PIPE, stdout=fh_out)
|
| |
+ p.communicate(fh_in.read())
|
| |
+ - self.assertEqual(p.returncode, 0)
|
| |
+ + self.assertReturnCode(p.returncode)
|
| |
+
|
| |
+ with io.open(self.output.name, 'wb') as fh:
|
| |
+ self.assertEqual(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-r', self.example_auth_out.name, 'example.com'], stdout=fh), 0)
|
| |
+
|
| |
+ def test_dnsviz_probe_names_input(self):
|
| |
+ with io.open(self.output.name, 'wb') as fh:
|
| |
+ - self.assertEqual(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-r', self.example_auth_out.name, '-f', self.names_file.name], stdout=fh), 0)
|
| |
+ + ret = subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-r', self.example_auth_out.name, '-f', self.names_file.name], stdout=fh)
|
| |
+ + self.assertReturnCode(ret)
|
| |
+
|
| |
+ with io.open(self.output.name, 'wb') as fh_out:
|
| |
+ with io.open(self.names_file.name, 'rb') as fh_in:
|
| |
+ @@ -64,7 +72,8 @@ class DNSProbeRunOfflineTestCase(unittest.TestCase):
|
| |
+
|
| |
+ def test_dnsviz_probe_output(self):
|
| |
+ with io.open(self.output.name, 'wb') as fh:
|
| |
+ - self.assertEqual(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-r', self.example_auth_out.name, 'example.com'], cwd=self.run_cwd, stdout=fh), 0)
|
| |
+ + ret = subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-r', self.example_auth_out.name, 'example.com'], cwd=self.run_cwd, stdout=fh)
|
| |
+ + self.assertReturnCode(ret)
|
| |
+
|
| |
+ with io.open(self.output.name, 'wb') as fh:
|
| |
+ self.assertEqual(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-r', self.example_auth_out.name, '-o', '-', 'example.com'], cwd=self.run_cwd, stdout=fh), 0)
|
| |
+ @@ -78,35 +87,35 @@ class DNSProbeRunOfflineTestCase(unittest.TestCase):
|
| |
+ with gzip.open(EXAMPLE_AUTHORITATIVE) as fh_in:
|
| |
+ p = subprocess.Popen([self.dnsviz_bin, 'probe', '-d', '0', '-r', '-', 'example.com'], stdin=subprocess.PIPE, stdout=fh_out)
|
| |
+ p.communicate(fh_in.read())
|
| |
+ - self.assertEqual(p.returncode, 0)
|
| |
+ + self.assertReturnCode(p.returncode)
|
| |
+
|
| |
+ with io.open(self.output.name, 'wb') as fh_out:
|
| |
+ with gzip.open(ROOT_AUTHORITATIVE) as fh_in:
|
| |
+ p = subprocess.Popen([self.dnsviz_bin, 'probe', '-d', '0', '-r', '-', '.'], stdin=subprocess.PIPE, stdout=fh_out)
|
| |
+ p.communicate(fh_in.read())
|
| |
+ - self.assertEqual(p.returncode, 0)
|
| |
+ + self.assertReturnCode(p.returncode)
|
| |
+
|
| |
+ def test_dnsviz_probe_rec(self):
|
| |
+ with io.open(self.output.name, 'wb') as fh_out:
|
| |
+ with gzip.open(EXAMPLE_RECURSIVE) as fh_in:
|
| |
+ p = subprocess.Popen([self.dnsviz_bin, 'probe', '-d', '0', '-r', '-', 'example.com'], stdin=subprocess.PIPE, stdout=fh_out)
|
| |
+ p.communicate(fh_in.read())
|
| |
+ - self.assertEqual(p.returncode, 0)
|
| |
+ + self.assertReturnCode(p.returncode)
|
| |
+
|
| |
+ with io.open(self.output.name, 'wb') as fh_out:
|
| |
+ with gzip.open(ROOT_RECURSIVE) as fh_in:
|
| |
+ p = subprocess.Popen([self.dnsviz_bin, 'probe', '-d', '0', '-r', '-', '.'], stdin=subprocess.PIPE, stdout=fh_out)
|
| |
+ p.communicate(fh_in.read())
|
| |
+ - self.assertEqual(p.returncode, 0)
|
| |
+ + self.assertReturnCode(p.returncode)
|
| |
+
|
| |
+ def test_dnsviz_probe_auth_local(self):
|
| |
+ with io.open(self.output.name, 'wb') as fh:
|
| |
+ - self.assertEqual(subprocess.call(
|
| |
+ + self.assertReturnCode(subprocess.call(
|
| |
+ [self.dnsviz_bin, 'probe', '-d', '0', '-A',
|
| |
+ '-x' 'example.com:%s' % EXAMPLE_COM_SIGNED,
|
| |
+ '-N' 'example.com:%s' % EXAMPLE_COM_DELEGATION,
|
| |
+ '-D' 'example.com:%s' % EXAMPLE_COM_DELEGATION,
|
| |
+ - 'example.com'], stdout=fh), 0)
|
| |
+ + 'example.com'], stdout=fh))
|
| |
+
|
| |
+ if __name__ == '__main__':
|
| |
+ unittest.main()
|
| |
+ diff --git a/tests/test_dnsviz_probe_run_online.py b/tests/test_dnsviz_probe_run_online.py
|
| |
+ index 8533d48..c74f5d6 100644
|
| |
+ --- a/tests/test_dnsviz_probe_run_online.py
|
| |
+ +++ b/tests/test_dnsviz_probe_run_online.py
|
| |
+ @@ -15,23 +15,29 @@ class DNSVizProbeRunOnlineTestCase(unittest.TestCase):
|
| |
+ def tearDown(self):
|
| |
+ os.remove(self.output.name)
|
| |
+
|
| |
+ + def assertReturnCode(self, retcode):
|
| |
+ + if retcode == 5:
|
| |
+ + self.skipTest("No recursive resolves found nor given")
|
| |
+ + else:
|
| |
+ + self.assertEqual(retcode, 0)
|
| |
+ +
|
| |
+ def test_dnsviz_probe_auth(self):
|
| |
+ with io.open(self.output.name, 'wb') as fh:
|
| |
+ - self.assertEqual(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-A', '.'], stdout=fh), 0)
|
| |
+ + self.assertReturnCode(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-A', '.'], stdout=fh))
|
| |
+
|
| |
+ with io.open(self.output.name, 'wb') as fh:
|
| |
+ - self.assertEqual(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-A', 'example.com'], stdout=fh), 0)
|
| |
+ + self.assertReturnCode(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-A', 'example.com'], stdout=fh))
|
| |
+
|
| |
+ def test_dnsviz_probe_rec(self):
|
| |
+ with io.open(self.output.name, 'wb') as fh:
|
| |
+ - self.assertEqual(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '.'], stdout=fh), 0)
|
| |
+ + self.assertReturnCode(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '.'], stdout=fh))
|
| |
+
|
| |
+ with io.open(self.output.name, 'wb') as fh:
|
| |
+ - self.assertEqual(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', 'example.com'], stdout=fh), 0)
|
| |
+ + self.assertReturnCode(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', 'example.com'], stdout=fh))
|
| |
+
|
| |
+ def test_dnsviz_probe_rec_multi(self):
|
| |
+ with io.open(self.output.name, 'wb') as fh:
|
| |
+ - self.assertEqual(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-t', '3', '.', 'example.com', 'example.net'], stdout=fh), 0)
|
| |
+ + self.assertReturnCode(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-t', '3', '.', 'example.com', 'example.net'], stdout=fh))
|
| |
+
|
| |
+
|
| |
+ if __name__ == '__main__':
|
| |
+ --
|
| |
+ 2.31.1
|
| |
+
|
| |
Multiple changes to be able to use %pytest macro.
It skips tests requiring working resolv.conf, which is not available during build in mock.
I found a problem with hang after tests. It does not happen on
fedpkg local
, but happens onfedpkg --release rawhide mockbuild
on my machine. It might be some threads are started but not terminated.Any ideas, what might be wrong, @cdeccio ?