Merge lp:~openstack-charmers/charms/trusty/nova-cloud-controller/fix-multi-vips into lp:~openstack-charmers-archive/charms/trusty/nova-cloud-controller/next

Proposed by Edward Hope-Morley
Status: Superseded
Proposed branch: lp:~openstack-charmers/charms/trusty/nova-cloud-controller/fix-multi-vips
Merge into: lp:~openstack-charmers-archive/charms/trusty/nova-cloud-controller/next
Diff against target: 177 lines (+83/-25)
2 files modified
hooks/nova_cc_context.py (+25/-22)
unit_tests/test_nova_cc_contexts.py (+58/-3)
To merge this branch: bzr merge lp:~openstack-charmers/charms/trusty/nova-cloud-controller/fix-multi-vips
Reviewer Review Type Date Requested Status
Ante Karamatić (community) Needs Fixing
OpenStack Charmers Pending
Review via email: mp+246926@code.launchpad.net

This proposal has been superseded by a proposal from 2015-01-20.

To post a comment you must log in.
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #854 nova-cloud-controller-next for hopem mp246926
    LINT OK: passed

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

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

charm_unit_test #883 nova-cloud-controller-next for hopem mp246926
    UNIT OK: passed

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

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

charm_amulet_test #1078 nova-cloud-controller-next for hopem mp246926
    AMULET OK: passed

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

Revision history for this message
Ante Karamatić (ivoks) :
review: Needs Fixing
Revision history for this message
Edward Hope-Morley (hopem) :
139. By Edward Hope-Morley

