Skip to content

Commit

Permalink
net: remove the word "on instance boot" from cloud-init generated con…
Browse files Browse the repository at this point in the history
…fig (#4457)

cloud-init does not necessarily generate its configuration files upon
instance boot. If cloud-init service is disabled or if cloud-init network
configuration is disabled either using Linux kernel command line
`network-config=disabled` or by cloud-init configuration

network:
  config: disabled

,cloud-init will not generate those config files. Hence, using the word
"on instance boot" on the config file header could be misleading on those
circumstances and confuse users. Remove it.

fixes: f47d811 ("Add a sysconfig renderer")

Signed-off-by: Ani Sinha <anisinha@redhat.com>
  • Loading branch information
ani-sinha authored Sep 26, 2023
1 parent c1f6f59 commit d9cdc29
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 42 deletions.
2 changes: 1 addition & 1 deletion cloudinit/net/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

def _make_header(sep="#"):
lines = [
"Created by cloud-init on instance boot automatically, do not edit.",
"Created by cloud-init automatically, do not edit.",
"",
]
for i in range(0, len(lines)):
Expand Down
4 changes: 2 additions & 2 deletions doc/rtd/reference/network-config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ Example output:

.. code-block::
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
BOOTPROTO=static
DEVICE=eth7
Expand All @@ -306,7 +306,7 @@ Example output:
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
BOOTPROTO=dhcp
DEVICE=eth9
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/cmd/devel/test_net_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"""

SAMPLE_SYSCONFIG_CONTENT = """\
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
BOOTPROTO=dhcp
DEVICE=eth0
Expand Down
70 changes: 32 additions & 38 deletions tests/unittests/test_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@
(
"etc/sysconfig/network/ifcfg-eth0",
"""
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
BOOTPROTO=static
IPADDR=172.19.1.34
Expand All @@ -548,15 +548,15 @@
(
"etc/resolv.conf",
"""
; Created by cloud-init on instance boot automatically, do not edit.
; Created by cloud-init automatically, do not edit.
;
nameserver 172.19.0.12
""".lstrip(),
),
(
"etc/NetworkManager/conf.d/99-cloud-init.conf",
"""
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
[main]
dns = none
Expand All @@ -576,7 +576,7 @@
(
"etc/sysconfig/network-scripts/ifcfg-eth0",
"""
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
BOOTPROTO=none
DEFROUTE=yes
Expand All @@ -594,15 +594,15 @@
(
"etc/resolv.conf",
"""
; Created by cloud-init on instance boot automatically, do not edit.
; Created by cloud-init automatically, do not edit.
;
nameserver 172.19.0.12
""".lstrip(),
),
(
"etc/NetworkManager/conf.d/99-cloud-init.conf",
"""
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
[main]
dns = none
Expand Down Expand Up @@ -697,7 +697,7 @@
(
"etc/sysconfig/network/ifcfg-eth0",
"""
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
BOOTPROTO=static
IPADDR=172.19.1.34
Expand All @@ -711,15 +711,15 @@
(
"etc/resolv.conf",
"""
; Created by cloud-init on instance boot automatically, do not edit.
; Created by cloud-init automatically, do not edit.
;
nameserver 172.19.0.12
""".lstrip(),
),
(
"etc/NetworkManager/conf.d/99-cloud-init.conf",
"""
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
[main]
dns = none
Expand All @@ -739,7 +739,7 @@
(
"etc/sysconfig/network-scripts/ifcfg-eth0",
"""
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
BOOTPROTO=none
DEFROUTE=yes
Expand All @@ -759,15 +759,15 @@
(
"etc/resolv.conf",
"""
; Created by cloud-init on instance boot automatically, do not edit.
; Created by cloud-init automatically, do not edit.
;
nameserver 172.19.0.12
""".lstrip(),
),
(
"etc/NetworkManager/conf.d/99-cloud-init.conf",
"""
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
[main]
dns = none
Expand Down Expand Up @@ -854,7 +854,7 @@
(
"etc/sysconfig/network/ifcfg-eth0",
"""
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
BOOTPROTO=static
IPADDR=172.19.1.34
Expand All @@ -869,15 +869,15 @@
(
"etc/resolv.conf",
"""
; Created by cloud-init on instance boot automatically, do not edit.
; Created by cloud-init automatically, do not edit.
;
nameserver 172.19.0.12
""".lstrip(),
),
(
"etc/NetworkManager/conf.d/99-cloud-init.conf",
"""
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
[main]
dns = none
Expand All @@ -897,7 +897,7 @@
(
"etc/sysconfig/network-scripts/ifcfg-eth0",
"""
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
BOOTPROTO=none
DEFROUTE=yes
Expand All @@ -921,15 +921,15 @@
(
"etc/resolv.conf",
"""
; Created by cloud-init on instance boot automatically, do not edit.
; Created by cloud-init automatically, do not edit.
;
nameserver 172.19.0.12
""".lstrip(),
),
(
"etc/NetworkManager/conf.d/99-cloud-init.conf",
"""
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
[main]
dns = none
Expand Down Expand Up @@ -3442,7 +3442,7 @@
),
"route6-bond0": textwrap.dedent(
"""\
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
2001:67c::/32 via 2001:67c:1562::1 dev bond0
3001:67c::/32 via 3001:67c:15::1 metric 10000 dev bond0
Expand Down Expand Up @@ -4583,10 +4583,7 @@ class TestRhelSysConfigRendering(CiTestCase):
with_logs = True

scripts_dir = "/etc/sysconfig/network-scripts"
header = (
"# Created by cloud-init on instance boot automatically, "
"do not edit.\n#\n"
)
header = "# Created by cloud-init automatically, do not edit.\n#\n"

expected_name = "expected_sysconfig_rhel"

Expand Down Expand Up @@ -4682,7 +4679,7 @@ def test_default_generation(
with open(os.path.join(render_dir, render_file)) as fh:
content = fh.read()
expected_content = """
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
BOOTPROTO=dhcp
DEVICE=eth1000
Expand Down Expand Up @@ -4890,7 +4887,7 @@ def test_network_config_v1_samples(self):
nspath = "/etc/sysconfig/network-scripts/"
self.assertNotIn(nspath + "ifcfg-lo", found.keys())
expected = """\
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
BOOTPROTO=none
DEFROUTE=yes
Expand Down Expand Up @@ -4920,7 +4917,7 @@ def test_network_config_v1_multi_iface_samples(self):
nspath = "/etc/sysconfig/network-scripts/"
self.assertNotIn(nspath + "ifcfg-lo", found.keys())
expected_i1 = """\
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
BOOTPROTO=none
DEFROUTE=yes
Expand All @@ -4937,7 +4934,7 @@ def test_network_config_v1_multi_iface_samples(self):
"""
self.assertEqual(expected_i1, found[nspath + "ifcfg-eth0"])
expected_i2 = """\
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
BOOTPROTO=dhcp
DEVICE=eth1
Expand Down Expand Up @@ -4965,7 +4962,7 @@ def test_config_with_explicit_loopback(self):
nspath = "/etc/sysconfig/network-scripts/"
self.assertNotIn(nspath + "ifcfg-lo", found.keys())
expected = """\
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
BOOTPROTO=dhcp
DEVICE=eth0
Expand Down Expand Up @@ -5412,7 +5409,7 @@ def test_from_v2_routes(self):
expected = {
"ifcfg-eth0": textwrap.dedent(
"""\
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
BOOTPROTO=none
DEFROUTE=yes
Expand All @@ -5438,7 +5435,7 @@ def test_from_v2_routes(self):
),
"route-eth0": textwrap.dedent(
"""\
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
ADDRESS0=10.54.0.1
GATEWAY0=0.0.0.0
Expand All @@ -5447,7 +5444,7 @@ def test_from_v2_routes(self):
),
"route6-eth0": textwrap.dedent(
"""\
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
2a00:1730:fff9:100::1/128 via ::0 dev eth0
::0/0 via 2a00:1730:fff9:100::1 dev eth0
Expand Down Expand Up @@ -5508,10 +5505,7 @@ class TestOpenSuseSysConfigRendering(CiTestCase):
with_logs = True

scripts_dir = "/etc/sysconfig/network"
header = (
"# Created by cloud-init on instance boot automatically, "
"do not edit.\n#\n"
)
header = "# Created by cloud-init automatically, do not edit.\n#\n"

expected_name = "expected_sysconfig_opensuse"

Expand Down Expand Up @@ -5598,7 +5592,7 @@ def test_default_generation(
with open(os.path.join(render_dir, render_file)) as fh:
content = fh.read()
expected_content = """
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
BOOTPROTO=dhcp4
LLADDR=07-1c-c6-75-a4-be
Expand Down Expand Up @@ -5716,7 +5710,7 @@ def test_network_config_v1_samples(self):
nspath = "/etc/sysconfig/network/"
self.assertNotIn(nspath + "ifcfg-lo", found.keys())
expected = """\
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
BOOTPROTO=static
IPADDR=10.0.2.15
Expand Down Expand Up @@ -5744,7 +5738,7 @@ def test_config_with_explicit_loopback(self):
nspath = "/etc/sysconfig/network/"
self.assertNotIn(nspath + "ifcfg-lo", found.keys())
expected = """\
# Created by cloud-init on instance boot automatically, do not edit.
# Created by cloud-init automatically, do not edit.
#
BOOTPROTO=dhcp
STARTMODE=auto
Expand Down

0 comments on commit d9cdc29

Please sign in to comment.