Merge lp:~james-page/charms/trusty/glance/network-splits-https into lp:~openstack-charmers-archive/charms/trusty/glance/next

Proposed by James Page
Status: Merged
Merged at revision: 65
Proposed branch: lp:~james-page/charms/trusty/glance/network-splits-https
Merge into: lp:~openstack-charmers-archive/charms/trusty/glance/next
Diff against target: 702 lines (+194/-210)
10 files modified
hooks/charmhelpers/contrib/network/ip.py (+2/-0)
hooks/charmhelpers/contrib/openstack/amulet/deployment.py (+30/-33)
hooks/charmhelpers/contrib/openstack/context.py (+68/-32)
hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg (+15/-11)
hooks/glance_relations.py (+13/-17)
templates/openstack_https_frontend (+0/-23)
tests/charmhelpers/contrib/amulet/deployment.py (+15/-10)
tests/charmhelpers/contrib/openstack/amulet/deployment.py (+30/-33)
unit_tests/test_glance_contexts.py (+18/-26)
unit_tests/test_glance_relations.py (+3/-25)
To merge this branch: bzr merge lp:~james-page/charms/trusty/glance/network-splits-https
Reviewer Review Type Date Requested Status
Liam Young (community) Approve
Review via email: mp+236908@code.launchpad.net

Description of the change

Add support for HTTPS+HA with multiple network endpoints.

To post a comment you must log in.
75. By James Page

Resync

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

Approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/charmhelpers/contrib/network/ip.py'
2--- hooks/charmhelpers/contrib/network/ip.py 2014-09-30 12:52:17 +0000
3+++ hooks/charmhelpers/contrib/network/ip.py 2014-10-02 19:25:42 +0000
4@@ -57,6 +57,8 @@
5 else:
6 if fatal:
7 not_found_error_out()
8+ else:
9+ return None
10
11 _validate_cidr(network)
12 network = netaddr.IPNetwork(network)
13
14=== modified file 'hooks/charmhelpers/contrib/openstack/amulet/deployment.py'
15--- hooks/charmhelpers/contrib/openstack/amulet/deployment.py 2014-09-26 12:41:07 +0000
16+++ hooks/charmhelpers/contrib/openstack/amulet/deployment.py 2014-10-02 19:25:42 +0000
17@@ -1,6 +1,3 @@
18-from bzrlib.branch import Branch
19-import os
20-import re
21 from charmhelpers.contrib.amulet.deployment import (
22 AmuletDeployment
23 )
24@@ -13,62 +10,62 @@
25 that is specifically for use by OpenStack charms.
26 """
27
28- def __init__(self, series=None, openstack=None, source=None):
29+ def __init__(self, series=None, openstack=None, source=None, stable=True):
30 """Initialize the deployment environment."""
31 super(OpenStackAmuletDeployment, self).__init__(series)
32 self.openstack = openstack
33 self.source = source
34-
35- def _is_dev_branch(self):
36- """Determine if branch being tested is a dev (i.e. next) branch."""
37- branch = Branch.open(os.getcwd())
38- parent = branch.get_parent()
39- pattern = re.compile("^.*/next/$")
40- if (pattern.match(parent)):
41- return True
42- else:
43- return False
44+ self.stable = stable
45+ # Note(coreycb): this needs to be changed when new next branches come
46+ # out.
47+ self.current_next = "trusty"
48
49 def _determine_branch_locations(self, other_services):
50 """Determine the branch locations for the other services.
51
52- If the branch being tested is a dev branch, then determine the
53- development branch locations for the other services. Otherwise,
54- the default charm store branches will be used."""
55- name = 0
56- if self._is_dev_branch():
57- updated_services = []
58- for svc in other_services:
59- if svc[name] in ['mysql', 'mongodb', 'rabbitmq-server']:
60- location = 'lp:charms/{}'.format(svc[name])
61+ Determine if the local branch being tested is derived from its
62+ stable or next (dev) branch, and based on this, use the corresonding
63+ stable or next branches for the other_services."""
64+ base_charms = ['mysql', 'mongodb', 'rabbitmq-server']
65+
66+ if self.stable:
67+ for svc in other_services:
68+ temp = 'lp:charms/{}'
69+ svc['location'] = temp.format(svc['name'])
70+ else:
71+ for svc in other_services:
72+ if svc['name'] in base_charms:
73+ temp = 'lp:charms/{}'
74+ svc['location'] = temp.format(svc['name'])
75 else:
76- temp = 'lp:~openstack-charmers/charms/trusty/{}/next'
77- location = temp.format(svc[name])
78- updated_services.append(svc + (location,))
79- other_services = updated_services
80+ temp = 'lp:~openstack-charmers/charms/{}/{}/next'
81+ svc['location'] = temp.format(self.current_next,
82+ svc['name'])
83 return other_services
84
85 def _add_services(self, this_service, other_services):
86 """Add services to the deployment and set openstack-origin/source."""
87- name = 0
88 other_services = self._determine_branch_locations(other_services)
89+
90 super(OpenStackAmuletDeployment, self)._add_services(this_service,
91 other_services)
92+
93 services = other_services
94 services.append(this_service)
95- use_source = ['mysql', 'mongodb', 'rabbitmq-server', 'ceph']
96+ use_source = ['mysql', 'mongodb', 'rabbitmq-server', 'ceph',
97+ 'ceph-osd', 'ceph-radosgw']
98
99 if self.openstack:
100 for svc in services:
101- if svc[name] not in use_source:
102+ if svc['name'] not in use_source:
103 config = {'openstack-origin': self.openstack}
104- self.d.configure(svc[name], config)
105+ self.d.configure(svc['name'], config)
106
107 if self.source:
108 for svc in services:
109- if svc[name] in use_source:
110+ if svc['name'] in use_source:
111 config = {'source': self.source}
112- self.d.configure(svc[name], config)
113+ self.d.configure(svc['name'], config)
114
115 def _configure_services(self, configs):
116 """Configure all of the services."""
117
118=== modified file 'hooks/charmhelpers/contrib/openstack/context.py'
119--- hooks/charmhelpers/contrib/openstack/context.py 2014-09-26 14:49:38 +0000
120+++ hooks/charmhelpers/contrib/openstack/context.py 2014-10-02 19:25:42 +0000
121@@ -52,6 +52,7 @@
122 from charmhelpers.contrib.network.ip import (
123 get_address_in_network,
124 get_ipv6_addr,
125+ get_netmask_for_address,
126 format_ipv6_addr,
127 is_address_in_network
128 )
129@@ -408,6 +409,9 @@
130 return ctxt
131
132
133+ADDRESS_TYPES = ['admin', 'internal', 'public']
134+
135+
136 class HAProxyContext(OSContextGenerator):
137 interfaces = ['cluster']
138
139@@ -420,7 +424,6 @@
140 if not relation_ids('cluster'):
141 return {}
142
143- cluster_hosts = {}
144 l_unit = local_unit().replace('/', '-')
145
146 if config('prefer-ipv6'):
147@@ -428,17 +431,49 @@
148 else:
149 addr = unit_get('private-address')
150
151- cluster_hosts[l_unit] = get_address_in_network(config('os-internal-network'),
152- addr)
153-
154- for rid in relation_ids('cluster'):
155- for unit in related_units(rid):
156- _unit = unit.replace('/', '-')
157- addr = relation_get('private-address', rid=rid, unit=unit)
158- cluster_hosts[_unit] = addr
159+ cluster_hosts = {}
160+
161+ # NOTE(jamespage): build out map of configured network endpoints
162+ # and associated backends
163+ for addr_type in ADDRESS_TYPES:
164+ laddr = get_address_in_network(
165+ config('os-{}-network'.format(addr_type)))
166+ if laddr:
167+ cluster_hosts[laddr] = {}
168+ cluster_hosts[laddr]['network'] = "{}/{}".format(
169+ laddr,
170+ get_netmask_for_address(laddr)
171+ )
172+ cluster_hosts[laddr]['backends'] = {}
173+ cluster_hosts[laddr]['backends'][l_unit] = laddr
174+ for rid in relation_ids('cluster'):
175+ for unit in related_units(rid):
176+ _unit = unit.replace('/', '-')
177+ _laddr = relation_get('{}-address'.format(addr_type),
178+ rid=rid, unit=unit)
179+ if _laddr:
180+ cluster_hosts[laddr]['backends'][_unit] = _laddr
181+
182+ # NOTE(jamespage) no split configurations found, just use
183+ # private addresses
184+ if not cluster_hosts:
185+ cluster_hosts[addr] = {}
186+ cluster_hosts[addr]['network'] = "{}/{}".format(
187+ addr,
188+ get_netmask_for_address(addr)
189+ )
190+ cluster_hosts[addr]['backends'] = {}
191+ cluster_hosts[addr]['backends'][l_unit] = addr
192+ for rid in relation_ids('cluster'):
193+ for unit in related_units(rid):
194+ _unit = unit.replace('/', '-')
195+ _laddr = relation_get('private-address',
196+ rid=rid, unit=unit)
197+ if _laddr:
198+ cluster_hosts[addr]['backends'][_unit] = _laddr
199
200 ctxt = {
201- 'units': cluster_hosts,
202+ 'frontends': cluster_hosts,
203 }
204
205 if config('haproxy-server-timeout'):
206@@ -455,12 +490,13 @@
207 ctxt['haproxy_host'] = '0.0.0.0'
208 ctxt['stat_port'] = ':8888'
209
210- if len(cluster_hosts.keys()) > 1:
211- # Enable haproxy when we have enough peers.
212- log('Ensuring haproxy enabled in /etc/default/haproxy.')
213- with open('/etc/default/haproxy', 'w') as out:
214- out.write('ENABLED=1\n')
215- return ctxt
216+ for frontend in cluster_hosts:
217+ if len(cluster_hosts[frontend]['backends']) > 1:
218+ # Enable haproxy when we have enough peers.
219+ log('Ensuring haproxy enabled in /etc/default/haproxy.')
220+ with open('/etc/default/haproxy', 'w') as out:
221+ out.write('ENABLED=1\n')
222+ return ctxt
223 log('HAProxy context is incomplete, this unit has no peers.')
224 return {}
225
226@@ -722,22 +758,22 @@
227
228 class OSConfigFlagContext(OSContextGenerator):
229
230- """
231- Responsible for adding user-defined config-flags in charm config to a
232- template context.
233-
234- NOTE: the value of config-flags may be a comma-separated list of
235- key=value pairs and some Openstack config files support
236- comma-separated lists as values.
237- """
238-
239- def __call__(self):
240- config_flags = config('config-flags')
241- if not config_flags:
242- return {}
243-
244- flags = config_flags_parser(config_flags)
245- return {'user_config_flags': flags}
246+ """
247+ Responsible for adding user-defined config-flags in charm config to a
248+ template context.
249+
250+ NOTE: the value of config-flags may be a comma-separated list of
251+ key=value pairs and some Openstack config files support
252+ comma-separated lists as values.
253+ """
254+
255+ def __call__(self):
256+ config_flags = config('config-flags')
257+ if not config_flags:
258+ return {}
259+
260+ flags = config_flags_parser(config_flags)
261+ return {'user_config_flags': flags}
262
263
264 class SubordinateConfigContext(OSContextGenerator):
265
266=== modified file 'hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg'
267--- hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg 2014-09-26 14:49:38 +0000
268+++ hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg 2014-10-02 19:25:42 +0000
269@@ -34,17 +34,21 @@
270 stats uri /
271 stats auth admin:password
272
273-{% if units -%}
274+{% if frontends -%}
275 {% for service, ports in service_ports.iteritems() -%}
276-listen {{ service }}_ipv4 0.0.0.0:{{ ports[0] }}
277- balance roundrobin
278- {% for unit, address in units.iteritems() -%}
279- server {{ unit }} {{ address }}:{{ ports[1] }} check
280- {% endfor %}
281-listen {{ service }}_ipv6 :::{{ ports[0] }}
282- balance roundrobin
283- {% for unit, address in units.iteritems() -%}
284- server {{ unit }} {{ address }}:{{ ports[1] }} check
285- {% endfor %}
286+frontend tcp-in_{{ service }}
287+ bind *:{{ ports[0] }}
288+ bind :::{{ ports[0] }}
289+ {% for frontend in frontends -%}
290+ acl net_{{ frontend }} dst {{ frontends[frontend]['network'] }}
291+ use_backend {{ service }}_{{ frontend }} if net_{{ frontend }}
292+ {% endfor %}
293+{% for frontend in frontends -%}
294+backend {{ service }}_{{ frontend }}
295+ balance leastconn
296+ {% for unit, address in frontends[frontend]['backends'].iteritems() -%}
297+ server {{ unit }} {{ address }}:{{ ports[1] }} check
298+ {% endfor %}
299+{% endfor -%}
300 {% endfor -%}
301 {% endif -%}
302
303=== modified file 'hooks/glance_relations.py'
304--- hooks/glance_relations.py 2014-09-30 05:56:22 +0000
305+++ hooks/glance_relations.py 2014-10-02 19:25:42 +0000
306@@ -71,6 +71,8 @@
307 PUBLIC, INTERNAL, ADMIN
308 )
309
310+from charmhelpers.contrib.openstack.context import ADDRESS_TYPES
311+
312 from subprocess import (
313 check_call,
314 call, )
315@@ -188,9 +190,6 @@
316
317 @hooks.hook('image-service-relation-joined')
318 def image_service_joined(relation_id=None):
319- if not eligible_leader(CLUSTER_RES):
320- return
321-
322 relation_data = {
323 'glance-api-server':
324 "{}:9292".format(canonical_url(CONFIGS, INTERNAL))
325@@ -248,10 +247,6 @@
326
327 @hooks.hook('identity-service-relation-joined')
328 def keystone_joined(relation_id=None):
329- if not eligible_leader(CLUSTER_RES):
330- juju_log('Deferring keystone_joined() to service leader.')
331- return
332-
333 public_url = '{}:9292'.format(canonical_url(CONFIGS, PUBLIC))
334 internal_url = '{}:9292'.format(canonical_url(CONFIGS, INTERNAL))
335 admin_url = '{}:9292'.format(canonical_url(CONFIGS, ADMIN))
336@@ -311,15 +306,19 @@
337
338 @hooks.hook('cluster-relation-joined')
339 def cluster_joined(relation_id=None):
340+ for addr_type in ADDRESS_TYPES:
341+ address = get_address_in_network(
342+ config('os-{}-network'.format(addr_type))
343+ )
344+ if address:
345+ relation_set(
346+ relation_id=relation_id,
347+ relation_settings={'{}-address'.format(addr_type): address}
348+ )
349 if config('prefer-ipv6'):
350 private_addr = get_ipv6_addr(exc_list=[config('vip')])[0]
351- else:
352- private_addr = unit_get('private-address')
353-
354- address = get_address_in_network(config('os-internal-network'),
355- private_addr)
356- relation_set(relation_id=relation_id,
357- relation_settings={'private-address': address})
358+ relation_set(relation_id=relation_id,
359+ relation_settings={'private-address': private_addr})
360
361
362 @hooks.hook('cluster-relation-changed')
363@@ -397,9 +396,6 @@
364 if not clustered or clustered in [None, 'None', '']:
365 juju_log('ha_changed: hacluster subordinate is not fully clustered.')
366 return
367- if not eligible_leader(CLUSTER_RES):
368- juju_log('ha_changed: hacluster complete but we are not leader.')
369- return
370
371 # reconfigure endpoint in keystone to point to clustered VIP.
372 [keystone_joined(rid) for rid in relation_ids('identity-service')]
373
374=== removed file 'templates/openstack_https_frontend'
375--- templates/openstack_https_frontend 2013-07-05 17:35:48 +0000
376+++ templates/openstack_https_frontend 1970-01-01 00:00:00 +0000
377@@ -1,23 +0,0 @@
378-{% if endpoints %}
379-{% for ext, int in endpoints %}
380-Listen {{ ext }}
381-NameVirtualHost *:{{ ext }}
382-<VirtualHost *:{{ ext }}>
383- ServerName {{ private_address }}
384- SSLEngine on
385- SSLCertificateFile /etc/apache2/ssl/{{ namespace }}/cert
386- SSLCertificateKeyFile /etc/apache2/ssl/{{ namespace }}/key
387- ProxyPass / http://localhost:{{ int }}/
388- ProxyPassReverse / http://localhost:{{ int }}/
389- ProxyPreserveHost on
390-</VirtualHost>
391-<Proxy *>
392- Order deny,allow
393- Allow from all
394-</Proxy>
395-<Location />
396- Order allow,deny
397- Allow from all
398-</Location>
399-{% endfor %}
400-{% endif %}
401
402=== removed symlink 'templates/openstack_https_frontend.conf'
403=== target was u'openstack_https_frontend'
404=== modified file 'tests/charmhelpers/contrib/amulet/deployment.py'
405--- tests/charmhelpers/contrib/amulet/deployment.py 2014-09-26 12:41:07 +0000
406+++ tests/charmhelpers/contrib/amulet/deployment.py 2014-10-02 19:25:42 +0000
407@@ -25,25 +25,30 @@
408
409 Add services to the deployment where this_service is the local charm
410 that we're testing and other_services are the other services that
411- are being used in the amulet tests.
412+ are being used in the local amulet tests.
413 """
414- name, units, location = range(3)
415-
416- if this_service[name] != os.path.basename(os.getcwd()):
417- s = this_service[name]
418+ if this_service['name'] != os.path.basename(os.getcwd()):
419+ s = this_service['name']
420 msg = "The charm's root directory name needs to be {}".format(s)
421 amulet.raise_status(amulet.FAIL, msg=msg)
422
423- self.d.add(this_service[name], units=this_service[units])
424+ if 'units' not in this_service:
425+ this_service['units'] = 1
426+
427+ self.d.add(this_service['name'], units=this_service['units'])
428
429 for svc in other_services:
430- if len(svc) > 2:
431- branch_location = svc[location]
432+ if 'location' in svc:
433+ branch_location = svc['location']
434 elif self.series:
435- branch_location = 'cs:{}/{}'.format(self.series, svc[name]),
436+ branch_location = 'cs:{}/{}'.format(self.series, svc['name']),
437 else:
438 branch_location = None
439- self.d.add(svc[name], charm=branch_location, units=svc[units])
440+
441+ if 'units' not in svc:
442+ svc['units'] = 1
443+
444+ self.d.add(svc['name'], charm=branch_location, units=svc['units'])
445
446 def _add_relations(self, relations):
447 """Add all of the relations for the services."""
448
449=== modified file 'tests/charmhelpers/contrib/openstack/amulet/deployment.py'
450--- tests/charmhelpers/contrib/openstack/amulet/deployment.py 2014-09-26 12:41:07 +0000
451+++ tests/charmhelpers/contrib/openstack/amulet/deployment.py 2014-10-02 19:25:42 +0000
452@@ -1,6 +1,3 @@
453-from bzrlib.branch import Branch
454-import os
455-import re
456 from charmhelpers.contrib.amulet.deployment import (
457 AmuletDeployment
458 )
459@@ -13,62 +10,62 @@
460 that is specifically for use by OpenStack charms.
461 """
462
463- def __init__(self, series=None, openstack=None, source=None):
464+ def __init__(self, series=None, openstack=None, source=None, stable=True):
465 """Initialize the deployment environment."""
466 super(OpenStackAmuletDeployment, self).__init__(series)
467 self.openstack = openstack
468 self.source = source
469-
470- def _is_dev_branch(self):
471- """Determine if branch being tested is a dev (i.e. next) branch."""
472- branch = Branch.open(os.getcwd())
473- parent = branch.get_parent()
474- pattern = re.compile("^.*/next/$")
475- if (pattern.match(parent)):
476- return True
477- else:
478- return False
479+ self.stable = stable
480+ # Note(coreycb): this needs to be changed when new next branches come
481+ # out.
482+ self.current_next = "trusty"
483
484 def _determine_branch_locations(self, other_services):
485 """Determine the branch locations for the other services.
486
487- If the branch being tested is a dev branch, then determine the
488- development branch locations for the other services. Otherwise,
489- the default charm store branches will be used."""
490- name = 0
491- if self._is_dev_branch():
492- updated_services = []
493- for svc in other_services:
494- if svc[name] in ['mysql', 'mongodb', 'rabbitmq-server']:
495- location = 'lp:charms/{}'.format(svc[name])
496+ Determine if the local branch being tested is derived from its
497+ stable or next (dev) branch, and based on this, use the corresonding
498+ stable or next branches for the other_services."""
499+ base_charms = ['mysql', 'mongodb', 'rabbitmq-server']
500+
501+ if self.stable:
502+ for svc in other_services:
503+ temp = 'lp:charms/{}'
504+ svc['location'] = temp.format(svc['name'])
505+ else:
506+ for svc in other_services:
507+ if svc['name'] in base_charms:
508+ temp = 'lp:charms/{}'
509+ svc['location'] = temp.format(svc['name'])
510 else:
511- temp = 'lp:~openstack-charmers/charms/trusty/{}/next'
512- location = temp.format(svc[name])
513- updated_services.append(svc + (location,))
514- other_services = updated_services
515+ temp = 'lp:~openstack-charmers/charms/{}/{}/next'
516+ svc['location'] = temp.format(self.current_next,
517+ svc['name'])
518 return other_services
519
520 def _add_services(self, this_service, other_services):
521 """Add services to the deployment and set openstack-origin/source."""
522- name = 0
523 other_services = self._determine_branch_locations(other_services)
524+
525 super(OpenStackAmuletDeployment, self)._add_services(this_service,
526 other_services)
527+
528 services = other_services
529 services.append(this_service)
530- use_source = ['mysql', 'mongodb', 'rabbitmq-server', 'ceph']
531+ use_source = ['mysql', 'mongodb', 'rabbitmq-server', 'ceph',
532+ 'ceph-osd', 'ceph-radosgw']
533
534 if self.openstack:
535 for svc in services:
536- if svc[name] not in use_source:
537+ if svc['name'] not in use_source:
538 config = {'openstack-origin': self.openstack}
539- self.d.configure(svc[name], config)
540+ self.d.configure(svc['name'], config)
541
542 if self.source:
543 for svc in services:
544- if svc[name] in use_source:
545+ if svc['name'] in use_source:
546 config = {'source': self.source}
547- self.d.configure(svc[name], config)
548+ self.d.configure(svc['name'], config)
549
550 def _configure_services(self, configs):
551 """Configure all of the services."""
552
553=== modified file 'unit_tests/test_glance_contexts.py'
554--- unit_tests/test_glance_contexts.py 2014-09-26 12:41:07 +0000
555+++ unit_tests/test_glance_contexts.py 2014-10-02 19:25:42 +0000
556@@ -1,5 +1,5 @@
557 import glance_contexts as contexts
558-from mock import patch
559+from mock import patch, MagicMock
560
561 from test_utils import (
562 CharmTestCase
563@@ -41,25 +41,18 @@
564 {'rbd_pool': service,
565 'rbd_user': service})
566
567- mod_ch_context = 'charmhelpers.contrib.openstack.context'
568-
569- @patch('%s.ApacheSSLContext.canonical_names' % (mod_ch_context))
570- @patch('%s.ApacheSSLContext.configure_ca' % (mod_ch_context))
571- @patch('%s.config' % (mod_ch_context))
572- @patch('%s.is_clustered' % (mod_ch_context))
573- @patch('%s.determine_apache_port' % (mod_ch_context))
574- @patch('%s.determine_api_port' % (mod_ch_context))
575- @patch('%s.unit_get' % (mod_ch_context))
576- @patch('%s.https' % (mod_ch_context))
577+ @patch('charmhelpers.contrib.openstack.context.config')
578+ @patch('charmhelpers.contrib.openstack.context.is_clustered')
579+ @patch('charmhelpers.contrib.openstack.context.determine_apache_port')
580+ @patch('charmhelpers.contrib.openstack.context.determine_api_port')
581+ @patch('charmhelpers.contrib.openstack.context.unit_get')
582+ @patch('charmhelpers.contrib.openstack.context.https')
583 def test_apache_ssl_context_service_enabled(self, mock_https,
584 mock_unit_get,
585 mock_determine_api_port,
586 mock_determine_apache_port,
587 mock_is_clustered,
588- mock_hookenv,
589- mock_configure_ca,
590- mock_cfg_canonical_names):
591- mock_cfg_canonical_names.return_value = ['name.a']
592+ mock_config):
593 mock_https.return_value = True
594 mock_unit_get.return_value = '1.2.3.4'
595 mock_determine_api_port.return_value = '12'
596@@ -67,17 +60,16 @@
597 mock_is_clustered.return_value = False
598
599 ctxt = contexts.ApacheSSLContext()
600- with patch.object(ctxt, 'enable_modules') as mock_enable_modules:
601- with patch.object(ctxt, 'configure_cert') as mock_configure_cert:
602- self.assertEquals(ctxt(), {'endpoints': [('1.2.3.4',
603- '1.2.3.4',
604- 34, 12)],
605- 'ext_ports': [34],
606- 'namespace': 'glance'})
607- self.assertTrue(mock_https.called)
608- mock_unit_get.assert_called_with('private-address')
609- self.assertTrue(mock_enable_modules.called)
610- self.assertTrue(mock_configure_cert.called)
611+ ctxt.enable_modules = MagicMock()
612+ ctxt.configure_cert = MagicMock()
613+ ctxt.configure_ca = MagicMock()
614+ ctxt.canonical_names = MagicMock()
615+ self.assertEquals(ctxt(), {'endpoints': [('1.2.3.4', '1.2.3.4',
616+ 34, 12)],
617+ 'ext_ports': [34],
618+ 'namespace': 'glance'})
619+ self.assertTrue(mock_https.called)
620+ mock_unit_get.assert_called_with('private-address')
621
622 @patch('charmhelpers.contrib.openstack.context.config')
623 @patch('glance_contexts.config')
624
625=== modified file 'unit_tests/test_glance_relations.py'
626--- unit_tests/test_glance_relations.py 2014-09-30 05:56:22 +0000
627+++ unit_tests/test_glance_relations.py 2014-10-02 19:25:42 +0000
628@@ -14,6 +14,8 @@
629
630 import glance_relations as relations
631
632+relations.hooks._config_save = False
633+
634 utils.register_configs = _reg
635 utils.restart_map = _map
636
637@@ -265,13 +267,7 @@
638 )
639 self.migrate_database.assert_called_with()
640
641- def test_image_service_joined_not_leader(self):
642- self.eligible_leader.return_value = False
643- relations.image_service_joined()
644- self.assertFalse(self.relation_set.called)
645-
646 def test_image_service_joined_leader(self):
647- self.eligible_leader.return_value = True
648 self.canonical_url.return_value = 'http://glancehost'
649 relations.image_service_joined()
650 args = {
651@@ -281,7 +277,6 @@
652 self.relation_set.assert_called_with(**args)
653
654 def test_image_service_joined_specified_interface(self):
655- self.eligible_leader.return_value = True
656 self.canonical_url.return_value = 'http://glancehost'
657 relations.image_service_joined(relation_id='image-service:1')
658 args = {
659@@ -361,14 +356,7 @@
660 self.ensure_ceph_pool.assert_called_with(service=self.service_name(),
661 replicas=2)
662
663- def test_keystone_joined_not_leader(self):
664- self.ceph_config_file.return_value = '/var/lib/charm/glance/ceph.conf'
665- self.eligible_leader.return_value = False
666- relations.keystone_joined()
667- self.assertFalse(self.relation_set.called)
668-
669 def test_keystone_joined(self):
670- self.eligible_leader.return_value = True
671 self.canonical_url.return_value = 'http://glancehost'
672 relations.keystone_joined()
673 ex = {
674@@ -382,7 +370,6 @@
675 self.relation_set.assert_called_with(**ex)
676
677 def test_keystone_joined_with_relation_id(self):
678- self.eligible_leader.return_value = True
679 self.canonical_url.return_value = 'http://glancehost'
680 relations.keystone_joined(relation_id='identity-service:0')
681 ex = {
682@@ -617,19 +604,10 @@
683 configs.write.call_args_list)
684 self.assertFalse(self.juju_log.called)
685
686- @patch.object(relations, 'keystone_joined')
687- def test_ha_relation_changed_not_leader(self, joined):
688- self.relation_get.return_value = True
689- self.eligible_leader.return_value = False
690- relations.ha_relation_changed()
691- self.assertTrue(self.juju_log.called)
692- self.assertFalse(joined.called)
693-
694 @patch.object(relations, 'image_service_joined')
695 @patch.object(relations, 'keystone_joined')
696- def test_ha_relation_changed_leader(self, ks_joined, image_joined):
697+ def test_ha_relation_changed(self, ks_joined, image_joined):
698 self.relation_get.return_value = True
699- self.eligible_leader.return_value = True
700 self.relation_ids.side_effect = [['identity:0'], ['image:1']]
701 relations.ha_relation_changed()
702 ks_joined.assert_called_with('identity:0')

Subscribers

People subscribed via source and target branches