removed neutron api version, added more unit tests

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/nova_cc_context.py'
2--- hooks/nova_cc_context.py 2014-12-19 10:25:03 +0000
3+++ hooks/nova_cc_context.py 2015-01-20 09:33:04 +0000
4@@ -4,7 +4,6 @@
5 relation_set,
6 log,
7 ERROR,
8- unit_get,
9 related_units,
10 relations_for_id,
11 relation_get,
12@@ -22,10 +21,9 @@
13 determine_apache_port,
14 determine_api_port,
15 https,
16- is_clustered,
17 )
18 from charmhelpers.contrib.network.ip import (
19- get_ipv6_addr,
20+ is_ipv6,
21 format_ipv6_addr,
22 )
23 from charmhelpers.contrib.openstack.ip import (
24@@ -196,30 +194,32 @@
25 return ctxt
26
27
28-def canonical_url(vip_setting='vip'):
29- '''
30- Returns the correct HTTP URL to this host given the state of HTTPS
31+def canonical_url():
32+ """Returns the correct HTTP URL to this host given the state of HTTPS
33 configuration and hacluster.
34-
35- :vip_setting: str: Setting in charm config that specifies
36- VIP address.
37- '''
38+ """
39 scheme = 'http'
40 if https():
41 scheme = 'https'
42
43- if config('prefer-ipv6'):
44- if is_clustered():
45- addr = '[%s]' % config(vip_setting)
46- else:
47- addr = '[%s]' % get_ipv6_addr(exc_list=[config('vip')])[0]
48- else:
49- if is_clustered():
50- addr = config(vip_setting)
51- else:
52- addr = unit_get('private-address')
53-
54- return '%s://%s' % (scheme, addr)
55+ address = resolve_address(INTERNAL)
56+ if is_ipv6(address):
57+ address = "[{}]".format(address)
58+
59+ return '%s://%s' % (scheme, address)
60+
61+
62+def use_local_neutron_api():
63+ """If no neutron-api relation exists returns True.
64+
65+ If no neutron-api relation exists we assume that we are going to use
66+ legacy-mode i.e. local neutron server.
67+ """
68+ for rid in relation_ids('neutron-api'):
69+ for unit in related_units(rid):
70+ return False
71+
72+ return True
73
74
75 class NeutronCCContext(context.NeutronContext):
76@@ -258,7 +258,10 @@
77 ','.join(_config['nvp-controllers'].split())
78 ctxt['nvp_controllers_list'] = \
79 _config['nvp-controllers'].split()
80+
81 ctxt['nova_url'] = "{}:8774/v2".format(canonical_url())
82+ if use_local_neutron_api():
83+ ctxt['neutron_url'] = "{}:9696".format(canonical_url())
84
85 return ctxt
86
87
88=== modified file 'unit_tests/test_nova_cc_contexts.py'
89--- unit_tests/test_nova_cc_contexts.py 2014-12-16 14:08:58 +0000
90+++ unit_tests/test_nova_cc_contexts.py 2015-01-20 09:33:04 +0000
91@@ -30,8 +30,8 @@
92 'related_units',
93 'config',
94 'log',
95- 'unit_get',
96 'relations_for_id',
97+ 'https',
98 ]
99
100
101@@ -50,7 +50,6 @@
102 @mock.patch.object(utils, 'os_release')
103 @mock.patch('charmhelpers.contrib.network.ip.log')
104 def test_instance_console_context_without_memcache(self, os_release, log_):
105- self.unit_get.return_value = '127.0.0.1'
106 self.relation_ids.return_value = 'cache:0'
107 self.related_units.return_value = 'memcached/0'
108 instance_console = context.InstanceConsoleContext()
109@@ -76,7 +75,6 @@
110 formated_ip):
111 memcached_servers = [{'private-address': formated_ip,
112 'port': '11211'}]
113- self.unit_get.return_value = ip
114 self.relation_ids.return_value = ['cache:0']
115 self.relations_for_id.return_value = memcached_servers
116 self.related_units.return_value = 'memcached/0'
117@@ -85,3 +83,60 @@
118 self.maxDiff = None
119 self.assertEqual({'memcached_servers': "%s:11211" % (formated_ip, )},
120 instance_console())
121+
122+ @mock.patch.object(context, 'use_local_neutron_api')
123+ @mock.patch('charmhelpers.contrib.openstack.ip.config')
124+ @mock.patch('charmhelpers.contrib.openstack.ip.is_clustered')
125+ def test_neutron_context_single_vip(self, mock_is_clustered, mock_config,
126+ mock_use_local_neutron_api):
127+ mock_use_local_neutron_api.return_value = True
128+ self.https.return_value = False
129+ mock_is_clustered.return_value = True
130+ config = {'vip': '10.0.0.1',
131+ 'os-internal-network': '10.0.0.1/24',
132+ 'os-admin-network': '10.0.1.0/24',
133+ 'os-public-network': '10.0.2.0/24'}
134+ mock_config.side_effect = lambda key: config[key]
135+
136+ mock_use_local_neutron_api.return_value = False
137+ ctxt = context.NeutronCCContext()()
138+ self.assertEqual(ctxt['nova_url'], 'http://10.0.0.1:8774/v2')
139+ self.assertFalse('neutron_url' in ctxt)
140+
141+ mock_use_local_neutron_api.return_value = True
142+ ctxt = context.NeutronCCContext()()
143+ self.assertEqual(ctxt['nova_url'], 'http://10.0.0.1:8774/v2')
144+ self.assertEqual(ctxt['neutron_url'], 'http://10.0.0.1:9696')
145+
146+ @mock.patch.object(context, 'use_local_neutron_api')
147+ @mock.patch('charmhelpers.contrib.openstack.ip.config')
148+ @mock.patch('charmhelpers.contrib.openstack.ip.is_clustered')
149+ def test_neutron_context_multi_vip(self, mock_is_clustered, mock_config,
150+ mock_use_local_neutron_api):
151+ self.https.return_value = False
152+ mock_is_clustered.return_value = True
153+ config = {'vip': '10.0.0.1 10.0.1.1 10.0.2.1',
154+ 'os-internal-network': '10.0.1.0/24',
155+ 'os-admin-network': '10.0.0.0/24',
156+ 'os-public-network': '10.0.2.0/24'}
157+ mock_config.side_effect = lambda key: config[key]
158+
159+ mock_use_local_neutron_api.return_value = False
160+ ctxt = context.NeutronCCContext()()
161+ self.assertEqual(ctxt['nova_url'], 'http://10.0.1.1:8774/v2')
162+ self.assertFalse('neutron_url' in ctxt)
163+
164+ mock_use_local_neutron_api.return_value = True
165+ ctxt = context.NeutronCCContext()()
166+ self.assertEqual(ctxt['nova_url'], 'http://10.0.1.1:8774/v2')
167+ self.assertEqual(ctxt['neutron_url'], 'http://10.0.1.1:9696')
168+
169+ def test_use_local_neutron_api(self):
170+ self.relation_ids.return_value = []
171+ self.related_units.return_value = []
172+ self.assertTrue(context.use_local_neutron_api())
173+ self.relation_ids.return_value = ['rel:0']
174+ self.related_units.return_value = []
175+ self.assertTrue(context.use_local_neutron_api())
176+ self.related_units.return_value = ['unit/0']
177+ self.assertFalse(context.use_local_neutron_api())

Subscribers

People subscribed via source and target branches