- Add cloud-init-hosts-template.patch (bsc#1064594)
+ Properly expand the /etc/hosst file when manage_etc_hosts is set OBS-URL: https://build.opensuse.org/package/show/Cloud:Tools/cloud-init?expand=0&rev=92
This commit is contained in:
parent
f65f28891b
commit
6927c014db
95
cloud-init-hosts-template.patch
Normal file
95
cloud-init-hosts-template.patch
Normal file
@ -0,0 +1,95 @@
|
||||
--- templates/hosts.suse.tmpl.orig
|
||||
+++ templates/hosts.suse.tmpl
|
||||
@@ -13,12 +13,18 @@ you need to add the following to config:
|
||||
# /etc/cloud/cloud.cfg or cloud-config from user-data
|
||||
#
|
||||
# The following lines are desirable for IPv4 capable hosts
|
||||
-127.0.0.1 localhost
|
||||
+127.0.0.1 {{fqdn}} {{hostname}}
|
||||
+127.0.0.1 localhost.localdomain localhost
|
||||
+127.0.0.1 localhost4.localdomain4 localhost4
|
||||
|
||||
# The following lines are desirable for IPv6 capable hosts
|
||||
+::1 {{fqdn}} {{hostname}}
|
||||
+::1 localhost.localdomain localhost
|
||||
+::1 localhost6.localdomain6 localhost6
|
||||
::1 localhost ipv6-localhost ipv6-loopback
|
||||
-fe00::0 ipv6-localnet
|
||||
|
||||
+
|
||||
+fe00::0 ipv6-localnet
|
||||
ff00::0 ipv6-mcastprefix
|
||||
ff02::1 ipv6-allnodes
|
||||
ff02::2 ipv6-allrouters
|
||||
--- /dev/null
|
||||
+++ tests/unittests/test_handler/test_handler_etc_hosts.py
|
||||
@@ -0,0 +1,69 @@
|
||||
+# This file is part of cloud-init. See LICENSE file for license information.
|
||||
+
|
||||
+from cloudinit.config import cc_update_etc_hosts
|
||||
+
|
||||
+from cloudinit import cloud
|
||||
+from cloudinit import distros
|
||||
+from cloudinit import helpers
|
||||
+from cloudinit import util
|
||||
+
|
||||
+from cloudinit.tests import helpers as t_help
|
||||
+
|
||||
+import logging
|
||||
+import os
|
||||
+import shutil
|
||||
+
|
||||
+LOG = logging.getLogger(__name__)
|
||||
+
|
||||
+
|
||||
+class TestHostsFile(t_help.FilesystemMockingTestCase):
|
||||
+ def setUp(self):
|
||||
+ super(TestHostsFile, self).setUp()
|
||||
+ self.tmp = self.tmp_dir()
|
||||
+
|
||||
+ def _fetch_distro(self, kind):
|
||||
+ cls = distros.fetch(kind)
|
||||
+ paths = helpers.Paths({})
|
||||
+ return cls(kind, {}, paths)
|
||||
+
|
||||
+ def test_write_etc_hosts_suse_localhost(self):
|
||||
+ cfg = {
|
||||
+ 'manage_etc_hosts': 'localhost',
|
||||
+ 'hostname': 'cloud-init.test.us'
|
||||
+ }
|
||||
+ os.makedirs('%s/etc/' % self.tmp)
|
||||
+ hosts_content = '192.168.1.1 blah.blah.us blah\n'
|
||||
+ fout = open('%s/etc/hosts' % self.tmp, 'w')
|
||||
+ fout.write(hosts_content)
|
||||
+ fout.close()
|
||||
+ distro = self._fetch_distro('sles')
|
||||
+ distro.hosts_fn = '%s/etc/hosts' % self.tmp
|
||||
+ paths = helpers.Paths({})
|
||||
+ ds = None
|
||||
+ cc = cloud.Cloud(ds, paths, {}, distro, None)
|
||||
+ self.patchUtils(self.tmp)
|
||||
+ cc_update_etc_hosts.handle('test', cfg, cc, LOG, [])
|
||||
+ contents = util.load_file('%s/etc/hosts' % self.tmp)
|
||||
+ if '127.0.0.1\tcloud-init.test.us\tcloud-init' not in contents:
|
||||
+ self.assertIsNone('No entry for 127.0.0.1 in etc/hosts')
|
||||
+ if '192.168.1.1\tblah.blah.us\tblah' not in contents:
|
||||
+ self.assertIsNone('Default etc/hosts content modified')
|
||||
+
|
||||
+ def test_write_etc_hosts_suse_template(self):
|
||||
+ cfg = {
|
||||
+ 'manage_etc_hosts': 'template',
|
||||
+ 'hostname': 'cloud-init.test.us'
|
||||
+ }
|
||||
+ shutil.copytree('templates', '%s/etc/cloud/templates' % self.tmp)
|
||||
+ distro = self._fetch_distro('sles')
|
||||
+ paths = helpers.Paths({})
|
||||
+ paths.template_tpl = '%s' % self.tmp + '/etc/cloud/templates/%s.tmpl'
|
||||
+ ds = None
|
||||
+ cc = cloud.Cloud(ds, paths, {}, distro, None)
|
||||
+ self.patchUtils(self.tmp)
|
||||
+ cc_update_etc_hosts.handle('test', cfg, cc, LOG, [])
|
||||
+ contents = util.load_file('%s/etc/hosts' % self.tmp)
|
||||
+ if '127.0.0.1 cloud-init.test.us cloud-init' not in contents:
|
||||
+ self.assertIsNone('No entry for 127.0.0.1 in etc/hosts')
|
||||
+ if '::1 cloud-init.test.us cloud-init' not in contents:
|
||||
+ self.assertIsNone('No entry for 127.0.0.1 in etc/hosts')
|
@ -1,3 +1,9 @@
|
||||
-------------------------------------------------------------------
|
||||
Wed Nov 8 21:26:15 UTC 2017 - rjschwei@suse.com
|
||||
|
||||
- Add cloud-init-hosts-template.patch (bsc#1064594)
|
||||
+ Properly expand the /etc/hosst file when manage_etc_hosts is set
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Thu Nov 2 13:16:49 UTC 2017 - rjschwei@suse.com
|
||||
|
||||
|
@ -26,9 +26,11 @@ Url: http://launchpad.net/cloud-init/
|
||||
Group: System/Management
|
||||
Source0: %{name}-%{version}.tar.gz
|
||||
Source1: rsyslog-cloud-init.cfg
|
||||
# FIXME zypp_add_repos.diff needs proposed for upstream merge
|
||||
# Remove Patch 4 & 5 for next source updated, included upstream
|
||||
Patch4: zypp_add_repos.diff
|
||||
Patch5: zypp_add_repo_test.patch
|
||||
# FIXME cloud-init-hosts-template.patch proposed for upstream merge (bsc#1064594)
|
||||
Patch6: cloud-init-hosts-template.patch
|
||||
Patch10: cloud-init-no-user-lock-if-already-locked.patch
|
||||
Patch12: fix-default-systemd-unit-dir.patch
|
||||
# FIXME cloud-init-more-tasks.patch proposed for upstream merge
|
||||
@ -190,6 +192,7 @@ Documentation and examples for cloud-init tools
|
||||
%setup -q
|
||||
%patch4 -p0
|
||||
%patch5 -p0
|
||||
%patch6
|
||||
%patch10 -p1
|
||||
%patch12
|
||||
%patch13
|
||||
|
Loading…
Reference in New Issue
Block a user