Merge ~rjschwei/cloud-init:hostsTemplate into cloud-init:master

Proposed by Robert Schweikert
Status: Merged
Approved by: Scott Moser
Approved revision: ec6db50dc7c8a620654cf7f085bae62f27229b87
Merged at revision: 22a14a6a6d45ae55d2c2307d7b097eef9863bb0c
Proposed branch: ~rjschwei/cloud-init:hostsTemplate
Merge into: cloud-init:master
Diff against target: 147 lines (+79/-30)
4 files modified
cloudinit/config/cc_update_etc_hosts.py (+2/-2)
dev/null (+0/-26)
templates/hosts.suse.tmpl (+8/-2)
tests/unittests/test_handler/test_handler_etc_hosts.py (+69/-0)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Scott Moser Approve
Review via email: mp+333418@code.launchpad.net

Commit message

hosts: Fix openSUSE and SLES setup for /etc/hosts and clarify docs.

The etc/hosts file is was not properly setup for openSUSE or SLES
when manage_etc_hosts is set in the config file.

Improve the doc to address the fact that the 'localhost' ip is
distribution dependent (not always 127.0.0.1).

LP: #1731022

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:ec6db50dc7c8a620654cf7f085bae62f27229b87
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~rjschwei/cloud-init/+git/cloud-init/+merge/333418/+edit-commit-message

https://jenkins.ubuntu.com/server/job/cloud-init-ci/480/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: MAAS Compatability Testing
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/480/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:ec6db50dc7c8a620654cf7f085bae62f27229b87
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~rjschwei/cloud-init/+git/cloud-init/+merge/333418/+edit-commit-message

https://jenkins.ubuntu.com/server/job/cloud-init-ci/484/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: MAAS Compatability Testing
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/484/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Scott Moser (smoser) wrote :
review: Approve
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:ec6db50dc7c8a620654cf7f085bae62f27229b87
https://jenkins.ubuntu.com/server/job/cloud-init-ci/486/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: MAAS Compatability Testing
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/486/rebuild

