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
diff --git a/cloudinit/config/cc_update_etc_hosts.py b/cloudinit/config/cc_update_etc_hosts.py
index b394784..c96eede 100644
--- a/cloudinit/config/cc_update_etc_hosts.py
+++ b/cloudinit/config/cc_update_etc_hosts.py
@@ -23,8 +23,8 @@ using the template located in ``/etc/cloud/templates/hosts.tmpl``. In the
2323
24If ``manage_etc_hosts`` is set to ``localhost``, then cloud-init will not24If ``manage_etc_hosts`` is set to ``localhost``, then cloud-init will not
25rewrite ``/etc/hosts`` entirely, but rather will ensure that a entry for the25rewrite ``/etc/hosts`` entirely, but rather will ensure that a entry for the
26fqdn with ip ``127.0.1.1`` is present in ``/etc/hosts`` (i.e.26fqdn with a distribution dependent ip is present in ``/etc/hosts`` (i.e.
27``ping <hostname>`` will ping ``127.0.1.1``).27``ping <hostname>`` will ping ``127.0.0.1`` or ``127.0.1.1`` or other ip).
2828
29.. note::29.. note::
30 if ``manage_etc_hosts`` is set ``true`` or ``template``, the contents30 if ``manage_etc_hosts`` is set ``true`` or ``template``, the contents
diff --git a/templates/hosts.opensuse.tmpl b/templates/hosts.opensuse.tmpl
31deleted file mode 10064431deleted file mode 100644
index 655da3f..0000000
--- a/templates/hosts.opensuse.tmpl
+++ /dev/null
@@ -1,26 +0,0 @@
1*
2 This file /etc/cloud/templates/hosts.opensuse.tmpl is only utilized
3 if enabled in cloud-config. Specifically, in order to enable it
4 you need to add the following to config:
5 manage_etc_hosts: True
6*#
7# Your system has configured 'manage_etc_hosts' as True.
8# As a result, if you wish for changes to this file to persist
9# then you will need to either
10# a.) make changes to the master file in
11# /etc/cloud/templates/hosts.opensuse.tmpl
12# b.) change or remove the value of 'manage_etc_hosts' in
13# /etc/cloud/cloud.cfg or cloud-config from user-data
14#
15# The following lines are desirable for IPv4 capable hosts
16127.0.0.1 localhost
17
18# The following lines are desirable for IPv6 capable hosts
19::1 localhost ipv6-localhost ipv6-loopback
20fe00::0 ipv6-localnet
21
22ff00::0 ipv6-mcastprefix
23ff02::1 ipv6-allnodes
24ff02::2 ipv6-allrouters
25ff02::3 ipv6-allhosts
26
diff --git a/templates/hosts.suse.tmpl b/templates/hosts.suse.tmpl
index b608269..8e664db 100644
--- a/templates/hosts.suse.tmpl
+++ b/templates/hosts.suse.tmpl
@@ -13,12 +13,18 @@ you need to add the following to config:
13# /etc/cloud/cloud.cfg or cloud-config from user-data13# /etc/cloud/cloud.cfg or cloud-config from user-data
14#14#
15# The following lines are desirable for IPv4 capable hosts15# The following lines are desirable for IPv4 capable hosts
16127.0.0.1 localhost16127.0.0.1 {{fqdn}} {{hostname}}
17127.0.0.1 localhost.localdomain localhost
18127.0.0.1 localhost4.localdomain4 localhost4
1719
18# The following lines are desirable for IPv6 capable hosts20# The following lines are desirable for IPv6 capable hosts
21::1 {{fqdn}} {{hostname}}
22::1 localhost.localdomain localhost
23::1 localhost6.localdomain6 localhost6
19::1 localhost ipv6-localhost ipv6-loopback24::1 localhost ipv6-localhost ipv6-loopback
20fe00::0 ipv6-localnet
2125
26
27fe00::0 ipv6-localnet
22ff00::0 ipv6-mcastprefix28ff00::0 ipv6-mcastprefix
23ff02::1 ipv6-allnodes29ff02::1 ipv6-allnodes
24ff02::2 ipv6-allrouters30ff02::2 ipv6-allrouters
diff --git a/tests/unittests/test_handler/test_handler_etc_hosts.py b/tests/unittests/test_handler/test_handler_etc_hosts.py
25new file mode 10064431new file mode 100644
index 0000000..ced05a8
--- /dev/null
+++ b/tests/unittests/test_handler/test_handler_etc_hosts.py
@@ -0,0 +1,69 @@
1# This file is part of cloud-init. See LICENSE file for license information.
2
3from cloudinit.config import cc_update_etc_hosts
4
5from cloudinit import cloud
6from cloudinit import distros
7from cloudinit import helpers
8from cloudinit import util
9
10from cloudinit.tests import helpers as t_help
11
12import logging
13import os
14import shutil
15
16LOG = logging.getLogger(__name__)
17
18
19class TestHostsFile(t_help.FilesystemMockingTestCase):
20 def setUp(self):
21 super(TestHostsFile, self).setUp()
22 self.tmp = self.tmp_dir()
23
24 def _fetch_distro(self, kind):
25 cls = distros.fetch(kind)
26 paths = helpers.Paths({})
27 return cls(kind, {}, paths)
28
29 def test_write_etc_hosts_suse_localhost(self):
30 cfg = {
31 'manage_etc_hosts': 'localhost',
32 'hostname': 'cloud-init.test.us'
33 }
34 os.makedirs('%s/etc/' % self.tmp)
35 hosts_content = '192.168.1.1 blah.blah.us blah\n'
36 fout = open('%s/etc/hosts' % self.tmp, 'w')
37 fout.write(hosts_content)
38 fout.close()
39 distro = self._fetch_distro('sles')
40 distro.hosts_fn = '%s/etc/hosts' % self.tmp
41 paths = helpers.Paths({})
42 ds = None
43 cc = cloud.Cloud(ds, paths, {}, distro, None)
44 self.patchUtils(self.tmp)
45 cc_update_etc_hosts.handle('test', cfg, cc, LOG, [])
46 contents = util.load_file('%s/etc/hosts' % self.tmp)
47 if '127.0.0.1\tcloud-init.test.us\tcloud-init' not in contents:
48 self.assertIsNone('No entry for 127.0.0.1 in etc/hosts')
49 if '192.168.1.1\tblah.blah.us\tblah' not in contents:
50 self.assertIsNone('Default etc/hosts content modified')
51
52 def test_write_etc_hosts_suse_template(self):
53 cfg = {
54 'manage_etc_hosts': 'template',
55 'hostname': 'cloud-init.test.us'
56 }
57 shutil.copytree('templates', '%s/etc/cloud/templates' % self.tmp)
58 distro = self._fetch_distro('sles')
59 paths = helpers.Paths({})
60 paths.template_tpl = '%s' % self.tmp + '/etc/cloud/templates/%s.tmpl'
61 ds = None
62 cc = cloud.Cloud(ds, paths, {}, distro, None)
63 self.patchUtils(self.tmp)
64 cc_update_etc_hosts.handle('test', cfg, cc, LOG, [])
65 contents = util.load_file('%s/etc/hosts' % self.tmp)
66 if '127.0.0.1 cloud-init.test.us cloud-init' not in contents:
67 self.assertIsNone('No entry for 127.0.0.1 in etc/hosts')
68 if '::1 cloud-init.test.us cloud-init' not in contents:
69 self.assertIsNone('No entry for 127.0.0.1 in etc/hosts')

Subscribers

People subscribed via source and target branches