Merge lp:~jjo/charms/trusty/neutron-gateway/add-hostname-resolution-to-etc_hosts-lp1489598 into lp:~openstack-charmers-archive/charms/trusty/neutron-gateway/next

Proposed by JuanJo Ciarlante
Status: Rejected
Rejected by: James Page
Proposed branch: lp:~jjo/charms/trusty/neutron-gateway/add-hostname-resolution-to-etc_hosts-lp1489598
Merge into: lp:~openstack-charmers-archive/charms/trusty/neutron-gateway/next
Diff against target: 129 lines (+55/-0)
3 files modified
hooks/neutron_hooks.py (+2/-0)
hooks/neutron_utils.py (+50/-0)
unit_tests/test_neutron_hooks.py (+3/-0)
To merge this branch: bzr merge lp:~jjo/charms/trusty/neutron-gateway/add-hostname-resolution-to-etc_hosts-lp1489598
Reviewer Review Type Date Requested Status
Liam Young (community) Disapprove
Review via email: mp+269551@code.launchpad.net
To post a comment you must log in.
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #8940 neutron-gateway-next for jjo mp269551
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/8940/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #8260 neutron-gateway-next for jjo mp269551
    UNIT FAIL: unit-test failed

UNIT Results (max last 2 lines):
make: *** [test] Error 1
ERROR:root:Make target returned non-zero.

Full unit test output: http://paste.ubuntu.com/12217794/
Build: http://10.245.162.77:8080/job/charm_unit_test/8260/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #8941 neutron-gateway-next for jjo mp269551
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/8941/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #8261 neutron-gateway-next for jjo mp269551
    UNIT FAIL: unit-test failed

UNIT Results (max last 2 lines):
make: *** [test] Error 1
ERROR:root:Make target returned non-zero.

Full unit test output: http://paste.ubuntu.com/12218049/
Build: http://10.245.162.77:8080/job/charm_unit_test/8261/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_amulet_test #6084 neutron-gateway-next for jjo mp269551
    AMULET FAIL: amulet-test failed

AMULET Results (max last 2 lines):
make: *** [functional_test] Error 124
ERROR:root:Make target returned non-zero.

Full amulet test output: http://paste.ubuntu.com/12218226/
Build: http://10.245.162.77:8080/job/charm_amulet_test/6084/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #8942 neutron-gateway-next for jjo mp269551
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/8942/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #8262 neutron-gateway-next for jjo mp269551
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/8262/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_amulet_test #6086 neutron-gateway-next for jjo mp269551
    AMULET FAIL: amulet-test failed

AMULET Results (max last 2 lines):
make: *** [functional_test] Error 124
ERROR:root:Make target returned non-zero.

Full amulet test output: http://paste.ubuntu.com/12218513/
Build: http://10.245.162.77:8080/job/charm_amulet_test/6086/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_amulet_test #6085 neutron-gateway-next for jjo mp269551
    AMULET OK: passed

Build: http://10.245.162.77:8080/job/charm_amulet_test/6085/

136. By JuanJo Ciarlante

[jjo] update /etc/hosts with own unit's hostname, fixes lp#1489598

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #9040 neutron-gateway-next for jjo mp269551
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/9040/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #8353 neutron-gateway-next for jjo mp269551
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/8353/

Revision history for this message
Liam Young (gnuoy) wrote :

I'd rather not try and manage the host file in the charm. I'm inclined to agree with https://bugs.launchpad.net/charms/+source/neutron-gateway/+bug/1489598/comments/2 and this should be fixed elsewhere

review: Disapprove

Unmerged revisions

136. By JuanJo Ciarlante

