Merge lp:~corey.bryant/charms/trusty/keystone/contrib.python.packages into lp:~openstack-charmers-archive/charms/trusty/keystone/next
- Trusty Tahr (14.04)
- contrib.python.packages
- Merge into next
Status: | Merged |
---|---|
Merged at revision: | 90 |
Proposed branch: | lp:~corey.bryant/charms/trusty/keystone/contrib.python.packages |
Merge into: | lp:~openstack-charmers-archive/charms/trusty/keystone/next |
Diff against target: |
3346 lines (+899/-536) 33 files modified
charm-helpers-hooks.yaml (+1/-0) hooks/charmhelpers/__init__.py (+22/-0) hooks/charmhelpers/contrib/hahelpers/cluster.py (+16/-7) hooks/charmhelpers/contrib/network/ip.py (+52/-48) hooks/charmhelpers/contrib/openstack/amulet/deployment.py (+2/-1) hooks/charmhelpers/contrib/openstack/amulet/utils.py (+3/-1) hooks/charmhelpers/contrib/openstack/context.py (+217/-219) hooks/charmhelpers/contrib/openstack/ip.py (+41/-27) hooks/charmhelpers/contrib/openstack/neutron.py (+4/-3) hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg (+2/-2) hooks/charmhelpers/contrib/openstack/templating.py (+5/-5) hooks/charmhelpers/contrib/openstack/utils.py (+122/-13) hooks/charmhelpers/contrib/peerstorage/__init__.py (+4/-3) hooks/charmhelpers/contrib/python/packages.py (+77/-0) hooks/charmhelpers/contrib/storage/linux/ceph.py (+83/-97) hooks/charmhelpers/contrib/storage/linux/loopback.py (+4/-4) hooks/charmhelpers/contrib/storage/linux/lvm.py (+1/-0) hooks/charmhelpers/contrib/storage/linux/utils.py (+3/-2) hooks/charmhelpers/contrib/unison/__init__.py (+21/-14) hooks/charmhelpers/core/fstab.py (+10/-8) hooks/charmhelpers/core/hookenv.py (+36/-16) hooks/charmhelpers/core/host.py (+43/-18) hooks/charmhelpers/core/services/helpers.py (+9/-5) hooks/charmhelpers/core/templating.py (+2/-1) hooks/charmhelpers/fetch/__init__.py (+13/-11) hooks/charmhelpers/fetch/archiveurl.py (+53/-16) hooks/charmhelpers/fetch/bzrurl.py (+5/-1) hooks/charmhelpers/fetch/giturl.py (+12/-5) tests/charmhelpers/__init__.py (+22/-0) tests/charmhelpers/contrib/amulet/deployment.py (+3/-3) tests/charmhelpers/contrib/amulet/utils.py (+6/-4) tests/charmhelpers/contrib/openstack/amulet/deployment.py (+2/-1) tests/charmhelpers/contrib/openstack/amulet/utils.py (+3/-1) |
To merge this branch: | bzr merge lp:~corey.bryant/charms/trusty/keystone/contrib.python.packages |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
OpenStack Charmers | Pending | ||
Review via email: mp+244323@code.launchpad.net |
Commit message
Description of the change
uosci-testing-bot (uosci-testing-bot) wrote : | # |
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #126 keystone-next for corey.bryant mp244323
UNIT FAIL: unit-test failed
UNIT Results (max last 2 lines):
FAILED (errors=3)
make: *** [unit_test] Error 1
Full unit test output: pastebin not avail., cmd error
Build: http://
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #76 keystone-next for corey.bryant mp244323
AMULET FAIL: amulet-test failed
AMULET Results (max last 2 lines):
ERROR subprocess encountered error code 2
make: *** [test] Error 2
Full amulet test output: pastebin not avail., cmd error
Build: http://
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #185 keystone-next for corey.bryant mp244323
LINT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #148 keystone-next for corey.bryant mp244323
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #103 keystone-next for corey.bryant mp244323
AMULET FAIL: amulet-test failed
AMULET Results (max last 2 lines):
ERROR subprocess encountered error code 1
make: *** [test] Error 1
Full amulet test output: pastebin not avail., cmd error
Build: http://
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #209 keystone-next for corey.bryant mp244323
LINT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #172 keystone-next for corey.bryant mp244323
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #127 keystone-next for corey.bryant mp244323
AMULET FAIL: amulet-test failed
AMULET Results (max last 2 lines):
ERROR subprocess encountered error code 1
make: *** [test] Error 1
Full amulet test output: pastebin not avail., cmd error
Build: http://
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #227 keystone-next for corey.bryant mp244323
LINT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #190 keystone-next for corey.bryant mp244323
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #144 keystone-next for corey.bryant mp244323
AMULET FAIL: amulet-test failed
AMULET Results (max last 2 lines):
ERROR subprocess encountered error code 1
make: *** [test] Error 1
Full amulet test output: pastebin not avail., cmd error
Build: http://
Preview Diff
1 | === modified file 'charm-helpers-hooks.yaml' | |||
2 | --- charm-helpers-hooks.yaml 2014-10-27 02:20:30 +0000 | |||
3 | +++ charm-helpers-hooks.yaml 2014-12-11 17:56:34 +0000 | |||
4 | @@ -12,3 +12,4 @@ | |||
5 | 12 | - payload.execd | 12 | - payload.execd |
6 | 13 | - contrib.peerstorage | 13 | - contrib.peerstorage |
7 | 14 | - contrib.network.ip | 14 | - contrib.network.ip |
8 | 15 | - contrib.python.packages | ||
9 | 15 | 16 | ||
10 | === added file 'hooks/charmhelpers/__init__.py' | |||
11 | --- hooks/charmhelpers/__init__.py 1970-01-01 00:00:00 +0000 | |||
12 | +++ hooks/charmhelpers/__init__.py 2014-12-11 17:56:34 +0000 | |||
13 | @@ -0,0 +1,22 @@ | |||
14 | 1 | # Bootstrap charm-helpers, installing its dependencies if necessary using | ||
15 | 2 | # only standard libraries. | ||
16 | 3 | import subprocess | ||
17 | 4 | import sys | ||
18 | 5 | |||
19 | 6 | try: | ||
20 | 7 | import six # flake8: noqa | ||
21 | 8 | except ImportError: | ||
22 | 9 | if sys.version_info.major == 2: | ||
23 | 10 | subprocess.check_call(['apt-get', 'install', '-y', 'python-six']) | ||
24 | 11 | else: | ||
25 | 12 | subprocess.check_call(['apt-get', 'install', '-y', 'python3-six']) | ||
26 | 13 | import six # flake8: noqa | ||
27 | 14 | |||
28 | 15 | try: | ||
29 | 16 | import yaml # flake8: noqa | ||
30 | 17 | except ImportError: | ||
31 | 18 | if sys.version_info.major == 2: | ||
32 | 19 | subprocess.check_call(['apt-get', 'install', '-y', 'python-yaml']) | ||
33 | 20 | else: | ||
34 | 21 | subprocess.check_call(['apt-get', 'install', '-y', 'python3-yaml']) | ||
35 | 22 | import yaml # flake8: noqa | ||
36 | 0 | 23 | ||
37 | === removed file 'hooks/charmhelpers/__init__.py' | |||
38 | === modified file 'hooks/charmhelpers/contrib/hahelpers/cluster.py' | |||
39 | --- hooks/charmhelpers/contrib/hahelpers/cluster.py 2014-10-06 20:51:06 +0000 | |||
40 | +++ hooks/charmhelpers/contrib/hahelpers/cluster.py 2014-12-11 17:56:34 +0000 | |||
41 | @@ -13,9 +13,10 @@ | |||
42 | 13 | 13 | ||
43 | 14 | import subprocess | 14 | import subprocess |
44 | 15 | import os | 15 | import os |
45 | 16 | |||
46 | 17 | from socket import gethostname as get_unit_hostname | 16 | from socket import gethostname as get_unit_hostname |
47 | 18 | 17 | ||
48 | 18 | import six | ||
49 | 19 | |||
50 | 19 | from charmhelpers.core.hookenv import ( | 20 | from charmhelpers.core.hookenv import ( |
51 | 20 | log, | 21 | log, |
52 | 21 | relation_ids, | 22 | relation_ids, |
53 | @@ -77,7 +78,7 @@ | |||
54 | 77 | "show", resource | 78 | "show", resource |
55 | 78 | ] | 79 | ] |
56 | 79 | try: | 80 | try: |
58 | 80 | status = subprocess.check_output(cmd) | 81 | status = subprocess.check_output(cmd).decode('UTF-8') |
59 | 81 | except subprocess.CalledProcessError: | 82 | except subprocess.CalledProcessError: |
60 | 82 | return False | 83 | return False |
61 | 83 | else: | 84 | else: |
62 | @@ -150,34 +151,42 @@ | |||
63 | 150 | return False | 151 | return False |
64 | 151 | 152 | ||
65 | 152 | 153 | ||
67 | 153 | def determine_api_port(public_port): | 154 | def determine_api_port(public_port, singlenode_mode=False): |
68 | 154 | ''' | 155 | ''' |
69 | 155 | Determine correct API server listening port based on | 156 | Determine correct API server listening port based on |
70 | 156 | existence of HTTPS reverse proxy and/or haproxy. | 157 | existence of HTTPS reverse proxy and/or haproxy. |
71 | 157 | 158 | ||
72 | 158 | public_port: int: standard public port for given service | 159 | public_port: int: standard public port for given service |
73 | 159 | 160 | ||
74 | 161 | singlenode_mode: boolean: Shuffle ports when only a single unit is present | ||
75 | 162 | |||
76 | 160 | returns: int: the correct listening port for the API service | 163 | returns: int: the correct listening port for the API service |
77 | 161 | ''' | 164 | ''' |
78 | 162 | i = 0 | 165 | i = 0 |
80 | 163 | if len(peer_units()) > 0 or is_clustered(): | 166 | if singlenode_mode: |
81 | 167 | i += 1 | ||
82 | 168 | elif len(peer_units()) > 0 or is_clustered(): | ||
83 | 164 | i += 1 | 169 | i += 1 |
84 | 165 | if https(): | 170 | if https(): |
85 | 166 | i += 1 | 171 | i += 1 |
86 | 167 | return public_port - (i * 10) | 172 | return public_port - (i * 10) |
87 | 168 | 173 | ||
88 | 169 | 174 | ||
90 | 170 | def determine_apache_port(public_port): | 175 | def determine_apache_port(public_port, singlenode_mode=False): |
91 | 171 | ''' | 176 | ''' |
92 | 172 | Description: Determine correct apache listening port based on public IP + | 177 | Description: Determine correct apache listening port based on public IP + |
93 | 173 | state of the cluster. | 178 | state of the cluster. |
94 | 174 | 179 | ||
95 | 175 | public_port: int: standard public port for given service | 180 | public_port: int: standard public port for given service |
96 | 176 | 181 | ||
97 | 182 | singlenode_mode: boolean: Shuffle ports when only a single unit is present | ||
98 | 183 | |||
99 | 177 | returns: int: the correct listening port for the HAProxy service | 184 | returns: int: the correct listening port for the HAProxy service |
100 | 178 | ''' | 185 | ''' |
101 | 179 | i = 0 | 186 | i = 0 |
103 | 180 | if len(peer_units()) > 0 or is_clustered(): | 187 | if singlenode_mode: |
104 | 188 | i += 1 | ||
105 | 189 | elif len(peer_units()) > 0 or is_clustered(): | ||
106 | 181 | i += 1 | 190 | i += 1 |
107 | 182 | return public_port - (i * 10) | 191 | return public_port - (i * 10) |
108 | 183 | 192 | ||
109 | @@ -197,7 +206,7 @@ | |||
110 | 197 | for setting in settings: | 206 | for setting in settings: |
111 | 198 | conf[setting] = config_get(setting) | 207 | conf[setting] = config_get(setting) |
112 | 199 | missing = [] | 208 | missing = [] |
114 | 200 | [missing.append(s) for s, v in conf.iteritems() if v is None] | 209 | [missing.append(s) for s, v in six.iteritems(conf) if v is None] |
115 | 201 | if missing: | 210 | if missing: |
116 | 202 | log('Insufficient config data to configure hacluster.', level=ERROR) | 211 | log('Insufficient config data to configure hacluster.', level=ERROR) |
117 | 203 | raise HAIncompleteConfig | 212 | raise HAIncompleteConfig |
118 | 204 | 213 | ||
119 | === modified file 'hooks/charmhelpers/contrib/network/ip.py' | |||
120 | --- hooks/charmhelpers/contrib/network/ip.py 2014-10-27 02:14:51 +0000 | |||
121 | +++ hooks/charmhelpers/contrib/network/ip.py 2014-12-11 17:56:34 +0000 | |||
122 | @@ -1,14 +1,12 @@ | |||
123 | 1 | import glob | 1 | import glob |
124 | 2 | import re | 2 | import re |
125 | 3 | import subprocess | 3 | import subprocess |
126 | 4 | import sys | ||
127 | 5 | 4 | ||
128 | 6 | from functools import partial | 5 | from functools import partial |
129 | 7 | 6 | ||
130 | 8 | from charmhelpers.core.hookenv import unit_get | 7 | from charmhelpers.core.hookenv import unit_get |
131 | 9 | from charmhelpers.fetch import apt_install | 8 | from charmhelpers.fetch import apt_install |
132 | 10 | from charmhelpers.core.hookenv import ( | 9 | from charmhelpers.core.hookenv import ( |
133 | 11 | ERROR, | ||
134 | 12 | log | 10 | log |
135 | 13 | ) | 11 | ) |
136 | 14 | 12 | ||
137 | @@ -33,31 +31,28 @@ | |||
138 | 33 | network) | 31 | network) |
139 | 34 | 32 | ||
140 | 35 | 33 | ||
141 | 34 | def no_ip_found_error_out(network): | ||
142 | 35 | errmsg = ("No IP address found in network: %s" % network) | ||
143 | 36 | raise ValueError(errmsg) | ||
144 | 37 | |||
145 | 38 | |||
146 | 36 | def get_address_in_network(network, fallback=None, fatal=False): | 39 | def get_address_in_network(network, fallback=None, fatal=False): |
149 | 37 | """ | 40 | """Get an IPv4 or IPv6 address within the network from the host. |
148 | 38 | Get an IPv4 or IPv6 address within the network from the host. | ||
150 | 39 | 41 | ||
151 | 40 | :param network (str): CIDR presentation format. For example, | 42 | :param network (str): CIDR presentation format. For example, |
152 | 41 | '192.168.1.0/24'. | 43 | '192.168.1.0/24'. |
153 | 42 | :param fallback (str): If no address is found, return fallback. | 44 | :param fallback (str): If no address is found, return fallback. |
154 | 43 | :param fatal (boolean): If no address is found, fallback is not | 45 | :param fatal (boolean): If no address is found, fallback is not |
155 | 44 | set and fatal is True then exit(1). | 46 | set and fatal is True then exit(1). |
156 | 45 | |||
157 | 46 | """ | 47 | """ |
158 | 47 | |||
159 | 48 | def not_found_error_out(): | ||
160 | 49 | log("No IP address found in network: %s" % network, | ||
161 | 50 | level=ERROR) | ||
162 | 51 | sys.exit(1) | ||
163 | 52 | |||
164 | 53 | if network is None: | 48 | if network is None: |
165 | 54 | if fallback is not None: | 49 | if fallback is not None: |
166 | 55 | return fallback | 50 | return fallback |
167 | 51 | |||
168 | 52 | if fatal: | ||
169 | 53 | no_ip_found_error_out(network) | ||
170 | 56 | else: | 54 | else: |
175 | 57 | if fatal: | 55 | return None |
172 | 58 | not_found_error_out() | ||
173 | 59 | else: | ||
174 | 60 | return None | ||
176 | 61 | 56 | ||
177 | 62 | _validate_cidr(network) | 57 | _validate_cidr(network) |
178 | 63 | network = netaddr.IPNetwork(network) | 58 | network = netaddr.IPNetwork(network) |
179 | @@ -69,6 +64,7 @@ | |||
180 | 69 | cidr = netaddr.IPNetwork("%s/%s" % (addr, netmask)) | 64 | cidr = netaddr.IPNetwork("%s/%s" % (addr, netmask)) |
181 | 70 | if cidr in network: | 65 | if cidr in network: |
182 | 71 | return str(cidr.ip) | 66 | return str(cidr.ip) |
183 | 67 | |||
184 | 72 | if network.version == 6 and netifaces.AF_INET6 in addresses: | 68 | if network.version == 6 and netifaces.AF_INET6 in addresses: |
185 | 73 | for addr in addresses[netifaces.AF_INET6]: | 69 | for addr in addresses[netifaces.AF_INET6]: |
186 | 74 | if not addr['addr'].startswith('fe80'): | 70 | if not addr['addr'].startswith('fe80'): |
187 | @@ -81,20 +77,20 @@ | |||
188 | 81 | return fallback | 77 | return fallback |
189 | 82 | 78 | ||
190 | 83 | if fatal: | 79 | if fatal: |
192 | 84 | not_found_error_out() | 80 | no_ip_found_error_out(network) |
193 | 85 | 81 | ||
194 | 86 | return None | 82 | return None |
195 | 87 | 83 | ||
196 | 88 | 84 | ||
197 | 89 | def is_ipv6(address): | 85 | def is_ipv6(address): |
199 | 90 | '''Determine whether provided address is IPv6 or not''' | 86 | """Determine whether provided address is IPv6 or not.""" |
200 | 91 | try: | 87 | try: |
201 | 92 | address = netaddr.IPAddress(address) | 88 | address = netaddr.IPAddress(address) |
202 | 93 | except netaddr.AddrFormatError: | 89 | except netaddr.AddrFormatError: |
203 | 94 | # probably a hostname - so not an address at all! | 90 | # probably a hostname - so not an address at all! |
204 | 95 | return False | 91 | return False |
207 | 96 | else: | 92 | |
208 | 97 | return address.version == 6 | 93 | return address.version == 6 |
209 | 98 | 94 | ||
210 | 99 | 95 | ||
211 | 100 | def is_address_in_network(network, address): | 96 | def is_address_in_network(network, address): |
212 | @@ -112,11 +108,13 @@ | |||
213 | 112 | except (netaddr.core.AddrFormatError, ValueError): | 108 | except (netaddr.core.AddrFormatError, ValueError): |
214 | 113 | raise ValueError("Network (%s) is not in CIDR presentation format" % | 109 | raise ValueError("Network (%s) is not in CIDR presentation format" % |
215 | 114 | network) | 110 | network) |
216 | 111 | |||
217 | 115 | try: | 112 | try: |
218 | 116 | address = netaddr.IPAddress(address) | 113 | address = netaddr.IPAddress(address) |
219 | 117 | except (netaddr.core.AddrFormatError, ValueError): | 114 | except (netaddr.core.AddrFormatError, ValueError): |
220 | 118 | raise ValueError("Address (%s) is not in correct presentation format" % | 115 | raise ValueError("Address (%s) is not in correct presentation format" % |
221 | 119 | address) | 116 | address) |
222 | 117 | |||
223 | 120 | if address in network: | 118 | if address in network: |
224 | 121 | return True | 119 | return True |
225 | 122 | else: | 120 | else: |
226 | @@ -146,6 +144,7 @@ | |||
227 | 146 | return iface | 144 | return iface |
228 | 147 | else: | 145 | else: |
229 | 148 | return addresses[netifaces.AF_INET][0][key] | 146 | return addresses[netifaces.AF_INET][0][key] |
230 | 147 | |||
231 | 149 | if address.version == 6 and netifaces.AF_INET6 in addresses: | 148 | if address.version == 6 and netifaces.AF_INET6 in addresses: |
232 | 150 | for addr in addresses[netifaces.AF_INET6]: | 149 | for addr in addresses[netifaces.AF_INET6]: |
233 | 151 | if not addr['addr'].startswith('fe80'): | 150 | if not addr['addr'].startswith('fe80'): |
234 | @@ -159,40 +158,42 @@ | |||
235 | 159 | return str(cidr).split('/')[1] | 158 | return str(cidr).split('/')[1] |
236 | 160 | else: | 159 | else: |
237 | 161 | return addr[key] | 160 | return addr[key] |
238 | 161 | |||
239 | 162 | return None | 162 | return None |
240 | 163 | 163 | ||
241 | 164 | 164 | ||
242 | 165 | get_iface_for_address = partial(_get_for_address, key='iface') | 165 | get_iface_for_address = partial(_get_for_address, key='iface') |
243 | 166 | 166 | ||
244 | 167 | |||
245 | 167 | get_netmask_for_address = partial(_get_for_address, key='netmask') | 168 | get_netmask_for_address = partial(_get_for_address, key='netmask') |
246 | 168 | 169 | ||
247 | 169 | 170 | ||
248 | 170 | def format_ipv6_addr(address): | 171 | def format_ipv6_addr(address): |
251 | 171 | """ | 172 | """If address is IPv6, wrap it in '[]' otherwise return None. |
252 | 172 | IPv6 needs to be wrapped with [] in url link to parse correctly. | 173 | |
253 | 174 | This is required by most configuration files when specifying IPv6 | ||
254 | 175 | addresses. | ||
255 | 173 | """ | 176 | """ |
256 | 174 | if is_ipv6(address): | 177 | if is_ipv6(address): |
260 | 175 | address = "[%s]" % address | 178 | return "[%s]" % address |
258 | 176 | else: | ||
259 | 177 | address = None | ||
261 | 178 | 179 | ||
263 | 179 | return address | 180 | return None |
264 | 180 | 181 | ||
265 | 181 | 182 | ||
266 | 182 | def get_iface_addr(iface='eth0', inet_type='AF_INET', inc_aliases=False, | 183 | def get_iface_addr(iface='eth0', inet_type='AF_INET', inc_aliases=False, |
267 | 183 | fatal=True, exc_list=None): | 184 | fatal=True, exc_list=None): |
271 | 184 | """ | 185 | """Return the assigned IP address for a given interface, if any.""" |
269 | 185 | Return the assigned IP address for a given interface, if any, or []. | ||
270 | 186 | """ | ||
272 | 187 | # Extract nic if passed /dev/ethX | 186 | # Extract nic if passed /dev/ethX |
273 | 188 | if '/' in iface: | 187 | if '/' in iface: |
274 | 189 | iface = iface.split('/')[-1] | 188 | iface = iface.split('/')[-1] |
275 | 189 | |||
276 | 190 | if not exc_list: | 190 | if not exc_list: |
277 | 191 | exc_list = [] | 191 | exc_list = [] |
278 | 192 | |||
279 | 192 | try: | 193 | try: |
280 | 193 | inet_num = getattr(netifaces, inet_type) | 194 | inet_num = getattr(netifaces, inet_type) |
281 | 194 | except AttributeError: | 195 | except AttributeError: |
283 | 195 | raise Exception('Unknown inet type ' + str(inet_type)) | 196 | raise Exception("Unknown inet type '%s'" % str(inet_type)) |
284 | 196 | 197 | ||
285 | 197 | interfaces = netifaces.interfaces() | 198 | interfaces = netifaces.interfaces() |
286 | 198 | if inc_aliases: | 199 | if inc_aliases: |
287 | @@ -200,15 +201,18 @@ | |||
288 | 200 | for _iface in interfaces: | 201 | for _iface in interfaces: |
289 | 201 | if iface == _iface or _iface.split(':')[0] == iface: | 202 | if iface == _iface or _iface.split(':')[0] == iface: |
290 | 202 | ifaces.append(_iface) | 203 | ifaces.append(_iface) |
291 | 204 | |||
292 | 203 | if fatal and not ifaces: | 205 | if fatal and not ifaces: |
293 | 204 | raise Exception("Invalid interface '%s'" % iface) | 206 | raise Exception("Invalid interface '%s'" % iface) |
294 | 207 | |||
295 | 205 | ifaces.sort() | 208 | ifaces.sort() |
296 | 206 | else: | 209 | else: |
297 | 207 | if iface not in interfaces: | 210 | if iface not in interfaces: |
298 | 208 | if fatal: | 211 | if fatal: |
300 | 209 | raise Exception("%s not found " % (iface)) | 212 | raise Exception("Interface '%s' not found " % (iface)) |
301 | 210 | else: | 213 | else: |
302 | 211 | return [] | 214 | return [] |
303 | 215 | |||
304 | 212 | else: | 216 | else: |
305 | 213 | ifaces = [iface] | 217 | ifaces = [iface] |
306 | 214 | 218 | ||
307 | @@ -219,10 +223,13 @@ | |||
308 | 219 | for entry in net_info[inet_num]: | 223 | for entry in net_info[inet_num]: |
309 | 220 | if 'addr' in entry and entry['addr'] not in exc_list: | 224 | if 'addr' in entry and entry['addr'] not in exc_list: |
310 | 221 | addresses.append(entry['addr']) | 225 | addresses.append(entry['addr']) |
311 | 226 | |||
312 | 222 | if fatal and not addresses: | 227 | if fatal and not addresses: |
313 | 223 | raise Exception("Interface '%s' doesn't have any %s addresses." % | 228 | raise Exception("Interface '%s' doesn't have any %s addresses." % |
314 | 224 | (iface, inet_type)) | 229 | (iface, inet_type)) |
316 | 225 | return addresses | 230 | |
317 | 231 | return sorted(addresses) | ||
318 | 232 | |||
319 | 226 | 233 | ||
320 | 227 | get_ipv4_addr = partial(get_iface_addr, inet_type='AF_INET') | 234 | get_ipv4_addr = partial(get_iface_addr, inet_type='AF_INET') |
321 | 228 | 235 | ||
322 | @@ -239,6 +246,7 @@ | |||
323 | 239 | raw = re.match(ll_key, _addr) | 246 | raw = re.match(ll_key, _addr) |
324 | 240 | if raw: | 247 | if raw: |
325 | 241 | _addr = raw.group(1) | 248 | _addr = raw.group(1) |
326 | 249 | |||
327 | 242 | if _addr == addr: | 250 | if _addr == addr: |
328 | 243 | log("Address '%s' is configured on iface '%s'" % | 251 | log("Address '%s' is configured on iface '%s'" % |
329 | 244 | (addr, iface)) | 252 | (addr, iface)) |
330 | @@ -249,8 +257,9 @@ | |||
331 | 249 | 257 | ||
332 | 250 | 258 | ||
333 | 251 | def sniff_iface(f): | 259 | def sniff_iface(f): |
336 | 252 | """If no iface provided, inject net iface inferred from unit private | 260 | """Ensure decorated function is called with a value for iface. |
337 | 253 | address. | 261 | |
338 | 262 | If no iface provided, inject net iface inferred from unit private address. | ||
339 | 254 | """ | 263 | """ |
340 | 255 | def iface_sniffer(*args, **kwargs): | 264 | def iface_sniffer(*args, **kwargs): |
341 | 256 | if not kwargs.get('iface', None): | 265 | if not kwargs.get('iface', None): |
342 | @@ -293,7 +302,7 @@ | |||
343 | 293 | if global_addrs: | 302 | if global_addrs: |
344 | 294 | # Make sure any found global addresses are not temporary | 303 | # Make sure any found global addresses are not temporary |
345 | 295 | cmd = ['ip', 'addr', 'show', iface] | 304 | cmd = ['ip', 'addr', 'show', iface] |
347 | 296 | out = subprocess.check_output(cmd) | 305 | out = subprocess.check_output(cmd).decode('UTF-8') |
348 | 297 | if dynamic_only: | 306 | if dynamic_only: |
349 | 298 | key = re.compile("inet6 (.+)/[0-9]+ scope global dynamic.*") | 307 | key = re.compile("inet6 (.+)/[0-9]+ scope global dynamic.*") |
350 | 299 | else: | 308 | else: |
351 | @@ -315,33 +324,28 @@ | |||
352 | 315 | return addrs | 324 | return addrs |
353 | 316 | 325 | ||
354 | 317 | if fatal: | 326 | if fatal: |
356 | 318 | raise Exception("Interface '%s' doesn't have a scope global " | 327 | raise Exception("Interface '%s' does not have a scope global " |
357 | 319 | "non-temporary ipv6 address." % iface) | 328 | "non-temporary ipv6 address." % iface) |
358 | 320 | 329 | ||
359 | 321 | return [] | 330 | return [] |
360 | 322 | 331 | ||
361 | 323 | 332 | ||
362 | 324 | def get_bridges(vnic_dir='/sys/devices/virtual/net'): | 333 | def get_bridges(vnic_dir='/sys/devices/virtual/net'): |
368 | 325 | """ | 334 | """Return a list of bridges on the system.""" |
369 | 326 | Return a list of bridges on the system or [] | 335 | b_regex = "%s/*/bridge" % vnic_dir |
370 | 327 | """ | 336 | return [x.replace(vnic_dir, '').split('/')[1] for x in glob.glob(b_regex)] |
366 | 328 | b_rgex = vnic_dir + '/*/bridge' | ||
367 | 329 | return [x.replace(vnic_dir, '').split('/')[1] for x in glob.glob(b_rgex)] | ||
371 | 330 | 337 | ||
372 | 331 | 338 | ||
373 | 332 | def get_bridge_nics(bridge, vnic_dir='/sys/devices/virtual/net'): | 339 | def get_bridge_nics(bridge, vnic_dir='/sys/devices/virtual/net'): |
379 | 333 | """ | 340 | """Return a list of nics comprising a given bridge on the system.""" |
380 | 334 | Return a list of nics comprising a given bridge on the system or [] | 341 | brif_regex = "%s/%s/brif/*" % (vnic_dir, bridge) |
381 | 335 | """ | 342 | return [x.split('/')[-1] for x in glob.glob(brif_regex)] |
377 | 336 | brif_rgex = "%s/%s/brif/*" % (vnic_dir, bridge) | ||
378 | 337 | return [x.split('/')[-1] for x in glob.glob(brif_rgex)] | ||
382 | 338 | 343 | ||
383 | 339 | 344 | ||
384 | 340 | def is_bridge_member(nic): | 345 | def is_bridge_member(nic): |
388 | 341 | """ | 346 | """Check if a given nic is a member of a bridge.""" |
386 | 342 | Check if a given nic is a member of a bridge | ||
387 | 343 | """ | ||
389 | 344 | for bridge in get_bridges(): | 347 | for bridge in get_bridges(): |
390 | 345 | if nic in get_bridge_nics(bridge): | 348 | if nic in get_bridge_nics(bridge): |
391 | 346 | return True | 349 | return True |
392 | 350 | |||
393 | 347 | return False | 351 | return False |
394 | 348 | 352 | ||
395 | === modified file 'hooks/charmhelpers/contrib/openstack/amulet/deployment.py' | |||
396 | --- hooks/charmhelpers/contrib/openstack/amulet/deployment.py 2014-10-06 20:51:06 +0000 | |||
397 | +++ hooks/charmhelpers/contrib/openstack/amulet/deployment.py 2014-12-11 17:56:34 +0000 | |||
398 | @@ -1,3 +1,4 @@ | |||
399 | 1 | import six | ||
400 | 1 | from charmhelpers.contrib.amulet.deployment import ( | 2 | from charmhelpers.contrib.amulet.deployment import ( |
401 | 2 | AmuletDeployment | 3 | AmuletDeployment |
402 | 3 | ) | 4 | ) |
403 | @@ -69,7 +70,7 @@ | |||
404 | 69 | 70 | ||
405 | 70 | def _configure_services(self, configs): | 71 | def _configure_services(self, configs): |
406 | 71 | """Configure all of the services.""" | 72 | """Configure all of the services.""" |
408 | 72 | for service, config in configs.iteritems(): | 73 | for service, config in six.iteritems(configs): |
409 | 73 | self.d.configure(service, config) | 74 | self.d.configure(service, config) |
410 | 74 | 75 | ||
411 | 75 | def _get_openstack_release(self): | 76 | def _get_openstack_release(self): |
412 | 76 | 77 | ||
413 | === modified file 'hooks/charmhelpers/contrib/openstack/amulet/utils.py' | |||
414 | --- hooks/charmhelpers/contrib/openstack/amulet/utils.py 2014-10-06 20:51:06 +0000 | |||
415 | +++ hooks/charmhelpers/contrib/openstack/amulet/utils.py 2014-12-11 17:56:34 +0000 | |||
416 | @@ -7,6 +7,8 @@ | |||
417 | 7 | import keystoneclient.v2_0 as keystone_client | 7 | import keystoneclient.v2_0 as keystone_client |
418 | 8 | import novaclient.v1_1.client as nova_client | 8 | import novaclient.v1_1.client as nova_client |
419 | 9 | 9 | ||
420 | 10 | import six | ||
421 | 11 | |||
422 | 10 | from charmhelpers.contrib.amulet.utils import ( | 12 | from charmhelpers.contrib.amulet.utils import ( |
423 | 11 | AmuletUtils | 13 | AmuletUtils |
424 | 12 | ) | 14 | ) |
425 | @@ -60,7 +62,7 @@ | |||
426 | 60 | expected service catalog endpoints. | 62 | expected service catalog endpoints. |
427 | 61 | """ | 63 | """ |
428 | 62 | self.log.debug('actual: {}'.format(repr(actual))) | 64 | self.log.debug('actual: {}'.format(repr(actual))) |
430 | 63 | for k, v in expected.iteritems(): | 65 | for k, v in six.iteritems(expected): |
431 | 64 | if k in actual: | 66 | if k in actual: |
432 | 65 | ret = self._validate_dict_data(expected[k][0], actual[k][0]) | 67 | ret = self._validate_dict_data(expected[k][0], actual[k][0]) |
433 | 66 | if ret: | 68 | if ret: |
434 | 67 | 69 | ||
435 | === modified file 'hooks/charmhelpers/contrib/openstack/context.py' | |||
436 | --- hooks/charmhelpers/contrib/openstack/context.py 2014-11-14 02:16:38 +0000 | |||
437 | +++ hooks/charmhelpers/contrib/openstack/context.py 2014-12-11 17:56:34 +0000 | |||
438 | @@ -1,18 +1,15 @@ | |||
439 | 1 | import json | 1 | import json |
440 | 2 | import os | 2 | import os |
441 | 3 | import time | 3 | import time |
442 | 4 | |||
443 | 5 | from base64 import b64decode | 4 | from base64 import b64decode |
444 | 5 | from subprocess import check_call | ||
445 | 6 | 6 | ||
449 | 7 | from subprocess import ( | 7 | import six |
447 | 8 | check_call | ||
448 | 9 | ) | ||
450 | 10 | 8 | ||
451 | 11 | from charmhelpers.fetch import ( | 9 | from charmhelpers.fetch import ( |
452 | 12 | apt_install, | 10 | apt_install, |
453 | 13 | filter_installed_packages, | 11 | filter_installed_packages, |
454 | 14 | ) | 12 | ) |
455 | 15 | |||
456 | 16 | from charmhelpers.core.hookenv import ( | 13 | from charmhelpers.core.hookenv import ( |
457 | 17 | config, | 14 | config, |
458 | 18 | is_relation_made, | 15 | is_relation_made, |
459 | @@ -24,44 +21,40 @@ | |||
460 | 24 | relation_set, | 21 | relation_set, |
461 | 25 | unit_get, | 22 | unit_get, |
462 | 26 | unit_private_ip, | 23 | unit_private_ip, |
463 | 24 | DEBUG, | ||
464 | 25 | INFO, | ||
465 | 26 | WARNING, | ||
466 | 27 | ERROR, | 27 | ERROR, |
467 | 28 | DEBUG | ||
468 | 29 | ) | 28 | ) |
469 | 30 | |||
470 | 31 | from charmhelpers.core.host import ( | 29 | from charmhelpers.core.host import ( |
471 | 32 | mkdir, | 30 | mkdir, |
473 | 33 | write_file | 31 | write_file, |
474 | 34 | ) | 32 | ) |
475 | 35 | |||
476 | 36 | from charmhelpers.contrib.hahelpers.cluster import ( | 33 | from charmhelpers.contrib.hahelpers.cluster import ( |
477 | 37 | determine_apache_port, | 34 | determine_apache_port, |
478 | 38 | determine_api_port, | 35 | determine_api_port, |
479 | 39 | https, | 36 | https, |
481 | 40 | is_clustered | 37 | is_clustered, |
482 | 41 | ) | 38 | ) |
483 | 42 | |||
484 | 43 | from charmhelpers.contrib.hahelpers.apache import ( | 39 | from charmhelpers.contrib.hahelpers.apache import ( |
485 | 44 | get_cert, | 40 | get_cert, |
486 | 45 | get_ca_cert, | 41 | get_ca_cert, |
487 | 46 | install_ca_cert, | 42 | install_ca_cert, |
488 | 47 | ) | 43 | ) |
489 | 48 | |||
490 | 49 | from charmhelpers.contrib.openstack.neutron import ( | 44 | from charmhelpers.contrib.openstack.neutron import ( |
491 | 50 | neutron_plugin_attribute, | 45 | neutron_plugin_attribute, |
492 | 51 | ) | 46 | ) |
493 | 52 | |||
494 | 53 | from charmhelpers.contrib.network.ip import ( | 47 | from charmhelpers.contrib.network.ip import ( |
495 | 54 | get_address_in_network, | 48 | get_address_in_network, |
496 | 55 | get_ipv6_addr, | 49 | get_ipv6_addr, |
497 | 56 | get_netmask_for_address, | 50 | get_netmask_for_address, |
498 | 57 | format_ipv6_addr, | 51 | format_ipv6_addr, |
500 | 58 | is_address_in_network | 52 | is_address_in_network, |
501 | 59 | ) | 53 | ) |
502 | 54 | from charmhelpers.contrib.openstack.utils import get_host_ip | ||
503 | 60 | 55 | ||
504 | 61 | from charmhelpers.contrib.openstack.utils import ( | ||
505 | 62 | get_host_ip, | ||
506 | 63 | ) | ||
507 | 64 | CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt' | 56 | CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt' |
508 | 57 | ADDRESS_TYPES = ['admin', 'internal', 'public'] | ||
509 | 65 | 58 | ||
510 | 66 | 59 | ||
511 | 67 | class OSContextError(Exception): | 60 | class OSContextError(Exception): |
512 | @@ -69,7 +62,7 @@ | |||
513 | 69 | 62 | ||
514 | 70 | 63 | ||
515 | 71 | def ensure_packages(packages): | 64 | def ensure_packages(packages): |
517 | 72 | '''Install but do not upgrade required plugin packages''' | 65 | """Install but do not upgrade required plugin packages.""" |
518 | 73 | required = filter_installed_packages(packages) | 66 | required = filter_installed_packages(packages) |
519 | 74 | if required: | 67 | if required: |
520 | 75 | apt_install(required, fatal=True) | 68 | apt_install(required, fatal=True) |
521 | @@ -77,20 +70,27 @@ | |||
522 | 77 | 70 | ||
523 | 78 | def context_complete(ctxt): | 71 | def context_complete(ctxt): |
524 | 79 | _missing = [] | 72 | _missing = [] |
526 | 80 | for k, v in ctxt.iteritems(): | 73 | for k, v in six.iteritems(ctxt): |
527 | 81 | if v is None or v == '': | 74 | if v is None or v == '': |
528 | 82 | _missing.append(k) | 75 | _missing.append(k) |
529 | 76 | |||
530 | 83 | if _missing: | 77 | if _missing: |
532 | 84 | log('Missing required data: %s' % ' '.join(_missing), level='INFO') | 78 | log('Missing required data: %s' % ' '.join(_missing), level=INFO) |
533 | 85 | return False | 79 | return False |
534 | 80 | |||
535 | 86 | return True | 81 | return True |
536 | 87 | 82 | ||
537 | 88 | 83 | ||
538 | 89 | def config_flags_parser(config_flags): | 84 | def config_flags_parser(config_flags): |
539 | 85 | """Parses config flags string into dict. | ||
540 | 86 | |||
541 | 87 | The provided config_flags string may be a list of comma-separated values | ||
542 | 88 | which themselves may be comma-separated list of values. | ||
543 | 89 | """ | ||
544 | 90 | if config_flags.find('==') >= 0: | 90 | if config_flags.find('==') >= 0: |
547 | 91 | log("config_flags is not in expected format (key=value)", | 91 | log("config_flags is not in expected format (key=value)", level=ERROR) |
546 | 92 | level=ERROR) | ||
548 | 93 | raise OSContextError | 92 | raise OSContextError |
549 | 93 | |||
550 | 94 | # strip the following from each value. | 94 | # strip the following from each value. |
551 | 95 | post_strippers = ' ,' | 95 | post_strippers = ' ,' |
552 | 96 | # we strip any leading/trailing '=' or ' ' from the string then | 96 | # we strip any leading/trailing '=' or ' ' from the string then |
553 | @@ -98,7 +98,7 @@ | |||
554 | 98 | split = config_flags.strip(' =').split('=') | 98 | split = config_flags.strip(' =').split('=') |
555 | 99 | limit = len(split) | 99 | limit = len(split) |
556 | 100 | flags = {} | 100 | flags = {} |
558 | 101 | for i in xrange(0, limit - 1): | 101 | for i in range(0, limit - 1): |
559 | 102 | current = split[i] | 102 | current = split[i] |
560 | 103 | next = split[i + 1] | 103 | next = split[i + 1] |
561 | 104 | vindex = next.rfind(',') | 104 | vindex = next.rfind(',') |
562 | @@ -113,17 +113,18 @@ | |||
563 | 113 | # if this not the first entry, expect an embedded key. | 113 | # if this not the first entry, expect an embedded key. |
564 | 114 | index = current.rfind(',') | 114 | index = current.rfind(',') |
565 | 115 | if index < 0: | 115 | if index < 0: |
568 | 116 | log("invalid config value(s) at index %s" % (i), | 116 | log("Invalid config value(s) at index %s" % (i), level=ERROR) |
567 | 117 | level=ERROR) | ||
569 | 118 | raise OSContextError | 117 | raise OSContextError |
570 | 119 | key = current[index + 1:] | 118 | key = current[index + 1:] |
571 | 120 | 119 | ||
572 | 121 | # Add to collection. | 120 | # Add to collection. |
573 | 122 | flags[key.strip(post_strippers)] = value.rstrip(post_strippers) | 121 | flags[key.strip(post_strippers)] = value.rstrip(post_strippers) |
574 | 122 | |||
575 | 123 | return flags | 123 | return flags |
576 | 124 | 124 | ||
577 | 125 | 125 | ||
578 | 126 | class OSContextGenerator(object): | 126 | class OSContextGenerator(object): |
579 | 127 | """Base class for all context generators.""" | ||
580 | 127 | interfaces = [] | 128 | interfaces = [] |
581 | 128 | 129 | ||
582 | 129 | def __call__(self): | 130 | def __call__(self): |
583 | @@ -135,11 +136,11 @@ | |||
584 | 135 | 136 | ||
585 | 136 | def __init__(self, | 137 | def __init__(self, |
586 | 137 | database=None, user=None, relation_prefix=None, ssl_dir=None): | 138 | database=None, user=None, relation_prefix=None, ssl_dir=None): |
592 | 138 | ''' | 139 | """Allows inspecting relation for settings prefixed with |
593 | 139 | Allows inspecting relation for settings prefixed with relation_prefix. | 140 | relation_prefix. This is useful for parsing access for multiple |
594 | 140 | This is useful for parsing access for multiple databases returned via | 141 | databases returned via the shared-db interface (eg, nova_password, |
595 | 141 | the shared-db interface (eg, nova_password, quantum_password) | 142 | quantum_password) |
596 | 142 | ''' | 143 | """ |
597 | 143 | self.relation_prefix = relation_prefix | 144 | self.relation_prefix = relation_prefix |
598 | 144 | self.database = database | 145 | self.database = database |
599 | 145 | self.user = user | 146 | self.user = user |
600 | @@ -149,9 +150,8 @@ | |||
601 | 149 | self.database = self.database or config('database') | 150 | self.database = self.database or config('database') |
602 | 150 | self.user = self.user or config('database-user') | 151 | self.user = self.user or config('database-user') |
603 | 151 | if None in [self.database, self.user]: | 152 | if None in [self.database, self.user]: |
607 | 152 | log('Could not generate shared_db context. ' | 153 | log("Could not generate shared_db context. Missing required charm " |
608 | 153 | 'Missing required charm config options. ' | 154 | "config options. (database name and user)", level=ERROR) |
606 | 154 | '(database name and user)') | ||
609 | 155 | raise OSContextError | 155 | raise OSContextError |
610 | 156 | 156 | ||
611 | 157 | ctxt = {} | 157 | ctxt = {} |
612 | @@ -204,23 +204,24 @@ | |||
613 | 204 | def __call__(self): | 204 | def __call__(self): |
614 | 205 | self.database = self.database or config('database') | 205 | self.database = self.database or config('database') |
615 | 206 | if self.database is None: | 206 | if self.database is None: |
619 | 207 | log('Could not generate postgresql_db context. ' | 207 | log('Could not generate postgresql_db context. Missing required ' |
620 | 208 | 'Missing required charm config options. ' | 208 | 'charm config options. (database name)', level=ERROR) |
618 | 209 | '(database name)') | ||
621 | 210 | raise OSContextError | 209 | raise OSContextError |
622 | 210 | |||
623 | 211 | ctxt = {} | 211 | ctxt = {} |
624 | 212 | |||
625 | 213 | for rid in relation_ids(self.interfaces[0]): | 212 | for rid in relation_ids(self.interfaces[0]): |
626 | 214 | for unit in related_units(rid): | 213 | for unit in related_units(rid): |
634 | 215 | ctxt = { | 214 | rel_host = relation_get('host', rid=rid, unit=unit) |
635 | 216 | 'database_host': relation_get('host', rid=rid, unit=unit), | 215 | rel_user = relation_get('user', rid=rid, unit=unit) |
636 | 217 | 'database': self.database, | 216 | rel_passwd = relation_get('password', rid=rid, unit=unit) |
637 | 218 | 'database_user': relation_get('user', rid=rid, unit=unit), | 217 | ctxt = {'database_host': rel_host, |
638 | 219 | 'database_password': relation_get('password', rid=rid, unit=unit), | 218 | 'database': self.database, |
639 | 220 | 'database_type': 'postgresql', | 219 | 'database_user': rel_user, |
640 | 221 | } | 220 | 'database_password': rel_passwd, |
641 | 221 | 'database_type': 'postgresql'} | ||
642 | 222 | if context_complete(ctxt): | 222 | if context_complete(ctxt): |
643 | 223 | return ctxt | 223 | return ctxt |
644 | 224 | |||
645 | 224 | return {} | 225 | return {} |
646 | 225 | 226 | ||
647 | 226 | 227 | ||
648 | @@ -229,23 +230,29 @@ | |||
649 | 229 | ca_path = os.path.join(ssl_dir, 'db-client.ca') | 230 | ca_path = os.path.join(ssl_dir, 'db-client.ca') |
650 | 230 | with open(ca_path, 'w') as fh: | 231 | with open(ca_path, 'w') as fh: |
651 | 231 | fh.write(b64decode(rdata['ssl_ca'])) | 232 | fh.write(b64decode(rdata['ssl_ca'])) |
652 | 233 | |||
653 | 232 | ctxt['database_ssl_ca'] = ca_path | 234 | ctxt['database_ssl_ca'] = ca_path |
654 | 233 | elif 'ssl_ca' in rdata: | 235 | elif 'ssl_ca' in rdata: |
656 | 234 | log("Charm not setup for ssl support but ssl ca found") | 236 | log("Charm not setup for ssl support but ssl ca found", level=INFO) |
657 | 235 | return ctxt | 237 | return ctxt |
658 | 238 | |||
659 | 236 | if 'ssl_cert' in rdata: | 239 | if 'ssl_cert' in rdata: |
660 | 237 | cert_path = os.path.join( | 240 | cert_path = os.path.join( |
661 | 238 | ssl_dir, 'db-client.cert') | 241 | ssl_dir, 'db-client.cert') |
662 | 239 | if not os.path.exists(cert_path): | 242 | if not os.path.exists(cert_path): |
664 | 240 | log("Waiting 1m for ssl client cert validity") | 243 | log("Waiting 1m for ssl client cert validity", level=INFO) |
665 | 241 | time.sleep(60) | 244 | time.sleep(60) |
666 | 245 | |||
667 | 242 | with open(cert_path, 'w') as fh: | 246 | with open(cert_path, 'w') as fh: |
668 | 243 | fh.write(b64decode(rdata['ssl_cert'])) | 247 | fh.write(b64decode(rdata['ssl_cert'])) |
669 | 248 | |||
670 | 244 | ctxt['database_ssl_cert'] = cert_path | 249 | ctxt['database_ssl_cert'] = cert_path |
671 | 245 | key_path = os.path.join(ssl_dir, 'db-client.key') | 250 | key_path = os.path.join(ssl_dir, 'db-client.key') |
672 | 246 | with open(key_path, 'w') as fh: | 251 | with open(key_path, 'w') as fh: |
673 | 247 | fh.write(b64decode(rdata['ssl_key'])) | 252 | fh.write(b64decode(rdata['ssl_key'])) |
674 | 253 | |||
675 | 248 | ctxt['database_ssl_key'] = key_path | 254 | ctxt['database_ssl_key'] = key_path |
676 | 255 | |||
677 | 249 | return ctxt | 256 | return ctxt |
678 | 250 | 257 | ||
679 | 251 | 258 | ||
680 | @@ -253,9 +260,8 @@ | |||
681 | 253 | interfaces = ['identity-service'] | 260 | interfaces = ['identity-service'] |
682 | 254 | 261 | ||
683 | 255 | def __call__(self): | 262 | def __call__(self): |
685 | 256 | log('Generating template context for identity-service') | 263 | log('Generating template context for identity-service', level=DEBUG) |
686 | 257 | ctxt = {} | 264 | ctxt = {} |
687 | 258 | |||
688 | 259 | for rid in relation_ids('identity-service'): | 265 | for rid in relation_ids('identity-service'): |
689 | 260 | for unit in related_units(rid): | 266 | for unit in related_units(rid): |
690 | 261 | rdata = relation_get(rid=rid, unit=unit) | 267 | rdata = relation_get(rid=rid, unit=unit) |
691 | @@ -263,26 +269,24 @@ | |||
692 | 263 | serv_host = format_ipv6_addr(serv_host) or serv_host | 269 | serv_host = format_ipv6_addr(serv_host) or serv_host |
693 | 264 | auth_host = rdata.get('auth_host') | 270 | auth_host = rdata.get('auth_host') |
694 | 265 | auth_host = format_ipv6_addr(auth_host) or auth_host | 271 | auth_host = format_ipv6_addr(auth_host) or auth_host |
709 | 266 | 272 | svc_protocol = rdata.get('service_protocol') or 'http' | |
710 | 267 | ctxt = { | 273 | auth_protocol = rdata.get('auth_protocol') or 'http' |
711 | 268 | 'service_port': rdata.get('service_port'), | 274 | ctxt = {'service_port': rdata.get('service_port'), |
712 | 269 | 'service_host': serv_host, | 275 | 'service_host': serv_host, |
713 | 270 | 'auth_host': auth_host, | 276 | 'auth_host': auth_host, |
714 | 271 | 'auth_port': rdata.get('auth_port'), | 277 | 'auth_port': rdata.get('auth_port'), |
715 | 272 | 'admin_tenant_name': rdata.get('service_tenant'), | 278 | 'admin_tenant_name': rdata.get('service_tenant'), |
716 | 273 | 'admin_user': rdata.get('service_username'), | 279 | 'admin_user': rdata.get('service_username'), |
717 | 274 | 'admin_password': rdata.get('service_password'), | 280 | 'admin_password': rdata.get('service_password'), |
718 | 275 | 'service_protocol': | 281 | 'service_protocol': svc_protocol, |
719 | 276 | rdata.get('service_protocol') or 'http', | 282 | 'auth_protocol': auth_protocol} |
706 | 277 | 'auth_protocol': | ||
707 | 278 | rdata.get('auth_protocol') or 'http', | ||
708 | 279 | } | ||
720 | 280 | if context_complete(ctxt): | 283 | if context_complete(ctxt): |
721 | 281 | # NOTE(jamespage) this is required for >= icehouse | 284 | # NOTE(jamespage) this is required for >= icehouse |
722 | 282 | # so a missing value just indicates keystone needs | 285 | # so a missing value just indicates keystone needs |
723 | 283 | # upgrading | 286 | # upgrading |
724 | 284 | ctxt['admin_tenant_id'] = rdata.get('service_tenant_id') | 287 | ctxt['admin_tenant_id'] = rdata.get('service_tenant_id') |
725 | 285 | return ctxt | 288 | return ctxt |
726 | 289 | |||
727 | 286 | return {} | 290 | return {} |
728 | 287 | 291 | ||
729 | 288 | 292 | ||
730 | @@ -295,21 +299,23 @@ | |||
731 | 295 | self.interfaces = [rel_name] | 299 | self.interfaces = [rel_name] |
732 | 296 | 300 | ||
733 | 297 | def __call__(self): | 301 | def __call__(self): |
735 | 298 | log('Generating template context for amqp') | 302 | log('Generating template context for amqp', level=DEBUG) |
736 | 299 | conf = config() | 303 | conf = config() |
737 | 300 | user_setting = 'rabbit-user' | ||
738 | 301 | vhost_setting = 'rabbit-vhost' | ||
739 | 302 | if self.relation_prefix: | 304 | if self.relation_prefix: |
742 | 303 | user_setting = self.relation_prefix + '-rabbit-user' | 305 | user_setting = '%s-rabbit-user' % (self.relation_prefix) |
743 | 304 | vhost_setting = self.relation_prefix + '-rabbit-vhost' | 306 | vhost_setting = '%s-rabbit-vhost' % (self.relation_prefix) |
744 | 307 | else: | ||
745 | 308 | user_setting = 'rabbit-user' | ||
746 | 309 | vhost_setting = 'rabbit-vhost' | ||
747 | 305 | 310 | ||
748 | 306 | try: | 311 | try: |
749 | 307 | username = conf[user_setting] | 312 | username = conf[user_setting] |
750 | 308 | vhost = conf[vhost_setting] | 313 | vhost = conf[vhost_setting] |
751 | 309 | except KeyError as e: | 314 | except KeyError as e: |
754 | 310 | log('Could not generate shared_db context. ' | 315 | log('Could not generate shared_db context. Missing required charm ' |
755 | 311 | 'Missing required charm config options: %s.' % e) | 316 | 'config options: %s.' % e, level=ERROR) |
756 | 312 | raise OSContextError | 317 | raise OSContextError |
757 | 318 | |||
758 | 313 | ctxt = {} | 319 | ctxt = {} |
759 | 314 | for rid in relation_ids(self.rel_name): | 320 | for rid in relation_ids(self.rel_name): |
760 | 315 | ha_vip_only = False | 321 | ha_vip_only = False |
761 | @@ -323,6 +329,7 @@ | |||
762 | 323 | host = relation_get('private-address', rid=rid, unit=unit) | 329 | host = relation_get('private-address', rid=rid, unit=unit) |
763 | 324 | host = format_ipv6_addr(host) or host | 330 | host = format_ipv6_addr(host) or host |
764 | 325 | ctxt['rabbitmq_host'] = host | 331 | ctxt['rabbitmq_host'] = host |
765 | 332 | |||
766 | 326 | ctxt.update({ | 333 | ctxt.update({ |
767 | 327 | 'rabbitmq_user': username, | 334 | 'rabbitmq_user': username, |
768 | 328 | 'rabbitmq_password': relation_get('password', rid=rid, | 335 | 'rabbitmq_password': relation_get('password', rid=rid, |
769 | @@ -333,6 +340,7 @@ | |||
770 | 333 | ssl_port = relation_get('ssl_port', rid=rid, unit=unit) | 340 | ssl_port = relation_get('ssl_port', rid=rid, unit=unit) |
771 | 334 | if ssl_port: | 341 | if ssl_port: |
772 | 335 | ctxt['rabbit_ssl_port'] = ssl_port | 342 | ctxt['rabbit_ssl_port'] = ssl_port |
773 | 343 | |||
774 | 336 | ssl_ca = relation_get('ssl_ca', rid=rid, unit=unit) | 344 | ssl_ca = relation_get('ssl_ca', rid=rid, unit=unit) |
775 | 337 | if ssl_ca: | 345 | if ssl_ca: |
776 | 338 | ctxt['rabbit_ssl_ca'] = ssl_ca | 346 | ctxt['rabbit_ssl_ca'] = ssl_ca |
777 | @@ -346,41 +354,45 @@ | |||
778 | 346 | if context_complete(ctxt): | 354 | if context_complete(ctxt): |
779 | 347 | if 'rabbit_ssl_ca' in ctxt: | 355 | if 'rabbit_ssl_ca' in ctxt: |
780 | 348 | if not self.ssl_dir: | 356 | if not self.ssl_dir: |
783 | 349 | log(("Charm not setup for ssl support " | 357 | log("Charm not setup for ssl support but ssl ca " |
784 | 350 | "but ssl ca found")) | 358 | "found", level=INFO) |
785 | 351 | break | 359 | break |
786 | 360 | |||
787 | 352 | ca_path = os.path.join( | 361 | ca_path = os.path.join( |
788 | 353 | self.ssl_dir, 'rabbit-client-ca.pem') | 362 | self.ssl_dir, 'rabbit-client-ca.pem') |
789 | 354 | with open(ca_path, 'w') as fh: | 363 | with open(ca_path, 'w') as fh: |
790 | 355 | fh.write(b64decode(ctxt['rabbit_ssl_ca'])) | 364 | fh.write(b64decode(ctxt['rabbit_ssl_ca'])) |
791 | 356 | ctxt['rabbit_ssl_ca'] = ca_path | 365 | ctxt['rabbit_ssl_ca'] = ca_path |
792 | 366 | |||
793 | 357 | # Sufficient information found = break out! | 367 | # Sufficient information found = break out! |
794 | 358 | break | 368 | break |
795 | 369 | |||
796 | 359 | # Used for active/active rabbitmq >= grizzly | 370 | # Used for active/active rabbitmq >= grizzly |
799 | 360 | if ('clustered' not in ctxt or ha_vip_only) \ | 371 | if (('clustered' not in ctxt or ha_vip_only) and |
800 | 361 | and len(related_units(rid)) > 1: | 372 | len(related_units(rid)) > 1): |
801 | 362 | rabbitmq_hosts = [] | 373 | rabbitmq_hosts = [] |
802 | 363 | for unit in related_units(rid): | 374 | for unit in related_units(rid): |
803 | 364 | host = relation_get('private-address', rid=rid, unit=unit) | 375 | host = relation_get('private-address', rid=rid, unit=unit) |
804 | 365 | host = format_ipv6_addr(host) or host | 376 | host = format_ipv6_addr(host) or host |
805 | 366 | rabbitmq_hosts.append(host) | 377 | rabbitmq_hosts.append(host) |
807 | 367 | ctxt['rabbitmq_hosts'] = ','.join(rabbitmq_hosts) | 378 | |
808 | 379 | ctxt['rabbitmq_hosts'] = ','.join(sorted(rabbitmq_hosts)) | ||
809 | 380 | |||
810 | 368 | if not context_complete(ctxt): | 381 | if not context_complete(ctxt): |
811 | 369 | return {} | 382 | return {} |
814 | 370 | else: | 383 | |
815 | 371 | return ctxt | 384 | return ctxt |
816 | 372 | 385 | ||
817 | 373 | 386 | ||
818 | 374 | class CephContext(OSContextGenerator): | 387 | class CephContext(OSContextGenerator): |
819 | 388 | """Generates context for /etc/ceph/ceph.conf templates.""" | ||
820 | 375 | interfaces = ['ceph'] | 389 | interfaces = ['ceph'] |
821 | 376 | 390 | ||
822 | 377 | def __call__(self): | 391 | def __call__(self): |
823 | 378 | '''This generates context for /etc/ceph/ceph.conf templates''' | ||
824 | 379 | if not relation_ids('ceph'): | 392 | if not relation_ids('ceph'): |
825 | 380 | return {} | 393 | return {} |
826 | 381 | 394 | ||
829 | 382 | log('Generating template context for ceph') | 395 | log('Generating template context for ceph', level=DEBUG) |
828 | 383 | |||
830 | 384 | mon_hosts = [] | 396 | mon_hosts = [] |
831 | 385 | auth = None | 397 | auth = None |
832 | 386 | key = None | 398 | key = None |
833 | @@ -389,18 +401,18 @@ | |||
834 | 389 | for unit in related_units(rid): | 401 | for unit in related_units(rid): |
835 | 390 | auth = relation_get('auth', rid=rid, unit=unit) | 402 | auth = relation_get('auth', rid=rid, unit=unit) |
836 | 391 | key = relation_get('key', rid=rid, unit=unit) | 403 | key = relation_get('key', rid=rid, unit=unit) |
840 | 392 | ceph_addr = \ | 404 | ceph_pub_addr = relation_get('ceph-public-address', rid=rid, |
841 | 393 | relation_get('ceph-public-address', rid=rid, unit=unit) or \ | 405 | unit=unit) |
842 | 394 | relation_get('private-address', rid=rid, unit=unit) | 406 | unit_priv_addr = relation_get('private-address', rid=rid, |
843 | 407 | unit=unit) | ||
844 | 408 | ceph_addr = ceph_pub_addr or unit_priv_addr | ||
845 | 395 | ceph_addr = format_ipv6_addr(ceph_addr) or ceph_addr | 409 | ceph_addr = format_ipv6_addr(ceph_addr) or ceph_addr |
846 | 396 | mon_hosts.append(ceph_addr) | 410 | mon_hosts.append(ceph_addr) |
847 | 397 | 411 | ||
854 | 398 | ctxt = { | 412 | ctxt = {'mon_hosts': ' '.join(sorted(mon_hosts)), |
855 | 399 | 'mon_hosts': ' '.join(mon_hosts), | 413 | 'auth': auth, |
856 | 400 | 'auth': auth, | 414 | 'key': key, |
857 | 401 | 'key': key, | 415 | 'use_syslog': use_syslog} |
852 | 402 | 'use_syslog': use_syslog | ||
853 | 403 | } | ||
858 | 404 | 416 | ||
859 | 405 | if not os.path.isdir('/etc/ceph'): | 417 | if not os.path.isdir('/etc/ceph'): |
860 | 406 | os.mkdir('/etc/ceph') | 418 | os.mkdir('/etc/ceph') |
861 | @@ -409,79 +421,68 @@ | |||
862 | 409 | return {} | 421 | return {} |
863 | 410 | 422 | ||
864 | 411 | ensure_packages(['ceph-common']) | 423 | ensure_packages(['ceph-common']) |
865 | 412 | |||
866 | 413 | return ctxt | 424 | return ctxt |
867 | 414 | 425 | ||
868 | 415 | 426 | ||
869 | 416 | ADDRESS_TYPES = ['admin', 'internal', 'public'] | ||
870 | 417 | |||
871 | 418 | |||
872 | 419 | class HAProxyContext(OSContextGenerator): | 427 | class HAProxyContext(OSContextGenerator): |
873 | 428 | """Provides half a context for the haproxy template, which describes | ||
874 | 429 | all peers to be included in the cluster. Each charm needs to include | ||
875 | 430 | its own context generator that describes the port mapping. | ||
876 | 431 | """ | ||
877 | 420 | interfaces = ['cluster'] | 432 | interfaces = ['cluster'] |
878 | 421 | 433 | ||
879 | 434 | def __init__(self, singlenode_mode=False): | ||
880 | 435 | self.singlenode_mode = singlenode_mode | ||
881 | 436 | |||
882 | 422 | def __call__(self): | 437 | def __call__(self): |
889 | 423 | ''' | 438 | if not relation_ids('cluster') and not self.singlenode_mode: |
884 | 424 | Builds half a context for the haproxy template, which describes | ||
885 | 425 | all peers to be included in the cluster. Each charm needs to include | ||
886 | 426 | its own context generator that describes the port mapping. | ||
887 | 427 | ''' | ||
888 | 428 | if not relation_ids('cluster'): | ||
890 | 429 | return {} | 439 | return {} |
891 | 430 | 440 | ||
892 | 431 | l_unit = local_unit().replace('/', '-') | ||
893 | 432 | |||
894 | 433 | if config('prefer-ipv6'): | 441 | if config('prefer-ipv6'): |
895 | 434 | addr = get_ipv6_addr(exc_list=[config('vip')])[0] | 442 | addr = get_ipv6_addr(exc_list=[config('vip')])[0] |
896 | 435 | else: | 443 | else: |
897 | 436 | addr = get_host_ip(unit_get('private-address')) | 444 | addr = get_host_ip(unit_get('private-address')) |
898 | 437 | 445 | ||
899 | 446 | l_unit = local_unit().replace('/', '-') | ||
900 | 438 | cluster_hosts = {} | 447 | cluster_hosts = {} |
901 | 439 | 448 | ||
902 | 440 | # NOTE(jamespage): build out map of configured network endpoints | 449 | # NOTE(jamespage): build out map of configured network endpoints |
903 | 441 | # and associated backends | 450 | # and associated backends |
904 | 442 | for addr_type in ADDRESS_TYPES: | 451 | for addr_type in ADDRESS_TYPES: |
907 | 443 | laddr = get_address_in_network( | 452 | cfg_opt = 'os-{}-network'.format(addr_type) |
908 | 444 | config('os-{}-network'.format(addr_type))) | 453 | laddr = get_address_in_network(config(cfg_opt)) |
909 | 445 | if laddr: | 454 | if laddr: |
917 | 446 | cluster_hosts[laddr] = {} | 455 | netmask = get_netmask_for_address(laddr) |
918 | 447 | cluster_hosts[laddr]['network'] = "{}/{}".format( | 456 | cluster_hosts[laddr] = {'network': "{}/{}".format(laddr, |
919 | 448 | laddr, | 457 | netmask), |
920 | 449 | get_netmask_for_address(laddr) | 458 | 'backends': {l_unit: laddr}} |
914 | 450 | ) | ||
915 | 451 | cluster_hosts[laddr]['backends'] = {} | ||
916 | 452 | cluster_hosts[laddr]['backends'][l_unit] = laddr | ||
921 | 453 | for rid in relation_ids('cluster'): | 459 | for rid in relation_ids('cluster'): |
922 | 454 | for unit in related_units(rid): | 460 | for unit in related_units(rid): |
923 | 455 | _unit = unit.replace('/', '-') | ||
924 | 456 | _laddr = relation_get('{}-address'.format(addr_type), | 461 | _laddr = relation_get('{}-address'.format(addr_type), |
925 | 457 | rid=rid, unit=unit) | 462 | rid=rid, unit=unit) |
926 | 458 | if _laddr: | 463 | if _laddr: |
927 | 464 | _unit = unit.replace('/', '-') | ||
928 | 459 | cluster_hosts[laddr]['backends'][_unit] = _laddr | 465 | cluster_hosts[laddr]['backends'][_unit] = _laddr |
929 | 460 | 466 | ||
930 | 461 | # NOTE(jamespage) no split configurations found, just use | 467 | # NOTE(jamespage) no split configurations found, just use |
931 | 462 | # private addresses | 468 | # private addresses |
932 | 463 | if not cluster_hosts: | 469 | if not cluster_hosts: |
940 | 464 | cluster_hosts[addr] = {} | 470 | netmask = get_netmask_for_address(addr) |
941 | 465 | cluster_hosts[addr]['network'] = "{}/{}".format( | 471 | cluster_hosts[addr] = {'network': "{}/{}".format(addr, netmask), |
942 | 466 | addr, | 472 | 'backends': {l_unit: addr}} |
936 | 467 | get_netmask_for_address(addr) | ||
937 | 468 | ) | ||
938 | 469 | cluster_hosts[addr]['backends'] = {} | ||
939 | 470 | cluster_hosts[addr]['backends'][l_unit] = addr | ||
943 | 471 | for rid in relation_ids('cluster'): | 473 | for rid in relation_ids('cluster'): |
944 | 472 | for unit in related_units(rid): | 474 | for unit in related_units(rid): |
945 | 473 | _unit = unit.replace('/', '-') | ||
946 | 474 | _laddr = relation_get('private-address', | 475 | _laddr = relation_get('private-address', |
947 | 475 | rid=rid, unit=unit) | 476 | rid=rid, unit=unit) |
948 | 476 | if _laddr: | 477 | if _laddr: |
949 | 478 | _unit = unit.replace('/', '-') | ||
950 | 477 | cluster_hosts[addr]['backends'][_unit] = _laddr | 479 | cluster_hosts[addr]['backends'][_unit] = _laddr |
951 | 478 | 480 | ||
955 | 479 | ctxt = { | 481 | ctxt = {'frontends': cluster_hosts} |
953 | 480 | 'frontends': cluster_hosts, | ||
954 | 481 | } | ||
956 | 482 | 482 | ||
957 | 483 | if config('haproxy-server-timeout'): | 483 | if config('haproxy-server-timeout'): |
958 | 484 | ctxt['haproxy_server_timeout'] = config('haproxy-server-timeout') | 484 | ctxt['haproxy_server_timeout'] = config('haproxy-server-timeout') |
959 | 485 | |||
960 | 485 | if config('haproxy-client-timeout'): | 486 | if config('haproxy-client-timeout'): |
961 | 486 | ctxt['haproxy_client_timeout'] = config('haproxy-client-timeout') | 487 | ctxt['haproxy_client_timeout'] = config('haproxy-client-timeout') |
962 | 487 | 488 | ||
963 | @@ -495,13 +496,18 @@ | |||
964 | 495 | ctxt['stat_port'] = ':8888' | 496 | ctxt['stat_port'] = ':8888' |
965 | 496 | 497 | ||
966 | 497 | for frontend in cluster_hosts: | 498 | for frontend in cluster_hosts: |
968 | 498 | if len(cluster_hosts[frontend]['backends']) > 1: | 499 | if (len(cluster_hosts[frontend]['backends']) > 1 or |
969 | 500 | self.singlenode_mode): | ||
970 | 499 | # Enable haproxy when we have enough peers. | 501 | # Enable haproxy when we have enough peers. |
972 | 500 | log('Ensuring haproxy enabled in /etc/default/haproxy.') | 502 | log('Ensuring haproxy enabled in /etc/default/haproxy.', |
973 | 503 | level=DEBUG) | ||
974 | 501 | with open('/etc/default/haproxy', 'w') as out: | 504 | with open('/etc/default/haproxy', 'w') as out: |
975 | 502 | out.write('ENABLED=1\n') | 505 | out.write('ENABLED=1\n') |
976 | 506 | |||
977 | 503 | return ctxt | 507 | return ctxt |
979 | 504 | log('HAProxy context is incomplete, this unit has no peers.') | 508 | |
980 | 509 | log('HAProxy context is incomplete, this unit has no peers.', | ||
981 | 510 | level=INFO) | ||
982 | 505 | return {} | 511 | return {} |
983 | 506 | 512 | ||
984 | 507 | 513 | ||
985 | @@ -509,29 +515,28 @@ | |||
986 | 509 | interfaces = ['image-service'] | 515 | interfaces = ['image-service'] |
987 | 510 | 516 | ||
988 | 511 | def __call__(self): | 517 | def __call__(self): |
994 | 512 | ''' | 518 | """Obtains the glance API server from the image-service relation. |
995 | 513 | Obtains the glance API server from the image-service relation. Useful | 519 | Useful in nova and cinder (currently). |
996 | 514 | in nova and cinder (currently). | 520 | """ |
997 | 515 | ''' | 521 | log('Generating template context for image-service.', level=DEBUG) |
993 | 516 | log('Generating template context for image-service.') | ||
998 | 517 | rids = relation_ids('image-service') | 522 | rids = relation_ids('image-service') |
999 | 518 | if not rids: | 523 | if not rids: |
1000 | 519 | return {} | 524 | return {} |
1001 | 525 | |||
1002 | 520 | for rid in rids: | 526 | for rid in rids: |
1003 | 521 | for unit in related_units(rid): | 527 | for unit in related_units(rid): |
1004 | 522 | api_server = relation_get('glance-api-server', | 528 | api_server = relation_get('glance-api-server', |
1005 | 523 | rid=rid, unit=unit) | 529 | rid=rid, unit=unit) |
1006 | 524 | if api_server: | 530 | if api_server: |
1007 | 525 | return {'glance_api_servers': api_server} | 531 | return {'glance_api_servers': api_server} |
1010 | 526 | log('ImageService context is incomplete. ' | 532 | |
1011 | 527 | 'Missing required relation data.') | 533 | log("ImageService context is incomplete. Missing required relation " |
1012 | 534 | "data.", level=INFO) | ||
1013 | 528 | return {} | 535 | return {} |
1014 | 529 | 536 | ||
1015 | 530 | 537 | ||
1016 | 531 | class ApacheSSLContext(OSContextGenerator): | 538 | class ApacheSSLContext(OSContextGenerator): |
1020 | 532 | 539 | """Generates a context for an apache vhost configuration that configures | |
1018 | 533 | """ | ||
1019 | 534 | Generates a context for an apache vhost configuration that configures | ||
1021 | 535 | HTTPS reverse proxying for one or many endpoints. Generated context | 540 | HTTPS reverse proxying for one or many endpoints. Generated context |
1022 | 536 | looks something like:: | 541 | looks something like:: |
1023 | 537 | 542 | ||
1024 | @@ -565,6 +570,7 @@ | |||
1025 | 565 | else: | 570 | else: |
1026 | 566 | cert_filename = 'cert' | 571 | cert_filename = 'cert' |
1027 | 567 | key_filename = 'key' | 572 | key_filename = 'key' |
1028 | 573 | |||
1029 | 568 | write_file(path=os.path.join(ssl_dir, cert_filename), | 574 | write_file(path=os.path.join(ssl_dir, cert_filename), |
1030 | 569 | content=b64decode(cert)) | 575 | content=b64decode(cert)) |
1031 | 570 | write_file(path=os.path.join(ssl_dir, key_filename), | 576 | write_file(path=os.path.join(ssl_dir, key_filename), |
1032 | @@ -576,7 +582,8 @@ | |||
1033 | 576 | install_ca_cert(b64decode(ca_cert)) | 582 | install_ca_cert(b64decode(ca_cert)) |
1034 | 577 | 583 | ||
1035 | 578 | def canonical_names(self): | 584 | def canonical_names(self): |
1037 | 579 | '''Figure out which canonical names clients will access this service''' | 585 | """Figure out which canonical names clients will access this service. |
1038 | 586 | """ | ||
1039 | 580 | cns = [] | 587 | cns = [] |
1040 | 581 | for r_id in relation_ids('identity-service'): | 588 | for r_id in relation_ids('identity-service'): |
1041 | 582 | for unit in related_units(r_id): | 589 | for unit in related_units(r_id): |
1042 | @@ -584,7 +591,8 @@ | |||
1043 | 584 | for k in rdata: | 591 | for k in rdata: |
1044 | 585 | if k.startswith('ssl_key_'): | 592 | if k.startswith('ssl_key_'): |
1045 | 586 | cns.append(k.lstrip('ssl_key_')) | 593 | cns.append(k.lstrip('ssl_key_')) |
1047 | 587 | return list(set(cns)) | 594 | |
1048 | 595 | return sorted(list(set(cns))) | ||
1049 | 588 | 596 | ||
1050 | 589 | def get_network_addresses(self): | 597 | def get_network_addresses(self): |
1051 | 590 | """For each network configured, return corresponding address and vip | 598 | """For each network configured, return corresponding address and vip |
1052 | @@ -603,9 +611,10 @@ | |||
1053 | 603 | ...] | 611 | ...] |
1054 | 604 | """ | 612 | """ |
1055 | 605 | addresses = [] | 613 | addresses = [] |
1056 | 606 | vips = [] | ||
1057 | 607 | if config('vip'): | 614 | if config('vip'): |
1058 | 608 | vips = config('vip').split() | 615 | vips = config('vip').split() |
1059 | 616 | else: | ||
1060 | 617 | vips = [] | ||
1061 | 609 | 618 | ||
1062 | 610 | for net_type in ['os-internal-network', 'os-admin-network', | 619 | for net_type in ['os-internal-network', 'os-admin-network', |
1063 | 611 | 'os-public-network']: | 620 | 'os-public-network']: |
1064 | @@ -614,7 +623,7 @@ | |||
1065 | 614 | if len(vips) > 1 and is_clustered(): | 623 | if len(vips) > 1 and is_clustered(): |
1066 | 615 | if not config(net_type): | 624 | if not config(net_type): |
1067 | 616 | log("Multiple networks configured but net_type " | 625 | log("Multiple networks configured but net_type " |
1069 | 617 | "is None (%s)." % net_type, level='WARNING') | 626 | "is None (%s)." % net_type, level=WARNING) |
1070 | 618 | continue | 627 | continue |
1071 | 619 | 628 | ||
1072 | 620 | for vip in vips: | 629 | for vip in vips: |
1073 | @@ -627,35 +636,35 @@ | |||
1074 | 627 | else: | 636 | else: |
1075 | 628 | addresses.append((addr, addr)) | 637 | addresses.append((addr, addr)) |
1076 | 629 | 638 | ||
1078 | 630 | return addresses | 639 | return sorted(addresses) |
1079 | 631 | 640 | ||
1080 | 632 | def __call__(self): | 641 | def __call__(self): |
1082 | 633 | if isinstance(self.external_ports, basestring): | 642 | if isinstance(self.external_ports, six.string_types): |
1083 | 634 | self.external_ports = [self.external_ports] | 643 | self.external_ports = [self.external_ports] |
1085 | 635 | if (not self.external_ports or not https()): | 644 | |
1086 | 645 | if not self.external_ports or not https(): | ||
1087 | 636 | return {} | 646 | return {} |
1088 | 637 | 647 | ||
1089 | 638 | self.configure_ca() | 648 | self.configure_ca() |
1090 | 639 | self.enable_modules() | 649 | self.enable_modules() |
1091 | 640 | 650 | ||
1097 | 641 | ctxt = { | 651 | ctxt = {'namespace': self.service_namespace, |
1098 | 642 | 'namespace': self.service_namespace, | 652 | 'endpoints': [], |
1099 | 643 | 'endpoints': [], | 653 | 'ext_ports': []} |
1095 | 644 | 'ext_ports': [] | ||
1096 | 645 | } | ||
1100 | 646 | 654 | ||
1101 | 647 | for cn in self.canonical_names(): | 655 | for cn in self.canonical_names(): |
1102 | 648 | self.configure_cert(cn) | 656 | self.configure_cert(cn) |
1103 | 649 | 657 | ||
1104 | 650 | addresses = self.get_network_addresses() | 658 | addresses = self.get_network_addresses() |
1106 | 651 | for address, endpoint in set(addresses): | 659 | for address, endpoint in sorted(set(addresses)): |
1107 | 652 | for api_port in self.external_ports: | 660 | for api_port in self.external_ports: |
1108 | 653 | ext_port = determine_apache_port(api_port) | 661 | ext_port = determine_apache_port(api_port) |
1109 | 654 | int_port = determine_api_port(api_port) | 662 | int_port = determine_api_port(api_port) |
1110 | 655 | portmap = (address, endpoint, int(ext_port), int(int_port)) | 663 | portmap = (address, endpoint, int(ext_port), int(int_port)) |
1111 | 656 | ctxt['endpoints'].append(portmap) | 664 | ctxt['endpoints'].append(portmap) |
1112 | 657 | ctxt['ext_ports'].append(int(ext_port)) | 665 | ctxt['ext_ports'].append(int(ext_port)) |
1114 | 658 | ctxt['ext_ports'] = list(set(ctxt['ext_ports'])) | 666 | |
1115 | 667 | ctxt['ext_ports'] = sorted(list(set(ctxt['ext_ports']))) | ||
1116 | 659 | return ctxt | 668 | return ctxt |
1117 | 660 | 669 | ||
1118 | 661 | 670 | ||
1119 | @@ -672,21 +681,23 @@ | |||
1120 | 672 | 681 | ||
1121 | 673 | @property | 682 | @property |
1122 | 674 | def packages(self): | 683 | def packages(self): |
1125 | 675 | return neutron_plugin_attribute( | 684 | return neutron_plugin_attribute(self.plugin, 'packages', |
1126 | 676 | self.plugin, 'packages', self.network_manager) | 685 | self.network_manager) |
1127 | 677 | 686 | ||
1128 | 678 | @property | 687 | @property |
1129 | 679 | def neutron_security_groups(self): | 688 | def neutron_security_groups(self): |
1130 | 680 | return None | 689 | return None |
1131 | 681 | 690 | ||
1132 | 682 | def _ensure_packages(self): | 691 | def _ensure_packages(self): |
1134 | 683 | [ensure_packages(pkgs) for pkgs in self.packages] | 692 | for pkgs in self.packages: |
1135 | 693 | ensure_packages(pkgs) | ||
1136 | 684 | 694 | ||
1137 | 685 | def _save_flag_file(self): | 695 | def _save_flag_file(self): |
1138 | 686 | if self.network_manager == 'quantum': | 696 | if self.network_manager == 'quantum': |
1139 | 687 | _file = '/etc/nova/quantum_plugin.conf' | 697 | _file = '/etc/nova/quantum_plugin.conf' |
1140 | 688 | else: | 698 | else: |
1141 | 689 | _file = '/etc/nova/neutron_plugin.conf' | 699 | _file = '/etc/nova/neutron_plugin.conf' |
1142 | 700 | |||
1143 | 690 | with open(_file, 'wb') as out: | 701 | with open(_file, 'wb') as out: |
1144 | 691 | out.write(self.plugin + '\n') | 702 | out.write(self.plugin + '\n') |
1145 | 692 | 703 | ||
1146 | @@ -695,13 +706,11 @@ | |||
1147 | 695 | self.network_manager) | 706 | self.network_manager) |
1148 | 696 | config = neutron_plugin_attribute(self.plugin, 'config', | 707 | config = neutron_plugin_attribute(self.plugin, 'config', |
1149 | 697 | self.network_manager) | 708 | self.network_manager) |
1157 | 698 | ovs_ctxt = { | 709 | ovs_ctxt = {'core_plugin': driver, |
1158 | 699 | 'core_plugin': driver, | 710 | 'neutron_plugin': 'ovs', |
1159 | 700 | 'neutron_plugin': 'ovs', | 711 | 'neutron_security_groups': self.neutron_security_groups, |
1160 | 701 | 'neutron_security_groups': self.neutron_security_groups, | 712 | 'local_ip': unit_private_ip(), |
1161 | 702 | 'local_ip': unit_private_ip(), | 713 | 'config': config} |
1155 | 703 | 'config': config | ||
1156 | 704 | } | ||
1162 | 705 | 714 | ||
1163 | 706 | return ovs_ctxt | 715 | return ovs_ctxt |
1164 | 707 | 716 | ||
1165 | @@ -710,13 +719,11 @@ | |||
1166 | 710 | self.network_manager) | 719 | self.network_manager) |
1167 | 711 | config = neutron_plugin_attribute(self.plugin, 'config', | 720 | config = neutron_plugin_attribute(self.plugin, 'config', |
1168 | 712 | self.network_manager) | 721 | self.network_manager) |
1176 | 713 | nvp_ctxt = { | 722 | nvp_ctxt = {'core_plugin': driver, |
1177 | 714 | 'core_plugin': driver, | 723 | 'neutron_plugin': 'nvp', |
1178 | 715 | 'neutron_plugin': 'nvp', | 724 | 'neutron_security_groups': self.neutron_security_groups, |
1179 | 716 | 'neutron_security_groups': self.neutron_security_groups, | 725 | 'local_ip': unit_private_ip(), |
1180 | 717 | 'local_ip': unit_private_ip(), | 726 | 'config': config} |
1174 | 718 | 'config': config | ||
1175 | 719 | } | ||
1181 | 720 | 727 | ||
1182 | 721 | return nvp_ctxt | 728 | return nvp_ctxt |
1183 | 722 | 729 | ||
1184 | @@ -726,18 +733,17 @@ | |||
1185 | 726 | n1kv_config = neutron_plugin_attribute(self.plugin, 'config', | 733 | n1kv_config = neutron_plugin_attribute(self.plugin, 'config', |
1186 | 727 | self.network_manager) | 734 | self.network_manager) |
1187 | 728 | n1kv_user_config_flags = config('n1kv-config-flags') | 735 | n1kv_user_config_flags = config('n1kv-config-flags') |
1200 | 729 | n1kv_ctxt = { | 736 | restrict_policy_profiles = config('n1kv-restrict-policy-profiles') |
1201 | 730 | 'core_plugin': driver, | 737 | n1kv_ctxt = {'core_plugin': driver, |
1202 | 731 | 'neutron_plugin': 'n1kv', | 738 | 'neutron_plugin': 'n1kv', |
1203 | 732 | 'neutron_security_groups': self.neutron_security_groups, | 739 | 'neutron_security_groups': self.neutron_security_groups, |
1204 | 733 | 'local_ip': unit_private_ip(), | 740 | 'local_ip': unit_private_ip(), |
1205 | 734 | 'config': n1kv_config, | 741 | 'config': n1kv_config, |
1206 | 735 | 'vsm_ip': config('n1kv-vsm-ip'), | 742 | 'vsm_ip': config('n1kv-vsm-ip'), |
1207 | 736 | 'vsm_username': config('n1kv-vsm-username'), | 743 | 'vsm_username': config('n1kv-vsm-username'), |
1208 | 737 | 'vsm_password': config('n1kv-vsm-password'), | 744 | 'vsm_password': config('n1kv-vsm-password'), |
1209 | 738 | 'restrict_policy_profiles': config( | 745 | 'restrict_policy_profiles': restrict_policy_profiles} |
1210 | 739 | 'n1kv-restrict-policy-profiles'), | 746 | |
1199 | 740 | } | ||
1211 | 741 | if n1kv_user_config_flags: | 747 | if n1kv_user_config_flags: |
1212 | 742 | flags = config_flags_parser(n1kv_user_config_flags) | 748 | flags = config_flags_parser(n1kv_user_config_flags) |
1213 | 743 | n1kv_ctxt['user_config_flags'] = flags | 749 | n1kv_ctxt['user_config_flags'] = flags |
1214 | @@ -749,13 +755,11 @@ | |||
1215 | 749 | self.network_manager) | 755 | self.network_manager) |
1216 | 750 | config = neutron_plugin_attribute(self.plugin, 'config', | 756 | config = neutron_plugin_attribute(self.plugin, 'config', |
1217 | 751 | self.network_manager) | 757 | self.network_manager) |
1225 | 752 | calico_ctxt = { | 758 | calico_ctxt = {'core_plugin': driver, |
1226 | 753 | 'core_plugin': driver, | 759 | 'neutron_plugin': 'Calico', |
1227 | 754 | 'neutron_plugin': 'Calico', | 760 | 'neutron_security_groups': self.neutron_security_groups, |
1228 | 755 | 'neutron_security_groups': self.neutron_security_groups, | 761 | 'local_ip': unit_private_ip(), |
1229 | 756 | 'local_ip': unit_private_ip(), | 762 | 'config': config} |
1223 | 757 | 'config': config | ||
1224 | 758 | } | ||
1230 | 759 | 763 | ||
1231 | 760 | return calico_ctxt | 764 | return calico_ctxt |
1232 | 761 | 765 | ||
1233 | @@ -764,15 +768,14 @@ | |||
1234 | 764 | proto = 'https' | 768 | proto = 'https' |
1235 | 765 | else: | 769 | else: |
1236 | 766 | proto = 'http' | 770 | proto = 'http' |
1237 | 771 | |||
1238 | 767 | if is_clustered(): | 772 | if is_clustered(): |
1239 | 768 | host = config('vip') | 773 | host = config('vip') |
1240 | 769 | else: | 774 | else: |
1241 | 770 | host = unit_get('private-address') | 775 | host = unit_get('private-address') |
1247 | 771 | url = '%s://%s:%s' % (proto, host, '9696') | 776 | |
1248 | 772 | ctxt = { | 777 | ctxt = {'network_manager': self.network_manager, |
1249 | 773 | 'network_manager': self.network_manager, | 778 | 'neutron_url': '%s://%s:%s' % (proto, host, '9696')} |
1245 | 774 | 'neutron_url': url, | ||
1246 | 775 | } | ||
1250 | 776 | return ctxt | 779 | return ctxt |
1251 | 777 | 780 | ||
1252 | 778 | def __call__(self): | 781 | def __call__(self): |
1253 | @@ -805,9 +808,7 @@ | |||
1254 | 805 | 808 | ||
1255 | 806 | 809 | ||
1256 | 807 | class OSConfigFlagContext(OSContextGenerator): | 810 | class OSConfigFlagContext(OSContextGenerator): |
1260 | 808 | 811 | """Provides support for user-defined config flags. | |
1258 | 809 | """ | ||
1259 | 810 | Provides support for user-defined config flags. | ||
1261 | 811 | 812 | ||
1262 | 812 | Users can define a comma-seperated list of key=value pairs | 813 | Users can define a comma-seperated list of key=value pairs |
1263 | 813 | in the charm configuration and apply them at any point in | 814 | in the charm configuration and apply them at any point in |
1264 | @@ -826,8 +827,9 @@ | |||
1265 | 826 | def __init__(self, charm_flag='config-flags', | 827 | def __init__(self, charm_flag='config-flags', |
1266 | 827 | template_flag='user_config_flags'): | 828 | template_flag='user_config_flags'): |
1267 | 828 | """ | 829 | """ |
1270 | 829 | charm_flag: config flags in charm configuration. | 830 | :param charm_flag: config flags in charm configuration. |
1271 | 830 | template_flag: insert point for user-defined flags template file. | 831 | :param template_flag: insert point for user-defined flags in template |
1272 | 832 | file. | ||
1273 | 831 | """ | 833 | """ |
1274 | 832 | super(OSConfigFlagContext, self).__init__() | 834 | super(OSConfigFlagContext, self).__init__() |
1275 | 833 | self._charm_flag = charm_flag | 835 | self._charm_flag = charm_flag |
1276 | @@ -883,7 +885,6 @@ | |||
1277 | 883 | }, | 885 | }, |
1278 | 884 | } | 886 | } |
1279 | 885 | } | 887 | } |
1280 | 886 | |||
1281 | 887 | """ | 888 | """ |
1282 | 888 | 889 | ||
1283 | 889 | def __init__(self, service, config_file, interface): | 890 | def __init__(self, service, config_file, interface): |
1284 | @@ -913,26 +914,28 @@ | |||
1285 | 913 | 914 | ||
1286 | 914 | if self.service not in sub_config: | 915 | if self.service not in sub_config: |
1287 | 915 | log('Found subordinate_config on %s but it contained' | 916 | log('Found subordinate_config on %s but it contained' |
1289 | 916 | 'nothing for %s service' % (rid, self.service)) | 917 | 'nothing for %s service' % (rid, self.service), |
1290 | 918 | level=INFO) | ||
1291 | 917 | continue | 919 | continue |
1292 | 918 | 920 | ||
1293 | 919 | sub_config = sub_config[self.service] | 921 | sub_config = sub_config[self.service] |
1294 | 920 | if self.config_file not in sub_config: | 922 | if self.config_file not in sub_config: |
1295 | 921 | log('Found subordinate_config on %s but it contained' | 923 | log('Found subordinate_config on %s but it contained' |
1297 | 922 | 'nothing for %s' % (rid, self.config_file)) | 924 | 'nothing for %s' % (rid, self.config_file), |
1298 | 925 | level=INFO) | ||
1299 | 923 | continue | 926 | continue |
1300 | 924 | 927 | ||
1301 | 925 | sub_config = sub_config[self.config_file] | 928 | sub_config = sub_config[self.config_file] |
1303 | 926 | for k, v in sub_config.iteritems(): | 929 | for k, v in six.iteritems(sub_config): |
1304 | 927 | if k == 'sections': | 930 | if k == 'sections': |
1307 | 928 | for section, config_dict in v.iteritems(): | 931 | for section, config_dict in six.iteritems(v): |
1308 | 929 | log("adding section '%s'" % (section)) | 932 | log("adding section '%s'" % (section), |
1309 | 933 | level=DEBUG) | ||
1310 | 930 | ctxt[k][section] = config_dict | 934 | ctxt[k][section] = config_dict |
1311 | 931 | else: | 935 | else: |
1312 | 932 | ctxt[k] = v | 936 | ctxt[k] = v |
1313 | 933 | 937 | ||
1314 | 934 | log("%d section(s) found" % (len(ctxt['sections'])), level=DEBUG) | 938 | log("%d section(s) found" % (len(ctxt['sections'])), level=DEBUG) |
1315 | 935 | |||
1316 | 936 | return ctxt | 939 | return ctxt |
1317 | 937 | 940 | ||
1318 | 938 | 941 | ||
1319 | @@ -944,15 +947,14 @@ | |||
1320 | 944 | False if config('debug') is None else config('debug') | 947 | False if config('debug') is None else config('debug') |
1321 | 945 | ctxt['verbose'] = \ | 948 | ctxt['verbose'] = \ |
1322 | 946 | False if config('verbose') is None else config('verbose') | 949 | False if config('verbose') is None else config('verbose') |
1323 | 950 | |||
1324 | 947 | return ctxt | 951 | return ctxt |
1325 | 948 | 952 | ||
1326 | 949 | 953 | ||
1327 | 950 | class SyslogContext(OSContextGenerator): | 954 | class SyslogContext(OSContextGenerator): |
1328 | 951 | 955 | ||
1329 | 952 | def __call__(self): | 956 | def __call__(self): |
1333 | 953 | ctxt = { | 957 | ctxt = {'use_syslog': config('use-syslog')} |
1331 | 954 | 'use_syslog': config('use-syslog') | ||
1332 | 955 | } | ||
1334 | 956 | return ctxt | 958 | return ctxt |
1335 | 957 | 959 | ||
1336 | 958 | 960 | ||
1337 | @@ -960,13 +962,9 @@ | |||
1338 | 960 | 962 | ||
1339 | 961 | def __call__(self): | 963 | def __call__(self): |
1340 | 962 | if config('prefer-ipv6'): | 964 | if config('prefer-ipv6'): |
1344 | 963 | return { | 965 | return {'bind_host': '::'} |
1342 | 964 | 'bind_host': '::' | ||
1343 | 965 | } | ||
1345 | 966 | else: | 966 | else: |
1349 | 967 | return { | 967 | return {'bind_host': '0.0.0.0'} |
1347 | 968 | 'bind_host': '0.0.0.0' | ||
1348 | 969 | } | ||
1350 | 970 | 968 | ||
1351 | 971 | 969 | ||
1352 | 972 | class WorkerConfigContext(OSContextGenerator): | 970 | class WorkerConfigContext(OSContextGenerator): |
1353 | @@ -978,13 +976,12 @@ | |||
1354 | 978 | except ImportError: | 976 | except ImportError: |
1355 | 979 | apt_install('python-psutil', fatal=True) | 977 | apt_install('python-psutil', fatal=True) |
1356 | 980 | from psutil import NUM_CPUS | 978 | from psutil import NUM_CPUS |
1357 | 979 | |||
1358 | 981 | return NUM_CPUS | 980 | return NUM_CPUS |
1359 | 982 | 981 | ||
1360 | 983 | def __call__(self): | 982 | def __call__(self): |
1365 | 984 | multiplier = config('worker-multiplier') or 1 | 983 | multiplier = config('worker-multiplier') or 0 |
1366 | 985 | ctxt = { | 984 | ctxt = {"workers": self.num_cpus * multiplier} |
1363 | 986 | "workers": self.num_cpus * multiplier | ||
1364 | 987 | } | ||
1367 | 988 | return ctxt | 985 | return ctxt |
1368 | 989 | 986 | ||
1369 | 990 | 987 | ||
1370 | @@ -998,22 +995,23 @@ | |||
1371 | 998 | for unit in related_units(rid): | 995 | for unit in related_units(rid): |
1372 | 999 | ctxt['zmq_nonce'] = relation_get('nonce', unit, rid) | 996 | ctxt['zmq_nonce'] = relation_get('nonce', unit, rid) |
1373 | 1000 | ctxt['zmq_host'] = relation_get('host', unit, rid) | 997 | ctxt['zmq_host'] = relation_get('host', unit, rid) |
1374 | 998 | |||
1375 | 1001 | return ctxt | 999 | return ctxt |
1376 | 1002 | 1000 | ||
1377 | 1003 | 1001 | ||
1378 | 1004 | class NotificationDriverContext(OSContextGenerator): | 1002 | class NotificationDriverContext(OSContextGenerator): |
1379 | 1005 | 1003 | ||
1381 | 1006 | def __init__(self, zmq_relation='zeromq-configuration', amqp_relation='amqp'): | 1004 | def __init__(self, zmq_relation='zeromq-configuration', |
1382 | 1005 | amqp_relation='amqp'): | ||
1383 | 1007 | """ | 1006 | """ |
1385 | 1008 | :param zmq_relation : Name of Zeromq relation to check | 1007 | :param zmq_relation: Name of Zeromq relation to check |
1386 | 1009 | """ | 1008 | """ |
1387 | 1010 | self.zmq_relation = zmq_relation | 1009 | self.zmq_relation = zmq_relation |
1388 | 1011 | self.amqp_relation = amqp_relation | 1010 | self.amqp_relation = amqp_relation |
1389 | 1012 | 1011 | ||
1390 | 1013 | def __call__(self): | 1012 | def __call__(self): |
1394 | 1014 | ctxt = { | 1013 | ctxt = {'notifications': 'False'} |
1392 | 1015 | 'notifications': 'False', | ||
1393 | 1016 | } | ||
1395 | 1017 | if is_relation_made(self.amqp_relation): | 1014 | if is_relation_made(self.amqp_relation): |
1396 | 1018 | ctxt['notifications'] = "True" | 1015 | ctxt['notifications'] = "True" |
1397 | 1016 | |||
1398 | 1019 | return ctxt | 1017 | return ctxt |
1399 | 1020 | 1018 | ||
1400 | === modified file 'hooks/charmhelpers/contrib/openstack/ip.py' | |||
1401 | --- hooks/charmhelpers/contrib/openstack/ip.py 2014-09-22 20:21:19 +0000 | |||
1402 | +++ hooks/charmhelpers/contrib/openstack/ip.py 2014-12-11 17:56:34 +0000 | |||
1403 | @@ -2,21 +2,19 @@ | |||
1404 | 2 | config, | 2 | config, |
1405 | 3 | unit_get, | 3 | unit_get, |
1406 | 4 | ) | 4 | ) |
1407 | 5 | |||
1408 | 6 | from charmhelpers.contrib.network.ip import ( | 5 | from charmhelpers.contrib.network.ip import ( |
1409 | 7 | get_address_in_network, | 6 | get_address_in_network, |
1410 | 8 | is_address_in_network, | 7 | is_address_in_network, |
1411 | 9 | is_ipv6, | 8 | is_ipv6, |
1412 | 10 | get_ipv6_addr, | 9 | get_ipv6_addr, |
1413 | 11 | ) | 10 | ) |
1414 | 12 | |||
1415 | 13 | from charmhelpers.contrib.hahelpers.cluster import is_clustered | 11 | from charmhelpers.contrib.hahelpers.cluster import is_clustered |
1416 | 14 | 12 | ||
1417 | 15 | PUBLIC = 'public' | 13 | PUBLIC = 'public' |
1418 | 16 | INTERNAL = 'int' | 14 | INTERNAL = 'int' |
1419 | 17 | ADMIN = 'admin' | 15 | ADMIN = 'admin' |
1420 | 18 | 16 | ||
1422 | 19 | _address_map = { | 17 | ADDRESS_MAP = { |
1423 | 20 | PUBLIC: { | 18 | PUBLIC: { |
1424 | 21 | 'config': 'os-public-network', | 19 | 'config': 'os-public-network', |
1425 | 22 | 'fallback': 'public-address' | 20 | 'fallback': 'public-address' |
1426 | @@ -33,16 +31,14 @@ | |||
1427 | 33 | 31 | ||
1428 | 34 | 32 | ||
1429 | 35 | def canonical_url(configs, endpoint_type=PUBLIC): | 33 | def canonical_url(configs, endpoint_type=PUBLIC): |
1432 | 36 | ''' | 34 | """Returns the correct HTTP URL to this host given the state of HTTPS |
1431 | 37 | Returns the correct HTTP URL to this host given the state of HTTPS | ||
1433 | 38 | configuration, hacluster and charm configuration. | 35 | configuration, hacluster and charm configuration. |
1434 | 39 | 36 | ||
1441 | 40 | :configs OSTemplateRenderer: A config tempating object to inspect for | 37 | :param configs: OSTemplateRenderer config templating object to inspect |
1442 | 41 | a complete https context. | 38 | for a complete https context. |
1443 | 42 | :endpoint_type str: The endpoint type to resolve. | 39 | :param endpoint_type: str endpoint type to resolve. |
1444 | 43 | 40 | :param returns: str base URL for services on the current service unit. | |
1445 | 44 | :returns str: Base URL for services on the current service unit. | 41 | """ |
1440 | 45 | ''' | ||
1446 | 46 | scheme = 'http' | 42 | scheme = 'http' |
1447 | 47 | if 'https' in configs.complete_contexts(): | 43 | if 'https' in configs.complete_contexts(): |
1448 | 48 | scheme = 'https' | 44 | scheme = 'https' |
1449 | @@ -53,27 +49,45 @@ | |||
1450 | 53 | 49 | ||
1451 | 54 | 50 | ||
1452 | 55 | def resolve_address(endpoint_type=PUBLIC): | 51 | def resolve_address(endpoint_type=PUBLIC): |
1453 | 52 | """Return unit address depending on net config. | ||
1454 | 53 | |||
1455 | 54 | If unit is clustered with vip(s) and has net splits defined, return vip on | ||
1456 | 55 | correct network. If clustered with no nets defined, return primary vip. | ||
1457 | 56 | |||
1458 | 57 | If not clustered, return unit address ensuring address is on configured net | ||
1459 | 58 | split if one is configured. | ||
1460 | 59 | |||
1461 | 60 | :param endpoint_type: Network endpoing type | ||
1462 | 61 | """ | ||
1463 | 56 | resolved_address = None | 62 | resolved_address = None |
1468 | 57 | if is_clustered(): | 63 | vips = config('vip') |
1469 | 58 | if config(_address_map[endpoint_type]['config']) is None: | 64 | if vips: |
1470 | 59 | # Assume vip is simple and pass back directly | 65 | vips = vips.split() |
1471 | 60 | resolved_address = config('vip') | 66 | |
1472 | 67 | net_type = ADDRESS_MAP[endpoint_type]['config'] | ||
1473 | 68 | net_addr = config(net_type) | ||
1474 | 69 | net_fallback = ADDRESS_MAP[endpoint_type]['fallback'] | ||
1475 | 70 | clustered = is_clustered() | ||
1476 | 71 | if clustered: | ||
1477 | 72 | if not net_addr: | ||
1478 | 73 | # If no net-splits defined, we expect a single vip | ||
1479 | 74 | resolved_address = vips[0] | ||
1480 | 61 | else: | 75 | else: |
1485 | 62 | for vip in config('vip').split(): | 76 | for vip in vips: |
1486 | 63 | if is_address_in_network( | 77 | if is_address_in_network(net_addr, vip): |
1483 | 64 | config(_address_map[endpoint_type]['config']), | ||
1484 | 65 | vip): | ||
1487 | 66 | resolved_address = vip | 78 | resolved_address = vip |
1488 | 79 | break | ||
1489 | 67 | else: | 80 | else: |
1490 | 68 | if config('prefer-ipv6'): | 81 | if config('prefer-ipv6'): |
1492 | 69 | fallback_addr = get_ipv6_addr(exc_list=[config('vip')])[0] | 82 | fallback_addr = get_ipv6_addr(exc_list=vips)[0] |
1493 | 70 | else: | 83 | else: |
1497 | 71 | fallback_addr = unit_get(_address_map[endpoint_type]['fallback']) | 84 | fallback_addr = unit_get(net_fallback) |
1498 | 72 | resolved_address = get_address_in_network( | 85 | |
1499 | 73 | config(_address_map[endpoint_type]['config']), fallback_addr) | 86 | resolved_address = get_address_in_network(net_addr, fallback_addr) |
1500 | 74 | 87 | ||
1501 | 75 | if resolved_address is None: | 88 | if resolved_address is None: |
1506 | 76 | raise ValueError('Unable to resolve a suitable IP address' | 89 | raise ValueError("Unable to resolve a suitable IP address based on " |
1507 | 77 | ' based on charm state and configuration') | 90 | "charm state and configuration. (net_type=%s, " |
1508 | 78 | else: | 91 | "clustered=%s)" % (net_type, clustered)) |
1509 | 79 | return resolved_address | 92 | |
1510 | 93 | return resolved_address | ||
1511 | 80 | 94 | ||
1512 | === modified file 'hooks/charmhelpers/contrib/openstack/neutron.py' | |||
1513 | --- hooks/charmhelpers/contrib/openstack/neutron.py 2014-11-13 04:44:29 +0000 | |||
1514 | +++ hooks/charmhelpers/contrib/openstack/neutron.py 2014-12-11 17:56:34 +0000 | |||
1515 | @@ -14,7 +14,7 @@ | |||
1516 | 14 | def headers_package(): | 14 | def headers_package(): |
1517 | 15 | """Ensures correct linux-headers for running kernel are installed, | 15 | """Ensures correct linux-headers for running kernel are installed, |
1518 | 16 | for building DKMS package""" | 16 | for building DKMS package""" |
1520 | 17 | kver = check_output(['uname', '-r']).strip() | 17 | kver = check_output(['uname', '-r']).decode('UTF-8').strip() |
1521 | 18 | return 'linux-headers-%s' % kver | 18 | return 'linux-headers-%s' % kver |
1522 | 19 | 19 | ||
1523 | 20 | QUANTUM_CONF_DIR = '/etc/quantum' | 20 | QUANTUM_CONF_DIR = '/etc/quantum' |
1524 | @@ -22,7 +22,7 @@ | |||
1525 | 22 | 22 | ||
1526 | 23 | def kernel_version(): | 23 | def kernel_version(): |
1527 | 24 | """ Retrieve the current major kernel version as a tuple e.g. (3, 13) """ | 24 | """ Retrieve the current major kernel version as a tuple e.g. (3, 13) """ |
1529 | 25 | kver = check_output(['uname', '-r']).strip() | 25 | kver = check_output(['uname', '-r']).decode('UTF-8').strip() |
1530 | 26 | kver = kver.split('.') | 26 | kver = kver.split('.') |
1531 | 27 | return (int(kver[0]), int(kver[1])) | 27 | return (int(kver[0]), int(kver[1])) |
1532 | 28 | 28 | ||
1533 | @@ -177,7 +177,8 @@ | |||
1534 | 177 | elif manager == 'neutron': | 177 | elif manager == 'neutron': |
1535 | 178 | plugins = neutron_plugins() | 178 | plugins = neutron_plugins() |
1536 | 179 | else: | 179 | else: |
1538 | 180 | log('Error: Network manager does not support plugins.') | 180 | log("Network manager '%s' does not support plugins." % (manager), |
1539 | 181 | level=ERROR) | ||
1540 | 181 | raise Exception | 182 | raise Exception |
1541 | 182 | 183 | ||
1542 | 183 | try: | 184 | try: |
1543 | 184 | 185 | ||
1544 | === modified file 'hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg' | |||
1545 | --- hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg 2014-10-06 20:51:06 +0000 | |||
1546 | +++ hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg 2014-12-11 17:56:34 +0000 | |||
1547 | @@ -35,7 +35,7 @@ | |||
1548 | 35 | stats auth admin:password | 35 | stats auth admin:password |
1549 | 36 | 36 | ||
1550 | 37 | {% if frontends -%} | 37 | {% if frontends -%} |
1552 | 38 | {% for service, ports in service_ports.iteritems() -%} | 38 | {% for service, ports in service_ports.items() -%} |
1553 | 39 | frontend tcp-in_{{ service }} | 39 | frontend tcp-in_{{ service }} |
1554 | 40 | bind *:{{ ports[0] }} | 40 | bind *:{{ ports[0] }} |
1555 | 41 | bind :::{{ ports[0] }} | 41 | bind :::{{ ports[0] }} |
1556 | @@ -46,7 +46,7 @@ | |||
1557 | 46 | {% for frontend in frontends -%} | 46 | {% for frontend in frontends -%} |
1558 | 47 | backend {{ service }}_{{ frontend }} | 47 | backend {{ service }}_{{ frontend }} |
1559 | 48 | balance leastconn | 48 | balance leastconn |
1561 | 49 | {% for unit, address in frontends[frontend]['backends'].iteritems() -%} | 49 | {% for unit, address in frontends[frontend]['backends'].items() -%} |
1562 | 50 | server {{ unit }} {{ address }}:{{ ports[1] }} check | 50 | server {{ unit }} {{ address }}:{{ ports[1] }} check |
1563 | 51 | {% endfor %} | 51 | {% endfor %} |
1564 | 52 | {% endfor -%} | 52 | {% endfor -%} |
1565 | 53 | 53 | ||
1566 | === modified file 'hooks/charmhelpers/contrib/openstack/templating.py' | |||
1567 | --- hooks/charmhelpers/contrib/openstack/templating.py 2014-07-25 08:13:49 +0000 | |||
1568 | +++ hooks/charmhelpers/contrib/openstack/templating.py 2014-12-11 17:56:34 +0000 | |||
1569 | @@ -1,13 +1,13 @@ | |||
1570 | 1 | import os | 1 | import os |
1571 | 2 | 2 | ||
1572 | 3 | import six | ||
1573 | 4 | |||
1574 | 3 | from charmhelpers.fetch import apt_install | 5 | from charmhelpers.fetch import apt_install |
1575 | 4 | |||
1576 | 5 | from charmhelpers.core.hookenv import ( | 6 | from charmhelpers.core.hookenv import ( |
1577 | 6 | log, | 7 | log, |
1578 | 7 | ERROR, | 8 | ERROR, |
1579 | 8 | INFO | 9 | INFO |
1580 | 9 | ) | 10 | ) |
1581 | 10 | |||
1582 | 11 | from charmhelpers.contrib.openstack.utils import OPENSTACK_CODENAMES | 11 | from charmhelpers.contrib.openstack.utils import OPENSTACK_CODENAMES |
1583 | 12 | 12 | ||
1584 | 13 | try: | 13 | try: |
1585 | @@ -43,7 +43,7 @@ | |||
1586 | 43 | order by OpenStack release. | 43 | order by OpenStack release. |
1587 | 44 | """ | 44 | """ |
1588 | 45 | tmpl_dirs = [(rel, os.path.join(templates_dir, rel)) | 45 | tmpl_dirs = [(rel, os.path.join(templates_dir, rel)) |
1590 | 46 | for rel in OPENSTACK_CODENAMES.itervalues()] | 46 | for rel in six.itervalues(OPENSTACK_CODENAMES)] |
1591 | 47 | 47 | ||
1592 | 48 | if not os.path.isdir(templates_dir): | 48 | if not os.path.isdir(templates_dir): |
1593 | 49 | log('Templates directory not found @ %s.' % templates_dir, | 49 | log('Templates directory not found @ %s.' % templates_dir, |
1594 | @@ -258,7 +258,7 @@ | |||
1595 | 258 | """ | 258 | """ |
1596 | 259 | Write out all registered config files. | 259 | Write out all registered config files. |
1597 | 260 | """ | 260 | """ |
1599 | 261 | [self.write(k) for k in self.templates.iterkeys()] | 261 | [self.write(k) for k in six.iterkeys(self.templates)] |
1600 | 262 | 262 | ||
1601 | 263 | def set_release(self, openstack_release): | 263 | def set_release(self, openstack_release): |
1602 | 264 | """ | 264 | """ |
1603 | @@ -275,5 +275,5 @@ | |||
1604 | 275 | ''' | 275 | ''' |
1605 | 276 | interfaces = [] | 276 | interfaces = [] |
1606 | 277 | [interfaces.extend(i.complete_contexts()) | 277 | [interfaces.extend(i.complete_contexts()) |
1608 | 278 | for i in self.templates.itervalues()] | 278 | for i in six.itervalues(self.templates)] |
1609 | 279 | return interfaces | 279 | return interfaces |
1610 | 280 | 280 | ||
1611 | === modified file 'hooks/charmhelpers/contrib/openstack/utils.py' | |||
1612 | --- hooks/charmhelpers/contrib/openstack/utils.py 2014-10-24 11:36:12 +0000 | |||
1613 | +++ hooks/charmhelpers/contrib/openstack/utils.py 2014-12-11 17:56:34 +0000 | |||
1614 | @@ -10,11 +10,13 @@ | |||
1615 | 10 | import socket | 10 | import socket |
1616 | 11 | import sys | 11 | import sys |
1617 | 12 | 12 | ||
1618 | 13 | import six | ||
1619 | 14 | import yaml | ||
1620 | 15 | |||
1621 | 13 | from charmhelpers.core.hookenv import ( | 16 | from charmhelpers.core.hookenv import ( |
1622 | 14 | config, | 17 | config, |
1623 | 15 | log as juju_log, | 18 | log as juju_log, |
1624 | 16 | charm_dir, | 19 | charm_dir, |
1625 | 17 | ERROR, | ||
1626 | 18 | INFO, | 20 | INFO, |
1627 | 19 | relation_ids, | 21 | relation_ids, |
1628 | 20 | relation_set | 22 | relation_set |
1629 | @@ -31,7 +33,8 @@ | |||
1630 | 31 | ) | 33 | ) |
1631 | 32 | 34 | ||
1632 | 33 | from charmhelpers.core.host import lsb_release, mounts, umount | 35 | from charmhelpers.core.host import lsb_release, mounts, umount |
1634 | 34 | from charmhelpers.fetch import apt_install, apt_cache | 36 | from charmhelpers.fetch import apt_install, apt_cache, install_remote |
1635 | 37 | from charmhelpers.contrib.python.packages import pip_install | ||
1636 | 35 | from charmhelpers.contrib.storage.linux.utils import is_block_device, zap_disk | 38 | from charmhelpers.contrib.storage.linux.utils import is_block_device, zap_disk |
1637 | 36 | from charmhelpers.contrib.storage.linux.loopback import ensure_loopback_device | 39 | from charmhelpers.contrib.storage.linux.loopback import ensure_loopback_device |
1638 | 37 | 40 | ||
1639 | @@ -113,7 +116,7 @@ | |||
1640 | 113 | 116 | ||
1641 | 114 | # Best guess match based on deb string provided | 117 | # Best guess match based on deb string provided |
1642 | 115 | if src.startswith('deb') or src.startswith('ppa'): | 118 | if src.startswith('deb') or src.startswith('ppa'): |
1644 | 116 | for k, v in OPENSTACK_CODENAMES.iteritems(): | 119 | for k, v in six.iteritems(OPENSTACK_CODENAMES): |
1645 | 117 | if v in src: | 120 | if v in src: |
1646 | 118 | return v | 121 | return v |
1647 | 119 | 122 | ||
1648 | @@ -134,7 +137,7 @@ | |||
1649 | 134 | 137 | ||
1650 | 135 | def get_os_version_codename(codename): | 138 | def get_os_version_codename(codename): |
1651 | 136 | '''Determine OpenStack version number from codename.''' | 139 | '''Determine OpenStack version number from codename.''' |
1653 | 137 | for k, v in OPENSTACK_CODENAMES.iteritems(): | 140 | for k, v in six.iteritems(OPENSTACK_CODENAMES): |
1654 | 138 | if v == codename: | 141 | if v == codename: |
1655 | 139 | return k | 142 | return k |
1656 | 140 | e = 'Could not derive OpenStack version for '\ | 143 | e = 'Could not derive OpenStack version for '\ |
1657 | @@ -194,7 +197,7 @@ | |||
1658 | 194 | else: | 197 | else: |
1659 | 195 | vers_map = OPENSTACK_CODENAMES | 198 | vers_map = OPENSTACK_CODENAMES |
1660 | 196 | 199 | ||
1662 | 197 | for version, cname in vers_map.iteritems(): | 200 | for version, cname in six.iteritems(vers_map): |
1663 | 198 | if cname == codename: | 201 | if cname == codename: |
1664 | 199 | return version | 202 | return version |
1665 | 200 | # e = "Could not determine OpenStack version for package: %s" % pkg | 203 | # e = "Could not determine OpenStack version for package: %s" % pkg |
1666 | @@ -318,7 +321,7 @@ | |||
1667 | 318 | rc_script.write( | 321 | rc_script.write( |
1668 | 319 | "#!/bin/bash\n") | 322 | "#!/bin/bash\n") |
1669 | 320 | [rc_script.write('export %s=%s\n' % (u, p)) | 323 | [rc_script.write('export %s=%s\n' % (u, p)) |
1671 | 321 | for u, p in env_vars.iteritems() if u != "script_path"] | 324 | for u, p in six.iteritems(env_vars) if u != "script_path"] |
1672 | 322 | 325 | ||
1673 | 323 | 326 | ||
1674 | 324 | def openstack_upgrade_available(package): | 327 | def openstack_upgrade_available(package): |
1675 | @@ -351,8 +354,8 @@ | |||
1676 | 351 | ''' | 354 | ''' |
1677 | 352 | _none = ['None', 'none', None] | 355 | _none = ['None', 'none', None] |
1678 | 353 | if (block_device in _none): | 356 | if (block_device in _none): |
1681 | 354 | error_out('prepare_storage(): Missing required input: ' | 357 | error_out('prepare_storage(): Missing required input: block_device=%s.' |
1682 | 355 | 'block_device=%s.' % block_device, level=ERROR) | 358 | % block_device) |
1683 | 356 | 359 | ||
1684 | 357 | if block_device.startswith('/dev/'): | 360 | if block_device.startswith('/dev/'): |
1685 | 358 | bdev = block_device | 361 | bdev = block_device |
1686 | @@ -368,8 +371,7 @@ | |||
1687 | 368 | bdev = '/dev/%s' % block_device | 371 | bdev = '/dev/%s' % block_device |
1688 | 369 | 372 | ||
1689 | 370 | if not is_block_device(bdev): | 373 | if not is_block_device(bdev): |
1692 | 371 | error_out('Failed to locate valid block device at %s' % bdev, | 374 | error_out('Failed to locate valid block device at %s' % bdev) |
1691 | 372 | level=ERROR) | ||
1693 | 373 | 375 | ||
1694 | 374 | return bdev | 376 | return bdev |
1695 | 375 | 377 | ||
1696 | @@ -418,7 +420,7 @@ | |||
1697 | 418 | 420 | ||
1698 | 419 | if isinstance(address, dns.name.Name): | 421 | if isinstance(address, dns.name.Name): |
1699 | 420 | rtype = 'PTR' | 422 | rtype = 'PTR' |
1701 | 421 | elif isinstance(address, basestring): | 423 | elif isinstance(address, six.string_types): |
1702 | 422 | rtype = 'A' | 424 | rtype = 'A' |
1703 | 423 | else: | 425 | else: |
1704 | 424 | return None | 426 | return None |
1705 | @@ -486,8 +488,7 @@ | |||
1706 | 486 | 'hostname': json.dumps(hosts)} | 488 | 'hostname': json.dumps(hosts)} |
1707 | 487 | 489 | ||
1708 | 488 | if relation_prefix: | 490 | if relation_prefix: |
1711 | 489 | keys = kwargs.keys() | 491 | for key in list(kwargs.keys()): |
1710 | 490 | for key in keys: | ||
1712 | 491 | kwargs["%s_%s" % (relation_prefix, key)] = kwargs[key] | 492 | kwargs["%s_%s" % (relation_prefix, key)] = kwargs[key] |
1713 | 492 | del kwargs[key] | 493 | del kwargs[key] |
1714 | 493 | 494 | ||
1715 | @@ -508,3 +509,111 @@ | |||
1716 | 508 | f(*args) | 509 | f(*args) |
1717 | 509 | return wrapped_f | 510 | return wrapped_f |
1718 | 510 | return wrap | 511 | return wrap |
1719 | 512 | |||
1720 | 513 | |||
1721 | 514 | def git_install_requested(): | ||
1722 | 515 | """Returns true if openstack-origin-git is specified.""" | ||
1723 | 516 | return config('openstack-origin-git') != "None" | ||
1724 | 517 | |||
1725 | 518 | |||
1726 | 519 | requirements_dir = None | ||
1727 | 520 | |||
1728 | 521 | |||
1729 | 522 | def git_clone_and_install(file_name, core_project): | ||
1730 | 523 | """Clone/install all OpenStack repos specified in yaml config file.""" | ||
1731 | 524 | global requirements_dir | ||
1732 | 525 | |||
1733 | 526 | if file_name == "None": | ||
1734 | 527 | return | ||
1735 | 528 | |||
1736 | 529 | yaml_file = os.path.join(charm_dir(), file_name) | ||
1737 | 530 | |||
1738 | 531 | # clone/install the requirements project first | ||
1739 | 532 | installed = _git_clone_and_install_subset(yaml_file, | ||
1740 | 533 | whitelist=['requirements']) | ||
1741 | 534 | if 'requirements' not in installed: | ||
1742 | 535 | error_out('requirements git repository must be specified') | ||
1743 | 536 | |||
1744 | 537 | # clone/install all other projects except requirements and the core project | ||
1745 | 538 | blacklist = ['requirements', core_project] | ||
1746 | 539 | _git_clone_and_install_subset(yaml_file, blacklist=blacklist, | ||
1747 | 540 | update_requirements=True) | ||
1748 | 541 | |||
1749 | 542 | # clone/install the core project | ||
1750 | 543 | whitelist = [core_project] | ||
1751 | 544 | installed = _git_clone_and_install_subset(yaml_file, whitelist=whitelist, | ||
1752 | 545 | update_requirements=True) | ||
1753 | 546 | if core_project not in installed: | ||
1754 | 547 | error_out('{} git repository must be specified'.format(core_project)) | ||
1755 | 548 | |||
1756 | 549 | |||
1757 | 550 | def _git_clone_and_install_subset(yaml_file, whitelist=[], blacklist=[], | ||
1758 | 551 | update_requirements=False): | ||
1759 | 552 | """Clone/install subset of OpenStack repos specified in yaml config file.""" | ||
1760 | 553 | global requirements_dir | ||
1761 | 554 | installed = [] | ||
1762 | 555 | |||
1763 | 556 | with open(yaml_file, 'r') as fd: | ||
1764 | 557 | projects = yaml.load(fd) | ||
1765 | 558 | for proj, val in projects.items(): | ||
1766 | 559 | # The project subset is chosen based on the following 3 rules: | ||
1767 | 560 | # 1) If project is in blacklist, we don't clone/install it, period. | ||
1768 | 561 | # 2) If whitelist is empty, we clone/install everything else. | ||
1769 | 562 | # 3) If whitelist is not empty, we clone/install everything in the | ||
1770 | 563 | # whitelist. | ||
1771 | 564 | if proj in blacklist: | ||
1772 | 565 | continue | ||
1773 | 566 | if whitelist and proj not in whitelist: | ||
1774 | 567 | continue | ||
1775 | 568 | repo = val['repository'] | ||
1776 | 569 | branch = val['branch'] | ||
1777 | 570 | repo_dir = _git_clone_and_install_single(repo, branch, | ||
1778 | 571 | update_requirements) | ||
1779 | 572 | if proj == 'requirements': | ||
1780 | 573 | requirements_dir = repo_dir | ||
1781 | 574 | installed.append(proj) | ||
1782 | 575 | return installed | ||
1783 | 576 | |||
1784 | 577 | |||
1785 | 578 | def _git_clone_and_install_single(repo, branch, update_requirements=False): | ||
1786 | 579 | """Clone and install a single git repository.""" | ||
1787 | 580 | dest_parent_dir = "/mnt/openstack-git/" | ||
1788 | 581 | dest_dir = os.path.join(dest_parent_dir, os.path.basename(repo)) | ||
1789 | 582 | |||
1790 | 583 | if not os.path.exists(dest_parent_dir): | ||
1791 | 584 | juju_log('Host dir not mounted at {}. ' | ||
1792 | 585 | 'Creating directory there instead.'.format(dest_parent_dir)) | ||
1793 | 586 | os.mkdir(dest_parent_dir) | ||
1794 | 587 | |||
1795 | 588 | if not os.path.exists(dest_dir): | ||
1796 | 589 | juju_log('Cloning git repo: {}, branch: {}'.format(repo, branch)) | ||
1797 | 590 | repo_dir = install_remote(repo, dest=dest_parent_dir, branch=branch) | ||
1798 | 591 | else: | ||
1799 | 592 | repo_dir = dest_dir | ||
1800 | 593 | |||
1801 | 594 | if update_requirements: | ||
1802 | 595 | if not requirements_dir: | ||
1803 | 596 | error_out('requirements repo must be cloned before ' | ||
1804 | 597 | 'updating from global requirements.') | ||
1805 | 598 | _git_update_requirements(repo_dir, requirements_dir) | ||
1806 | 599 | |||
1807 | 600 | juju_log('Installing git repo from dir: {}'.format(repo_dir)) | ||
1808 | 601 | pip_install(repo_dir) | ||
1809 | 602 | |||
1810 | 603 | return repo_dir | ||
1811 | 604 | |||
1812 | 605 | |||
1813 | 606 | def _git_update_requirements(package_dir, reqs_dir): | ||
1814 | 607 | """Update from global requirements. | ||
1815 | 608 | |||
1816 | 609 | Update an OpenStack git directory's requirements.txt and | ||
1817 | 610 | test-requirements.txt from global-requirements.txt.""" | ||
1818 | 611 | orig_dir = os.getcwd() | ||
1819 | 612 | os.chdir(reqs_dir) | ||
1820 | 613 | cmd = "python update.py {}".format(package_dir) | ||
1821 | 614 | try: | ||
1822 | 615 | subprocess.check_call(cmd.split(' ')) | ||
1823 | 616 | except subprocess.CalledProcessError: | ||
1824 | 617 | package = os.path.basename(package_dir) | ||
1825 | 618 | error_out("Error updating {} from global-requirements.txt".format(package)) | ||
1826 | 619 | os.chdir(orig_dir) | ||
1827 | 511 | 620 | ||
1828 | === modified file 'hooks/charmhelpers/contrib/peerstorage/__init__.py' | |||
1829 | --- hooks/charmhelpers/contrib/peerstorage/__init__.py 2014-10-06 20:53:09 +0000 | |||
1830 | +++ hooks/charmhelpers/contrib/peerstorage/__init__.py 2014-12-11 17:56:34 +0000 | |||
1831 | @@ -1,3 +1,4 @@ | |||
1832 | 1 | import six | ||
1833 | 1 | from charmhelpers.core.hookenv import relation_id as current_relation_id | 2 | from charmhelpers.core.hookenv import relation_id as current_relation_id |
1834 | 2 | from charmhelpers.core.hookenv import ( | 3 | from charmhelpers.core.hookenv import ( |
1835 | 3 | is_relation_made, | 4 | is_relation_made, |
1836 | @@ -93,7 +94,7 @@ | |||
1837 | 93 | if ex in echo_data: | 94 | if ex in echo_data: |
1838 | 94 | echo_data.pop(ex) | 95 | echo_data.pop(ex) |
1839 | 95 | else: | 96 | else: |
1841 | 96 | for attribute, value in rdata.iteritems(): | 97 | for attribute, value in six.iteritems(rdata): |
1842 | 97 | for include in includes: | 98 | for include in includes: |
1843 | 98 | if include in attribute: | 99 | if include in attribute: |
1844 | 99 | echo_data[attribute] = value | 100 | echo_data[attribute] = value |
1845 | @@ -119,8 +120,8 @@ | |||
1846 | 119 | relation_settings=relation_settings, | 120 | relation_settings=relation_settings, |
1847 | 120 | **kwargs) | 121 | **kwargs) |
1848 | 121 | if is_relation_made(peer_relation_name): | 122 | if is_relation_made(peer_relation_name): |
1851 | 122 | for key, value in dict(kwargs.items() + | 123 | for key, value in six.iteritems(dict(list(kwargs.items()) + |
1852 | 123 | relation_settings.items()).iteritems(): | 124 | list(relation_settings.items()))): |
1853 | 124 | key_prefix = relation_id or current_relation_id() | 125 | key_prefix = relation_id or current_relation_id() |
1854 | 125 | peer_store(key_prefix + delimiter + key, | 126 | peer_store(key_prefix + delimiter + key, |
1855 | 126 | value, | 127 | value, |
1856 | 127 | 128 | ||
1857 | === added directory 'hooks/charmhelpers/contrib/python' | |||
1858 | === added file 'hooks/charmhelpers/contrib/python/__init__.py' | |||
1859 | === added file 'hooks/charmhelpers/contrib/python/packages.py' | |||
1860 | --- hooks/charmhelpers/contrib/python/packages.py 1970-01-01 00:00:00 +0000 | |||
1861 | +++ hooks/charmhelpers/contrib/python/packages.py 2014-12-11 17:56:34 +0000 | |||
1862 | @@ -0,0 +1,77 @@ | |||
1863 | 1 | #!/usr/bin/env python | ||
1864 | 2 | # coding: utf-8 | ||
1865 | 3 | |||
1866 | 4 | __author__ = "Jorge Niedbalski <jorge.niedbalski@canonical.com>" | ||
1867 | 5 | |||
1868 | 6 | from charmhelpers.fetch import apt_install, apt_update | ||
1869 | 7 | from charmhelpers.core.hookenv import log | ||
1870 | 8 | |||
1871 | 9 | try: | ||
1872 | 10 | from pip import main as pip_execute | ||
1873 | 11 | except ImportError: | ||
1874 | 12 | apt_update() | ||
1875 | 13 | apt_install('python-pip') | ||
1876 | 14 | from pip import main as pip_execute | ||
1877 | 15 | |||
1878 | 16 | |||
1879 | 17 | def parse_options(given, available): | ||
1880 | 18 | """Given a set of options, check if available""" | ||
1881 | 19 | for key, value in sorted(given.items()): | ||
1882 | 20 | if key in available: | ||
1883 | 21 | yield "--{0}={1}".format(key, value) | ||
1884 | 22 | |||
1885 | 23 | |||
1886 | 24 | def pip_install_requirements(requirements, **options): | ||
1887 | 25 | """Install a requirements file """ | ||
1888 | 26 | command = ["install"] | ||
1889 | 27 | |||
1890 | 28 | available_options = ('proxy', 'src', 'log', ) | ||
1891 | 29 | for option in parse_options(options, available_options): | ||
1892 | 30 | command.append(option) | ||
1893 | 31 | |||
1894 | 32 | command.append("-r {0}".format(requirements)) | ||
1895 | 33 | log("Installing from file: {} with options: {}".format(requirements, | ||
1896 | 34 | command)) | ||
1897 | 35 | pip_execute(command) | ||
1898 | 36 | |||
1899 | 37 | |||
1900 | 38 | def pip_install(package, fatal=False, **options): | ||
1901 | 39 | """Install a python package""" | ||
1902 | 40 | command = ["install"] | ||
1903 | 41 | |||
1904 | 42 | available_options = ('proxy', 'src', 'log', "index-url", ) | ||
1905 | 43 | for option in parse_options(options, available_options): | ||
1906 | 44 | command.append(option) | ||
1907 | 45 | |||
1908 | 46 | if isinstance(package, list): | ||
1909 | 47 | command.extend(package) | ||
1910 | 48 | else: | ||
1911 | 49 | command.append(package) | ||
1912 | 50 | |||
1913 | 51 | log("Installing {} package with options: {}".format(package, | ||
1914 | 52 | command)) | ||
1915 | 53 | pip_execute(command) | ||
1916 | 54 | |||
1917 | 55 | |||
1918 | 56 | def pip_uninstall(package, **options): | ||
1919 | 57 | """Uninstall a python package""" | ||
1920 | 58 | command = ["uninstall", "-q", "-y"] | ||
1921 | 59 | |||
1922 | 60 | available_options = ('proxy', 'log', ) | ||
1923 | 61 | for option in parse_options(options, available_options): | ||
1924 | 62 | command.append(option) | ||
1925 | 63 | |||
1926 | 64 | if isinstance(package, list): | ||
1927 | 65 | command.extend(package) | ||
1928 | 66 | else: | ||
1929 | 67 | command.append(package) | ||
1930 | 68 | |||
1931 | 69 | log("Uninstalling {} package with options: {}".format(package, | ||
1932 | 70 | command)) | ||
1933 | 71 | pip_execute(command) | ||
1934 | 72 | |||
1935 | 73 | |||
1936 | 74 | def pip_list(): | ||
1937 | 75 | """Returns the list of current python installed packages | ||
1938 | 76 | """ | ||
1939 | 77 | return pip_execute(["list"]) | ||
1940 | 0 | 78 | ||
1941 | === modified file 'hooks/charmhelpers/contrib/storage/linux/ceph.py' | |||
1942 | --- hooks/charmhelpers/contrib/storage/linux/ceph.py 2014-10-24 11:36:12 +0000 | |||
1943 | +++ hooks/charmhelpers/contrib/storage/linux/ceph.py 2014-12-11 17:56:34 +0000 | |||
1944 | @@ -16,19 +16,18 @@ | |||
1945 | 16 | from subprocess import ( | 16 | from subprocess import ( |
1946 | 17 | check_call, | 17 | check_call, |
1947 | 18 | check_output, | 18 | check_output, |
1949 | 19 | CalledProcessError | 19 | CalledProcessError, |
1950 | 20 | ) | 20 | ) |
1951 | 21 | |||
1952 | 22 | from charmhelpers.core.hookenv import ( | 21 | from charmhelpers.core.hookenv import ( |
1953 | 23 | relation_get, | 22 | relation_get, |
1954 | 24 | relation_ids, | 23 | relation_ids, |
1955 | 25 | related_units, | 24 | related_units, |
1956 | 26 | log, | 25 | log, |
1957 | 26 | DEBUG, | ||
1958 | 27 | INFO, | 27 | INFO, |
1959 | 28 | WARNING, | 28 | WARNING, |
1961 | 29 | ERROR | 29 | ERROR, |
1962 | 30 | ) | 30 | ) |
1963 | 31 | |||
1964 | 32 | from charmhelpers.core.host import ( | 31 | from charmhelpers.core.host import ( |
1965 | 33 | mount, | 32 | mount, |
1966 | 34 | mounts, | 33 | mounts, |
1967 | @@ -37,7 +36,6 @@ | |||
1968 | 37 | service_running, | 36 | service_running, |
1969 | 38 | umount, | 37 | umount, |
1970 | 39 | ) | 38 | ) |
1971 | 40 | |||
1972 | 41 | from charmhelpers.fetch import ( | 39 | from charmhelpers.fetch import ( |
1973 | 42 | apt_install, | 40 | apt_install, |
1974 | 43 | ) | 41 | ) |
1975 | @@ -56,99 +54,85 @@ | |||
1976 | 56 | 54 | ||
1977 | 57 | 55 | ||
1978 | 58 | def install(): | 56 | def install(): |
1980 | 59 | ''' Basic Ceph client installation ''' | 57 | """Basic Ceph client installation.""" |
1981 | 60 | ceph_dir = "/etc/ceph" | 58 | ceph_dir = "/etc/ceph" |
1982 | 61 | if not os.path.exists(ceph_dir): | 59 | if not os.path.exists(ceph_dir): |
1983 | 62 | os.mkdir(ceph_dir) | 60 | os.mkdir(ceph_dir) |
1984 | 61 | |||
1985 | 63 | apt_install('ceph-common', fatal=True) | 62 | apt_install('ceph-common', fatal=True) |
1986 | 64 | 63 | ||
1987 | 65 | 64 | ||
1988 | 66 | def rbd_exists(service, pool, rbd_img): | 65 | def rbd_exists(service, pool, rbd_img): |
1990 | 67 | ''' Check to see if a RADOS block device exists ''' | 66 | """Check to see if a RADOS block device exists.""" |
1991 | 68 | try: | 67 | try: |
1994 | 69 | out = check_output(['rbd', 'list', '--id', service, | 68 | out = check_output(['rbd', 'list', '--id', |
1995 | 70 | '--pool', pool]) | 69 | service, '--pool', pool]).decode('UTF-8') |
1996 | 71 | except CalledProcessError: | 70 | except CalledProcessError: |
1997 | 72 | return False | 71 | return False |
2000 | 73 | else: | 72 | |
2001 | 74 | return rbd_img in out | 73 | return rbd_img in out |
2002 | 75 | 74 | ||
2003 | 76 | 75 | ||
2004 | 77 | def create_rbd_image(service, pool, image, sizemb): | 76 | def create_rbd_image(service, pool, image, sizemb): |
2017 | 78 | ''' Create a new RADOS block device ''' | 77 | """Create a new RADOS block device.""" |
2018 | 79 | cmd = [ | 78 | cmd = ['rbd', 'create', image, '--size', str(sizemb), '--id', service, |
2019 | 80 | 'rbd', | 79 | '--pool', pool] |
2008 | 81 | 'create', | ||
2009 | 82 | image, | ||
2010 | 83 | '--size', | ||
2011 | 84 | str(sizemb), | ||
2012 | 85 | '--id', | ||
2013 | 86 | service, | ||
2014 | 87 | '--pool', | ||
2015 | 88 | pool | ||
2016 | 89 | ] | ||
2020 | 90 | check_call(cmd) | 80 | check_call(cmd) |
2021 | 91 | 81 | ||
2022 | 92 | 82 | ||
2023 | 93 | def pool_exists(service, name): | 83 | def pool_exists(service, name): |
2025 | 94 | ''' Check to see if a RADOS pool already exists ''' | 84 | """Check to see if a RADOS pool already exists.""" |
2026 | 95 | try: | 85 | try: |
2028 | 96 | out = check_output(['rados', '--id', service, 'lspools']) | 86 | out = check_output(['rados', '--id', service, |
2029 | 87 | 'lspools']).decode('UTF-8') | ||
2030 | 97 | except CalledProcessError: | 88 | except CalledProcessError: |
2031 | 98 | return False | 89 | return False |
2034 | 99 | else: | 90 | |
2035 | 100 | return name in out | 91 | return name in out |
2036 | 101 | 92 | ||
2037 | 102 | 93 | ||
2038 | 103 | def get_osds(service): | 94 | def get_osds(service): |
2043 | 104 | ''' | 95 | """Return a list of all Ceph Object Storage Daemons currently in the |
2044 | 105 | Return a list of all Ceph Object Storage Daemons | 96 | cluster. |
2045 | 106 | currently in the cluster | 97 | """ |
2042 | 107 | ''' | ||
2046 | 108 | version = ceph_version() | 98 | version = ceph_version() |
2047 | 109 | if version and version >= '0.56': | 99 | if version and version >= '0.56': |
2048 | 110 | return json.loads(check_output(['ceph', '--id', service, | 100 | return json.loads(check_output(['ceph', '--id', service, |
2052 | 111 | 'osd', 'ls', '--format=json'])) | 101 | 'osd', 'ls', |
2053 | 112 | else: | 102 | '--format=json']).decode('UTF-8')) |
2054 | 113 | return None | 103 | |
2055 | 104 | return None | ||
2056 | 114 | 105 | ||
2057 | 115 | 106 | ||
2058 | 116 | def create_pool(service, name, replicas=3): | 107 | def create_pool(service, name, replicas=3): |
2060 | 117 | ''' Create a new RADOS pool ''' | 108 | """Create a new RADOS pool.""" |
2061 | 118 | if pool_exists(service, name): | 109 | if pool_exists(service, name): |
2062 | 119 | log("Ceph pool {} already exists, skipping creation".format(name), | 110 | log("Ceph pool {} already exists, skipping creation".format(name), |
2063 | 120 | level=WARNING) | 111 | level=WARNING) |
2064 | 121 | return | 112 | return |
2065 | 113 | |||
2066 | 122 | # Calculate the number of placement groups based | 114 | # Calculate the number of placement groups based |
2067 | 123 | # on upstream recommended best practices. | 115 | # on upstream recommended best practices. |
2068 | 124 | osds = get_osds(service) | 116 | osds = get_osds(service) |
2069 | 125 | if osds: | 117 | if osds: |
2071 | 126 | pgnum = (len(osds) * 100 / replicas) | 118 | pgnum = (len(osds) * 100 // replicas) |
2072 | 127 | else: | 119 | else: |
2073 | 128 | # NOTE(james-page): Default to 200 for older ceph versions | 120 | # NOTE(james-page): Default to 200 for older ceph versions |
2074 | 129 | # which don't support OSD query from cli | 121 | # which don't support OSD query from cli |
2075 | 130 | pgnum = 200 | 122 | pgnum = 200 |
2081 | 131 | cmd = [ | 123 | |
2082 | 132 | 'ceph', '--id', service, | 124 | cmd = ['ceph', '--id', service, 'osd', 'pool', 'create', name, str(pgnum)] |
2078 | 133 | 'osd', 'pool', 'create', | ||
2079 | 134 | name, str(pgnum) | ||
2080 | 135 | ] | ||
2083 | 136 | check_call(cmd) | 125 | check_call(cmd) |
2089 | 137 | cmd = [ | 126 | |
2090 | 138 | 'ceph', '--id', service, | 127 | cmd = ['ceph', '--id', service, 'osd', 'pool', 'set', name, 'size', |
2091 | 139 | 'osd', 'pool', 'set', name, | 128 | str(replicas)] |
2087 | 140 | 'size', str(replicas) | ||
2088 | 141 | ] | ||
2092 | 142 | check_call(cmd) | 129 | check_call(cmd) |
2093 | 143 | 130 | ||
2094 | 144 | 131 | ||
2095 | 145 | def delete_pool(service, name): | 132 | def delete_pool(service, name): |
2102 | 146 | ''' Delete a RADOS pool from ceph ''' | 133 | """Delete a RADOS pool from ceph.""" |
2103 | 147 | cmd = [ | 134 | cmd = ['ceph', '--id', service, 'osd', 'pool', 'delete', name, |
2104 | 148 | 'ceph', '--id', service, | 135 | '--yes-i-really-really-mean-it'] |
2099 | 149 | 'osd', 'pool', 'delete', | ||
2100 | 150 | name, '--yes-i-really-really-mean-it' | ||
2101 | 151 | ] | ||
2105 | 152 | check_call(cmd) | 136 | check_call(cmd) |
2106 | 153 | 137 | ||
2107 | 154 | 138 | ||
2108 | @@ -161,44 +145,43 @@ | |||
2109 | 161 | 145 | ||
2110 | 162 | 146 | ||
2111 | 163 | def create_keyring(service, key): | 147 | def create_keyring(service, key): |
2113 | 164 | ''' Create a new Ceph keyring containing key''' | 148 | """Create a new Ceph keyring containing key.""" |
2114 | 165 | keyring = _keyring_path(service) | 149 | keyring = _keyring_path(service) |
2115 | 166 | if os.path.exists(keyring): | 150 | if os.path.exists(keyring): |
2117 | 167 | log('ceph: Keyring exists at %s.' % keyring, level=WARNING) | 151 | log('Ceph keyring exists at %s.' % keyring, level=WARNING) |
2118 | 168 | return | 152 | return |
2126 | 169 | cmd = [ | 153 | |
2127 | 170 | 'ceph-authtool', | 154 | cmd = ['ceph-authtool', keyring, '--create-keyring', |
2128 | 171 | keyring, | 155 | '--name=client.{}'.format(service), '--add-key={}'.format(key)] |
2122 | 172 | '--create-keyring', | ||
2123 | 173 | '--name=client.{}'.format(service), | ||
2124 | 174 | '--add-key={}'.format(key) | ||
2125 | 175 | ] | ||
2129 | 176 | check_call(cmd) | 156 | check_call(cmd) |
2131 | 177 | log('ceph: Created new ring at %s.' % keyring, level=INFO) | 157 | log('Created new ceph keyring at %s.' % keyring, level=DEBUG) |
2132 | 178 | 158 | ||
2133 | 179 | 159 | ||
2134 | 180 | def create_key_file(service, key): | 160 | def create_key_file(service, key): |
2136 | 181 | ''' Create a file containing key ''' | 161 | """Create a file containing key.""" |
2137 | 182 | keyfile = _keyfile_path(service) | 162 | keyfile = _keyfile_path(service) |
2138 | 183 | if os.path.exists(keyfile): | 163 | if os.path.exists(keyfile): |
2140 | 184 | log('ceph: Keyfile exists at %s.' % keyfile, level=WARNING) | 164 | log('Keyfile exists at %s.' % keyfile, level=WARNING) |
2141 | 185 | return | 165 | return |
2142 | 166 | |||
2143 | 186 | with open(keyfile, 'w') as fd: | 167 | with open(keyfile, 'w') as fd: |
2144 | 187 | fd.write(key) | 168 | fd.write(key) |
2146 | 188 | log('ceph: Created new keyfile at %s.' % keyfile, level=INFO) | 169 | |
2147 | 170 | log('Created new keyfile at %s.' % keyfile, level=INFO) | ||
2148 | 189 | 171 | ||
2149 | 190 | 172 | ||
2150 | 191 | def get_ceph_nodes(): | 173 | def get_ceph_nodes(): |
2152 | 192 | ''' Query named relation 'ceph' to detemine current nodes ''' | 174 | """Query named relation 'ceph' to determine current nodes.""" |
2153 | 193 | hosts = [] | 175 | hosts = [] |
2154 | 194 | for r_id in relation_ids('ceph'): | 176 | for r_id in relation_ids('ceph'): |
2155 | 195 | for unit in related_units(r_id): | 177 | for unit in related_units(r_id): |
2156 | 196 | hosts.append(relation_get('private-address', unit=unit, rid=r_id)) | 178 | hosts.append(relation_get('private-address', unit=unit, rid=r_id)) |
2157 | 179 | |||
2158 | 197 | return hosts | 180 | return hosts |
2159 | 198 | 181 | ||
2160 | 199 | 182 | ||
2161 | 200 | def configure(service, key, auth, use_syslog): | 183 | def configure(service, key, auth, use_syslog): |
2163 | 201 | ''' Perform basic configuration of Ceph ''' | 184 | """Perform basic configuration of Ceph.""" |
2164 | 202 | create_keyring(service, key) | 185 | create_keyring(service, key) |
2165 | 203 | create_key_file(service, key) | 186 | create_key_file(service, key) |
2166 | 204 | hosts = get_ceph_nodes() | 187 | hosts = get_ceph_nodes() |
2167 | @@ -211,17 +194,17 @@ | |||
2168 | 211 | 194 | ||
2169 | 212 | 195 | ||
2170 | 213 | def image_mapped(name): | 196 | def image_mapped(name): |
2172 | 214 | ''' Determine whether a RADOS block device is mapped locally ''' | 197 | """Determine whether a RADOS block device is mapped locally.""" |
2173 | 215 | try: | 198 | try: |
2175 | 216 | out = check_output(['rbd', 'showmapped']) | 199 | out = check_output(['rbd', 'showmapped']).decode('UTF-8') |
2176 | 217 | except CalledProcessError: | 200 | except CalledProcessError: |
2177 | 218 | return False | 201 | return False |
2180 | 219 | else: | 202 | |
2181 | 220 | return name in out | 203 | return name in out |
2182 | 221 | 204 | ||
2183 | 222 | 205 | ||
2184 | 223 | def map_block_storage(service, pool, image): | 206 | def map_block_storage(service, pool, image): |
2186 | 224 | ''' Map a RADOS block device for local use ''' | 207 | """Map a RADOS block device for local use.""" |
2187 | 225 | cmd = [ | 208 | cmd = [ |
2188 | 226 | 'rbd', | 209 | 'rbd', |
2189 | 227 | 'map', | 210 | 'map', |
2190 | @@ -235,31 +218,32 @@ | |||
2191 | 235 | 218 | ||
2192 | 236 | 219 | ||
2193 | 237 | def filesystem_mounted(fs): | 220 | def filesystem_mounted(fs): |
2195 | 238 | ''' Determine whether a filesytems is already mounted ''' | 221 | """Determine whether a filesytems is already mounted.""" |
2196 | 239 | return fs in [f for f, m in mounts()] | 222 | return fs in [f for f, m in mounts()] |
2197 | 240 | 223 | ||
2198 | 241 | 224 | ||
2199 | 242 | def make_filesystem(blk_device, fstype='ext4', timeout=10): | 225 | def make_filesystem(blk_device, fstype='ext4', timeout=10): |
2201 | 243 | ''' Make a new filesystem on the specified block device ''' | 226 | """Make a new filesystem on the specified block device.""" |
2202 | 244 | count = 0 | 227 | count = 0 |
2203 | 245 | e_noent = os.errno.ENOENT | 228 | e_noent = os.errno.ENOENT |
2204 | 246 | while not os.path.exists(blk_device): | 229 | while not os.path.exists(blk_device): |
2205 | 247 | if count >= timeout: | 230 | if count >= timeout: |
2207 | 248 | log('ceph: gave up waiting on block device %s' % blk_device, | 231 | log('Gave up waiting on block device %s' % blk_device, |
2208 | 249 | level=ERROR) | 232 | level=ERROR) |
2209 | 250 | raise IOError(e_noent, os.strerror(e_noent), blk_device) | 233 | raise IOError(e_noent, os.strerror(e_noent), blk_device) |
2212 | 251 | log('ceph: waiting for block device %s to appear' % blk_device, | 234 | |
2213 | 252 | level=INFO) | 235 | log('Waiting for block device %s to appear' % blk_device, |
2214 | 236 | level=DEBUG) | ||
2215 | 253 | count += 1 | 237 | count += 1 |
2216 | 254 | time.sleep(1) | 238 | time.sleep(1) |
2217 | 255 | else: | 239 | else: |
2219 | 256 | log('ceph: Formatting block device %s as filesystem %s.' % | 240 | log('Formatting block device %s as filesystem %s.' % |
2220 | 257 | (blk_device, fstype), level=INFO) | 241 | (blk_device, fstype), level=INFO) |
2221 | 258 | check_call(['mkfs', '-t', fstype, blk_device]) | 242 | check_call(['mkfs', '-t', fstype, blk_device]) |
2222 | 259 | 243 | ||
2223 | 260 | 244 | ||
2224 | 261 | def place_data_on_block_device(blk_device, data_src_dst): | 245 | def place_data_on_block_device(blk_device, data_src_dst): |
2226 | 262 | ''' Migrate data in data_src_dst to blk_device and then remount ''' | 246 | """Migrate data in data_src_dst to blk_device and then remount.""" |
2227 | 263 | # mount block device into /mnt | 247 | # mount block device into /mnt |
2228 | 264 | mount(blk_device, '/mnt') | 248 | mount(blk_device, '/mnt') |
2229 | 265 | # copy data to /mnt | 249 | # copy data to /mnt |
2230 | @@ -279,8 +263,8 @@ | |||
2231 | 279 | 263 | ||
2232 | 280 | # TODO: re-use | 264 | # TODO: re-use |
2233 | 281 | def modprobe(module): | 265 | def modprobe(module): |
2236 | 282 | ''' Load a kernel module and configure for auto-load on reboot ''' | 266 | """Load a kernel module and configure for auto-load on reboot.""" |
2237 | 283 | log('ceph: Loading kernel module', level=INFO) | 267 | log('Loading kernel module', level=INFO) |
2238 | 284 | cmd = ['modprobe', module] | 268 | cmd = ['modprobe', module] |
2239 | 285 | check_call(cmd) | 269 | check_call(cmd) |
2240 | 286 | with open('/etc/modules', 'r+') as modules: | 270 | with open('/etc/modules', 'r+') as modules: |
2241 | @@ -289,7 +273,7 @@ | |||
2242 | 289 | 273 | ||
2243 | 290 | 274 | ||
2244 | 291 | def copy_files(src, dst, symlinks=False, ignore=None): | 275 | def copy_files(src, dst, symlinks=False, ignore=None): |
2246 | 292 | ''' Copy files from src to dst ''' | 276 | """Copy files from src to dst.""" |
2247 | 293 | for item in os.listdir(src): | 277 | for item in os.listdir(src): |
2248 | 294 | s = os.path.join(src, item) | 278 | s = os.path.join(src, item) |
2249 | 295 | d = os.path.join(dst, item) | 279 | d = os.path.join(dst, item) |
2250 | @@ -302,8 +286,7 @@ | |||
2251 | 302 | def ensure_ceph_storage(service, pool, rbd_img, sizemb, mount_point, | 286 | def ensure_ceph_storage(service, pool, rbd_img, sizemb, mount_point, |
2252 | 303 | blk_device, fstype, system_services=[], | 287 | blk_device, fstype, system_services=[], |
2253 | 304 | replicas=3): | 288 | replicas=3): |
2256 | 305 | """ | 289 | """NOTE: This function must only be called from a single service unit for |
2255 | 306 | NOTE: This function must only be called from a single service unit for | ||
2257 | 307 | the same rbd_img otherwise data loss will occur. | 290 | the same rbd_img otherwise data loss will occur. |
2258 | 308 | 291 | ||
2259 | 309 | Ensures given pool and RBD image exists, is mapped to a block device, | 292 | Ensures given pool and RBD image exists, is mapped to a block device, |
2260 | @@ -317,15 +300,16 @@ | |||
2261 | 317 | """ | 300 | """ |
2262 | 318 | # Ensure pool, RBD image, RBD mappings are in place. | 301 | # Ensure pool, RBD image, RBD mappings are in place. |
2263 | 319 | if not pool_exists(service, pool): | 302 | if not pool_exists(service, pool): |
2265 | 320 | log('ceph: Creating new pool {}.'.format(pool)) | 303 | log('Creating new pool {}.'.format(pool), level=INFO) |
2266 | 321 | create_pool(service, pool, replicas=replicas) | 304 | create_pool(service, pool, replicas=replicas) |
2267 | 322 | 305 | ||
2268 | 323 | if not rbd_exists(service, pool, rbd_img): | 306 | if not rbd_exists(service, pool, rbd_img): |
2270 | 324 | log('ceph: Creating RBD image ({}).'.format(rbd_img)) | 307 | log('Creating RBD image ({}).'.format(rbd_img), level=INFO) |
2271 | 325 | create_rbd_image(service, pool, rbd_img, sizemb) | 308 | create_rbd_image(service, pool, rbd_img, sizemb) |
2272 | 326 | 309 | ||
2273 | 327 | if not image_mapped(rbd_img): | 310 | if not image_mapped(rbd_img): |
2275 | 328 | log('ceph: Mapping RBD Image {} as a Block Device.'.format(rbd_img)) | 311 | log('Mapping RBD Image {} as a Block Device.'.format(rbd_img), |
2276 | 312 | level=INFO) | ||
2277 | 329 | map_block_storage(service, pool, rbd_img) | 313 | map_block_storage(service, pool, rbd_img) |
2278 | 330 | 314 | ||
2279 | 331 | # make file system | 315 | # make file system |
2280 | @@ -340,45 +324,47 @@ | |||
2281 | 340 | 324 | ||
2282 | 341 | for svc in system_services: | 325 | for svc in system_services: |
2283 | 342 | if service_running(svc): | 326 | if service_running(svc): |
2286 | 343 | log('ceph: Stopping services {} prior to migrating data.' | 327 | log('Stopping services {} prior to migrating data.' |
2287 | 344 | .format(svc)) | 328 | .format(svc), level=DEBUG) |
2288 | 345 | service_stop(svc) | 329 | service_stop(svc) |
2289 | 346 | 330 | ||
2290 | 347 | place_data_on_block_device(blk_device, mount_point) | 331 | place_data_on_block_device(blk_device, mount_point) |
2291 | 348 | 332 | ||
2292 | 349 | for svc in system_services: | 333 | for svc in system_services: |
2295 | 350 | log('ceph: Starting service {} after migrating data.' | 334 | log('Starting service {} after migrating data.' |
2296 | 351 | .format(svc)) | 335 | .format(svc), level=DEBUG) |
2297 | 352 | service_start(svc) | 336 | service_start(svc) |
2298 | 353 | 337 | ||
2299 | 354 | 338 | ||
2300 | 355 | def ensure_ceph_keyring(service, user=None, group=None): | 339 | def ensure_ceph_keyring(service, user=None, group=None): |
2304 | 356 | ''' | 340 | """Ensures a ceph keyring is created for a named service and optionally |
2305 | 357 | Ensures a ceph keyring is created for a named service | 341 | ensures user and group ownership. |
2303 | 358 | and optionally ensures user and group ownership. | ||
2306 | 359 | 342 | ||
2307 | 360 | Returns False if no ceph key is available in relation state. | 343 | Returns False if no ceph key is available in relation state. |
2309 | 361 | ''' | 344 | """ |
2310 | 362 | key = None | 345 | key = None |
2311 | 363 | for rid in relation_ids('ceph'): | 346 | for rid in relation_ids('ceph'): |
2312 | 364 | for unit in related_units(rid): | 347 | for unit in related_units(rid): |
2313 | 365 | key = relation_get('key', rid=rid, unit=unit) | 348 | key = relation_get('key', rid=rid, unit=unit) |
2314 | 366 | if key: | 349 | if key: |
2315 | 367 | break | 350 | break |
2316 | 351 | |||
2317 | 368 | if not key: | 352 | if not key: |
2318 | 369 | return False | 353 | return False |
2319 | 354 | |||
2320 | 370 | create_keyring(service=service, key=key) | 355 | create_keyring(service=service, key=key) |
2321 | 371 | keyring = _keyring_path(service) | 356 | keyring = _keyring_path(service) |
2322 | 372 | if user and group: | 357 | if user and group: |
2323 | 373 | check_call(['chown', '%s.%s' % (user, group), keyring]) | 358 | check_call(['chown', '%s.%s' % (user, group), keyring]) |
2324 | 359 | |||
2325 | 374 | return True | 360 | return True |
2326 | 375 | 361 | ||
2327 | 376 | 362 | ||
2328 | 377 | def ceph_version(): | 363 | def ceph_version(): |
2330 | 378 | ''' Retrieve the local version of ceph ''' | 364 | """Retrieve the local version of ceph.""" |
2331 | 379 | if os.path.exists('/usr/bin/ceph'): | 365 | if os.path.exists('/usr/bin/ceph'): |
2332 | 380 | cmd = ['ceph', '-v'] | 366 | cmd = ['ceph', '-v'] |
2334 | 381 | output = check_output(cmd) | 367 | output = check_output(cmd).decode('US-ASCII') |
2335 | 382 | output = output.split() | 368 | output = output.split() |
2336 | 383 | if len(output) > 3: | 369 | if len(output) > 3: |
2337 | 384 | return output[2] | 370 | return output[2] |
2338 | 385 | 371 | ||
2339 | === modified file 'hooks/charmhelpers/contrib/storage/linux/loopback.py' | |||
2340 | --- hooks/charmhelpers/contrib/storage/linux/loopback.py 2014-03-27 10:54:38 +0000 | |||
2341 | +++ hooks/charmhelpers/contrib/storage/linux/loopback.py 2014-12-11 17:56:34 +0000 | |||
2342 | @@ -1,12 +1,12 @@ | |||
2343 | 1 | |||
2344 | 2 | import os | 1 | import os |
2345 | 3 | import re | 2 | import re |
2346 | 4 | |||
2347 | 5 | from subprocess import ( | 3 | from subprocess import ( |
2348 | 6 | check_call, | 4 | check_call, |
2349 | 7 | check_output, | 5 | check_output, |
2350 | 8 | ) | 6 | ) |
2351 | 9 | 7 | ||
2352 | 8 | import six | ||
2353 | 9 | |||
2354 | 10 | 10 | ||
2355 | 11 | ################################################## | 11 | ################################################## |
2356 | 12 | # loopback device helpers. | 12 | # loopback device helpers. |
2357 | @@ -37,7 +37,7 @@ | |||
2358 | 37 | ''' | 37 | ''' |
2359 | 38 | file_path = os.path.abspath(file_path) | 38 | file_path = os.path.abspath(file_path) |
2360 | 39 | check_call(['losetup', '--find', file_path]) | 39 | check_call(['losetup', '--find', file_path]) |
2362 | 40 | for d, f in loopback_devices().iteritems(): | 40 | for d, f in six.iteritems(loopback_devices()): |
2363 | 41 | if f == file_path: | 41 | if f == file_path: |
2364 | 42 | return d | 42 | return d |
2365 | 43 | 43 | ||
2366 | @@ -51,7 +51,7 @@ | |||
2367 | 51 | 51 | ||
2368 | 52 | :returns: str: Full path to the ensured loopback device (eg, /dev/loop0) | 52 | :returns: str: Full path to the ensured loopback device (eg, /dev/loop0) |
2369 | 53 | ''' | 53 | ''' |
2371 | 54 | for d, f in loopback_devices().iteritems(): | 54 | for d, f in six.iteritems(loopback_devices()): |
2372 | 55 | if f == path: | 55 | if f == path: |
2373 | 56 | return d | 56 | return d |
2374 | 57 | 57 | ||
2375 | 58 | 58 | ||
2376 | === modified file 'hooks/charmhelpers/contrib/storage/linux/lvm.py' | |||
2377 | --- hooks/charmhelpers/contrib/storage/linux/lvm.py 2014-05-19 11:42:30 +0000 | |||
2378 | +++ hooks/charmhelpers/contrib/storage/linux/lvm.py 2014-12-11 17:56:34 +0000 | |||
2379 | @@ -61,6 +61,7 @@ | |||
2380 | 61 | vg = None | 61 | vg = None |
2381 | 62 | pvd = check_output(['pvdisplay', block_device]).splitlines() | 62 | pvd = check_output(['pvdisplay', block_device]).splitlines() |
2382 | 63 | for l in pvd: | 63 | for l in pvd: |
2383 | 64 | l = l.decode('UTF-8') | ||
2384 | 64 | if l.strip().startswith('VG Name'): | 65 | if l.strip().startswith('VG Name'): |
2385 | 65 | vg = ' '.join(l.strip().split()[2:]) | 66 | vg = ' '.join(l.strip().split()[2:]) |
2386 | 66 | return vg | 67 | return vg |
2387 | 67 | 68 | ||
2388 | === modified file 'hooks/charmhelpers/contrib/storage/linux/utils.py' | |||
2389 | --- hooks/charmhelpers/contrib/storage/linux/utils.py 2014-09-15 07:44:00 +0000 | |||
2390 | +++ hooks/charmhelpers/contrib/storage/linux/utils.py 2014-12-11 17:56:34 +0000 | |||
2391 | @@ -30,7 +30,8 @@ | |||
2392 | 30 | # sometimes sgdisk exits non-zero; this is OK, dd will clean up | 30 | # sometimes sgdisk exits non-zero; this is OK, dd will clean up |
2393 | 31 | call(['sgdisk', '--zap-all', '--mbrtogpt', | 31 | call(['sgdisk', '--zap-all', '--mbrtogpt', |
2394 | 32 | '--clear', block_device]) | 32 | '--clear', block_device]) |
2396 | 33 | dev_end = check_output(['blockdev', '--getsz', block_device]) | 33 | dev_end = check_output(['blockdev', '--getsz', |
2397 | 34 | block_device]).decode('UTF-8') | ||
2398 | 34 | gpt_end = int(dev_end.split()[0]) - 100 | 35 | gpt_end = int(dev_end.split()[0]) - 100 |
2399 | 35 | check_call(['dd', 'if=/dev/zero', 'of=%s' % (block_device), | 36 | check_call(['dd', 'if=/dev/zero', 'of=%s' % (block_device), |
2400 | 36 | 'bs=1M', 'count=1']) | 37 | 'bs=1M', 'count=1']) |
2401 | @@ -47,7 +48,7 @@ | |||
2402 | 47 | it doesn't. | 48 | it doesn't. |
2403 | 48 | ''' | 49 | ''' |
2404 | 49 | is_partition = bool(re.search(r".*[0-9]+\b", device)) | 50 | is_partition = bool(re.search(r".*[0-9]+\b", device)) |
2406 | 50 | out = check_output(['mount']) | 51 | out = check_output(['mount']).decode('UTF-8') |
2407 | 51 | if is_partition: | 52 | if is_partition: |
2408 | 52 | return bool(re.search(device + r"\b", out)) | 53 | return bool(re.search(device + r"\b", out)) |
2409 | 53 | return bool(re.search(device + r"[0-9]+\b", out)) | 54 | return bool(re.search(device + r"[0-9]+\b", out)) |
2410 | 54 | 55 | ||
2411 | === modified file 'hooks/charmhelpers/contrib/unison/__init__.py' | |||
2412 | --- hooks/charmhelpers/contrib/unison/__init__.py 2014-03-27 10:54:38 +0000 | |||
2413 | +++ hooks/charmhelpers/contrib/unison/__init__.py 2014-12-11 17:56:34 +0000 | |||
2414 | @@ -185,13 +185,14 @@ | |||
2415 | 185 | relation_set(ssh_authorized_hosts=authed_hosts) | 185 | relation_set(ssh_authorized_hosts=authed_hosts) |
2416 | 186 | 186 | ||
2417 | 187 | 187 | ||
2419 | 188 | def _run_as_user(user): | 188 | def _run_as_user(user, gid=None): |
2420 | 189 | try: | 189 | try: |
2421 | 190 | user = pwd.getpwnam(user) | 190 | user = pwd.getpwnam(user) |
2422 | 191 | except KeyError: | 191 | except KeyError: |
2423 | 192 | log('Invalid user: %s' % user) | 192 | log('Invalid user: %s' % user) |
2424 | 193 | raise Exception | 193 | raise Exception |
2426 | 194 | uid, gid = user.pw_uid, user.pw_gid | 194 | uid = user.pw_uid |
2427 | 195 | gid = gid or user.pw_gid | ||
2428 | 195 | os.environ['HOME'] = user.pw_dir | 196 | os.environ['HOME'] = user.pw_dir |
2429 | 196 | 197 | ||
2430 | 197 | def _inner(): | 198 | def _inner(): |
2431 | @@ -200,8 +201,8 @@ | |||
2432 | 200 | return _inner | 201 | return _inner |
2433 | 201 | 202 | ||
2434 | 202 | 203 | ||
2437 | 203 | def run_as_user(user, cmd): | 204 | def run_as_user(user, cmd, gid=None): |
2438 | 204 | return check_output(cmd, preexec_fn=_run_as_user(user), cwd='/') | 205 | return check_output(cmd, preexec_fn=_run_as_user(user, gid), cwd='/') |
2439 | 205 | 206 | ||
2440 | 206 | 207 | ||
2441 | 207 | def collect_authed_hosts(peer_interface): | 208 | def collect_authed_hosts(peer_interface): |
2442 | @@ -227,8 +228,8 @@ | |||
2443 | 227 | return hosts | 228 | return hosts |
2444 | 228 | 229 | ||
2445 | 229 | 230 | ||
2448 | 230 | def sync_path_to_host(path, host, user, verbose=False): | 231 | def sync_path_to_host(path, host, user, verbose=False, cmd=None, gid=None): |
2449 | 231 | cmd = copy(BASE_CMD) | 232 | cmd = cmd or copy(BASE_CMD) |
2450 | 232 | if not verbose: | 233 | if not verbose: |
2451 | 233 | cmd.append('-silent') | 234 | cmd.append('-silent') |
2452 | 234 | 235 | ||
2453 | @@ -241,17 +242,23 @@ | |||
2454 | 241 | 242 | ||
2455 | 242 | try: | 243 | try: |
2456 | 243 | log('Syncing local path %s to %s@%s:%s' % (path, user, host, path)) | 244 | log('Syncing local path %s to %s@%s:%s' % (path, user, host, path)) |
2458 | 244 | run_as_user(user, cmd) | 245 | run_as_user(user, cmd, gid) |
2459 | 245 | except: | 246 | except: |
2460 | 246 | log('Error syncing remote files') | 247 | log('Error syncing remote files') |
2461 | 247 | 248 | ||
2462 | 248 | 249 | ||
2464 | 249 | def sync_to_peer(host, user, paths=[], verbose=False): | 250 | def sync_to_peer(host, user, paths=None, verbose=False, cmd=None, gid=None): |
2465 | 250 | '''Sync paths to an specific host''' | 251 | '''Sync paths to an specific host''' |
2470 | 251 | [sync_path_to_host(p, host, user, verbose) for p in paths] | 252 | if paths: |
2471 | 252 | 253 | for p in paths: | |
2472 | 253 | 254 | sync_path_to_host(p, host, user, verbose, cmd, gid) | |
2473 | 254 | def sync_to_peers(peer_interface, user, paths=[], verbose=False): | 255 | |
2474 | 256 | |||
2475 | 257 | def sync_to_peers(peer_interface, user, paths=None, | ||
2476 | 258 | verbose=False, cmd=None, gid=None): | ||
2477 | 255 | '''Sync all hosts to an specific path''' | 259 | '''Sync all hosts to an specific path''' |
2480 | 256 | for host in collect_authed_hosts(peer_interface): | 260 | '''The type of group is integer, it allows user has permissions to ''' |
2481 | 257 | sync_to_peer(host, user, paths, verbose) | 261 | '''operate a directory have a different group id with the user id.''' |
2482 | 262 | if paths: | ||
2483 | 263 | for host in collect_authed_hosts(peer_interface): | ||
2484 | 264 | sync_to_peer(host, user, paths, verbose, cmd, gid) | ||
2485 | 258 | 265 | ||
2486 | === modified file 'hooks/charmhelpers/core/fstab.py' | |||
2487 | --- hooks/charmhelpers/core/fstab.py 2014-06-24 17:11:12 +0000 | |||
2488 | +++ hooks/charmhelpers/core/fstab.py 2014-12-11 17:56:34 +0000 | |||
2489 | @@ -3,10 +3,11 @@ | |||
2490 | 3 | 3 | ||
2491 | 4 | __author__ = 'Jorge Niedbalski R. <jorge.niedbalski@canonical.com>' | 4 | __author__ = 'Jorge Niedbalski R. <jorge.niedbalski@canonical.com>' |
2492 | 5 | 5 | ||
2493 | 6 | import io | ||
2494 | 6 | import os | 7 | import os |
2495 | 7 | 8 | ||
2496 | 8 | 9 | ||
2498 | 9 | class Fstab(file): | 10 | class Fstab(io.FileIO): |
2499 | 10 | """This class extends file in order to implement a file reader/writer | 11 | """This class extends file in order to implement a file reader/writer |
2500 | 11 | for file `/etc/fstab` | 12 | for file `/etc/fstab` |
2501 | 12 | """ | 13 | """ |
2502 | @@ -24,8 +25,8 @@ | |||
2503 | 24 | options = "defaults" | 25 | options = "defaults" |
2504 | 25 | 26 | ||
2505 | 26 | self.options = options | 27 | self.options = options |
2508 | 27 | self.d = d | 28 | self.d = int(d) |
2509 | 28 | self.p = p | 29 | self.p = int(p) |
2510 | 29 | 30 | ||
2511 | 30 | def __eq__(self, o): | 31 | def __eq__(self, o): |
2512 | 31 | return str(self) == str(o) | 32 | return str(self) == str(o) |
2513 | @@ -45,7 +46,7 @@ | |||
2514 | 45 | self._path = path | 46 | self._path = path |
2515 | 46 | else: | 47 | else: |
2516 | 47 | self._path = self.DEFAULT_PATH | 48 | self._path = self.DEFAULT_PATH |
2518 | 48 | file.__init__(self, self._path, 'r+') | 49 | super(Fstab, self).__init__(self._path, 'rb+') |
2519 | 49 | 50 | ||
2520 | 50 | def _hydrate_entry(self, line): | 51 | def _hydrate_entry(self, line): |
2521 | 51 | # NOTE: use split with no arguments to split on any | 52 | # NOTE: use split with no arguments to split on any |
2522 | @@ -58,8 +59,9 @@ | |||
2523 | 58 | def entries(self): | 59 | def entries(self): |
2524 | 59 | self.seek(0) | 60 | self.seek(0) |
2525 | 60 | for line in self.readlines(): | 61 | for line in self.readlines(): |
2526 | 62 | line = line.decode('us-ascii') | ||
2527 | 61 | try: | 63 | try: |
2529 | 62 | if not line.startswith("#"): | 64 | if line.strip() and not line.startswith("#"): |
2530 | 63 | yield self._hydrate_entry(line) | 65 | yield self._hydrate_entry(line) |
2531 | 64 | except ValueError: | 66 | except ValueError: |
2532 | 65 | pass | 67 | pass |
2533 | @@ -75,14 +77,14 @@ | |||
2534 | 75 | if self.get_entry_by_attr('device', entry.device): | 77 | if self.get_entry_by_attr('device', entry.device): |
2535 | 76 | return False | 78 | return False |
2536 | 77 | 79 | ||
2538 | 78 | self.write(str(entry) + '\n') | 80 | self.write((str(entry) + '\n').encode('us-ascii')) |
2539 | 79 | self.truncate() | 81 | self.truncate() |
2540 | 80 | return entry | 82 | return entry |
2541 | 81 | 83 | ||
2542 | 82 | def remove_entry(self, entry): | 84 | def remove_entry(self, entry): |
2543 | 83 | self.seek(0) | 85 | self.seek(0) |
2544 | 84 | 86 | ||
2546 | 85 | lines = self.readlines() | 87 | lines = [l.decode('us-ascii') for l in self.readlines()] |
2547 | 86 | 88 | ||
2548 | 87 | found = False | 89 | found = False |
2549 | 88 | for index, line in enumerate(lines): | 90 | for index, line in enumerate(lines): |
2550 | @@ -97,7 +99,7 @@ | |||
2551 | 97 | lines.remove(line) | 99 | lines.remove(line) |
2552 | 98 | 100 | ||
2553 | 99 | self.seek(0) | 101 | self.seek(0) |
2555 | 100 | self.write(''.join(lines)) | 102 | self.write(''.join(lines).encode('us-ascii')) |
2556 | 101 | self.truncate() | 103 | self.truncate() |
2557 | 102 | return True | 104 | return True |
2558 | 103 | 105 | ||
2559 | 104 | 106 | ||
2560 | === modified file 'hooks/charmhelpers/core/hookenv.py' | |||
2561 | --- hooks/charmhelpers/core/hookenv.py 2014-10-24 11:36:12 +0000 | |||
2562 | +++ hooks/charmhelpers/core/hookenv.py 2014-12-11 17:56:34 +0000 | |||
2563 | @@ -9,9 +9,14 @@ | |||
2564 | 9 | import yaml | 9 | import yaml |
2565 | 10 | import subprocess | 10 | import subprocess |
2566 | 11 | import sys | 11 | import sys |
2567 | 12 | import UserDict | ||
2568 | 13 | from subprocess import CalledProcessError | 12 | from subprocess import CalledProcessError |
2569 | 14 | 13 | ||
2570 | 14 | import six | ||
2571 | 15 | if not six.PY3: | ||
2572 | 16 | from UserDict import UserDict | ||
2573 | 17 | else: | ||
2574 | 18 | from collections import UserDict | ||
2575 | 19 | |||
2576 | 15 | CRITICAL = "CRITICAL" | 20 | CRITICAL = "CRITICAL" |
2577 | 16 | ERROR = "ERROR" | 21 | ERROR = "ERROR" |
2578 | 17 | WARNING = "WARNING" | 22 | WARNING = "WARNING" |
2579 | @@ -63,16 +68,18 @@ | |||
2580 | 63 | command = ['juju-log'] | 68 | command = ['juju-log'] |
2581 | 64 | if level: | 69 | if level: |
2582 | 65 | command += ['-l', level] | 70 | command += ['-l', level] |
2583 | 71 | if not isinstance(message, six.string_types): | ||
2584 | 72 | message = repr(message) | ||
2585 | 66 | command += [message] | 73 | command += [message] |
2586 | 67 | subprocess.call(command) | 74 | subprocess.call(command) |
2587 | 68 | 75 | ||
2588 | 69 | 76 | ||
2590 | 70 | class Serializable(UserDict.IterableUserDict): | 77 | class Serializable(UserDict): |
2591 | 71 | """Wrapper, an object that can be serialized to yaml or json""" | 78 | """Wrapper, an object that can be serialized to yaml or json""" |
2592 | 72 | 79 | ||
2593 | 73 | def __init__(self, obj): | 80 | def __init__(self, obj): |
2594 | 74 | # wrap the object | 81 | # wrap the object |
2596 | 75 | UserDict.IterableUserDict.__init__(self) | 82 | UserDict.__init__(self) |
2597 | 76 | self.data = obj | 83 | self.data = obj |
2598 | 77 | 84 | ||
2599 | 78 | def __getattr__(self, attr): | 85 | def __getattr__(self, attr): |
2600 | @@ -218,7 +225,7 @@ | |||
2601 | 218 | prev_keys = [] | 225 | prev_keys = [] |
2602 | 219 | if self._prev_dict is not None: | 226 | if self._prev_dict is not None: |
2603 | 220 | prev_keys = self._prev_dict.keys() | 227 | prev_keys = self._prev_dict.keys() |
2605 | 221 | return list(set(prev_keys + dict.keys(self))) | 228 | return list(set(prev_keys + list(dict.keys(self)))) |
2606 | 222 | 229 | ||
2607 | 223 | def load_previous(self, path=None): | 230 | def load_previous(self, path=None): |
2608 | 224 | """Load previous copy of config from disk. | 231 | """Load previous copy of config from disk. |
2609 | @@ -269,7 +276,7 @@ | |||
2610 | 269 | 276 | ||
2611 | 270 | """ | 277 | """ |
2612 | 271 | if self._prev_dict: | 278 | if self._prev_dict: |
2614 | 272 | for k, v in self._prev_dict.iteritems(): | 279 | for k, v in six.iteritems(self._prev_dict): |
2615 | 273 | if k not in self: | 280 | if k not in self: |
2616 | 274 | self[k] = v | 281 | self[k] = v |
2617 | 275 | with open(self.path, 'w') as f: | 282 | with open(self.path, 'w') as f: |
2618 | @@ -284,7 +291,8 @@ | |||
2619 | 284 | config_cmd_line.append(scope) | 291 | config_cmd_line.append(scope) |
2620 | 285 | config_cmd_line.append('--format=json') | 292 | config_cmd_line.append('--format=json') |
2621 | 286 | try: | 293 | try: |
2623 | 287 | config_data = json.loads(subprocess.check_output(config_cmd_line)) | 294 | config_data = json.loads( |
2624 | 295 | subprocess.check_output(config_cmd_line).decode('UTF-8')) | ||
2625 | 288 | if scope is not None: | 296 | if scope is not None: |
2626 | 289 | return config_data | 297 | return config_data |
2627 | 290 | return Config(config_data) | 298 | return Config(config_data) |
2628 | @@ -303,10 +311,10 @@ | |||
2629 | 303 | if unit: | 311 | if unit: |
2630 | 304 | _args.append(unit) | 312 | _args.append(unit) |
2631 | 305 | try: | 313 | try: |
2633 | 306 | return json.loads(subprocess.check_output(_args)) | 314 | return json.loads(subprocess.check_output(_args).decode('UTF-8')) |
2634 | 307 | except ValueError: | 315 | except ValueError: |
2635 | 308 | return None | 316 | return None |
2637 | 309 | except CalledProcessError, e: | 317 | except CalledProcessError as e: |
2638 | 310 | if e.returncode == 2: | 318 | if e.returncode == 2: |
2639 | 311 | return None | 319 | return None |
2640 | 312 | raise | 320 | raise |
2641 | @@ -318,7 +326,7 @@ | |||
2642 | 318 | relation_cmd_line = ['relation-set'] | 326 | relation_cmd_line = ['relation-set'] |
2643 | 319 | if relation_id is not None: | 327 | if relation_id is not None: |
2644 | 320 | relation_cmd_line.extend(('-r', relation_id)) | 328 | relation_cmd_line.extend(('-r', relation_id)) |
2646 | 321 | for k, v in (relation_settings.items() + kwargs.items()): | 329 | for k, v in (list(relation_settings.items()) + list(kwargs.items())): |
2647 | 322 | if v is None: | 330 | if v is None: |
2648 | 323 | relation_cmd_line.append('{}='.format(k)) | 331 | relation_cmd_line.append('{}='.format(k)) |
2649 | 324 | else: | 332 | else: |
2650 | @@ -335,7 +343,8 @@ | |||
2651 | 335 | relid_cmd_line = ['relation-ids', '--format=json'] | 343 | relid_cmd_line = ['relation-ids', '--format=json'] |
2652 | 336 | if reltype is not None: | 344 | if reltype is not None: |
2653 | 337 | relid_cmd_line.append(reltype) | 345 | relid_cmd_line.append(reltype) |
2655 | 338 | return json.loads(subprocess.check_output(relid_cmd_line)) or [] | 346 | return json.loads( |
2656 | 347 | subprocess.check_output(relid_cmd_line).decode('UTF-8')) or [] | ||
2657 | 339 | return [] | 348 | return [] |
2658 | 340 | 349 | ||
2659 | 341 | 350 | ||
2660 | @@ -346,7 +355,8 @@ | |||
2661 | 346 | units_cmd_line = ['relation-list', '--format=json'] | 355 | units_cmd_line = ['relation-list', '--format=json'] |
2662 | 347 | if relid is not None: | 356 | if relid is not None: |
2663 | 348 | units_cmd_line.extend(('-r', relid)) | 357 | units_cmd_line.extend(('-r', relid)) |
2665 | 349 | return json.loads(subprocess.check_output(units_cmd_line)) or [] | 358 | return json.loads( |
2666 | 359 | subprocess.check_output(units_cmd_line).decode('UTF-8')) or [] | ||
2667 | 350 | 360 | ||
2668 | 351 | 361 | ||
2669 | 352 | @cached | 362 | @cached |
2670 | @@ -386,21 +396,31 @@ | |||
2671 | 386 | 396 | ||
2672 | 387 | 397 | ||
2673 | 388 | @cached | 398 | @cached |
2674 | 399 | def metadata(): | ||
2675 | 400 | """Get the current charm metadata.yaml contents as a python object""" | ||
2676 | 401 | with open(os.path.join(charm_dir(), 'metadata.yaml')) as md: | ||
2677 | 402 | return yaml.safe_load(md) | ||
2678 | 403 | |||
2679 | 404 | |||
2680 | 405 | @cached | ||
2681 | 389 | def relation_types(): | 406 | def relation_types(): |
2682 | 390 | """Get a list of relation types supported by this charm""" | 407 | """Get a list of relation types supported by this charm""" |
2683 | 391 | charmdir = os.environ.get('CHARM_DIR', '') | ||
2684 | 392 | mdf = open(os.path.join(charmdir, 'metadata.yaml')) | ||
2685 | 393 | md = yaml.safe_load(mdf) | ||
2686 | 394 | rel_types = [] | 408 | rel_types = [] |
2687 | 409 | md = metadata() | ||
2688 | 395 | for key in ('provides', 'requires', 'peers'): | 410 | for key in ('provides', 'requires', 'peers'): |
2689 | 396 | section = md.get(key) | 411 | section = md.get(key) |
2690 | 397 | if section: | 412 | if section: |
2691 | 398 | rel_types.extend(section.keys()) | 413 | rel_types.extend(section.keys()) |
2692 | 399 | mdf.close() | ||
2693 | 400 | return rel_types | 414 | return rel_types |
2694 | 401 | 415 | ||
2695 | 402 | 416 | ||
2696 | 403 | @cached | 417 | @cached |
2697 | 418 | def charm_name(): | ||
2698 | 419 | """Get the name of the current charm as is specified on metadata.yaml""" | ||
2699 | 420 | return metadata().get('name') | ||
2700 | 421 | |||
2701 | 422 | |||
2702 | 423 | @cached | ||
2703 | 404 | def relations(): | 424 | def relations(): |
2704 | 405 | """Get a nested dictionary of relation data for all related units""" | 425 | """Get a nested dictionary of relation data for all related units""" |
2705 | 406 | rels = {} | 426 | rels = {} |
2706 | @@ -455,7 +475,7 @@ | |||
2707 | 455 | """Get the unit ID for the remote unit""" | 475 | """Get the unit ID for the remote unit""" |
2708 | 456 | _args = ['unit-get', '--format=json', attribute] | 476 | _args = ['unit-get', '--format=json', attribute] |
2709 | 457 | try: | 477 | try: |
2711 | 458 | return json.loads(subprocess.check_output(_args)) | 478 | return json.loads(subprocess.check_output(_args).decode('UTF-8')) |
2712 | 459 | except ValueError: | 479 | except ValueError: |
2713 | 460 | return None | 480 | return None |
2714 | 461 | 481 | ||
2715 | 462 | 482 | ||
2716 | === modified file 'hooks/charmhelpers/core/host.py' | |||
2717 | --- hooks/charmhelpers/core/host.py 2014-10-24 11:36:12 +0000 | |||
2718 | +++ hooks/charmhelpers/core/host.py 2014-12-11 17:56:34 +0000 | |||
2719 | @@ -14,11 +14,12 @@ | |||
2720 | 14 | import subprocess | 14 | import subprocess |
2721 | 15 | import hashlib | 15 | import hashlib |
2722 | 16 | from contextlib import contextmanager | 16 | from contextlib import contextmanager |
2723 | 17 | |||
2724 | 18 | from collections import OrderedDict | 17 | from collections import OrderedDict |
2725 | 19 | 18 | ||
2728 | 20 | from hookenv import log | 19 | import six |
2729 | 21 | from fstab import Fstab | 20 | |
2730 | 21 | from .hookenv import log | ||
2731 | 22 | from .fstab import Fstab | ||
2732 | 22 | 23 | ||
2733 | 23 | 24 | ||
2734 | 24 | def service_start(service_name): | 25 | def service_start(service_name): |
2735 | @@ -54,7 +55,9 @@ | |||
2736 | 54 | def service_running(service): | 55 | def service_running(service): |
2737 | 55 | """Determine whether a system service is running""" | 56 | """Determine whether a system service is running""" |
2738 | 56 | try: | 57 | try: |
2740 | 57 | output = subprocess.check_output(['service', service, 'status'], stderr=subprocess.STDOUT) | 58 | output = subprocess.check_output( |
2741 | 59 | ['service', service, 'status'], | ||
2742 | 60 | stderr=subprocess.STDOUT).decode('UTF-8') | ||
2743 | 58 | except subprocess.CalledProcessError: | 61 | except subprocess.CalledProcessError: |
2744 | 59 | return False | 62 | return False |
2745 | 60 | else: | 63 | else: |
2746 | @@ -67,7 +70,9 @@ | |||
2747 | 67 | def service_available(service_name): | 70 | def service_available(service_name): |
2748 | 68 | """Determine whether a system service is available""" | 71 | """Determine whether a system service is available""" |
2749 | 69 | try: | 72 | try: |
2751 | 70 | subprocess.check_output(['service', service_name, 'status'], stderr=subprocess.STDOUT) | 73 | subprocess.check_output( |
2752 | 74 | ['service', service_name, 'status'], | ||
2753 | 75 | stderr=subprocess.STDOUT).decode('UTF-8') | ||
2754 | 71 | except subprocess.CalledProcessError as e: | 76 | except subprocess.CalledProcessError as e: |
2755 | 72 | return 'unrecognized service' not in e.output | 77 | return 'unrecognized service' not in e.output |
2756 | 73 | else: | 78 | else: |
2757 | @@ -96,6 +101,26 @@ | |||
2758 | 96 | return user_info | 101 | return user_info |
2759 | 97 | 102 | ||
2760 | 98 | 103 | ||
2761 | 104 | def add_group(group_name, system_group=False): | ||
2762 | 105 | """Add a group to the system""" | ||
2763 | 106 | try: | ||
2764 | 107 | group_info = grp.getgrnam(group_name) | ||
2765 | 108 | log('group {0} already exists!'.format(group_name)) | ||
2766 | 109 | except KeyError: | ||
2767 | 110 | log('creating group {0}'.format(group_name)) | ||
2768 | 111 | cmd = ['addgroup'] | ||
2769 | 112 | if system_group: | ||
2770 | 113 | cmd.append('--system') | ||
2771 | 114 | else: | ||
2772 | 115 | cmd.extend([ | ||
2773 | 116 | '--group', | ||
2774 | 117 | ]) | ||
2775 | 118 | cmd.append(group_name) | ||
2776 | 119 | subprocess.check_call(cmd) | ||
2777 | 120 | group_info = grp.getgrnam(group_name) | ||
2778 | 121 | return group_info | ||
2779 | 122 | |||
2780 | 123 | |||
2781 | 99 | def add_user_to_group(username, group): | 124 | def add_user_to_group(username, group): |
2782 | 100 | """Add a user to a group""" | 125 | """Add a user to a group""" |
2783 | 101 | cmd = [ | 126 | cmd = [ |
2784 | @@ -115,7 +140,7 @@ | |||
2785 | 115 | cmd.append(from_path) | 140 | cmd.append(from_path) |
2786 | 116 | cmd.append(to_path) | 141 | cmd.append(to_path) |
2787 | 117 | log(" ".join(cmd)) | 142 | log(" ".join(cmd)) |
2789 | 118 | return subprocess.check_output(cmd).strip() | 143 | return subprocess.check_output(cmd).decode('UTF-8').strip() |
2790 | 119 | 144 | ||
2791 | 120 | 145 | ||
2792 | 121 | def symlink(source, destination): | 146 | def symlink(source, destination): |
2793 | @@ -130,7 +155,7 @@ | |||
2794 | 130 | subprocess.check_call(cmd) | 155 | subprocess.check_call(cmd) |
2795 | 131 | 156 | ||
2796 | 132 | 157 | ||
2798 | 133 | def mkdir(path, owner='root', group='root', perms=0555, force=False): | 158 | def mkdir(path, owner='root', group='root', perms=0o555, force=False): |
2799 | 134 | """Create a directory""" | 159 | """Create a directory""" |
2800 | 135 | log("Making dir {} {}:{} {:o}".format(path, owner, group, | 160 | log("Making dir {} {}:{} {:o}".format(path, owner, group, |
2801 | 136 | perms)) | 161 | perms)) |
2802 | @@ -146,7 +171,7 @@ | |||
2803 | 146 | os.chown(realpath, uid, gid) | 171 | os.chown(realpath, uid, gid) |
2804 | 147 | 172 | ||
2805 | 148 | 173 | ||
2807 | 149 | def write_file(path, content, owner='root', group='root', perms=0444): | 174 | def write_file(path, content, owner='root', group='root', perms=0o444): |
2808 | 150 | """Create or overwrite a file with the contents of a string""" | 175 | """Create or overwrite a file with the contents of a string""" |
2809 | 151 | log("Writing file {} {}:{} {:o}".format(path, owner, group, perms)) | 176 | log("Writing file {} {}:{} {:o}".format(path, owner, group, perms)) |
2810 | 152 | uid = pwd.getpwnam(owner).pw_uid | 177 | uid = pwd.getpwnam(owner).pw_uid |
2811 | @@ -177,7 +202,7 @@ | |||
2812 | 177 | cmd_args.extend([device, mountpoint]) | 202 | cmd_args.extend([device, mountpoint]) |
2813 | 178 | try: | 203 | try: |
2814 | 179 | subprocess.check_output(cmd_args) | 204 | subprocess.check_output(cmd_args) |
2816 | 180 | except subprocess.CalledProcessError, e: | 205 | except subprocess.CalledProcessError as e: |
2817 | 181 | log('Error mounting {} at {}\n{}'.format(device, mountpoint, e.output)) | 206 | log('Error mounting {} at {}\n{}'.format(device, mountpoint, e.output)) |
2818 | 182 | return False | 207 | return False |
2819 | 183 | 208 | ||
2820 | @@ -191,7 +216,7 @@ | |||
2821 | 191 | cmd_args = ['umount', mountpoint] | 216 | cmd_args = ['umount', mountpoint] |
2822 | 192 | try: | 217 | try: |
2823 | 193 | subprocess.check_output(cmd_args) | 218 | subprocess.check_output(cmd_args) |
2825 | 194 | except subprocess.CalledProcessError, e: | 219 | except subprocess.CalledProcessError as e: |
2826 | 195 | log('Error unmounting {}\n{}'.format(mountpoint, e.output)) | 220 | log('Error unmounting {}\n{}'.format(mountpoint, e.output)) |
2827 | 196 | return False | 221 | return False |
2828 | 197 | 222 | ||
2829 | @@ -218,8 +243,8 @@ | |||
2830 | 218 | """ | 243 | """ |
2831 | 219 | if os.path.exists(path): | 244 | if os.path.exists(path): |
2832 | 220 | h = getattr(hashlib, hash_type)() | 245 | h = getattr(hashlib, hash_type)() |
2835 | 221 | with open(path, 'r') as source: | 246 | with open(path, 'rb') as source: |
2836 | 222 | h.update(source.read()) # IGNORE:E1101 - it does have update | 247 | h.update(source.read()) |
2837 | 223 | return h.hexdigest() | 248 | return h.hexdigest() |
2838 | 224 | else: | 249 | else: |
2839 | 225 | return None | 250 | return None |
2840 | @@ -297,7 +322,7 @@ | |||
2841 | 297 | if length is None: | 322 | if length is None: |
2842 | 298 | length = random.choice(range(35, 45)) | 323 | length = random.choice(range(35, 45)) |
2843 | 299 | alphanumeric_chars = [ | 324 | alphanumeric_chars = [ |
2845 | 300 | l for l in (string.letters + string.digits) | 325 | l for l in (string.ascii_letters + string.digits) |
2846 | 301 | if l not in 'l0QD1vAEIOUaeiou'] | 326 | if l not in 'l0QD1vAEIOUaeiou'] |
2847 | 302 | random_chars = [ | 327 | random_chars = [ |
2848 | 303 | random.choice(alphanumeric_chars) for _ in range(length)] | 328 | random.choice(alphanumeric_chars) for _ in range(length)] |
2849 | @@ -306,14 +331,14 @@ | |||
2850 | 306 | 331 | ||
2851 | 307 | def list_nics(nic_type): | 332 | def list_nics(nic_type): |
2852 | 308 | '''Return a list of nics of given type(s)''' | 333 | '''Return a list of nics of given type(s)''' |
2854 | 309 | if isinstance(nic_type, basestring): | 334 | if isinstance(nic_type, six.string_types): |
2855 | 310 | int_types = [nic_type] | 335 | int_types = [nic_type] |
2856 | 311 | else: | 336 | else: |
2857 | 312 | int_types = nic_type | 337 | int_types = nic_type |
2858 | 313 | interfaces = [] | 338 | interfaces = [] |
2859 | 314 | for int_type in int_types: | 339 | for int_type in int_types: |
2860 | 315 | cmd = ['ip', 'addr', 'show', 'label', int_type + '*'] | 340 | cmd = ['ip', 'addr', 'show', 'label', int_type + '*'] |
2862 | 316 | ip_output = subprocess.check_output(cmd).split('\n') | 341 | ip_output = subprocess.check_output(cmd).decode('UTF-8').split('\n') |
2863 | 317 | ip_output = (line for line in ip_output if line) | 342 | ip_output = (line for line in ip_output if line) |
2864 | 318 | for line in ip_output: | 343 | for line in ip_output: |
2865 | 319 | if line.split()[1].startswith(int_type): | 344 | if line.split()[1].startswith(int_type): |
2866 | @@ -335,7 +360,7 @@ | |||
2867 | 335 | 360 | ||
2868 | 336 | def get_nic_mtu(nic): | 361 | def get_nic_mtu(nic): |
2869 | 337 | cmd = ['ip', 'addr', 'show', nic] | 362 | cmd = ['ip', 'addr', 'show', nic] |
2871 | 338 | ip_output = subprocess.check_output(cmd).split('\n') | 363 | ip_output = subprocess.check_output(cmd).decode('UTF-8').split('\n') |
2872 | 339 | mtu = "" | 364 | mtu = "" |
2873 | 340 | for line in ip_output: | 365 | for line in ip_output: |
2874 | 341 | words = line.split() | 366 | words = line.split() |
2875 | @@ -346,7 +371,7 @@ | |||
2876 | 346 | 371 | ||
2877 | 347 | def get_nic_hwaddr(nic): | 372 | def get_nic_hwaddr(nic): |
2878 | 348 | cmd = ['ip', '-o', '-0', 'addr', 'show', nic] | 373 | cmd = ['ip', '-o', '-0', 'addr', 'show', nic] |
2880 | 349 | ip_output = subprocess.check_output(cmd) | 374 | ip_output = subprocess.check_output(cmd).decode('UTF-8') |
2881 | 350 | hwaddr = "" | 375 | hwaddr = "" |
2882 | 351 | words = ip_output.split() | 376 | words = ip_output.split() |
2883 | 352 | if 'link/ether' in words: | 377 | if 'link/ether' in words: |
2884 | @@ -363,8 +388,8 @@ | |||
2885 | 363 | 388 | ||
2886 | 364 | ''' | 389 | ''' |
2887 | 365 | import apt_pkg | 390 | import apt_pkg |
2888 | 366 | from charmhelpers.fetch import apt_cache | ||
2889 | 367 | if not pkgcache: | 391 | if not pkgcache: |
2890 | 392 | from charmhelpers.fetch import apt_cache | ||
2891 | 368 | pkgcache = apt_cache() | 393 | pkgcache = apt_cache() |
2892 | 369 | pkg = pkgcache[package] | 394 | pkg = pkgcache[package] |
2893 | 370 | return apt_pkg.version_compare(pkg.current_ver.ver_str, revno) | 395 | return apt_pkg.version_compare(pkg.current_ver.ver_str, revno) |
2894 | 371 | 396 | ||
2895 | === modified file 'hooks/charmhelpers/core/services/helpers.py' | |||
2896 | --- hooks/charmhelpers/core/services/helpers.py 2014-10-06 20:51:06 +0000 | |||
2897 | +++ hooks/charmhelpers/core/services/helpers.py 2014-12-11 17:56:34 +0000 | |||
2898 | @@ -196,7 +196,7 @@ | |||
2899 | 196 | if not os.path.isabs(file_name): | 196 | if not os.path.isabs(file_name): |
2900 | 197 | file_name = os.path.join(hookenv.charm_dir(), file_name) | 197 | file_name = os.path.join(hookenv.charm_dir(), file_name) |
2901 | 198 | with open(file_name, 'w') as file_stream: | 198 | with open(file_name, 'w') as file_stream: |
2903 | 199 | os.fchmod(file_stream.fileno(), 0600) | 199 | os.fchmod(file_stream.fileno(), 0o600) |
2904 | 200 | yaml.dump(config_data, file_stream) | 200 | yaml.dump(config_data, file_stream) |
2905 | 201 | 201 | ||
2906 | 202 | def read_context(self, file_name): | 202 | def read_context(self, file_name): |
2907 | @@ -211,15 +211,19 @@ | |||
2908 | 211 | 211 | ||
2909 | 212 | class TemplateCallback(ManagerCallback): | 212 | class TemplateCallback(ManagerCallback): |
2910 | 213 | """ | 213 | """ |
2914 | 214 | Callback class that will render a Jinja2 template, for use as a ready action. | 214 | Callback class that will render a Jinja2 template, for use as a ready |
2915 | 215 | 215 | action. | |
2916 | 216 | :param str source: The template source file, relative to `$CHARM_DIR/templates` | 216 | |
2917 | 217 | :param str source: The template source file, relative to | ||
2918 | 218 | `$CHARM_DIR/templates` | ||
2919 | 219 | |||
2920 | 217 | :param str target: The target to write the rendered template to | 220 | :param str target: The target to write the rendered template to |
2921 | 218 | :param str owner: The owner of the rendered file | 221 | :param str owner: The owner of the rendered file |
2922 | 219 | :param str group: The group of the rendered file | 222 | :param str group: The group of the rendered file |
2923 | 220 | :param int perms: The permissions of the rendered file | 223 | :param int perms: The permissions of the rendered file |
2924 | 221 | """ | 224 | """ |
2926 | 222 | def __init__(self, source, target, owner='root', group='root', perms=0444): | 225 | def __init__(self, source, target, |
2927 | 226 | owner='root', group='root', perms=0o444): | ||
2928 | 223 | self.source = source | 227 | self.source = source |
2929 | 224 | self.target = target | 228 | self.target = target |
2930 | 225 | self.owner = owner | 229 | self.owner = owner |
2931 | 226 | 230 | ||
2932 | === modified file 'hooks/charmhelpers/core/templating.py' | |||
2933 | --- hooks/charmhelpers/core/templating.py 2014-08-13 13:11:49 +0000 | |||
2934 | +++ hooks/charmhelpers/core/templating.py 2014-12-11 17:56:34 +0000 | |||
2935 | @@ -4,7 +4,8 @@ | |||
2936 | 4 | from charmhelpers.core import hookenv | 4 | from charmhelpers.core import hookenv |
2937 | 5 | 5 | ||
2938 | 6 | 6 | ||
2940 | 7 | def render(source, target, context, owner='root', group='root', perms=0444, templates_dir=None): | 7 | def render(source, target, context, owner='root', group='root', |
2941 | 8 | perms=0o444, templates_dir=None): | ||
2942 | 8 | """ | 9 | """ |
2943 | 9 | Render a template. | 10 | Render a template. |
2944 | 10 | 11 | ||
2945 | 11 | 12 | ||
2946 | === modified file 'hooks/charmhelpers/fetch/__init__.py' | |||
2947 | --- hooks/charmhelpers/fetch/__init__.py 2014-10-24 11:36:12 +0000 | |||
2948 | +++ hooks/charmhelpers/fetch/__init__.py 2014-12-11 17:56:34 +0000 | |||
2949 | @@ -5,10 +5,6 @@ | |||
2950 | 5 | from charmhelpers.core.host import ( | 5 | from charmhelpers.core.host import ( |
2951 | 6 | lsb_release | 6 | lsb_release |
2952 | 7 | ) | 7 | ) |
2953 | 8 | from urlparse import ( | ||
2954 | 9 | urlparse, | ||
2955 | 10 | urlunparse, | ||
2956 | 11 | ) | ||
2957 | 12 | import subprocess | 8 | import subprocess |
2958 | 13 | from charmhelpers.core.hookenv import ( | 9 | from charmhelpers.core.hookenv import ( |
2959 | 14 | config, | 10 | config, |
2960 | @@ -16,6 +12,12 @@ | |||
2961 | 16 | ) | 12 | ) |
2962 | 17 | import os | 13 | import os |
2963 | 18 | 14 | ||
2964 | 15 | import six | ||
2965 | 16 | if six.PY3: | ||
2966 | 17 | from urllib.parse import urlparse, urlunparse | ||
2967 | 18 | else: | ||
2968 | 19 | from urlparse import urlparse, urlunparse | ||
2969 | 20 | |||
2970 | 19 | 21 | ||
2971 | 20 | CLOUD_ARCHIVE = """# Ubuntu Cloud Archive | 22 | CLOUD_ARCHIVE = """# Ubuntu Cloud Archive |
2972 | 21 | deb http://ubuntu-cloud.archive.canonical.com/ubuntu {} main | 23 | deb http://ubuntu-cloud.archive.canonical.com/ubuntu {} main |
2973 | @@ -149,7 +151,7 @@ | |||
2974 | 149 | cmd = ['apt-get', '--assume-yes'] | 151 | cmd = ['apt-get', '--assume-yes'] |
2975 | 150 | cmd.extend(options) | 152 | cmd.extend(options) |
2976 | 151 | cmd.append('install') | 153 | cmd.append('install') |
2978 | 152 | if isinstance(packages, basestring): | 154 | if isinstance(packages, six.string_types): |
2979 | 153 | cmd.append(packages) | 155 | cmd.append(packages) |
2980 | 154 | else: | 156 | else: |
2981 | 155 | cmd.extend(packages) | 157 | cmd.extend(packages) |
2982 | @@ -182,7 +184,7 @@ | |||
2983 | 182 | def apt_purge(packages, fatal=False): | 184 | def apt_purge(packages, fatal=False): |
2984 | 183 | """Purge one or more packages""" | 185 | """Purge one or more packages""" |
2985 | 184 | cmd = ['apt-get', '--assume-yes', 'purge'] | 186 | cmd = ['apt-get', '--assume-yes', 'purge'] |
2987 | 185 | if isinstance(packages, basestring): | 187 | if isinstance(packages, six.string_types): |
2988 | 186 | cmd.append(packages) | 188 | cmd.append(packages) |
2989 | 187 | else: | 189 | else: |
2990 | 188 | cmd.extend(packages) | 190 | cmd.extend(packages) |
2991 | @@ -193,7 +195,7 @@ | |||
2992 | 193 | def apt_hold(packages, fatal=False): | 195 | def apt_hold(packages, fatal=False): |
2993 | 194 | """Hold one or more packages""" | 196 | """Hold one or more packages""" |
2994 | 195 | cmd = ['apt-mark', 'hold'] | 197 | cmd = ['apt-mark', 'hold'] |
2996 | 196 | if isinstance(packages, basestring): | 198 | if isinstance(packages, six.string_types): |
2997 | 197 | cmd.append(packages) | 199 | cmd.append(packages) |
2998 | 198 | else: | 200 | else: |
2999 | 199 | cmd.extend(packages) | 201 | cmd.extend(packages) |
3000 | @@ -260,7 +262,7 @@ | |||
3001 | 260 | 262 | ||
3002 | 261 | if key: | 263 | if key: |
3003 | 262 | if '-----BEGIN PGP PUBLIC KEY BLOCK-----' in key: | 264 | if '-----BEGIN PGP PUBLIC KEY BLOCK-----' in key: |
3005 | 263 | with NamedTemporaryFile() as key_file: | 265 | with NamedTemporaryFile('w+') as key_file: |
3006 | 264 | key_file.write(key) | 266 | key_file.write(key) |
3007 | 265 | key_file.flush() | 267 | key_file.flush() |
3008 | 266 | key_file.seek(0) | 268 | key_file.seek(0) |
3009 | @@ -297,14 +299,14 @@ | |||
3010 | 297 | sources = safe_load((config(sources_var) or '').strip()) or [] | 299 | sources = safe_load((config(sources_var) or '').strip()) or [] |
3011 | 298 | keys = safe_load((config(keys_var) or '').strip()) or None | 300 | keys = safe_load((config(keys_var) or '').strip()) or None |
3012 | 299 | 301 | ||
3014 | 300 | if isinstance(sources, basestring): | 302 | if isinstance(sources, six.string_types): |
3015 | 301 | sources = [sources] | 303 | sources = [sources] |
3016 | 302 | 304 | ||
3017 | 303 | if keys is None: | 305 | if keys is None: |
3018 | 304 | for source in sources: | 306 | for source in sources: |
3019 | 305 | add_source(source, None) | 307 | add_source(source, None) |
3020 | 306 | else: | 308 | else: |
3022 | 307 | if isinstance(keys, basestring): | 309 | if isinstance(keys, six.string_types): |
3023 | 308 | keys = [keys] | 310 | keys = [keys] |
3024 | 309 | 311 | ||
3025 | 310 | if len(sources) != len(keys): | 312 | if len(sources) != len(keys): |
3026 | @@ -401,7 +403,7 @@ | |||
3027 | 401 | while result is None or result == APT_NO_LOCK: | 403 | while result is None or result == APT_NO_LOCK: |
3028 | 402 | try: | 404 | try: |
3029 | 403 | result = subprocess.check_call(cmd, env=env) | 405 | result = subprocess.check_call(cmd, env=env) |
3031 | 404 | except subprocess.CalledProcessError, e: | 406 | except subprocess.CalledProcessError as e: |
3032 | 405 | retry_count = retry_count + 1 | 407 | retry_count = retry_count + 1 |
3033 | 406 | if retry_count > APT_NO_LOCK_RETRY_COUNT: | 408 | if retry_count > APT_NO_LOCK_RETRY_COUNT: |
3034 | 407 | raise | 409 | raise |
3035 | 408 | 410 | ||
3036 | === modified file 'hooks/charmhelpers/fetch/archiveurl.py' | |||
3037 | --- hooks/charmhelpers/fetch/archiveurl.py 2014-10-06 20:51:06 +0000 | |||
3038 | +++ hooks/charmhelpers/fetch/archiveurl.py 2014-12-11 17:56:34 +0000 | |||
3039 | @@ -1,8 +1,23 @@ | |||
3040 | 1 | import os | 1 | import os |
3041 | 2 | import urllib2 | ||
3042 | 3 | from urllib import urlretrieve | ||
3043 | 4 | import urlparse | ||
3044 | 5 | import hashlib | 2 | import hashlib |
3045 | 3 | import re | ||
3046 | 4 | |||
3047 | 5 | import six | ||
3048 | 6 | if six.PY3: | ||
3049 | 7 | from urllib.request import ( | ||
3050 | 8 | build_opener, install_opener, urlopen, urlretrieve, | ||
3051 | 9 | HTTPPasswordMgrWithDefaultRealm, HTTPBasicAuthHandler, | ||
3052 | 10 | ) | ||
3053 | 11 | from urllib.parse import urlparse, urlunparse, parse_qs | ||
3054 | 12 | from urllib.error import URLError | ||
3055 | 13 | else: | ||
3056 | 14 | from urllib import urlretrieve | ||
3057 | 15 | from urllib2 import ( | ||
3058 | 16 | build_opener, install_opener, urlopen, | ||
3059 | 17 | HTTPPasswordMgrWithDefaultRealm, HTTPBasicAuthHandler, | ||
3060 | 18 | URLError | ||
3061 | 19 | ) | ||
3062 | 20 | from urlparse import urlparse, urlunparse, parse_qs | ||
3063 | 6 | 21 | ||
3064 | 7 | from charmhelpers.fetch import ( | 22 | from charmhelpers.fetch import ( |
3065 | 8 | BaseFetchHandler, | 23 | BaseFetchHandler, |
3066 | @@ -15,6 +30,24 @@ | |||
3067 | 15 | from charmhelpers.core.host import mkdir, check_hash | 30 | from charmhelpers.core.host import mkdir, check_hash |
3068 | 16 | 31 | ||
3069 | 17 | 32 | ||
3070 | 33 | def splituser(host): | ||
3071 | 34 | '''urllib.splituser(), but six's support of this seems broken''' | ||
3072 | 35 | _userprog = re.compile('^(.*)@(.*)$') | ||
3073 | 36 | match = _userprog.match(host) | ||
3074 | 37 | if match: | ||
3075 | 38 | return match.group(1, 2) | ||
3076 | 39 | return None, host | ||
3077 | 40 | |||
3078 | 41 | |||
3079 | 42 | def splitpasswd(user): | ||
3080 | 43 | '''urllib.splitpasswd(), but six's support of this is missing''' | ||
3081 | 44 | _passwdprog = re.compile('^([^:]*):(.*)$', re.S) | ||
3082 | 45 | match = _passwdprog.match(user) | ||
3083 | 46 | if match: | ||
3084 | 47 | return match.group(1, 2) | ||
3085 | 48 | return user, None | ||
3086 | 49 | |||
3087 | 50 | |||
3088 | 18 | class ArchiveUrlFetchHandler(BaseFetchHandler): | 51 | class ArchiveUrlFetchHandler(BaseFetchHandler): |
3089 | 19 | """ | 52 | """ |
3090 | 20 | Handler to download archive files from arbitrary URLs. | 53 | Handler to download archive files from arbitrary URLs. |
3091 | @@ -42,20 +75,20 @@ | |||
3092 | 42 | """ | 75 | """ |
3093 | 43 | # propogate all exceptions | 76 | # propogate all exceptions |
3094 | 44 | # URLError, OSError, etc | 77 | # URLError, OSError, etc |
3096 | 45 | proto, netloc, path, params, query, fragment = urlparse.urlparse(source) | 78 | proto, netloc, path, params, query, fragment = urlparse(source) |
3097 | 46 | if proto in ('http', 'https'): | 79 | if proto in ('http', 'https'): |
3099 | 47 | auth, barehost = urllib2.splituser(netloc) | 80 | auth, barehost = splituser(netloc) |
3100 | 48 | if auth is not None: | 81 | if auth is not None: |
3104 | 49 | source = urlparse.urlunparse((proto, barehost, path, params, query, fragment)) | 82 | source = urlunparse((proto, barehost, path, params, query, fragment)) |
3105 | 50 | username, password = urllib2.splitpasswd(auth) | 83 | username, password = splitpasswd(auth) |
3106 | 51 | passman = urllib2.HTTPPasswordMgrWithDefaultRealm() | 84 | passman = HTTPPasswordMgrWithDefaultRealm() |
3107 | 52 | # Realm is set to None in add_password to force the username and password | 85 | # Realm is set to None in add_password to force the username and password |
3108 | 53 | # to be used whatever the realm | 86 | # to be used whatever the realm |
3109 | 54 | passman.add_password(None, source, username, password) | 87 | passman.add_password(None, source, username, password) |
3114 | 55 | authhandler = urllib2.HTTPBasicAuthHandler(passman) | 88 | authhandler = HTTPBasicAuthHandler(passman) |
3115 | 56 | opener = urllib2.build_opener(authhandler) | 89 | opener = build_opener(authhandler) |
3116 | 57 | urllib2.install_opener(opener) | 90 | install_opener(opener) |
3117 | 58 | response = urllib2.urlopen(source) | 91 | response = urlopen(source) |
3118 | 59 | try: | 92 | try: |
3119 | 60 | with open(dest, 'w') as dest_file: | 93 | with open(dest, 'w') as dest_file: |
3120 | 61 | dest_file.write(response.read()) | 94 | dest_file.write(response.read()) |
3121 | @@ -91,17 +124,21 @@ | |||
3122 | 91 | url_parts = self.parse_url(source) | 124 | url_parts = self.parse_url(source) |
3123 | 92 | dest_dir = os.path.join(os.environ.get('CHARM_DIR'), 'fetched') | 125 | dest_dir = os.path.join(os.environ.get('CHARM_DIR'), 'fetched') |
3124 | 93 | if not os.path.exists(dest_dir): | 126 | if not os.path.exists(dest_dir): |
3126 | 94 | mkdir(dest_dir, perms=0755) | 127 | mkdir(dest_dir, perms=0o755) |
3127 | 95 | dld_file = os.path.join(dest_dir, os.path.basename(url_parts.path)) | 128 | dld_file = os.path.join(dest_dir, os.path.basename(url_parts.path)) |
3128 | 96 | try: | 129 | try: |
3129 | 97 | self.download(source, dld_file) | 130 | self.download(source, dld_file) |
3131 | 98 | except urllib2.URLError as e: | 131 | except URLError as e: |
3132 | 99 | raise UnhandledSource(e.reason) | 132 | raise UnhandledSource(e.reason) |
3133 | 100 | except OSError as e: | 133 | except OSError as e: |
3134 | 101 | raise UnhandledSource(e.strerror) | 134 | raise UnhandledSource(e.strerror) |
3136 | 102 | options = urlparse.parse_qs(url_parts.fragment) | 135 | options = parse_qs(url_parts.fragment) |
3137 | 103 | for key, value in options.items(): | 136 | for key, value in options.items(): |
3139 | 104 | if key in hashlib.algorithms: | 137 | if not six.PY3: |
3140 | 138 | algorithms = hashlib.algorithms | ||
3141 | 139 | else: | ||
3142 | 140 | algorithms = hashlib.algorithms_available | ||
3143 | 141 | if key in algorithms: | ||
3144 | 105 | check_hash(dld_file, value, key) | 142 | check_hash(dld_file, value, key) |
3145 | 106 | if checksum: | 143 | if checksum: |
3146 | 107 | check_hash(dld_file, checksum, hash_type) | 144 | check_hash(dld_file, checksum, hash_type) |
3147 | 108 | 145 | ||
3148 | === modified file 'hooks/charmhelpers/fetch/bzrurl.py' | |||
3149 | --- hooks/charmhelpers/fetch/bzrurl.py 2014-06-24 17:11:12 +0000 | |||
3150 | +++ hooks/charmhelpers/fetch/bzrurl.py 2014-12-11 17:56:34 +0000 | |||
3151 | @@ -5,6 +5,10 @@ | |||
3152 | 5 | ) | 5 | ) |
3153 | 6 | from charmhelpers.core.host import mkdir | 6 | from charmhelpers.core.host import mkdir |
3154 | 7 | 7 | ||
3155 | 8 | import six | ||
3156 | 9 | if six.PY3: | ||
3157 | 10 | raise ImportError('bzrlib does not support Python3') | ||
3158 | 11 | |||
3159 | 8 | try: | 12 | try: |
3160 | 9 | from bzrlib.branch import Branch | 13 | from bzrlib.branch import Branch |
3161 | 10 | except ImportError: | 14 | except ImportError: |
3162 | @@ -42,7 +46,7 @@ | |||
3163 | 42 | dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched", | 46 | dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched", |
3164 | 43 | branch_name) | 47 | branch_name) |
3165 | 44 | if not os.path.exists(dest_dir): | 48 | if not os.path.exists(dest_dir): |
3167 | 45 | mkdir(dest_dir, perms=0755) | 49 | mkdir(dest_dir, perms=0o755) |
3168 | 46 | try: | 50 | try: |
3169 | 47 | self.branch(source, dest_dir) | 51 | self.branch(source, dest_dir) |
3170 | 48 | except OSError as e: | 52 | except OSError as e: |
3171 | 49 | 53 | ||
3172 | === modified file 'hooks/charmhelpers/fetch/giturl.py' | |||
3173 | --- hooks/charmhelpers/fetch/giturl.py 2014-10-24 11:36:12 +0000 | |||
3174 | +++ hooks/charmhelpers/fetch/giturl.py 2014-12-11 17:56:34 +0000 | |||
3175 | @@ -5,6 +5,10 @@ | |||
3176 | 5 | ) | 5 | ) |
3177 | 6 | from charmhelpers.core.host import mkdir | 6 | from charmhelpers.core.host import mkdir |
3178 | 7 | 7 | ||
3179 | 8 | import six | ||
3180 | 9 | if six.PY3: | ||
3181 | 10 | raise ImportError('GitPython does not support Python 3') | ||
3182 | 11 | |||
3183 | 8 | try: | 12 | try: |
3184 | 9 | from git import Repo | 13 | from git import Repo |
3185 | 10 | except ImportError: | 14 | except ImportError: |
3186 | @@ -17,7 +21,7 @@ | |||
3187 | 17 | """Handler for git branches via generic and github URLs""" | 21 | """Handler for git branches via generic and github URLs""" |
3188 | 18 | def can_handle(self, source): | 22 | def can_handle(self, source): |
3189 | 19 | url_parts = self.parse_url(source) | 23 | url_parts = self.parse_url(source) |
3191 | 20 | #TODO (mattyw) no support for ssh git@ yet | 24 | # TODO (mattyw) no support for ssh git@ yet |
3192 | 21 | if url_parts.scheme not in ('http', 'https', 'git'): | 25 | if url_parts.scheme not in ('http', 'https', 'git'): |
3193 | 22 | return False | 26 | return False |
3194 | 23 | else: | 27 | else: |
3195 | @@ -30,13 +34,16 @@ | |||
3196 | 30 | repo = Repo.clone_from(source, dest) | 34 | repo = Repo.clone_from(source, dest) |
3197 | 31 | repo.git.checkout(branch) | 35 | repo.git.checkout(branch) |
3198 | 32 | 36 | ||
3200 | 33 | def install(self, source, branch="master"): | 37 | def install(self, source, branch="master", dest=None): |
3201 | 34 | url_parts = self.parse_url(source) | 38 | url_parts = self.parse_url(source) |
3202 | 35 | branch_name = url_parts.path.strip("/").split("/")[-1] | 39 | branch_name = url_parts.path.strip("/").split("/")[-1] |
3205 | 36 | dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched", | 40 | if dest: |
3206 | 37 | branch_name) | 41 | dest_dir = os.path.join(dest, branch_name) |
3207 | 42 | else: | ||
3208 | 43 | dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched", | ||
3209 | 44 | branch_name) | ||
3210 | 38 | if not os.path.exists(dest_dir): | 45 | if not os.path.exists(dest_dir): |
3212 | 39 | mkdir(dest_dir, perms=0755) | 46 | mkdir(dest_dir, perms=0o755) |
3213 | 40 | try: | 47 | try: |
3214 | 41 | self.clone(source, dest_dir, branch) | 48 | self.clone(source, dest_dir, branch) |
3215 | 42 | except OSError as e: | 49 | except OSError as e: |
3216 | 43 | 50 | ||
3217 | === modified file 'tests/charmhelpers/__init__.py' | |||
3218 | --- tests/charmhelpers/__init__.py 2014-06-24 17:11:12 +0000 | |||
3219 | +++ tests/charmhelpers/__init__.py 2014-12-11 17:56:34 +0000 | |||
3220 | @@ -0,0 +1,22 @@ | |||
3221 | 1 | # Bootstrap charm-helpers, installing its dependencies if necessary using | ||
3222 | 2 | # only standard libraries. | ||
3223 | 3 | import subprocess | ||
3224 | 4 | import sys | ||
3225 | 5 | |||
3226 | 6 | try: | ||
3227 | 7 | import six # flake8: noqa | ||
3228 | 8 | except ImportError: | ||
3229 | 9 | if sys.version_info.major == 2: | ||
3230 | 10 | subprocess.check_call(['apt-get', 'install', '-y', 'python-six']) | ||
3231 | 11 | else: | ||
3232 | 12 | subprocess.check_call(['apt-get', 'install', '-y', 'python3-six']) | ||
3233 | 13 | import six # flake8: noqa | ||
3234 | 14 | |||
3235 | 15 | try: | ||
3236 | 16 | import yaml # flake8: noqa | ||
3237 | 17 | except ImportError: | ||
3238 | 18 | if sys.version_info.major == 2: | ||
3239 | 19 | subprocess.check_call(['apt-get', 'install', '-y', 'python-yaml']) | ||
3240 | 20 | else: | ||
3241 | 21 | subprocess.check_call(['apt-get', 'install', '-y', 'python3-yaml']) | ||
3242 | 22 | import yaml # flake8: noqa | ||
3243 | 0 | 23 | ||
3244 | === modified file 'tests/charmhelpers/contrib/amulet/deployment.py' | |||
3245 | --- tests/charmhelpers/contrib/amulet/deployment.py 2014-10-06 20:51:06 +0000 | |||
3246 | +++ tests/charmhelpers/contrib/amulet/deployment.py 2014-12-11 17:56:34 +0000 | |||
3247 | @@ -1,6 +1,6 @@ | |||
3248 | 1 | import amulet | 1 | import amulet |
3249 | 2 | |||
3250 | 3 | import os | 2 | import os |
3251 | 3 | import six | ||
3252 | 4 | 4 | ||
3253 | 5 | 5 | ||
3254 | 6 | class AmuletDeployment(object): | 6 | class AmuletDeployment(object): |
3255 | @@ -52,12 +52,12 @@ | |||
3256 | 52 | 52 | ||
3257 | 53 | def _add_relations(self, relations): | 53 | def _add_relations(self, relations): |
3258 | 54 | """Add all of the relations for the services.""" | 54 | """Add all of the relations for the services.""" |
3260 | 55 | for k, v in relations.iteritems(): | 55 | for k, v in six.iteritems(relations): |
3261 | 56 | self.d.relate(k, v) | 56 | self.d.relate(k, v) |
3262 | 57 | 57 | ||
3263 | 58 | def _configure_services(self, configs): | 58 | def _configure_services(self, configs): |
3264 | 59 | """Configure all of the services.""" | 59 | """Configure all of the services.""" |
3266 | 60 | for service, config in configs.iteritems(): | 60 | for service, config in six.iteritems(configs): |
3267 | 61 | self.d.configure(service, config) | 61 | self.d.configure(service, config) |
3268 | 62 | 62 | ||
3269 | 63 | def _deploy(self): | 63 | def _deploy(self): |
3270 | 64 | 64 | ||
3271 | === modified file 'tests/charmhelpers/contrib/amulet/utils.py' | |||
3272 | --- tests/charmhelpers/contrib/amulet/utils.py 2014-07-30 15:11:18 +0000 | |||
3273 | +++ tests/charmhelpers/contrib/amulet/utils.py 2014-12-11 17:56:34 +0000 | |||
3274 | @@ -5,6 +5,8 @@ | |||
3275 | 5 | import sys | 5 | import sys |
3276 | 6 | import time | 6 | import time |
3277 | 7 | 7 | ||
3278 | 8 | import six | ||
3279 | 9 | |||
3280 | 8 | 10 | ||
3281 | 9 | class AmuletUtils(object): | 11 | class AmuletUtils(object): |
3282 | 10 | """Amulet utilities. | 12 | """Amulet utilities. |
3283 | @@ -58,7 +60,7 @@ | |||
3284 | 58 | Verify the specified services are running on the corresponding | 60 | Verify the specified services are running on the corresponding |
3285 | 59 | service units. | 61 | service units. |
3286 | 60 | """ | 62 | """ |
3288 | 61 | for k, v in commands.iteritems(): | 63 | for k, v in six.iteritems(commands): |
3289 | 62 | for cmd in v: | 64 | for cmd in v: |
3290 | 63 | output, code = k.run(cmd) | 65 | output, code = k.run(cmd) |
3291 | 64 | if code != 0: | 66 | if code != 0: |
3292 | @@ -100,11 +102,11 @@ | |||
3293 | 100 | longs, or can be a function that evaluate a variable and returns a | 102 | longs, or can be a function that evaluate a variable and returns a |
3294 | 101 | bool. | 103 | bool. |
3295 | 102 | """ | 104 | """ |
3297 | 103 | for k, v in expected.iteritems(): | 105 | for k, v in six.iteritems(expected): |
3298 | 104 | if k in actual: | 106 | if k in actual: |
3300 | 105 | if (isinstance(v, basestring) or | 107 | if (isinstance(v, six.string_types) or |
3301 | 106 | isinstance(v, bool) or | 108 | isinstance(v, bool) or |
3303 | 107 | isinstance(v, (int, long))): | 109 | isinstance(v, six.integer_types)): |
3304 | 108 | if v != actual[k]: | 110 | if v != actual[k]: |
3305 | 109 | return "{}:{}".format(k, actual[k]) | 111 | return "{}:{}".format(k, actual[k]) |
3306 | 110 | elif not v(actual[k]): | 112 | elif not v(actual[k]): |
3307 | 111 | 113 | ||
3308 | === modified file 'tests/charmhelpers/contrib/openstack/amulet/deployment.py' | |||
3309 | --- tests/charmhelpers/contrib/openstack/amulet/deployment.py 2014-10-06 20:51:06 +0000 | |||
3310 | +++ tests/charmhelpers/contrib/openstack/amulet/deployment.py 2014-12-11 17:56:34 +0000 | |||
3311 | @@ -1,3 +1,4 @@ | |||
3312 | 1 | import six | ||
3313 | 1 | from charmhelpers.contrib.amulet.deployment import ( | 2 | from charmhelpers.contrib.amulet.deployment import ( |
3314 | 2 | AmuletDeployment | 3 | AmuletDeployment |
3315 | 3 | ) | 4 | ) |
3316 | @@ -69,7 +70,7 @@ | |||
3317 | 69 | 70 | ||
3318 | 70 | def _configure_services(self, configs): | 71 | def _configure_services(self, configs): |
3319 | 71 | """Configure all of the services.""" | 72 | """Configure all of the services.""" |
3321 | 72 | for service, config in configs.iteritems(): | 73 | for service, config in six.iteritems(configs): |
3322 | 73 | self.d.configure(service, config) | 74 | self.d.configure(service, config) |
3323 | 74 | 75 | ||
3324 | 75 | def _get_openstack_release(self): | 76 | def _get_openstack_release(self): |
3325 | 76 | 77 | ||
3326 | === modified file 'tests/charmhelpers/contrib/openstack/amulet/utils.py' | |||
3327 | --- tests/charmhelpers/contrib/openstack/amulet/utils.py 2014-10-06 20:51:06 +0000 | |||
3328 | +++ tests/charmhelpers/contrib/openstack/amulet/utils.py 2014-12-11 17:56:34 +0000 | |||
3329 | @@ -7,6 +7,8 @@ | |||
3330 | 7 | import keystoneclient.v2_0 as keystone_client | 7 | import keystoneclient.v2_0 as keystone_client |
3331 | 8 | import novaclient.v1_1.client as nova_client | 8 | import novaclient.v1_1.client as nova_client |
3332 | 9 | 9 | ||
3333 | 10 | import six | ||
3334 | 11 | |||
3335 | 10 | from charmhelpers.contrib.amulet.utils import ( | 12 | from charmhelpers.contrib.amulet.utils import ( |
3336 | 11 | AmuletUtils | 13 | AmuletUtils |
3337 | 12 | ) | 14 | ) |
3338 | @@ -60,7 +62,7 @@ | |||
3339 | 60 | expected service catalog endpoints. | 62 | expected service catalog endpoints. |
3340 | 61 | """ | 63 | """ |
3341 | 62 | self.log.debug('actual: {}'.format(repr(actual))) | 64 | self.log.debug('actual: {}'.format(repr(actual))) |
3343 | 63 | for k, v in expected.iteritems(): | 65 | for k, v in six.iteritems(expected): |
3344 | 64 | if k in actual: | 66 | if k in actual: |
3345 | 65 | ret = self._validate_dict_data(expected[k][0], actual[k][0]) | 67 | ret = self._validate_dict_data(expected[k][0], actual[k][0]) |
3346 | 66 | if ret: | 68 | if ret: |
charm_lint_check #163 keystone-next for corey.bryant mp244323
LINT OK: passed
Build: http:// 10.230. 18.80:8080/ job/charm_ lint_check/ 163/