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