Fix unit tests depending on /etc/resolv.conf

Two unit tests loaded dns-python code that reads from /etc/resolv.conf on the
test host. If there are no nameservers listed in that file, the test would fail
even though it is not needed for the test.
This patch mocks out the calls dns-python makes that read the resolver records.

Closes-bug: #2064916
Change-Id: Id1949eab3ff9d02150527725c5d305e914942fa8
This commit is contained in:
Michael Johnson 2024-05-06 22:01:10 +00:00
parent b26b3aff50
commit 71bffee11f

View File

@ -55,6 +55,9 @@ class MdnsHandleTest(oslotest.base.BaseTestCase):
self.assertIsInstance(self.handler.worker_api,
worker_rpcapi.WorkerAPI)
@mock.patch.object(dns.resolver.BaseResolver, "read_registry", mock.Mock())
@mock.patch.object(dns.resolver.BaseResolver, "read_resolv_conf",
mock.Mock())
@mock.patch.object(rpc, 'get_client', mock.Mock())
@mock.patch.object(dns.resolver.Resolver, 'resolve')
def test_notify(self, mock_query):
@ -84,6 +87,9 @@ class MdnsHandleTest(oslotest.base.BaseTestCase):
self.stdlog.logger.output
)
@mock.patch.object(dns.resolver.BaseResolver, "read_registry", mock.Mock())
@mock.patch.object(dns.resolver.BaseResolver, "read_resolv_conf",
mock.Mock())
@mock.patch.object(dns.resolver.Resolver, 'resolve')
def test_notify_same_serial(self, mock_query):
self.storage.find_zone.return_value = objects.Zone(