[jjo] update /etc/hosts with own unit's hostname, fixes lp#1489598

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/neutron_hooks.py'
2--- hooks/neutron_hooks.py 2015-05-07 09:27:07 +0000
3+++ hooks/neutron_hooks.py 2015-08-30 01:44:37 +0000
4@@ -64,6 +64,7 @@
5 reassign_agent_resources,
6 stop_neutron_ha_monitor_daemon,
7 use_l3ha,
8+ update_etc_hosts,
9 )
10
11 hooks = Hooks()
12@@ -107,6 +108,7 @@
13 do_openstack_upgrade()
14 CONFIGS.write_all()
15
16+ update_etc_hosts()
17 update_nrpe_config()
18
19 sysctl_dict = config('sysctl')
20
21=== modified file 'hooks/neutron_utils.py'
22--- hooks/neutron_utils.py 2015-07-09 11:02:45 +0000
23+++ hooks/neutron_utils.py 2015-08-30 01:44:37 +0000
24@@ -1,6 +1,8 @@
25 import os
26 import shutil
27 import subprocess
28+import tempfile
29+import socket
30 from shutil import copy2
31 from charmhelpers.core.host import (
32 adduser,
33@@ -23,6 +25,7 @@
34 relations_of_type,
35 unit_private_ip,
36 is_relation_made,
37+ unit_get,
38 )
39 from charmhelpers.core.templating import render
40 from charmhelpers.fetch import (
41@@ -220,6 +223,7 @@
42 'quantum-metadata-agent',
43 'quantum-plugin-openvswitch-agent',
44 ]
45+HOSTS_FILE = '/etc/hosts'
46
47
48 def get_early_packages():
49@@ -279,6 +283,52 @@
50 def use_l3ha():
51 return NeutronAPIContext()()['enable_l3ha']
52
53+
54+def update_etc_hosts():
55+ hostname = socket.gethostname()
56+ addr = unit_get('private-address')
57+ hosts_map = {addr: hostname}
58+ # only need to add myself to /etc/hosts
59+ update_hosts_file(hosts_map)
60+
61+
62+def update_hosts_file(map):
63+ """neutron-gateway needs own hostname resolution to work properly,
64+ see https://bugs.launchpad.net/charms/+source/neutron-gateway/+bug/1489598
65+ """
66+ with open(HOSTS_FILE, 'r') as hosts:
67+ lines = hosts.readlines()
68+
69+ log("Updating %s with: %s (current: %s)" % (HOSTS_FILE, map, lines),
70+ level=DEBUG)
71+
72+ newlines = []
73+ for ip, hostname in map.items():
74+ if not ip or not hostname:
75+ continue
76+
77+ keepers = []
78+ for line in lines:
79+ _line = line.split()
80+ if len(line) < 2 or not (_line[0] == ip or hostname in _line[1:]):
81+ keepers.append(line)
82+ else:
83+ log("Marking line '%s' for update or removal" % (line.strip()),
84+ level=DEBUG)
85+
86+ lines = keepers
87+ newlines.append("%s %s\n" % (ip, hostname))
88+
89+ lines += newlines
90+
91+ with tempfile.NamedTemporaryFile(delete=False) as tmpfile:
92+ with open(tmpfile.name, 'w') as hosts:
93+ for line in lines:
94+ hosts.write(line)
95+
96+ os.rename(tmpfile.name, HOSTS_FILE)
97+ os.chmod(HOSTS_FILE, 0o644)
98+
99 EXT_PORT_CONF = '/etc/init/ext-port.conf'
100 PHY_NIC_MTU_CONF = '/etc/init/os-charm-phy-nic-mtu.conf'
101 TEMPLATES = 'templates'
102
103=== modified file 'unit_tests/test_neutron_hooks.py'
104--- unit_tests/test_neutron_hooks.py 2015-07-09 11:02:45 +0000
105+++ unit_tests/test_neutron_hooks.py 2015-08-30 01:44:37 +0000
106@@ -51,6 +51,7 @@
107 'cleanup_ovs_netns',
108 'stop_neutron_ha_monitor_daemon',
109 'use_l3ha',
110+ 'update_etc_hosts',
111 ]
112
113
114@@ -157,6 +158,7 @@
115 self._call_hook('config-changed')
116 self.assertTrue(self.do_openstack_upgrade.called)
117 self.assertTrue(self.configure_ovs.called)
118+ self.assertTrue(self.update_etc_hosts.called)
119 self.assertTrue(_db_joined.called)
120 self.assertTrue(_pgsql_db_joined.called)
121 self.assertTrue(_amqp_joined.called)
122@@ -172,6 +174,7 @@
123 self._call_hook('config-changed')
124 self.assertTrue(self.do_openstack_upgrade.called)
125 self.assertTrue(self.configure_ovs.called)
126+ self.assertTrue(self.update_etc_hosts.called)
127
128 @patch.object(hooks, 'git_install_requested')
129 def test_config_changed_n1kv(self, git_requested):

Subscribers

People subscribed via source and target branches