summaryrefslogtreecommitdiff
path: root/tests/unittests/config/test_cc_resolv_conf.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unittests/config/test_cc_resolv_conf.py')
-rw-r--r--tests/unittests/config/test_cc_resolv_conf.py76
1 files changed, 40 insertions, 36 deletions
diff --git a/tests/unittests/config/test_cc_resolv_conf.py b/tests/unittests/config/test_cc_resolv_conf.py
index ab2de17a..8896a4e8 100644
--- a/tests/unittests/config/test_cc_resolv_conf.py
+++ b/tests/unittests/config/test_cc_resolv_conf.py
@@ -4,19 +4,16 @@ import logging
import os
import shutil
import tempfile
-import pytest
from copy import deepcopy
from unittest import mock
-from cloudinit import cloud
-from cloudinit import distros
-from cloudinit import helpers
-from cloudinit import util
+import pytest
-from tests.unittests import helpers as t_help
-from tests.unittests.util import MockDistro
+from cloudinit import cloud, distros, helpers, util
from cloudinit.config import cc_resolv_conf
from cloudinit.config.cc_resolv_conf import generate_resolv_conf
+from tests.unittests import helpers as t_help
+from tests.unittests.util import MockDistro
LOG = logging.getLogger(__name__)
EXPECTED_HEADER = """\
@@ -29,17 +26,17 @@ EXPECTED_HEADER = """\
class TestResolvConf(t_help.FilesystemMockingTestCase):
with_logs = True
- cfg = {'manage_resolv_conf': True, 'resolv_conf': {}}
+ cfg = {"manage_resolv_conf": True, "resolv_conf": {}}
def setUp(self):
super(TestResolvConf, self).setUp()
self.tmp = tempfile.mkdtemp()
- util.ensure_dir(os.path.join(self.tmp, 'data'))
+ util.ensure_dir(os.path.join(self.tmp, "data"))
self.addCleanup(shutil.rmtree, self.tmp)
def _fetch_distro(self, kind, conf=None):
cls = distros.fetch(kind)
- paths = helpers.Paths({'cloud_dir': self.tmp})
+ paths = helpers.Paths({"cloud_dir": self.tmp})
conf = {} if conf is None else conf
return cls(kind, conf, paths)
@@ -47,67 +44,73 @@ class TestResolvConf(t_help.FilesystemMockingTestCase):
if not cc:
ds = None
distro = self._fetch_distro(distro_name, conf)
- paths = helpers.Paths({'cloud_dir': self.tmp})
+ paths = helpers.Paths({"cloud_dir": self.tmp})
cc = cloud.Cloud(ds, paths, {}, distro, None)
- cc_resolv_conf.handle('cc_resolv_conf', conf, cc, LOG, [])
+ cc_resolv_conf.handle("cc_resolv_conf", conf, cc, LOG, [])
@mock.patch("cloudinit.config.cc_resolv_conf.templater.render_to_file")
def test_resolv_conf_systemd_resolved(self, m_render_to_file):
- self.call_resolv_conf_handler('photon', self.cfg)
+ self.call_resolv_conf_handler("photon", self.cfg)
assert [
- mock.call(mock.ANY, '/etc/systemd/resolved.conf', mock.ANY)
+ mock.call(mock.ANY, "/etc/systemd/resolved.conf", mock.ANY)
] == m_render_to_file.call_args_list
@mock.patch("cloudinit.config.cc_resolv_conf.templater.render_to_file")
def test_resolv_conf_no_param(self, m_render_to_file):
tmp = deepcopy(self.cfg)
self.logs.truncate(0)
- tmp.pop('resolv_conf')
- self.call_resolv_conf_handler('photon', tmp)
+ tmp.pop("resolv_conf")
+ self.call_resolv_conf_handler("photon", tmp)
- self.assertIn('manage_resolv_conf True but no parameters provided',
- self.logs.getvalue())
+ self.assertIn(
+ "manage_resolv_conf True but no parameters provided",
+ self.logs.getvalue(),
+ )
assert [
- mock.call(mock.ANY, '/etc/systemd/resolved.conf', mock.ANY)
+ mock.call(mock.ANY, "/etc/systemd/resolved.conf", mock.ANY)
] not in m_render_to_file.call_args_list
@mock.patch("cloudinit.config.cc_resolv_conf.templater.render_to_file")
def test_resolv_conf_manage_resolv_conf_false(self, m_render_to_file):
tmp = deepcopy(self.cfg)
self.logs.truncate(0)
- tmp['manage_resolv_conf'] = False
- self.call_resolv_conf_handler('photon', tmp)
- self.assertIn("'manage_resolv_conf' present but set to False",
- self.logs.getvalue())
+ tmp["manage_resolv_conf"] = False
+ self.call_resolv_conf_handler("photon", tmp)
+ self.assertIn(
+ "'manage_resolv_conf' present but set to False",
+ self.logs.getvalue(),
+ )
assert [
- mock.call(mock.ANY, '/etc/systemd/resolved.conf', mock.ANY)
+ mock.call(mock.ANY, "/etc/systemd/resolved.conf", mock.ANY)
] not in m_render_to_file.call_args_list
@mock.patch("cloudinit.config.cc_resolv_conf.templater.render_to_file")
def test_resolv_conf_etc_resolv_conf(self, m_render_to_file):
- self.call_resolv_conf_handler('rhel', self.cfg)
+ self.call_resolv_conf_handler("rhel", self.cfg)
assert [
- mock.call(mock.ANY, '/etc/resolv.conf', mock.ANY)
+ mock.call(mock.ANY, "/etc/resolv.conf", mock.ANY)
] == m_render_to_file.call_args_list
@mock.patch("cloudinit.config.cc_resolv_conf.templater.render_to_file")
def test_resolv_conf_invalid_resolve_conf_fn(self, m_render_to_file):
ds = None
- distro = self._fetch_distro('rhel', self.cfg)
- paths = helpers.Paths({'cloud_dir': self.tmp})
+ distro = self._fetch_distro("rhel", self.cfg)
+ paths = helpers.Paths({"cloud_dir": self.tmp})
cc = cloud.Cloud(ds, paths, {}, distro, None)
- cc.distro.resolve_conf_fn = 'bla'
+ cc.distro.resolve_conf_fn = "bla"
self.logs.truncate(0)
- self.call_resolv_conf_handler('rhel', self.cfg, cc)
+ self.call_resolv_conf_handler("rhel", self.cfg, cc)
- self.assertIn('No template found, not rendering resolve configs',
- self.logs.getvalue())
+ self.assertIn(
+ "No template found, not rendering resolve configs",
+ self.logs.getvalue(),
+ )
assert [
- mock.call(mock.ANY, '/etc/resolv.conf', mock.ANY)
+ mock.call(mock.ANY, "/etc/resolv.conf", mock.ANY)
] not in m_render_to_file.call_args_list
@@ -119,9 +122,9 @@ class TestGenerateResolvConf:
@mock.patch("cloudinit.config.cc_resolv_conf.templater.render_to_file")
def test_dist_resolv_conf_fn(self, m_render_to_file):
self.dist.resolve_conf_fn = "/tmp/resolv-test.conf"
- generate_resolv_conf(self.tmpl_fn,
- mock.MagicMock(),
- self.dist.resolve_conf_fn)
+ generate_resolv_conf(
+ self.tmpl_fn, mock.MagicMock(), self.dist.resolve_conf_fn
+ )
assert [
mock.call(mock.ANY, self.dist.resolve_conf_fn, mock.ANY)
@@ -190,4 +193,5 @@ class TestGenerateResolvConf:
mock.call(mock.ANY, expected_content, mode=mock.ANY)
] == m_write_file.call_args_list
+
# vi: ts=4 expandtab