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