Merge lp:~gandelman-a/charm-helpers/image_service_ctxt into lp:charm-helpers

Proposed by Adam Gandelman
Status: Merged
Merged at revision: 60
Proposed branch: lp:~gandelman-a/charm-helpers/image_service_ctxt
Merge into: lp:charm-helpers
Diff against target: 117 lines (+51/-9)
5 files modified
charmhelpers/contrib/openstack/context.py (+23/-0)
charmhelpers/contrib/openstack/templates/ceph.conf (+2/-2)
charmhelpers/contrib/openstack/templates/haproxy.cfg (+3/-3)
charmhelpers/contrib/openstack/templates/openstack_https_frontend (+4/-4)
tests/contrib/openstack/test_os_contexts.py (+19/-0)
To merge this branch: bzr merge lp:~gandelman-a/charm-helpers/image_service_ctxt
Reviewer Review Type Date Requested Status
Charm Helper Maintainers Pending
Review via email: mp+175965@code.launchpad.net

Description of the change

Adds another OpenStack context generator for image-service relations, to be shared across nova and cinder charms. Also updated the templates to prevent unnecessary whitespace in rendered configs.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/openstack/context.py'
2--- charmhelpers/contrib/openstack/context.py 2013-07-12 08:18:11 +0000
3+++ charmhelpers/contrib/openstack/context.py 2013-07-19 23:38:34 +0000
4@@ -206,6 +206,29 @@
5 return {}
6
7
8+class ImageServiceContext(OSContextGenerator):
9+ interfaces = ['image-servce']
10+
11+ def __call__(self):
12+ '''
13+ Obtains the glance API server from the image-service relation. Useful
14+ in nova and cinder (currently).
15+ '''
16+ log('Generating template context for image-service.')
17+ rids = relation_ids('image-service')
18+ if not rids:
19+ return {}
20+ for rid in rids:
21+ for unit in related_units(rid):
22+ api_server = relation_get('glance-api-server',
23+ rid=rid, unit=unit)
24+ if api_server:
25+ return {'glance_api_servers': api_server}
26+ log('ImageService context is incomplete. '
27+ 'Missing required relation data.')
28+ return {}
29+
30+
31 class ApacheSSLContext(OSContextGenerator):
32 """
33 Generates a context for an apache vhost configuration that configures
34
35=== modified file 'charmhelpers/contrib/openstack/templates/ceph.conf'
36--- charmhelpers/contrib/openstack/templates/ceph.conf 2013-07-04 01:37:18 +0000
37+++ charmhelpers/contrib/openstack/templates/ceph.conf 2013-07-19 23:38:34 +0000
38@@ -3,9 +3,9 @@
39 # cinder configuration file maintained by Juju
40 # local changes may be overwritten.
41 ###############################################################################
42-{% if auth %}
43+{% if auth -%}
44 [global]
45 auth_supported = {{ auth }}
46 keyring = /etc/ceph/$cluster.$name.keyring
47 mon host = {{ mon_hosts }}
48-{% endif %}
49+{% endif -%}
50
51=== modified file 'charmhelpers/contrib/openstack/templates/haproxy.cfg'
52--- charmhelpers/contrib/openstack/templates/haproxy.cfg 2013-07-04 01:37:18 +0000
53+++ charmhelpers/contrib/openstack/templates/haproxy.cfg 2013-07-19 23:38:34 +0000
54@@ -25,7 +25,7 @@
55 stats uri /
56 stats auth admin:password
57
58-{% if units %}
59+{% if units -%}
60 {% for service, ports in service_ports.iteritems() -%}
61 listen {{ service }} 0.0.0.0:{{ ports[0] }}
62 balance roundrobin
63@@ -33,5 +33,5 @@
64 {% for unit, address in units.iteritems() -%}
65 server {{ unit }} {{ address }}:{{ ports[1] }} check
66 {% endfor %}
67-{% endfor %}
68-{% endif %}
69+{% endfor -%}
70+{% endif -%}
71
72=== modified file 'charmhelpers/contrib/openstack/templates/openstack_https_frontend'
73--- charmhelpers/contrib/openstack/templates/openstack_https_frontend 2013-07-04 02:25:57 +0000
74+++ charmhelpers/contrib/openstack/templates/openstack_https_frontend 2013-07-19 23:38:34 +0000
75@@ -1,5 +1,5 @@
76-{% if endpoints %}
77-{% for ext, int in endpoints %}
78+{% if endpoints -%}
79+{% for ext, int in endpoints -%}
80 Listen {{ ext }}
81 NameVirtualHost *:{{ ext }}
82 <VirtualHost *:{{ ext }}>
83@@ -19,5 +19,5 @@
84 Order allow,deny
85 Allow from all
86 </Location>
87-{% endfor %}
88-{% endif %}
89+{% endfor -%}
90+{% endif -%}
91
92=== modified file 'tests/contrib/openstack/test_os_contexts.py'
93--- tests/contrib/openstack/test_os_contexts.py 2013-07-11 01:27:03 +0000
94+++ tests/contrib/openstack/test_os_contexts.py 2013-07-19 23:38:34 +0000
95@@ -452,3 +452,22 @@
96 # appropriate bits are b64decoded.
97 decode = [call('SSL_CERT'), call('SSL_KEY'), call('CA_CERT')]
98 self.assertEquals(decode, self.b64decode.call_args_list)
99+
100+ def test_image_service_context_missing_data(self):
101+ '''Test image-service with missing relation and missing data'''
102+ image_service = context.ImageServiceContext()
103+ self.relation_ids.return_value = []
104+ self.assertEquals({}, image_service())
105+ self.relation_ids.return_value = ['image-service:0']
106+ self.related_units.return_value = ['glance/0']
107+ self.relation_get.return_value = None
108+ self.assertEquals({}, image_service())
109+
110+ def test_image_service_context_with_data(self):
111+ '''Test image-service with required data'''
112+ image_service = context.ImageServiceContext()
113+ self.relation_ids.return_value = ['image-service:0']
114+ self.related_units.return_value = ['glance/0']
115+ self.relation_get.return_value = 'http://glancehost:9292'
116+ self.assertEquals({'glance_api_servers': 'http://glancehost:9292'},
117+ image_service())

Subscribers

People subscribed via source and target branches