review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/config/cc_update_etc_hosts.py b/cloudinit/config/cc_update_etc_hosts.py
2index b394784..c96eede 100644
3--- a/cloudinit/config/cc_update_etc_hosts.py
4+++ b/cloudinit/config/cc_update_etc_hosts.py
5@@ -23,8 +23,8 @@ using the template located in ``/etc/cloud/templates/hosts.tmpl``. In the
6
7 If ``manage_etc_hosts`` is set to ``localhost``, then cloud-init will not
8 rewrite ``/etc/hosts`` entirely, but rather will ensure that a entry for the
9-fqdn with ip ``127.0.1.1`` is present in ``/etc/hosts`` (i.e.
10-``ping <hostname>`` will ping ``127.0.1.1``).
11+fqdn with a distribution dependent ip is present in ``/etc/hosts`` (i.e.
12+``ping <hostname>`` will ping ``127.0.0.1`` or ``127.0.1.1`` or other ip).
13
14 .. note::
15 if ``manage_etc_hosts`` is set ``true`` or ``template``, the contents
16diff --git a/templates/hosts.opensuse.tmpl b/templates/hosts.opensuse.tmpl
17deleted file mode 100644
18index 655da3f..0000000
19--- a/templates/hosts.opensuse.tmpl
20+++ /dev/null
21@@ -1,26 +0,0 @@
22-*
23- This file /etc/cloud/templates/hosts.opensuse.tmpl is only utilized
24- if enabled in cloud-config. Specifically, in order to enable it
25- you need to add the following to config:
26- manage_etc_hosts: True
27-*#
28-# Your system has configured 'manage_etc_hosts' as True.
29-# As a result, if you wish for changes to this file to persist
30-# then you will need to either
31-# a.) make changes to the master file in
32-# /etc/cloud/templates/hosts.opensuse.tmpl
33-# b.) change or remove the value of 'manage_etc_hosts' in
34-# /etc/cloud/cloud.cfg or cloud-config from user-data
35-#
36-# The following lines are desirable for IPv4 capable hosts
37-127.0.0.1 localhost
38-
39-# The following lines are desirable for IPv6 capable hosts
40-::1 localhost ipv6-localhost ipv6-loopback
41-fe00::0 ipv6-localnet
42-
43-ff00::0 ipv6-mcastprefix
44-ff02::1 ipv6-allnodes
45-ff02::2 ipv6-allrouters
46-ff02::3 ipv6-allhosts
47-
48diff --git a/templates/hosts.suse.tmpl b/templates/hosts.suse.tmpl
49index b608269..8e664db 100644
50--- a/templates/hosts.suse.tmpl
51+++ b/templates/hosts.suse.tmpl
52@@ -13,12 +13,18 @@ you need to add the following to config:
53 # /etc/cloud/cloud.cfg or cloud-config from user-data
54 #
55 # The following lines are desirable for IPv4 capable hosts
56-127.0.0.1 localhost
57+127.0.0.1 {{fqdn}} {{hostname}}
58+127.0.0.1 localhost.localdomain localhost
59+127.0.0.1 localhost4.localdomain4 localhost4
60
61 # The following lines are desirable for IPv6 capable hosts
62+::1 {{fqdn}} {{hostname}}
63+::1 localhost.localdomain localhost
64+::1 localhost6.localdomain6 localhost6
65 ::1 localhost ipv6-localhost ipv6-loopback
66-fe00::0 ipv6-localnet
67
68+
69+fe00::0 ipv6-localnet
70 ff00::0 ipv6-mcastprefix
71 ff02::1 ipv6-allnodes
72 ff02::2 ipv6-allrouters
73diff --git a/tests/unittests/test_handler/test_handler_etc_hosts.py b/tests/unittests/test_handler/test_handler_etc_hosts.py
74new file mode 100644
75index 0000000..ced05a8
76--- /dev/null
77+++ b/tests/unittests/test_handler/test_handler_etc_hosts.py
78@@ -0,0 +1,69 @@
79+# This file is part of cloud-init. See LICENSE file for license information.
80+
81+from cloudinit.config import cc_update_etc_hosts
82+
83+from cloudinit import cloud
84+from cloudinit import distros
85+from cloudinit import helpers
86+from cloudinit import util
87+
88+from cloudinit.tests import helpers as t_help
89+
90+import logging
91+import os
92+import shutil
93+
94+LOG = logging.getLogger(__name__)
95+
96+
97+class TestHostsFile(t_help.FilesystemMockingTestCase):
98+ def setUp(self):
99+ super(TestHostsFile, self).setUp()
100+ self.tmp = self.tmp_dir()
101+
102+ def _fetch_distro(self, kind):
103+ cls = distros.fetch(kind)
104+ paths = helpers.Paths({})
105+ return cls(kind, {}, paths)
106+
107+ def test_write_etc_hosts_suse_localhost(self):
108+ cfg = {
109+ 'manage_etc_hosts': 'localhost',
110+ 'hostname': 'cloud-init.test.us'
111+ }
112+ os.makedirs('%s/etc/' % self.tmp)
113+ hosts_content = '192.168.1.1 blah.blah.us blah\n'
114+ fout = open('%s/etc/hosts' % self.tmp, 'w')
115+ fout.write(hosts_content)
116+ fout.close()
117+ distro = self._fetch_distro('sles')
118+ distro.hosts_fn = '%s/etc/hosts' % self.tmp
119+ paths = helpers.Paths({})
120+ ds = None
121+ cc = cloud.Cloud(ds, paths, {}, distro, None)
122+ self.patchUtils(self.tmp)
123+ cc_update_etc_hosts.handle('test', cfg, cc, LOG, [])
124+ contents = util.load_file('%s/etc/hosts' % self.tmp)
125+ if '127.0.0.1\tcloud-init.test.us\tcloud-init' not in contents:
126+ self.assertIsNone('No entry for 127.0.0.1 in etc/hosts')
127+ if '192.168.1.1\tblah.blah.us\tblah' not in contents:
128+ self.assertIsNone('Default etc/hosts content modified')
129+
130+ def test_write_etc_hosts_suse_template(self):
131+ cfg = {
132+ 'manage_etc_hosts': 'template',
133+ 'hostname': 'cloud-init.test.us'
134+ }
135+ shutil.copytree('templates', '%s/etc/cloud/templates' % self.tmp)
136+ distro = self._fetch_distro('sles')
137+ paths = helpers.Paths({})
138+ paths.template_tpl = '%s' % self.tmp + '/etc/cloud/templates/%s.tmpl'
139+ ds = None
140+ cc = cloud.Cloud(ds, paths, {}, distro, None)
141+ self.patchUtils(self.tmp)
142+ cc_update_etc_hosts.handle('test', cfg, cc, LOG, [])
143+ contents = util.load_file('%s/etc/hosts' % self.tmp)
144+ if '127.0.0.1 cloud-init.test.us cloud-init' not in contents:
145+ self.assertIsNone('No entry for 127.0.0.1 in etc/hosts')
146+ if '::1 cloud-init.test.us cloud-init' not in contents:
147+ self.assertIsNone('No entry for 127.0.0.1 in etc/hosts')

Subscribers

People subscribed via source and target branches