| Server IP : 82.148.16.210 / Your IP : 216.73.216.19 Web Server : nginx/1.29.5 System : Linux mail.sarafai.ru 6.1.0-43-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.162-1 (2026-02-08) x86_64 User : root ( 0) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /lib/cloudinit/config/tests/ |
Upload File : |
from unittest import mock
import pytest
from cloudinit.config.cc_resolv_conf import generate_resolv_conf
EXPECTED_HEADER = """\
# Your system has been configured with 'manage-resolv-conf' set to true.
# As a result, cloud-init has written this file with configuration data
# that it has been provided. Cloud-init, by default, will write this file
# a single time (PER_ONCE).
#\n\n"""
class TestGenerateResolvConf:
@mock.patch("cloudinit.config.cc_resolv_conf.templater.render_to_file")
def test_default_target_fname_is_etc_resolvconf(self, m_render_to_file):
generate_resolv_conf("templates/resolv.conf.tmpl", mock.MagicMock())
assert [
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_target_fname_is_used_if_passed(self, m_render_to_file):
generate_resolv_conf(
"templates/resolv.conf.tmpl", mock.MagicMock(), "/use/this/path"
)
assert [
mock.call(mock.ANY, "/use/this/path", mock.ANY)
] == m_render_to_file.call_args_list
# Patch in templater so we can assert on the actual generated content
@mock.patch("cloudinit.templater.util.write_file")
# Parameterise with the value to be passed to generate_resolv_conf as the
# params parameter, and the expected line after the header as
# expected_extra_line.
@pytest.mark.parametrize(
"params,expected_extra_line",
[
# No options
({}, None),
# Just a true flag
({"options": {"foo": True}}, "options foo"),
# Just a false flag
({"options": {"foo": False}}, None),
# Just an option
({"options": {"foo": "some_value"}}, "options foo:some_value"),
# A true flag and an option
(
{"options": {"foo": "some_value", "bar": True}},
"options bar foo:some_value",
),
# Two options
(
{"options": {"foo": "some_value", "bar": "other_value"}},
"options bar:other_value foo:some_value",
),
# Everything
(
{
"options": {
"foo": "some_value",
"bar": "other_value",
"baz": False,
"spam": True,
}
},
"options spam bar:other_value foo:some_value",
),
],
)
def test_flags_and_options(
self, m_write_file, params, expected_extra_line
):
generate_resolv_conf("templates/resolv.conf.tmpl", params)
expected_content = EXPECTED_HEADER
if expected_extra_line is not None:
# If we have any extra lines, expect a trailing newline
expected_content += "\n".join([expected_extra_line, ""])
assert [
mock.call(mock.ANY, expected_content, mode=mock.ANY)
] == m_write_file.call_args_list