Merge lp:~1chb1n/charms/trusty/odl-controller/next-amulet-mitaka-1601 into lp:~openstack-charmers-archive/charms/trusty/odl-controller/next
- Trusty Tahr (14.04)
- next-amulet-mitaka-1601
- Merge into next
Status: | Rejected |
---|---|
Rejected by: | Ryan Beisner |
Proposed branch: | lp:~1chb1n/charms/trusty/odl-controller/next-amulet-mitaka-1601 |
Merge into: | lp:~openstack-charmers-archive/charms/trusty/odl-controller/next |
Diff against target: |
2070 lines (+889/-288) 20 files modified
hooks/charmhelpers/contrib/network/ip.py (+21/-19) hooks/charmhelpers/contrib/openstack/amulet/deployment.py (+9/-3) hooks/charmhelpers/contrib/openstack/context.py (+32/-2) hooks/charmhelpers/contrib/openstack/files/check_haproxy.sh (+7/-5) hooks/charmhelpers/contrib/openstack/neutron.py (+8/-8) hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg (+19/-11) hooks/charmhelpers/contrib/openstack/utils.py (+100/-54) hooks/charmhelpers/contrib/python/packages.py (+13/-4) hooks/charmhelpers/contrib/storage/linux/ceph.py (+441/-59) hooks/charmhelpers/contrib/storage/linux/loopback.py (+10/-0) hooks/charmhelpers/core/hookenv.py (+41/-7) hooks/charmhelpers/core/host.py (+103/-43) hooks/charmhelpers/core/services/helpers.py (+11/-5) hooks/charmhelpers/core/templating.py (+13/-7) hooks/charmhelpers/fetch/__init__.py (+9/-1) hooks/charmhelpers/fetch/archiveurl.py (+1/-1) hooks/charmhelpers/fetch/bzrurl.py (+22/-32) hooks/charmhelpers/fetch/giturl.py (+20/-23) tests/basic_deployment.py (+1/-1) tests/charmhelpers/contrib/openstack/amulet/deployment.py (+8/-3) |
To merge this branch: | bzr merge lp:~1chb1n/charms/trusty/odl-controller/next-amulet-mitaka-1601 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
James Page | Needs Fixing | ||
Review via email: mp+283530@code.launchpad.net |
Commit message
Description of the change
Enable mitaka amulet test; update test for neutron catalog names (lp1535410).
uosci-testing-bot (uosci-testing-bot) wrote : | # |
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #16692 odl-controller-next for 1chb1n mp283530
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #8939 odl-controller-next for 1chb1n mp283530
AMULET FAIL: amulet-test failed
AMULET Results (max last 2 lines):
make: *** [functional_test] Error 1
ERROR:root:Make target returned non-zero.
Full amulet test output: http://
Build: http://
- 19. By Ryan Beisner
-
sync charmhelpers for mitaka cloud archive recognition
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #17930 odl-controller-next for 1chb1n mp283530
LINT OK: passed
Build: http://
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #16755 odl-controller-next for 1chb1n mp283530
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #8955 odl-controller-next for 1chb1n mp283530
AMULET FAIL: amulet-test failed
AMULET Results (max last 2 lines):
make: *** [functional_test] Error 1
ERROR:root:Make target returned non-zero.
Full amulet test output: http://
Build: http://
James Page (james-page) wrote : | # |
Ryan
there is a bug in charm-helpers that I fixed this morning that causes odl-controller to fail to install - a resync on this MP should resolve.
- 20. By Ryan Beisner
-
resync charm helpers
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #16764 odl-controller-next for 1chb1n mp283530
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #17940 odl-controller-next for 1chb1n mp283530
LINT OK: passed
Build: http://
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #8965 odl-controller-next for 1chb1n mp283530
AMULET FAIL: amulet-test failed
AMULET Results (max last 2 lines):
make: *** [functional_test] Error 1
ERROR:root:Make target returned non-zero.
Full amulet test output: http://
Build: http://
Unmerged revisions
- 20. By Ryan Beisner
-
resync charm helpers
- 19. By Ryan Beisner
-
sync charmhelpers for mitaka cloud archive recognition
- 18. By Ryan Beisner
-
enable mitaka amulet test
- 17. By Ryan Beisner
-
update test for neutron catalog names (lp1535410)
Preview Diff
1 | === modified file 'hooks/charmhelpers/contrib/network/ip.py' | |||
2 | --- hooks/charmhelpers/contrib/network/ip.py 2015-11-11 14:57:38 +0000 | |||
3 | +++ hooks/charmhelpers/contrib/network/ip.py 2016-01-22 14:18:52 +0000 | |||
4 | @@ -53,7 +53,7 @@ | |||
5 | 53 | 53 | ||
6 | 54 | 54 | ||
7 | 55 | def no_ip_found_error_out(network): | 55 | def no_ip_found_error_out(network): |
9 | 56 | errmsg = ("No IP address found in network: %s" % network) | 56 | errmsg = ("No IP address found in network(s): %s" % network) |
10 | 57 | raise ValueError(errmsg) | 57 | raise ValueError(errmsg) |
11 | 58 | 58 | ||
12 | 59 | 59 | ||
13 | @@ -61,7 +61,7 @@ | |||
14 | 61 | """Get an IPv4 or IPv6 address within the network from the host. | 61 | """Get an IPv4 or IPv6 address within the network from the host. |
15 | 62 | 62 | ||
16 | 63 | :param network (str): CIDR presentation format. For example, | 63 | :param network (str): CIDR presentation format. For example, |
18 | 64 | '192.168.1.0/24'. | 64 | '192.168.1.0/24'. Supports multiple networks as a space-delimited list. |
19 | 65 | :param fallback (str): If no address is found, return fallback. | 65 | :param fallback (str): If no address is found, return fallback. |
20 | 66 | :param fatal (boolean): If no address is found, fallback is not | 66 | :param fatal (boolean): If no address is found, fallback is not |
21 | 67 | set and fatal is True then exit(1). | 67 | set and fatal is True then exit(1). |
22 | @@ -75,24 +75,26 @@ | |||
23 | 75 | else: | 75 | else: |
24 | 76 | return None | 76 | return None |
25 | 77 | 77 | ||
36 | 78 | _validate_cidr(network) | 78 | networks = network.split() or [network] |
37 | 79 | network = netaddr.IPNetwork(network) | 79 | for network in networks: |
38 | 80 | for iface in netifaces.interfaces(): | 80 | _validate_cidr(network) |
39 | 81 | addresses = netifaces.ifaddresses(iface) | 81 | network = netaddr.IPNetwork(network) |
40 | 82 | if network.version == 4 and netifaces.AF_INET in addresses: | 82 | for iface in netifaces.interfaces(): |
41 | 83 | addr = addresses[netifaces.AF_INET][0]['addr'] | 83 | addresses = netifaces.ifaddresses(iface) |
42 | 84 | netmask = addresses[netifaces.AF_INET][0]['netmask'] | 84 | if network.version == 4 and netifaces.AF_INET in addresses: |
43 | 85 | cidr = netaddr.IPNetwork("%s/%s" % (addr, netmask)) | 85 | addr = addresses[netifaces.AF_INET][0]['addr'] |
44 | 86 | if cidr in network: | 86 | netmask = addresses[netifaces.AF_INET][0]['netmask'] |
45 | 87 | return str(cidr.ip) | 87 | cidr = netaddr.IPNetwork("%s/%s" % (addr, netmask)) |
46 | 88 | if cidr in network: | ||
47 | 89 | return str(cidr.ip) | ||
48 | 88 | 90 | ||
56 | 89 | if network.version == 6 and netifaces.AF_INET6 in addresses: | 91 | if network.version == 6 and netifaces.AF_INET6 in addresses: |
57 | 90 | for addr in addresses[netifaces.AF_INET6]: | 92 | for addr in addresses[netifaces.AF_INET6]: |
58 | 91 | if not addr['addr'].startswith('fe80'): | 93 | if not addr['addr'].startswith('fe80'): |
59 | 92 | cidr = netaddr.IPNetwork("%s/%s" % (addr['addr'], | 94 | cidr = netaddr.IPNetwork("%s/%s" % (addr['addr'], |
60 | 93 | addr['netmask'])) | 95 | addr['netmask'])) |
61 | 94 | if cidr in network: | 96 | if cidr in network: |
62 | 95 | return str(cidr.ip) | 97 | return str(cidr.ip) |
63 | 96 | 98 | ||
64 | 97 | if fallback is not None: | 99 | if fallback is not None: |
65 | 98 | return fallback | 100 | return fallback |
66 | 99 | 101 | ||
67 | === modified file 'hooks/charmhelpers/contrib/openstack/amulet/deployment.py' | |||
68 | --- hooks/charmhelpers/contrib/openstack/amulet/deployment.py 2015-11-11 14:57:38 +0000 | |||
69 | +++ hooks/charmhelpers/contrib/openstack/amulet/deployment.py 2016-01-22 14:18:52 +0000 | |||
70 | @@ -124,7 +124,9 @@ | |||
71 | 124 | 'ceph-osd', 'ceph-radosgw'] | 124 | 'ceph-osd', 'ceph-radosgw'] |
72 | 125 | 125 | ||
73 | 126 | # Charms which can not use openstack-origin, ie. many subordinates | 126 | # Charms which can not use openstack-origin, ie. many subordinates |
75 | 127 | no_origin = ['cinder-ceph', 'hacluster', 'neutron-openvswitch', 'nrpe'] | 127 | no_origin = ['cinder-ceph', 'hacluster', 'neutron-openvswitch', 'nrpe', |
76 | 128 | 'openvswitch-odl', 'neutron-api-odl', 'odl-controller', | ||
77 | 129 | 'cinder-backup'] | ||
78 | 128 | 130 | ||
79 | 129 | if self.openstack: | 131 | if self.openstack: |
80 | 130 | for svc in services: | 132 | for svc in services: |
81 | @@ -224,7 +226,8 @@ | |||
82 | 224 | self.precise_havana, self.precise_icehouse, | 226 | self.precise_havana, self.precise_icehouse, |
83 | 225 | self.trusty_icehouse, self.trusty_juno, self.utopic_juno, | 227 | self.trusty_icehouse, self.trusty_juno, self.utopic_juno, |
84 | 226 | self.trusty_kilo, self.vivid_kilo, self.trusty_liberty, | 228 | self.trusty_kilo, self.vivid_kilo, self.trusty_liberty, |
86 | 227 | self.wily_liberty) = range(12) | 229 | self.wily_liberty, self.trusty_mitaka, |
87 | 230 | self.xenial_mitaka) = range(14) | ||
88 | 228 | 231 | ||
89 | 229 | releases = { | 232 | releases = { |
90 | 230 | ('precise', None): self.precise_essex, | 233 | ('precise', None): self.precise_essex, |
91 | @@ -236,9 +239,11 @@ | |||
92 | 236 | ('trusty', 'cloud:trusty-juno'): self.trusty_juno, | 239 | ('trusty', 'cloud:trusty-juno'): self.trusty_juno, |
93 | 237 | ('trusty', 'cloud:trusty-kilo'): self.trusty_kilo, | 240 | ('trusty', 'cloud:trusty-kilo'): self.trusty_kilo, |
94 | 238 | ('trusty', 'cloud:trusty-liberty'): self.trusty_liberty, | 241 | ('trusty', 'cloud:trusty-liberty'): self.trusty_liberty, |
95 | 242 | ('trusty', 'cloud:trusty-mitaka'): self.trusty_mitaka, | ||
96 | 239 | ('utopic', None): self.utopic_juno, | 243 | ('utopic', None): self.utopic_juno, |
97 | 240 | ('vivid', None): self.vivid_kilo, | 244 | ('vivid', None): self.vivid_kilo, |
99 | 241 | ('wily', None): self.wily_liberty} | 245 | ('wily', None): self.wily_liberty, |
100 | 246 | ('xenial', None): self.xenial_mitaka} | ||
101 | 242 | return releases[(self.series, self.openstack)] | 247 | return releases[(self.series, self.openstack)] |
102 | 243 | 248 | ||
103 | 244 | def _get_openstack_release_string(self): | 249 | def _get_openstack_release_string(self): |
104 | @@ -255,6 +260,7 @@ | |||
105 | 255 | ('utopic', 'juno'), | 260 | ('utopic', 'juno'), |
106 | 256 | ('vivid', 'kilo'), | 261 | ('vivid', 'kilo'), |
107 | 257 | ('wily', 'liberty'), | 262 | ('wily', 'liberty'), |
108 | 263 | ('xenial', 'mitaka'), | ||
109 | 258 | ]) | 264 | ]) |
110 | 259 | if self.openstack: | 265 | if self.openstack: |
111 | 260 | os_origin = self.openstack.split(':')[1] | 266 | os_origin = self.openstack.split(':')[1] |
112 | 261 | 267 | ||
113 | === modified file 'hooks/charmhelpers/contrib/openstack/context.py' | |||
114 | --- hooks/charmhelpers/contrib/openstack/context.py 2015-11-11 14:57:38 +0000 | |||
115 | +++ hooks/charmhelpers/contrib/openstack/context.py 2016-01-22 14:18:52 +0000 | |||
116 | @@ -57,6 +57,7 @@ | |||
117 | 57 | get_nic_hwaddr, | 57 | get_nic_hwaddr, |
118 | 58 | mkdir, | 58 | mkdir, |
119 | 59 | write_file, | 59 | write_file, |
120 | 60 | pwgen, | ||
121 | 60 | ) | 61 | ) |
122 | 61 | from charmhelpers.contrib.hahelpers.cluster import ( | 62 | from charmhelpers.contrib.hahelpers.cluster import ( |
123 | 62 | determine_apache_port, | 63 | determine_apache_port, |
124 | @@ -87,6 +88,8 @@ | |||
125 | 87 | is_bridge_member, | 88 | is_bridge_member, |
126 | 88 | ) | 89 | ) |
127 | 89 | from charmhelpers.contrib.openstack.utils import get_host_ip | 90 | from charmhelpers.contrib.openstack.utils import get_host_ip |
128 | 91 | from charmhelpers.core.unitdata import kv | ||
129 | 92 | |||
130 | 90 | CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt' | 93 | CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt' |
131 | 91 | ADDRESS_TYPES = ['admin', 'internal', 'public'] | 94 | ADDRESS_TYPES = ['admin', 'internal', 'public'] |
132 | 92 | 95 | ||
133 | @@ -626,15 +629,28 @@ | |||
134 | 626 | if config('haproxy-client-timeout'): | 629 | if config('haproxy-client-timeout'): |
135 | 627 | ctxt['haproxy_client_timeout'] = config('haproxy-client-timeout') | 630 | ctxt['haproxy_client_timeout'] = config('haproxy-client-timeout') |
136 | 628 | 631 | ||
137 | 632 | if config('haproxy-queue-timeout'): | ||
138 | 633 | ctxt['haproxy_queue_timeout'] = config('haproxy-queue-timeout') | ||
139 | 634 | |||
140 | 635 | if config('haproxy-connect-timeout'): | ||
141 | 636 | ctxt['haproxy_connect_timeout'] = config('haproxy-connect-timeout') | ||
142 | 637 | |||
143 | 629 | if config('prefer-ipv6'): | 638 | if config('prefer-ipv6'): |
144 | 630 | ctxt['ipv6'] = True | 639 | ctxt['ipv6'] = True |
145 | 631 | ctxt['local_host'] = 'ip6-localhost' | 640 | ctxt['local_host'] = 'ip6-localhost' |
146 | 632 | ctxt['haproxy_host'] = '::' | 641 | ctxt['haproxy_host'] = '::' |
147 | 633 | ctxt['stat_port'] = ':::8888' | ||
148 | 634 | else: | 642 | else: |
149 | 635 | ctxt['local_host'] = '127.0.0.1' | 643 | ctxt['local_host'] = '127.0.0.1' |
150 | 636 | ctxt['haproxy_host'] = '0.0.0.0' | 644 | ctxt['haproxy_host'] = '0.0.0.0' |
152 | 637 | ctxt['stat_port'] = ':8888' | 645 | |
153 | 646 | ctxt['stat_port'] = '8888' | ||
154 | 647 | |||
155 | 648 | db = kv() | ||
156 | 649 | ctxt['stat_password'] = db.get('stat-password') | ||
157 | 650 | if not ctxt['stat_password']: | ||
158 | 651 | ctxt['stat_password'] = db.set('stat-password', | ||
159 | 652 | pwgen(32)) | ||
160 | 653 | db.flush() | ||
161 | 638 | 654 | ||
162 | 639 | for frontend in cluster_hosts: | 655 | for frontend in cluster_hosts: |
163 | 640 | if (len(cluster_hosts[frontend]['backends']) > 1 or | 656 | if (len(cluster_hosts[frontend]['backends']) > 1 or |
164 | @@ -1088,6 +1104,20 @@ | |||
165 | 1088 | config_flags_parser(config_flags)} | 1104 | config_flags_parser(config_flags)} |
166 | 1089 | 1105 | ||
167 | 1090 | 1106 | ||
168 | 1107 | class LibvirtConfigFlagsContext(OSContextGenerator): | ||
169 | 1108 | """ | ||
170 | 1109 | This context provides support for extending | ||
171 | 1110 | the libvirt section through user-defined flags. | ||
172 | 1111 | """ | ||
173 | 1112 | def __call__(self): | ||
174 | 1113 | ctxt = {} | ||
175 | 1114 | libvirt_flags = config('libvirt-flags') | ||
176 | 1115 | if libvirt_flags: | ||
177 | 1116 | ctxt['libvirt_flags'] = config_flags_parser( | ||
178 | 1117 | libvirt_flags) | ||
179 | 1118 | return ctxt | ||
180 | 1119 | |||
181 | 1120 | |||
182 | 1091 | class SubordinateConfigContext(OSContextGenerator): | 1121 | class SubordinateConfigContext(OSContextGenerator): |
183 | 1092 | 1122 | ||
184 | 1093 | """ | 1123 | """ |
185 | 1094 | 1124 | ||
186 | === modified file 'hooks/charmhelpers/contrib/openstack/files/check_haproxy.sh' | |||
187 | --- hooks/charmhelpers/contrib/openstack/files/check_haproxy.sh 2015-07-22 12:10:31 +0000 | |||
188 | +++ hooks/charmhelpers/contrib/openstack/files/check_haproxy.sh 2016-01-22 14:18:52 +0000 | |||
189 | @@ -9,15 +9,17 @@ | |||
190 | 9 | CRITICAL=0 | 9 | CRITICAL=0 |
191 | 10 | NOTACTIVE='' | 10 | NOTACTIVE='' |
192 | 11 | LOGFILE=/var/log/nagios/check_haproxy.log | 11 | LOGFILE=/var/log/nagios/check_haproxy.log |
194 | 12 | AUTH=$(grep -r "stats auth" /etc/haproxy | head -1 | awk '{print $4}') | 12 | AUTH=$(grep -r "stats auth" /etc/haproxy | awk 'NR=1{print $4}') |
195 | 13 | 13 | ||
197 | 14 | for appserver in $(grep ' server' /etc/haproxy/haproxy.cfg | awk '{print $2'}); | 14 | typeset -i N_INSTANCES=0 |
198 | 15 | for appserver in $(awk '/^\s+server/{print $2}' /etc/haproxy/haproxy.cfg) | ||
199 | 15 | do | 16 | do |
201 | 16 | output=$(/usr/lib/nagios/plugins/check_http -a ${AUTH} -I 127.0.0.1 -p 8888 --regex="class=\"(active|backup)(2|3).*${appserver}" -e ' 200 OK') | 17 | N_INSTANCES=N_INSTANCES+1 |
202 | 18 | output=$(/usr/lib/nagios/plugins/check_http -a ${AUTH} -I 127.0.0.1 -p 8888 -u '/;csv' --regex=",${appserver},.*,UP.*" -e ' 200 OK') | ||
203 | 17 | if [ $? != 0 ]; then | 19 | if [ $? != 0 ]; then |
204 | 18 | date >> $LOGFILE | 20 | date >> $LOGFILE |
205 | 19 | echo $output >> $LOGFILE | 21 | echo $output >> $LOGFILE |
207 | 20 | /usr/lib/nagios/plugins/check_http -a ${AUTH} -I 127.0.0.1 -p 8888 -v | grep $appserver >> $LOGFILE 2>&1 | 22 | /usr/lib/nagios/plugins/check_http -a ${AUTH} -I 127.0.0.1 -p 8888 -u '/;csv' -v | grep ",${appserver}," >> $LOGFILE 2>&1 |
208 | 21 | CRITICAL=1 | 23 | CRITICAL=1 |
209 | 22 | NOTACTIVE="${NOTACTIVE} $appserver" | 24 | NOTACTIVE="${NOTACTIVE} $appserver" |
210 | 23 | fi | 25 | fi |
211 | @@ -28,5 +30,5 @@ | |||
212 | 28 | exit 2 | 30 | exit 2 |
213 | 29 | fi | 31 | fi |
214 | 30 | 32 | ||
216 | 31 | echo "OK: All haproxy instances looking good" | 33 | echo "OK: All haproxy instances ($N_INSTANCES) looking good" |
217 | 32 | exit 0 | 34 | exit 0 |
218 | 33 | 35 | ||
219 | === modified file 'hooks/charmhelpers/contrib/openstack/neutron.py' | |||
220 | --- hooks/charmhelpers/contrib/openstack/neutron.py 2015-11-11 14:57:38 +0000 | |||
221 | +++ hooks/charmhelpers/contrib/openstack/neutron.py 2016-01-22 14:18:52 +0000 | |||
222 | @@ -50,7 +50,7 @@ | |||
223 | 50 | if kernel_version() >= (3, 13): | 50 | if kernel_version() >= (3, 13): |
224 | 51 | return [] | 51 | return [] |
225 | 52 | else: | 52 | else: |
227 | 53 | return ['openvswitch-datapath-dkms'] | 53 | return [headers_package(), 'openvswitch-datapath-dkms'] |
228 | 54 | 54 | ||
229 | 55 | 55 | ||
230 | 56 | # legacy | 56 | # legacy |
231 | @@ -70,7 +70,7 @@ | |||
232 | 70 | relation_prefix='neutron', | 70 | relation_prefix='neutron', |
233 | 71 | ssl_dir=QUANTUM_CONF_DIR)], | 71 | ssl_dir=QUANTUM_CONF_DIR)], |
234 | 72 | 'services': ['quantum-plugin-openvswitch-agent'], | 72 | 'services': ['quantum-plugin-openvswitch-agent'], |
236 | 73 | 'packages': [[headers_package()] + determine_dkms_package(), | 73 | 'packages': [determine_dkms_package(), |
237 | 74 | ['quantum-plugin-openvswitch-agent']], | 74 | ['quantum-plugin-openvswitch-agent']], |
238 | 75 | 'server_packages': ['quantum-server', | 75 | 'server_packages': ['quantum-server', |
239 | 76 | 'quantum-plugin-openvswitch'], | 76 | 'quantum-plugin-openvswitch'], |
240 | @@ -111,7 +111,7 @@ | |||
241 | 111 | relation_prefix='neutron', | 111 | relation_prefix='neutron', |
242 | 112 | ssl_dir=NEUTRON_CONF_DIR)], | 112 | ssl_dir=NEUTRON_CONF_DIR)], |
243 | 113 | 'services': ['neutron-plugin-openvswitch-agent'], | 113 | 'services': ['neutron-plugin-openvswitch-agent'], |
245 | 114 | 'packages': [[headers_package()] + determine_dkms_package(), | 114 | 'packages': [determine_dkms_package(), |
246 | 115 | ['neutron-plugin-openvswitch-agent']], | 115 | ['neutron-plugin-openvswitch-agent']], |
247 | 116 | 'server_packages': ['neutron-server', | 116 | 'server_packages': ['neutron-server', |
248 | 117 | 'neutron-plugin-openvswitch'], | 117 | 'neutron-plugin-openvswitch'], |
249 | @@ -155,7 +155,7 @@ | |||
250 | 155 | relation_prefix='neutron', | 155 | relation_prefix='neutron', |
251 | 156 | ssl_dir=NEUTRON_CONF_DIR)], | 156 | ssl_dir=NEUTRON_CONF_DIR)], |
252 | 157 | 'services': [], | 157 | 'services': [], |
254 | 158 | 'packages': [[headers_package()] + determine_dkms_package(), | 158 | 'packages': [determine_dkms_package(), |
255 | 159 | ['neutron-plugin-cisco']], | 159 | ['neutron-plugin-cisco']], |
256 | 160 | 'server_packages': ['neutron-server', | 160 | 'server_packages': ['neutron-server', |
257 | 161 | 'neutron-plugin-cisco'], | 161 | 'neutron-plugin-cisco'], |
258 | @@ -174,7 +174,7 @@ | |||
259 | 174 | 'neutron-dhcp-agent', | 174 | 'neutron-dhcp-agent', |
260 | 175 | 'nova-api-metadata', | 175 | 'nova-api-metadata', |
261 | 176 | 'etcd'], | 176 | 'etcd'], |
263 | 177 | 'packages': [[headers_package()] + determine_dkms_package(), | 177 | 'packages': [determine_dkms_package(), |
264 | 178 | ['calico-compute', | 178 | ['calico-compute', |
265 | 179 | 'bird', | 179 | 'bird', |
266 | 180 | 'neutron-dhcp-agent', | 180 | 'neutron-dhcp-agent', |
267 | @@ -204,8 +204,8 @@ | |||
268 | 204 | database=config('database'), | 204 | database=config('database'), |
269 | 205 | ssl_dir=NEUTRON_CONF_DIR)], | 205 | ssl_dir=NEUTRON_CONF_DIR)], |
270 | 206 | 'services': [], | 206 | 'services': [], |
273 | 207 | 'packages': [['plumgrid-lxc'], | 207 | 'packages': ['plumgrid-lxc', |
274 | 208 | ['iovisor-dkms']], | 208 | 'iovisor-dkms'], |
275 | 209 | 'server_packages': ['neutron-server', | 209 | 'server_packages': ['neutron-server', |
276 | 210 | 'neutron-plugin-plumgrid'], | 210 | 'neutron-plugin-plumgrid'], |
277 | 211 | 'server_services': ['neutron-server'] | 211 | 'server_services': ['neutron-server'] |
278 | @@ -219,7 +219,7 @@ | |||
279 | 219 | relation_prefix='neutron', | 219 | relation_prefix='neutron', |
280 | 220 | ssl_dir=NEUTRON_CONF_DIR)], | 220 | ssl_dir=NEUTRON_CONF_DIR)], |
281 | 221 | 'services': [], | 221 | 'services': [], |
283 | 222 | 'packages': [[headers_package()] + determine_dkms_package()], | 222 | 'packages': [determine_dkms_package()], |
284 | 223 | 'server_packages': ['neutron-server', | 223 | 'server_packages': ['neutron-server', |
285 | 224 | 'python-neutron-plugin-midonet'], | 224 | 'python-neutron-plugin-midonet'], |
286 | 225 | 'server_services': ['neutron-server'] | 225 | 'server_services': ['neutron-server'] |
287 | 226 | 226 | ||
288 | === modified file 'hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg' | |||
289 | --- hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg 2015-02-19 22:08:13 +0000 | |||
290 | +++ hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg 2016-01-22 14:18:52 +0000 | |||
291 | @@ -12,27 +12,35 @@ | |||
292 | 12 | option tcplog | 12 | option tcplog |
293 | 13 | option dontlognull | 13 | option dontlognull |
294 | 14 | retries 3 | 14 | retries 3 |
298 | 15 | timeout queue 1000 | 15 | {%- if haproxy_queue_timeout %} |
299 | 16 | timeout connect 1000 | 16 | timeout queue {{ haproxy_queue_timeout }} |
300 | 17 | {% if haproxy_client_timeout -%} | 17 | {%- else %} |
301 | 18 | timeout queue 5000 | ||
302 | 19 | {%- endif %} | ||
303 | 20 | {%- if haproxy_connect_timeout %} | ||
304 | 21 | timeout connect {{ haproxy_connect_timeout }} | ||
305 | 22 | {%- else %} | ||
306 | 23 | timeout connect 5000 | ||
307 | 24 | {%- endif %} | ||
308 | 25 | {%- if haproxy_client_timeout %} | ||
309 | 18 | timeout client {{ haproxy_client_timeout }} | 26 | timeout client {{ haproxy_client_timeout }} |
311 | 19 | {% else -%} | 27 | {%- else %} |
312 | 20 | timeout client 30000 | 28 | timeout client 30000 |
316 | 21 | {% endif -%} | 29 | {%- endif %} |
317 | 22 | 30 | {%- if haproxy_server_timeout %} | |
315 | 23 | {% if haproxy_server_timeout -%} | ||
318 | 24 | timeout server {{ haproxy_server_timeout }} | 31 | timeout server {{ haproxy_server_timeout }} |
320 | 25 | {% else -%} | 32 | {%- else %} |
321 | 26 | timeout server 30000 | 33 | timeout server 30000 |
323 | 27 | {% endif -%} | 34 | {%- endif %} |
324 | 28 | 35 | ||
326 | 29 | listen stats {{ stat_port }} | 36 | listen stats |
327 | 37 | bind {{ local_host }}:{{ stat_port }} | ||
328 | 30 | mode http | 38 | mode http |
329 | 31 | stats enable | 39 | stats enable |
330 | 32 | stats hide-version | 40 | stats hide-version |
331 | 33 | stats realm Haproxy\ Statistics | 41 | stats realm Haproxy\ Statistics |
332 | 34 | stats uri / | 42 | stats uri / |
334 | 35 | stats auth admin:password | 43 | stats auth admin:{{ stat_password }} |
335 | 36 | 44 | ||
336 | 37 | {% if frontends -%} | 45 | {% if frontends -%} |
337 | 38 | {% for service, ports in service_ports.items() -%} | 46 | {% for service, ports in service_ports.items() -%} |
338 | 39 | 47 | ||
339 | === modified file 'hooks/charmhelpers/contrib/openstack/utils.py' | |||
340 | --- hooks/charmhelpers/contrib/openstack/utils.py 2015-11-11 14:57:38 +0000 | |||
341 | +++ hooks/charmhelpers/contrib/openstack/utils.py 2016-01-22 14:18:52 +0000 | |||
342 | @@ -86,6 +86,7 @@ | |||
343 | 86 | ('utopic', 'juno'), | 86 | ('utopic', 'juno'), |
344 | 87 | ('vivid', 'kilo'), | 87 | ('vivid', 'kilo'), |
345 | 88 | ('wily', 'liberty'), | 88 | ('wily', 'liberty'), |
346 | 89 | ('xenial', 'mitaka'), | ||
347 | 89 | ]) | 90 | ]) |
348 | 90 | 91 | ||
349 | 91 | 92 | ||
350 | @@ -99,61 +100,70 @@ | |||
351 | 99 | ('2014.2', 'juno'), | 100 | ('2014.2', 'juno'), |
352 | 100 | ('2015.1', 'kilo'), | 101 | ('2015.1', 'kilo'), |
353 | 101 | ('2015.2', 'liberty'), | 102 | ('2015.2', 'liberty'), |
354 | 103 | ('2016.1', 'mitaka'), | ||
355 | 102 | ]) | 104 | ]) |
356 | 103 | 105 | ||
358 | 104 | # The ugly duckling | 106 | # The ugly duckling - must list releases oldest to newest |
359 | 105 | SWIFT_CODENAMES = OrderedDict([ | 107 | SWIFT_CODENAMES = OrderedDict([ |
381 | 106 | ('1.4.3', 'diablo'), | 108 | ('diablo', |
382 | 107 | ('1.4.8', 'essex'), | 109 | ['1.4.3']), |
383 | 108 | ('1.7.4', 'folsom'), | 110 | ('essex', |
384 | 109 | ('1.8.0', 'grizzly'), | 111 | ['1.4.8']), |
385 | 110 | ('1.7.7', 'grizzly'), | 112 | ('folsom', |
386 | 111 | ('1.7.6', 'grizzly'), | 113 | ['1.7.4']), |
387 | 112 | ('1.10.0', 'havana'), | 114 | ('grizzly', |
388 | 113 | ('1.9.1', 'havana'), | 115 | ['1.7.6', '1.7.7', '1.8.0']), |
389 | 114 | ('1.9.0', 'havana'), | 116 | ('havana', |
390 | 115 | ('1.13.1', 'icehouse'), | 117 | ['1.9.0', '1.9.1', '1.10.0']), |
391 | 116 | ('1.13.0', 'icehouse'), | 118 | ('icehouse', |
392 | 117 | ('1.12.0', 'icehouse'), | 119 | ['1.11.0', '1.12.0', '1.13.0', '1.13.1']), |
393 | 118 | ('1.11.0', 'icehouse'), | 120 | ('juno', |
394 | 119 | ('2.0.0', 'juno'), | 121 | ['2.0.0', '2.1.0', '2.2.0']), |
395 | 120 | ('2.1.0', 'juno'), | 122 | ('kilo', |
396 | 121 | ('2.2.0', 'juno'), | 123 | ['2.2.1', '2.2.2']), |
397 | 122 | ('2.2.1', 'kilo'), | 124 | ('liberty', |
398 | 123 | ('2.2.2', 'kilo'), | 125 | ['2.3.0', '2.4.0', '2.5.0']), |
399 | 124 | ('2.3.0', 'liberty'), | 126 | ('mitaka', |
400 | 125 | ('2.4.0', 'liberty'), | 127 | ['2.5.0']), |
380 | 126 | ('2.5.0', 'liberty'), | ||
401 | 127 | ]) | 128 | ]) |
402 | 128 | 129 | ||
403 | 129 | # >= Liberty version->codename mapping | 130 | # >= Liberty version->codename mapping |
404 | 130 | PACKAGE_CODENAMES = { | 131 | PACKAGE_CODENAMES = { |
405 | 131 | 'nova-common': OrderedDict([ | 132 | 'nova-common': OrderedDict([ |
407 | 132 | ('12.0.0', 'liberty'), | 133 | ('12.0', 'liberty'), |
408 | 134 | ('13.0', 'mitaka'), | ||
409 | 133 | ]), | 135 | ]), |
410 | 134 | 'neutron-common': OrderedDict([ | 136 | 'neutron-common': OrderedDict([ |
412 | 135 | ('7.0.0', 'liberty'), | 137 | ('7.0', 'liberty'), |
413 | 138 | ('8.0', 'mitaka'), | ||
414 | 136 | ]), | 139 | ]), |
415 | 137 | 'cinder-common': OrderedDict([ | 140 | 'cinder-common': OrderedDict([ |
417 | 138 | ('7.0.0', 'liberty'), | 141 | ('7.0', 'liberty'), |
418 | 142 | ('8.0', 'mitaka'), | ||
419 | 139 | ]), | 143 | ]), |
420 | 140 | 'keystone': OrderedDict([ | 144 | 'keystone': OrderedDict([ |
422 | 141 | ('8.0.0', 'liberty'), | 145 | ('8.0', 'liberty'), |
423 | 146 | ('9.0', 'mitaka'), | ||
424 | 142 | ]), | 147 | ]), |
425 | 143 | 'horizon-common': OrderedDict([ | 148 | 'horizon-common': OrderedDict([ |
427 | 144 | ('8.0.0', 'liberty'), | 149 | ('8.0', 'liberty'), |
428 | 150 | ('9.0', 'mitaka'), | ||
429 | 145 | ]), | 151 | ]), |
430 | 146 | 'ceilometer-common': OrderedDict([ | 152 | 'ceilometer-common': OrderedDict([ |
432 | 147 | ('5.0.0', 'liberty'), | 153 | ('5.0', 'liberty'), |
433 | 154 | ('6.0', 'mitaka'), | ||
434 | 148 | ]), | 155 | ]), |
435 | 149 | 'heat-common': OrderedDict([ | 156 | 'heat-common': OrderedDict([ |
437 | 150 | ('5.0.0', 'liberty'), | 157 | ('5.0', 'liberty'), |
438 | 158 | ('6.0', 'mitaka'), | ||
439 | 151 | ]), | 159 | ]), |
440 | 152 | 'glance-common': OrderedDict([ | 160 | 'glance-common': OrderedDict([ |
442 | 153 | ('11.0.0', 'liberty'), | 161 | ('11.0', 'liberty'), |
443 | 162 | ('12.0', 'mitaka'), | ||
444 | 154 | ]), | 163 | ]), |
445 | 155 | 'openstack-dashboard': OrderedDict([ | 164 | 'openstack-dashboard': OrderedDict([ |
447 | 156 | ('8.0.0', 'liberty'), | 165 | ('8.0', 'liberty'), |
448 | 166 | ('9.0', 'mitaka'), | ||
449 | 157 | ]), | 167 | ]), |
450 | 158 | } | 168 | } |
451 | 159 | 169 | ||
452 | @@ -216,6 +226,33 @@ | |||
453 | 216 | error_out(e) | 226 | error_out(e) |
454 | 217 | 227 | ||
455 | 218 | 228 | ||
456 | 229 | def get_os_version_codename_swift(codename): | ||
457 | 230 | '''Determine OpenStack version number of swift from codename.''' | ||
458 | 231 | for k, v in six.iteritems(SWIFT_CODENAMES): | ||
459 | 232 | if k == codename: | ||
460 | 233 | return v[-1] | ||
461 | 234 | e = 'Could not derive swift version for '\ | ||
462 | 235 | 'codename: %s' % codename | ||
463 | 236 | error_out(e) | ||
464 | 237 | |||
465 | 238 | |||
466 | 239 | def get_swift_codename(version): | ||
467 | 240 | '''Determine OpenStack codename that corresponds to swift version.''' | ||
468 | 241 | codenames = [k for k, v in six.iteritems(SWIFT_CODENAMES) if version in v] | ||
469 | 242 | if len(codenames) > 1: | ||
470 | 243 | # If more than one release codename contains this version we determine | ||
471 | 244 | # the actual codename based on the highest available install source. | ||
472 | 245 | for codename in reversed(codenames): | ||
473 | 246 | releases = UBUNTU_OPENSTACK_RELEASE | ||
474 | 247 | release = [k for k, v in six.iteritems(releases) if codename in v] | ||
475 | 248 | ret = subprocess.check_output(['apt-cache', 'policy', 'swift']) | ||
476 | 249 | if codename in ret or release[0] in ret: | ||
477 | 250 | return codename | ||
478 | 251 | elif len(codenames) == 1: | ||
479 | 252 | return codenames[0] | ||
480 | 253 | return None | ||
481 | 254 | |||
482 | 255 | |||
483 | 219 | def get_os_codename_package(package, fatal=True): | 256 | def get_os_codename_package(package, fatal=True): |
484 | 220 | '''Derive OpenStack release codename from an installed package.''' | 257 | '''Derive OpenStack release codename from an installed package.''' |
485 | 221 | import apt_pkg as apt | 258 | import apt_pkg as apt |
486 | @@ -240,7 +277,14 @@ | |||
487 | 240 | error_out(e) | 277 | error_out(e) |
488 | 241 | 278 | ||
489 | 242 | vers = apt.upstream_version(pkg.current_ver.ver_str) | 279 | vers = apt.upstream_version(pkg.current_ver.ver_str) |
491 | 243 | match = re.match('^(\d+)\.(\d+)\.(\d+)', vers) | 280 | if 'swift' in pkg.name: |
492 | 281 | # Fully x.y.z match for swift versions | ||
493 | 282 | match = re.match('^(\d+)\.(\d+)\.(\d+)', vers) | ||
494 | 283 | else: | ||
495 | 284 | # x.y match only for 20XX.X | ||
496 | 285 | # and ignore patch level for other packages | ||
497 | 286 | match = re.match('^(\d+)\.(\d+)', vers) | ||
498 | 287 | |||
499 | 244 | if match: | 288 | if match: |
500 | 245 | vers = match.group(0) | 289 | vers = match.group(0) |
501 | 246 | 290 | ||
502 | @@ -252,13 +296,8 @@ | |||
503 | 252 | # < Liberty co-ordinated project versions | 296 | # < Liberty co-ordinated project versions |
504 | 253 | try: | 297 | try: |
505 | 254 | if 'swift' in pkg.name: | 298 | if 'swift' in pkg.name: |
511 | 255 | swift_vers = vers[:5] | 299 | return get_swift_codename(vers) |
507 | 256 | if swift_vers not in SWIFT_CODENAMES: | ||
508 | 257 | # Deal with 1.10.0 upward | ||
509 | 258 | swift_vers = vers[:6] | ||
510 | 259 | return SWIFT_CODENAMES[swift_vers] | ||
512 | 260 | else: | 300 | else: |
513 | 261 | vers = vers[:6] | ||
514 | 262 | return OPENSTACK_CODENAMES[vers] | 301 | return OPENSTACK_CODENAMES[vers] |
515 | 263 | except KeyError: | 302 | except KeyError: |
516 | 264 | if not fatal: | 303 | if not fatal: |
517 | @@ -276,12 +315,14 @@ | |||
518 | 276 | 315 | ||
519 | 277 | if 'swift' in pkg: | 316 | if 'swift' in pkg: |
520 | 278 | vers_map = SWIFT_CODENAMES | 317 | vers_map = SWIFT_CODENAMES |
521 | 318 | for cname, version in six.iteritems(vers_map): | ||
522 | 319 | if cname == codename: | ||
523 | 320 | return version[-1] | ||
524 | 279 | else: | 321 | else: |
525 | 280 | vers_map = OPENSTACK_CODENAMES | 322 | vers_map = OPENSTACK_CODENAMES |
530 | 281 | 323 | for version, cname in six.iteritems(vers_map): | |
531 | 282 | for version, cname in six.iteritems(vers_map): | 324 | if cname == codename: |
532 | 283 | if cname == codename: | 325 | return version |
529 | 284 | return version | ||
533 | 285 | # e = "Could not determine OpenStack version for package: %s" % pkg | 326 | # e = "Could not determine OpenStack version for package: %s" % pkg |
534 | 286 | # error_out(e) | 327 | # error_out(e) |
535 | 287 | 328 | ||
536 | @@ -377,6 +418,9 @@ | |||
537 | 377 | 'liberty': 'trusty-updates/liberty', | 418 | 'liberty': 'trusty-updates/liberty', |
538 | 378 | 'liberty/updates': 'trusty-updates/liberty', | 419 | 'liberty/updates': 'trusty-updates/liberty', |
539 | 379 | 'liberty/proposed': 'trusty-proposed/liberty', | 420 | 'liberty/proposed': 'trusty-proposed/liberty', |
540 | 421 | 'mitaka': 'trusty-updates/mitaka', | ||
541 | 422 | 'mitaka/updates': 'trusty-updates/mitaka', | ||
542 | 423 | 'mitaka/proposed': 'trusty-proposed/mitaka', | ||
543 | 380 | } | 424 | } |
544 | 381 | 425 | ||
545 | 382 | try: | 426 | try: |
546 | @@ -444,11 +488,16 @@ | |||
547 | 444 | cur_vers = get_os_version_package(package) | 488 | cur_vers = get_os_version_package(package) |
548 | 445 | if "swift" in package: | 489 | if "swift" in package: |
549 | 446 | codename = get_os_codename_install_source(src) | 490 | codename = get_os_codename_install_source(src) |
551 | 447 | available_vers = get_os_version_codename(codename, SWIFT_CODENAMES) | 491 | avail_vers = get_os_version_codename_swift(codename) |
552 | 448 | else: | 492 | else: |
554 | 449 | available_vers = get_os_version_install_source(src) | 493 | avail_vers = get_os_version_install_source(src) |
555 | 450 | apt.init() | 494 | apt.init() |
557 | 451 | return apt.version_compare(available_vers, cur_vers) == 1 | 495 | if "swift" in package: |
558 | 496 | major_cur_vers = cur_vers.split('.', 1)[0] | ||
559 | 497 | major_avail_vers = avail_vers.split('.', 1)[0] | ||
560 | 498 | major_diff = apt.version_compare(major_avail_vers, major_cur_vers) | ||
561 | 499 | return avail_vers > cur_vers and (major_diff == 1 or major_diff == 0) | ||
562 | 500 | return apt.version_compare(avail_vers, cur_vers) == 1 | ||
563 | 452 | 501 | ||
564 | 453 | 502 | ||
565 | 454 | def ensure_block_device(block_device): | 503 | def ensure_block_device(block_device): |
566 | @@ -577,7 +626,7 @@ | |||
567 | 577 | return yaml.load(projects_yaml) | 626 | return yaml.load(projects_yaml) |
568 | 578 | 627 | ||
569 | 579 | 628 | ||
571 | 580 | def git_clone_and_install(projects_yaml, core_project, depth=1): | 629 | def git_clone_and_install(projects_yaml, core_project): |
572 | 581 | """ | 630 | """ |
573 | 582 | Clone/install all specified OpenStack repositories. | 631 | Clone/install all specified OpenStack repositories. |
574 | 583 | 632 | ||
575 | @@ -627,6 +676,9 @@ | |||
576 | 627 | for p in projects['repositories']: | 676 | for p in projects['repositories']: |
577 | 628 | repo = p['repository'] | 677 | repo = p['repository'] |
578 | 629 | branch = p['branch'] | 678 | branch = p['branch'] |
579 | 679 | depth = '1' | ||
580 | 680 | if 'depth' in p.keys(): | ||
581 | 681 | depth = p['depth'] | ||
582 | 630 | if p['name'] == 'requirements': | 682 | if p['name'] == 'requirements': |
583 | 631 | repo_dir = _git_clone_and_install_single(repo, branch, depth, | 683 | repo_dir = _git_clone_and_install_single(repo, branch, depth, |
584 | 632 | parent_dir, http_proxy, | 684 | parent_dir, http_proxy, |
585 | @@ -671,19 +723,13 @@ | |||
586 | 671 | """ | 723 | """ |
587 | 672 | Clone and install a single git repository. | 724 | Clone and install a single git repository. |
588 | 673 | """ | 725 | """ |
589 | 674 | dest_dir = os.path.join(parent_dir, os.path.basename(repo)) | ||
590 | 675 | |||
591 | 676 | if not os.path.exists(parent_dir): | 726 | if not os.path.exists(parent_dir): |
592 | 677 | juju_log('Directory already exists at {}. ' | 727 | juju_log('Directory already exists at {}. ' |
593 | 678 | 'No need to create directory.'.format(parent_dir)) | 728 | 'No need to create directory.'.format(parent_dir)) |
594 | 679 | os.mkdir(parent_dir) | 729 | os.mkdir(parent_dir) |
595 | 680 | 730 | ||
602 | 681 | if not os.path.exists(dest_dir): | 731 | juju_log('Cloning git repo: {}, branch: {}'.format(repo, branch)) |
603 | 682 | juju_log('Cloning git repo: {}, branch: {}'.format(repo, branch)) | 732 | repo_dir = install_remote(repo, dest=parent_dir, branch=branch, depth=depth) |
598 | 683 | repo_dir = install_remote(repo, dest=parent_dir, branch=branch, | ||
599 | 684 | depth=depth) | ||
600 | 685 | else: | ||
601 | 686 | repo_dir = dest_dir | ||
604 | 687 | 733 | ||
605 | 688 | venv = os.path.join(parent_dir, 'venv') | 734 | venv = os.path.join(parent_dir, 'venv') |
606 | 689 | 735 | ||
607 | 690 | 736 | ||
608 | === modified file 'hooks/charmhelpers/contrib/python/packages.py' | |||
609 | --- hooks/charmhelpers/contrib/python/packages.py 2015-11-11 14:57:38 +0000 | |||
610 | +++ hooks/charmhelpers/contrib/python/packages.py 2016-01-22 14:18:52 +0000 | |||
611 | @@ -42,8 +42,12 @@ | |||
612 | 42 | yield "--{0}={1}".format(key, value) | 42 | yield "--{0}={1}".format(key, value) |
613 | 43 | 43 | ||
614 | 44 | 44 | ||
617 | 45 | def pip_install_requirements(requirements, **options): | 45 | def pip_install_requirements(requirements, constraints=None, **options): |
618 | 46 | """Install a requirements file """ | 46 | """Install a requirements file. |
619 | 47 | |||
620 | 48 | :param constraints: Path to pip constraints file. | ||
621 | 49 | http://pip.readthedocs.org/en/stable/user_guide/#constraints-files | ||
622 | 50 | """ | ||
623 | 47 | command = ["install"] | 51 | command = ["install"] |
624 | 48 | 52 | ||
625 | 49 | available_options = ('proxy', 'src', 'log', ) | 53 | available_options = ('proxy', 'src', 'log', ) |
626 | @@ -51,8 +55,13 @@ | |||
627 | 51 | command.append(option) | 55 | command.append(option) |
628 | 52 | 56 | ||
629 | 53 | command.append("-r {0}".format(requirements)) | 57 | command.append("-r {0}".format(requirements)) |
632 | 54 | log("Installing from file: {} with options: {}".format(requirements, | 58 | if constraints: |
633 | 55 | command)) | 59 | command.append("-c {0}".format(constraints)) |
634 | 60 | log("Installing from file: {} with constraints {} " | ||
635 | 61 | "and options: {}".format(requirements, constraints, command)) | ||
636 | 62 | else: | ||
637 | 63 | log("Installing from file: {} with options: {}".format(requirements, | ||
638 | 64 | command)) | ||
639 | 56 | pip_execute(command) | 65 | pip_execute(command) |
640 | 57 | 66 | ||
641 | 58 | 67 | ||
642 | 59 | 68 | ||
643 | === modified file 'hooks/charmhelpers/contrib/storage/linux/ceph.py' | |||
644 | --- hooks/charmhelpers/contrib/storage/linux/ceph.py 2015-11-11 14:57:38 +0000 | |||
645 | +++ hooks/charmhelpers/contrib/storage/linux/ceph.py 2016-01-22 14:18:52 +0000 | |||
646 | @@ -23,6 +23,8 @@ | |||
647 | 23 | # James Page <james.page@ubuntu.com> | 23 | # James Page <james.page@ubuntu.com> |
648 | 24 | # Adam Gandelman <adamg@ubuntu.com> | 24 | # Adam Gandelman <adamg@ubuntu.com> |
649 | 25 | # | 25 | # |
650 | 26 | import bisect | ||
651 | 27 | import six | ||
652 | 26 | 28 | ||
653 | 27 | import os | 29 | import os |
654 | 28 | import shutil | 30 | import shutil |
655 | @@ -72,6 +74,394 @@ | |||
656 | 72 | err to syslog = {use_syslog} | 74 | err to syslog = {use_syslog} |
657 | 73 | clog to syslog = {use_syslog} | 75 | clog to syslog = {use_syslog} |
658 | 74 | """ | 76 | """ |
659 | 77 | # For 50 < osds < 240,000 OSDs (Roughly 1 Exabyte at 6T OSDs) | ||
660 | 78 | powers_of_two = [8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608] | ||
661 | 79 | |||
662 | 80 | |||
663 | 81 | def validator(value, valid_type, valid_range=None): | ||
664 | 82 | """ | ||
665 | 83 | Used to validate these: http://docs.ceph.com/docs/master/rados/operations/pools/#set-pool-values | ||
666 | 84 | Example input: | ||
667 | 85 | validator(value=1, | ||
668 | 86 | valid_type=int, | ||
669 | 87 | valid_range=[0, 2]) | ||
670 | 88 | This says I'm testing value=1. It must be an int inclusive in [0,2] | ||
671 | 89 | |||
672 | 90 | :param value: The value to validate | ||
673 | 91 | :param valid_type: The type that value should be. | ||
674 | 92 | :param valid_range: A range of values that value can assume. | ||
675 | 93 | :return: | ||
676 | 94 | """ | ||
677 | 95 | assert isinstance(value, valid_type), "{} is not a {}".format( | ||
678 | 96 | value, | ||
679 | 97 | valid_type) | ||
680 | 98 | if valid_range is not None: | ||
681 | 99 | assert isinstance(valid_range, list), \ | ||
682 | 100 | "valid_range must be a list, was given {}".format(valid_range) | ||
683 | 101 | # If we're dealing with strings | ||
684 | 102 | if valid_type is six.string_types: | ||
685 | 103 | assert value in valid_range, \ | ||
686 | 104 | "{} is not in the list {}".format(value, valid_range) | ||
687 | 105 | # Integer, float should have a min and max | ||
688 | 106 | else: | ||
689 | 107 | if len(valid_range) != 2: | ||
690 | 108 | raise ValueError( | ||
691 | 109 | "Invalid valid_range list of {} for {}. " | ||
692 | 110 | "List must be [min,max]".format(valid_range, value)) | ||
693 | 111 | assert value >= valid_range[0], \ | ||
694 | 112 | "{} is less than minimum allowed value of {}".format( | ||
695 | 113 | value, valid_range[0]) | ||
696 | 114 | assert value <= valid_range[1], \ | ||
697 | 115 | "{} is greater than maximum allowed value of {}".format( | ||
698 | 116 | value, valid_range[1]) | ||
699 | 117 | |||
700 | 118 | |||
701 | 119 | class PoolCreationError(Exception): | ||
702 | 120 | """ | ||
703 | 121 | A custom error to inform the caller that a pool creation failed. Provides an error message | ||
704 | 122 | """ | ||
705 | 123 | def __init__(self, message): | ||
706 | 124 | super(PoolCreationError, self).__init__(message) | ||
707 | 125 | |||
708 | 126 | |||
709 | 127 | class Pool(object): | ||
710 | 128 | """ | ||
711 | 129 | An object oriented approach to Ceph pool creation. This base class is inherited by ReplicatedPool and ErasurePool. | ||
712 | 130 | Do not call create() on this base class as it will not do anything. Instantiate a child class and call create(). | ||
713 | 131 | """ | ||
714 | 132 | def __init__(self, service, name): | ||
715 | 133 | self.service = service | ||
716 | 134 | self.name = name | ||
717 | 135 | |||
718 | 136 | # Create the pool if it doesn't exist already | ||
719 | 137 | # To be implemented by subclasses | ||
720 | 138 | def create(self): | ||
721 | 139 | pass | ||
722 | 140 | |||
723 | 141 | def add_cache_tier(self, cache_pool, mode): | ||
724 | 142 | """ | ||
725 | 143 | Adds a new cache tier to an existing pool. | ||
726 | 144 | :param cache_pool: six.string_types. The cache tier pool name to add. | ||
727 | 145 | :param mode: six.string_types. The caching mode to use for this pool. valid range = ["readonly", "writeback"] | ||
728 | 146 | :return: None | ||
729 | 147 | """ | ||
730 | 148 | # Check the input types and values | ||
731 | 149 | validator(value=cache_pool, valid_type=six.string_types) | ||
732 | 150 | validator(value=mode, valid_type=six.string_types, valid_range=["readonly", "writeback"]) | ||
733 | 151 | |||
734 | 152 | check_call(['ceph', '--id', self.service, 'osd', 'tier', 'add', self.name, cache_pool]) | ||
735 | 153 | check_call(['ceph', '--id', self.service, 'osd', 'tier', 'cache-mode', cache_pool, mode]) | ||
736 | 154 | check_call(['ceph', '--id', self.service, 'osd', 'tier', 'set-overlay', self.name, cache_pool]) | ||
737 | 155 | check_call(['ceph', '--id', self.service, 'osd', 'pool', 'set', cache_pool, 'hit_set_type', 'bloom']) | ||
738 | 156 | |||
739 | 157 | def remove_cache_tier(self, cache_pool): | ||
740 | 158 | """ | ||
741 | 159 | Removes a cache tier from Ceph. Flushes all dirty objects from writeback pools and waits for that to complete. | ||
742 | 160 | :param cache_pool: six.string_types. The cache tier pool name to remove. | ||
743 | 161 | :return: None | ||
744 | 162 | """ | ||
745 | 163 | # read-only is easy, writeback is much harder | ||
746 | 164 | mode = get_cache_mode(cache_pool) | ||
747 | 165 | if mode == 'readonly': | ||
748 | 166 | check_call(['ceph', '--id', self.service, 'osd', 'tier', 'cache-mode', cache_pool, 'none']) | ||
749 | 167 | check_call(['ceph', '--id', self.service, 'osd', 'tier', 'remove', self.name, cache_pool]) | ||
750 | 168 | |||
751 | 169 | elif mode == 'writeback': | ||
752 | 170 | check_call(['ceph', '--id', self.service, 'osd', 'tier', 'cache-mode', cache_pool, 'forward']) | ||
753 | 171 | # Flush the cache and wait for it to return | ||
754 | 172 | check_call(['ceph', '--id', self.service, '-p', cache_pool, 'cache-flush-evict-all']) | ||
755 | 173 | check_call(['ceph', '--id', self.service, 'osd', 'tier', 'remove-overlay', self.name]) | ||
756 | 174 | check_call(['ceph', '--id', self.service, 'osd', 'tier', 'remove', self.name, cache_pool]) | ||
757 | 175 | |||
758 | 176 | def get_pgs(self, pool_size): | ||
759 | 177 | """ | ||
760 | 178 | :param pool_size: int. pool_size is either the number of replicas for replicated pools or the K+M sum for | ||
761 | 179 | erasure coded pools | ||
762 | 180 | :return: int. The number of pgs to use. | ||
763 | 181 | """ | ||
764 | 182 | validator(value=pool_size, valid_type=int) | ||
765 | 183 | osds = get_osds(self.service) | ||
766 | 184 | if not osds: | ||
767 | 185 | # NOTE(james-page): Default to 200 for older ceph versions | ||
768 | 186 | # which don't support OSD query from cli | ||
769 | 187 | return 200 | ||
770 | 188 | |||
771 | 189 | # Calculate based on Ceph best practices | ||
772 | 190 | if osds < 5: | ||
773 | 191 | return 128 | ||
774 | 192 | elif 5 < osds < 10: | ||
775 | 193 | return 512 | ||
776 | 194 | elif 10 < osds < 50: | ||
777 | 195 | return 4096 | ||
778 | 196 | else: | ||
779 | 197 | estimate = (osds * 100) / pool_size | ||
780 | 198 | # Return the next nearest power of 2 | ||
781 | 199 | index = bisect.bisect_right(powers_of_two, estimate) | ||
782 | 200 | return powers_of_two[index] | ||
783 | 201 | |||
784 | 202 | |||
785 | 203 | class ReplicatedPool(Pool): | ||
786 | 204 | def __init__(self, service, name, replicas=2): | ||
787 | 205 | super(ReplicatedPool, self).__init__(service=service, name=name) | ||
788 | 206 | self.replicas = replicas | ||
789 | 207 | |||
790 | 208 | def create(self): | ||
791 | 209 | if not pool_exists(self.service, self.name): | ||
792 | 210 | # Create it | ||
793 | 211 | pgs = self.get_pgs(self.replicas) | ||
794 | 212 | cmd = ['ceph', '--id', self.service, 'osd', 'pool', 'create', self.name, str(pgs)] | ||
795 | 213 | try: | ||
796 | 214 | check_call(cmd) | ||
797 | 215 | except CalledProcessError: | ||
798 | 216 | raise | ||
799 | 217 | |||
800 | 218 | |||
801 | 219 | # Default jerasure erasure coded pool | ||
802 | 220 | class ErasurePool(Pool): | ||
803 | 221 | def __init__(self, service, name, erasure_code_profile="default"): | ||
804 | 222 | super(ErasurePool, self).__init__(service=service, name=name) | ||
805 | 223 | self.erasure_code_profile = erasure_code_profile | ||
806 | 224 | |||
807 | 225 | def create(self): | ||
808 | 226 | if not pool_exists(self.service, self.name): | ||
809 | 227 | # Try to find the erasure profile information so we can properly size the pgs | ||
810 | 228 | erasure_profile = get_erasure_profile(service=self.service, name=self.erasure_code_profile) | ||
811 | 229 | |||
812 | 230 | # Check for errors | ||
813 | 231 | if erasure_profile is None: | ||
814 | 232 | log(message='Failed to discover erasure_profile named={}'.format(self.erasure_code_profile), | ||
815 | 233 | level=ERROR) | ||
816 | 234 | raise PoolCreationError(message='unable to find erasure profile {}'.format(self.erasure_code_profile)) | ||
817 | 235 | if 'k' not in erasure_profile or 'm' not in erasure_profile: | ||
818 | 236 | # Error | ||
819 | 237 | log(message='Unable to find k (data chunks) or m (coding chunks) in {}'.format(erasure_profile), | ||
820 | 238 | level=ERROR) | ||
821 | 239 | raise PoolCreationError( | ||
822 | 240 | message='unable to find k (data chunks) or m (coding chunks) in {}'.format(erasure_profile)) | ||
823 | 241 | |||
824 | 242 | pgs = self.get_pgs(int(erasure_profile['k']) + int(erasure_profile['m'])) | ||
825 | 243 | # Create it | ||
826 | 244 | cmd = ['ceph', '--id', self.service, 'osd', 'pool', 'create', self.name, str(pgs), | ||
827 | 245 | 'erasure', self.erasure_code_profile] | ||
828 | 246 | try: | ||
829 | 247 | check_call(cmd) | ||
830 | 248 | except CalledProcessError: | ||
831 | 249 | raise | ||
832 | 250 | |||
833 | 251 | """Get an existing erasure code profile if it already exists. | ||
834 | 252 | Returns json formatted output""" | ||
835 | 253 | |||
836 | 254 | |||
837 | 255 | def get_erasure_profile(service, name): | ||
838 | 256 | """ | ||
839 | 257 | :param service: six.string_types. The Ceph user name to run the command under | ||
840 | 258 | :param name: | ||
841 | 259 | :return: | ||
842 | 260 | """ | ||
843 | 261 | try: | ||
844 | 262 | out = check_output(['ceph', '--id', service, | ||
845 | 263 | 'osd', 'erasure-code-profile', 'get', | ||
846 | 264 | name, '--format=json']) | ||
847 | 265 | return json.loads(out) | ||
848 | 266 | except (CalledProcessError, OSError, ValueError): | ||
849 | 267 | return None | ||
850 | 268 | |||
851 | 269 | |||
852 | 270 | def pool_set(service, pool_name, key, value): | ||
853 | 271 | """ | ||
854 | 272 | Sets a value for a RADOS pool in ceph. | ||
855 | 273 | :param service: six.string_types. The Ceph user name to run the command under | ||
856 | 274 | :param pool_name: six.string_types | ||
857 | 275 | :param key: six.string_types | ||
858 | 276 | :param value: | ||
859 | 277 | :return: None. Can raise CalledProcessError | ||
860 | 278 | """ | ||
861 | 279 | cmd = ['ceph', '--id', service, 'osd', 'pool', 'set', pool_name, key, value] | ||
862 | 280 | try: | ||
863 | 281 | check_call(cmd) | ||
864 | 282 | except CalledProcessError: | ||
865 | 283 | raise | ||
866 | 284 | |||
867 | 285 | |||
868 | 286 | def snapshot_pool(service, pool_name, snapshot_name): | ||
869 | 287 | """ | ||
870 | 288 | Snapshots a RADOS pool in ceph. | ||
871 | 289 | :param service: six.string_types. The Ceph user name to run the command under | ||
872 | 290 | :param pool_name: six.string_types | ||
873 | 291 | :param snapshot_name: six.string_types | ||
874 | 292 | :return: None. Can raise CalledProcessError | ||
875 | 293 | """ | ||
876 | 294 | cmd = ['ceph', '--id', service, 'osd', 'pool', 'mksnap', pool_name, snapshot_name] | ||
877 | 295 | try: | ||
878 | 296 | check_call(cmd) | ||
879 | 297 | except CalledProcessError: | ||
880 | 298 | raise | ||
881 | 299 | |||
882 | 300 | |||
883 | 301 | def remove_pool_snapshot(service, pool_name, snapshot_name): | ||
884 | 302 | """ | ||
885 | 303 | Remove a snapshot from a RADOS pool in ceph. | ||
886 | 304 | :param service: six.string_types. The Ceph user name to run the command under | ||
887 | 305 | :param pool_name: six.string_types | ||
888 | 306 | :param snapshot_name: six.string_types | ||
889 | 307 | :return: None. Can raise CalledProcessError | ||
890 | 308 | """ | ||
891 | 309 | cmd = ['ceph', '--id', service, 'osd', 'pool', 'rmsnap', pool_name, snapshot_name] | ||
892 | 310 | try: | ||
893 | 311 | check_call(cmd) | ||
894 | 312 | except CalledProcessError: | ||
895 | 313 | raise | ||
896 | 314 | |||
897 | 315 | |||
898 | 316 | # max_bytes should be an int or long | ||
899 | 317 | def set_pool_quota(service, pool_name, max_bytes): | ||
900 | 318 | """ | ||
901 | 319 | :param service: six.string_types. The Ceph user name to run the command under | ||
902 | 320 | :param pool_name: six.string_types | ||
903 | 321 | :param max_bytes: int or long | ||
904 | 322 | :return: None. Can raise CalledProcessError | ||
905 | 323 | """ | ||
906 | 324 | # Set a byte quota on a RADOS pool in ceph. | ||
907 | 325 | cmd = ['ceph', '--id', service, 'osd', 'pool', 'set-quota', pool_name, 'max_bytes', max_bytes] | ||
908 | 326 | try: | ||
909 | 327 | check_call(cmd) | ||
910 | 328 | except CalledProcessError: | ||
911 | 329 | raise | ||
912 | 330 | |||
913 | 331 | |||
914 | 332 | def remove_pool_quota(service, pool_name): | ||
915 | 333 | """ | ||
916 | 334 | Set a byte quota on a RADOS pool in ceph. | ||
917 | 335 | :param service: six.string_types. The Ceph user name to run the command under | ||
918 | 336 | :param pool_name: six.string_types | ||
919 | 337 | :return: None. Can raise CalledProcessError | ||
920 | 338 | """ | ||
921 | 339 | cmd = ['ceph', '--id', service, 'osd', 'pool', 'set-quota', pool_name, 'max_bytes', '0'] | ||
922 | 340 | try: | ||
923 | 341 | check_call(cmd) | ||
924 | 342 | except CalledProcessError: | ||
925 | 343 | raise | ||
926 | 344 | |||
927 | 345 | |||
928 | 346 | def create_erasure_profile(service, profile_name, erasure_plugin_name='jerasure', failure_domain='host', | ||
929 | 347 | data_chunks=2, coding_chunks=1, | ||
930 | 348 | locality=None, durability_estimator=None): | ||
931 | 349 | """ | ||
932 | 350 | Create a new erasure code profile if one does not already exist for it. Updates | ||
933 | 351 | the profile if it exists. Please see http://docs.ceph.com/docs/master/rados/operations/erasure-code-profile/ | ||
934 | 352 | for more details | ||
935 | 353 | :param service: six.string_types. The Ceph user name to run the command under | ||
936 | 354 | :param profile_name: six.string_types | ||
937 | 355 | :param erasure_plugin_name: six.string_types | ||
938 | 356 | :param failure_domain: six.string_types. One of ['chassis', 'datacenter', 'host', 'osd', 'pdu', 'pod', 'rack', 'region', | ||
939 | 357 | 'room', 'root', 'row']) | ||
940 | 358 | :param data_chunks: int | ||
941 | 359 | :param coding_chunks: int | ||
942 | 360 | :param locality: int | ||
943 | 361 | :param durability_estimator: int | ||
944 | 362 | :return: None. Can raise CalledProcessError | ||
945 | 363 | """ | ||
946 | 364 | # Ensure this failure_domain is allowed by Ceph | ||
947 | 365 | validator(failure_domain, six.string_types, | ||
948 | 366 | ['chassis', 'datacenter', 'host', 'osd', 'pdu', 'pod', 'rack', 'region', 'room', 'root', 'row']) | ||
949 | 367 | |||
950 | 368 | cmd = ['ceph', '--id', service, 'osd', 'erasure-code-profile', 'set', profile_name, | ||
951 | 369 | 'plugin=' + erasure_plugin_name, 'k=' + str(data_chunks), 'm=' + str(coding_chunks), | ||
952 | 370 | 'ruleset_failure_domain=' + failure_domain] | ||
953 | 371 | if locality is not None and durability_estimator is not None: | ||
954 | 372 | raise ValueError("create_erasure_profile should be called with k, m and one of l or c but not both.") | ||
955 | 373 | |||
956 | 374 | # Add plugin specific information | ||
957 | 375 | if locality is not None: | ||
958 | 376 | # For local erasure codes | ||
959 | 377 | cmd.append('l=' + str(locality)) | ||
960 | 378 | if durability_estimator is not None: | ||
961 | 379 | # For Shec erasure codes | ||
962 | 380 | cmd.append('c=' + str(durability_estimator)) | ||
963 | 381 | |||
964 | 382 | if erasure_profile_exists(service, profile_name): | ||
965 | 383 | cmd.append('--force') | ||
966 | 384 | |||
967 | 385 | try: | ||
968 | 386 | check_call(cmd) | ||
969 | 387 | except CalledProcessError: | ||
970 | 388 | raise | ||
971 | 389 | |||
972 | 390 | |||
973 | 391 | def rename_pool(service, old_name, new_name): | ||
974 | 392 | """ | ||
975 | 393 | Rename a Ceph pool from old_name to new_name | ||
976 | 394 | :param service: six.string_types. The Ceph user name to run the command under | ||
977 | 395 | :param old_name: six.string_types | ||
978 | 396 | :param new_name: six.string_types | ||
979 | 397 | :return: None | ||
980 | 398 | """ | ||
981 | 399 | validator(value=old_name, valid_type=six.string_types) | ||
982 | 400 | validator(value=new_name, valid_type=six.string_types) | ||
983 | 401 | |||
984 | 402 | cmd = ['ceph', '--id', service, 'osd', 'pool', 'rename', old_name, new_name] | ||
985 | 403 | check_call(cmd) | ||
986 | 404 | |||
987 | 405 | |||
988 | 406 | def erasure_profile_exists(service, name): | ||
989 | 407 | """ | ||
990 | 408 | Check to see if an Erasure code profile already exists. | ||
991 | 409 | :param service: six.string_types. The Ceph user name to run the command under | ||
992 | 410 | :param name: six.string_types | ||
993 | 411 | :return: int or None | ||
994 | 412 | """ | ||
995 | 413 | validator(value=name, valid_type=six.string_types) | ||
996 | 414 | try: | ||
997 | 415 | check_call(['ceph', '--id', service, | ||
998 | 416 | 'osd', 'erasure-code-profile', 'get', | ||
999 | 417 | name]) | ||
1000 | 418 | return True | ||
1001 | 419 | except CalledProcessError: | ||
1002 | 420 | return False | ||
1003 | 421 | |||
1004 | 422 | |||
1005 | 423 | def get_cache_mode(service, pool_name): | ||
1006 | 424 | """ | ||
1007 | 425 | Find the current caching mode of the pool_name given. | ||
1008 | 426 | :param service: six.string_types. The Ceph user name to run the command under | ||
1009 | 427 | :param pool_name: six.string_types | ||
1010 | 428 | :return: int or None | ||
1011 | 429 | """ | ||
1012 | 430 | validator(value=service, valid_type=six.string_types) | ||
1013 | 431 | validator(value=pool_name, valid_type=six.string_types) | ||
1014 | 432 | out = check_output(['ceph', '--id', service, 'osd', 'dump', '--format=json']) | ||
1015 | 433 | try: | ||
1016 | 434 | osd_json = json.loads(out) | ||
1017 | 435 | for pool in osd_json['pools']: | ||
1018 | 436 | if pool['pool_name'] == pool_name: | ||
1019 | 437 | return pool['cache_mode'] | ||
1020 | 438 | return None | ||
1021 | 439 | except ValueError: | ||
1022 | 440 | raise | ||
1023 | 441 | |||
1024 | 442 | |||
1025 | 443 | def pool_exists(service, name): | ||
1026 | 444 | """Check to see if a RADOS pool already exists.""" | ||
1027 | 445 | try: | ||
1028 | 446 | out = check_output(['rados', '--id', service, | ||
1029 | 447 | 'lspools']).decode('UTF-8') | ||
1030 | 448 | except CalledProcessError: | ||
1031 | 449 | return False | ||
1032 | 450 | |||
1033 | 451 | return name in out | ||
1034 | 452 | |||
1035 | 453 | |||
1036 | 454 | def get_osds(service): | ||
1037 | 455 | """Return a list of all Ceph Object Storage Daemons currently in the | ||
1038 | 456 | cluster. | ||
1039 | 457 | """ | ||
1040 | 458 | version = ceph_version() | ||
1041 | 459 | if version and version >= '0.56': | ||
1042 | 460 | return json.loads(check_output(['ceph', '--id', service, | ||
1043 | 461 | 'osd', 'ls', | ||
1044 | 462 | '--format=json']).decode('UTF-8')) | ||
1045 | 463 | |||
1046 | 464 | return None | ||
1047 | 75 | 465 | ||
1048 | 76 | 466 | ||
1049 | 77 | def install(): | 467 | def install(): |
1050 | @@ -101,53 +491,37 @@ | |||
1051 | 101 | check_call(cmd) | 491 | check_call(cmd) |
1052 | 102 | 492 | ||
1053 | 103 | 493 | ||
1079 | 104 | def pool_exists(service, name): | 494 | def update_pool(client, pool, settings): |
1080 | 105 | """Check to see if a RADOS pool already exists.""" | 495 | cmd = ['ceph', '--id', client, 'osd', 'pool', 'set', pool] |
1081 | 106 | try: | 496 | for k, v in six.iteritems(settings): |
1082 | 107 | out = check_output(['rados', '--id', service, | 497 | cmd.append(k) |
1083 | 108 | 'lspools']).decode('UTF-8') | 498 | cmd.append(v) |
1084 | 109 | except CalledProcessError: | 499 | |
1085 | 110 | return False | 500 | check_call(cmd) |
1086 | 111 | 501 | ||
1087 | 112 | return name in out | 502 | |
1088 | 113 | 503 | def create_pool(service, name, replicas=3, pg_num=None): | |
1064 | 114 | |||
1065 | 115 | def get_osds(service): | ||
1066 | 116 | """Return a list of all Ceph Object Storage Daemons currently in the | ||
1067 | 117 | cluster. | ||
1068 | 118 | """ | ||
1069 | 119 | version = ceph_version() | ||
1070 | 120 | if version and version >= '0.56': | ||
1071 | 121 | return json.loads(check_output(['ceph', '--id', service, | ||
1072 | 122 | 'osd', 'ls', | ||
1073 | 123 | '--format=json']).decode('UTF-8')) | ||
1074 | 124 | |||
1075 | 125 | return None | ||
1076 | 126 | |||
1077 | 127 | |||
1078 | 128 | def create_pool(service, name, replicas=3): | ||
1089 | 129 | """Create a new RADOS pool.""" | 504 | """Create a new RADOS pool.""" |
1090 | 130 | if pool_exists(service, name): | 505 | if pool_exists(service, name): |
1091 | 131 | log("Ceph pool {} already exists, skipping creation".format(name), | 506 | log("Ceph pool {} already exists, skipping creation".format(name), |
1092 | 132 | level=WARNING) | 507 | level=WARNING) |
1093 | 133 | return | 508 | return |
1094 | 134 | 509 | ||
1111 | 135 | # Calculate the number of placement groups based | 510 | if not pg_num: |
1112 | 136 | # on upstream recommended best practices. | 511 | # Calculate the number of placement groups based |
1113 | 137 | osds = get_osds(service) | 512 | # on upstream recommended best practices. |
1114 | 138 | if osds: | 513 | osds = get_osds(service) |
1115 | 139 | pgnum = (len(osds) * 100 // replicas) | 514 | if osds: |
1116 | 140 | else: | 515 | pg_num = (len(osds) * 100 // replicas) |
1117 | 141 | # NOTE(james-page): Default to 200 for older ceph versions | 516 | else: |
1118 | 142 | # which don't support OSD query from cli | 517 | # NOTE(james-page): Default to 200 for older ceph versions |
1119 | 143 | pgnum = 200 | 518 | # which don't support OSD query from cli |
1120 | 144 | 519 | pg_num = 200 | |
1121 | 145 | cmd = ['ceph', '--id', service, 'osd', 'pool', 'create', name, str(pgnum)] | 520 | |
1122 | 146 | check_call(cmd) | 521 | cmd = ['ceph', '--id', service, 'osd', 'pool', 'create', name, str(pg_num)] |
1123 | 147 | 522 | check_call(cmd) | |
1124 | 148 | cmd = ['ceph', '--id', service, 'osd', 'pool', 'set', name, 'size', | 523 | |
1125 | 149 | str(replicas)] | 524 | update_pool(service, name, settings={'size': str(replicas)}) |
1110 | 150 | check_call(cmd) | ||
1126 | 151 | 525 | ||
1127 | 152 | 526 | ||
1128 | 153 | def delete_pool(service, name): | 527 | def delete_pool(service, name): |
1129 | @@ -202,10 +576,10 @@ | |||
1130 | 202 | log('Created new keyfile at %s.' % keyfile, level=INFO) | 576 | log('Created new keyfile at %s.' % keyfile, level=INFO) |
1131 | 203 | 577 | ||
1132 | 204 | 578 | ||
1135 | 205 | def get_ceph_nodes(): | 579 | def get_ceph_nodes(relation='ceph'): |
1136 | 206 | """Query named relation 'ceph' to determine current nodes.""" | 580 | """Query named relation to determine current nodes.""" |
1137 | 207 | hosts = [] | 581 | hosts = [] |
1139 | 208 | for r_id in relation_ids('ceph'): | 582 | for r_id in relation_ids(relation): |
1140 | 209 | for unit in related_units(r_id): | 583 | for unit in related_units(r_id): |
1141 | 210 | hosts.append(relation_get('private-address', unit=unit, rid=r_id)) | 584 | hosts.append(relation_get('private-address', unit=unit, rid=r_id)) |
1142 | 211 | 585 | ||
1143 | @@ -357,14 +731,14 @@ | |||
1144 | 357 | service_start(svc) | 731 | service_start(svc) |
1145 | 358 | 732 | ||
1146 | 359 | 733 | ||
1148 | 360 | def ensure_ceph_keyring(service, user=None, group=None): | 734 | def ensure_ceph_keyring(service, user=None, group=None, relation='ceph'): |
1149 | 361 | """Ensures a ceph keyring is created for a named service and optionally | 735 | """Ensures a ceph keyring is created for a named service and optionally |
1150 | 362 | ensures user and group ownership. | 736 | ensures user and group ownership. |
1151 | 363 | 737 | ||
1152 | 364 | Returns False if no ceph key is available in relation state. | 738 | Returns False if no ceph key is available in relation state. |
1153 | 365 | """ | 739 | """ |
1154 | 366 | key = None | 740 | key = None |
1156 | 367 | for rid in relation_ids('ceph'): | 741 | for rid in relation_ids(relation): |
1157 | 368 | for unit in related_units(rid): | 742 | for unit in related_units(rid): |
1158 | 369 | key = relation_get('key', rid=rid, unit=unit) | 743 | key = relation_get('key', rid=rid, unit=unit) |
1159 | 370 | if key: | 744 | if key: |
1160 | @@ -405,6 +779,7 @@ | |||
1161 | 405 | 779 | ||
1162 | 406 | The API is versioned and defaults to version 1. | 780 | The API is versioned and defaults to version 1. |
1163 | 407 | """ | 781 | """ |
1164 | 782 | |||
1165 | 408 | def __init__(self, api_version=1, request_id=None): | 783 | def __init__(self, api_version=1, request_id=None): |
1166 | 409 | self.api_version = api_version | 784 | self.api_version = api_version |
1167 | 410 | if request_id: | 785 | if request_id: |
1168 | @@ -413,9 +788,16 @@ | |||
1169 | 413 | self.request_id = str(uuid.uuid1()) | 788 | self.request_id = str(uuid.uuid1()) |
1170 | 414 | self.ops = [] | 789 | self.ops = [] |
1171 | 415 | 790 | ||
1173 | 416 | def add_op_create_pool(self, name, replica_count=3): | 791 | def add_op_create_pool(self, name, replica_count=3, pg_num=None): |
1174 | 792 | """Adds an operation to create a pool. | ||
1175 | 793 | |||
1176 | 794 | @param pg_num setting: optional setting. If not provided, this value | ||
1177 | 795 | will be calculated by the broker based on how many OSDs are in the | ||
1178 | 796 | cluster at the time of creation. Note that, if provided, this value | ||
1179 | 797 | will be capped at the current available maximum. | ||
1180 | 798 | """ | ||
1181 | 417 | self.ops.append({'op': 'create-pool', 'name': name, | 799 | self.ops.append({'op': 'create-pool', 'name': name, |
1183 | 418 | 'replicas': replica_count}) | 800 | 'replicas': replica_count, 'pg_num': pg_num}) |
1184 | 419 | 801 | ||
1185 | 420 | def set_ops(self, ops): | 802 | def set_ops(self, ops): |
1186 | 421 | """Set request ops to provided value. | 803 | """Set request ops to provided value. |
1187 | @@ -433,8 +815,8 @@ | |||
1188 | 433 | def _ops_equal(self, other): | 815 | def _ops_equal(self, other): |
1189 | 434 | if len(self.ops) == len(other.ops): | 816 | if len(self.ops) == len(other.ops): |
1190 | 435 | for req_no in range(0, len(self.ops)): | 817 | for req_no in range(0, len(self.ops)): |
1193 | 436 | for key in ['replicas', 'name', 'op']: | 818 | for key in ['replicas', 'name', 'op', 'pg_num']: |
1194 | 437 | if self.ops[req_no][key] != other.ops[req_no][key]: | 819 | if self.ops[req_no].get(key) != other.ops[req_no].get(key): |
1195 | 438 | return False | 820 | return False |
1196 | 439 | else: | 821 | else: |
1197 | 440 | return False | 822 | return False |
1198 | @@ -540,7 +922,7 @@ | |||
1199 | 540 | return request | 922 | return request |
1200 | 541 | 923 | ||
1201 | 542 | 924 | ||
1203 | 543 | def get_request_states(request): | 925 | def get_request_states(request, relation='ceph'): |
1204 | 544 | """Return a dict of requests per relation id with their corresponding | 926 | """Return a dict of requests per relation id with their corresponding |
1205 | 545 | completion state. | 927 | completion state. |
1206 | 546 | 928 | ||
1207 | @@ -552,7 +934,7 @@ | |||
1208 | 552 | """ | 934 | """ |
1209 | 553 | complete = [] | 935 | complete = [] |
1210 | 554 | requests = {} | 936 | requests = {} |
1212 | 555 | for rid in relation_ids('ceph'): | 937 | for rid in relation_ids(relation): |
1213 | 556 | complete = False | 938 | complete = False |
1214 | 557 | previous_request = get_previous_request(rid) | 939 | previous_request = get_previous_request(rid) |
1215 | 558 | if request == previous_request: | 940 | if request == previous_request: |
1216 | @@ -570,14 +952,14 @@ | |||
1217 | 570 | return requests | 952 | return requests |
1218 | 571 | 953 | ||
1219 | 572 | 954 | ||
1221 | 573 | def is_request_sent(request): | 955 | def is_request_sent(request, relation='ceph'): |
1222 | 574 | """Check to see if a functionally equivalent request has already been sent | 956 | """Check to see if a functionally equivalent request has already been sent |
1223 | 575 | 957 | ||
1224 | 576 | Returns True if a similair request has been sent | 958 | Returns True if a similair request has been sent |
1225 | 577 | 959 | ||
1226 | 578 | @param request: A CephBrokerRq object | 960 | @param request: A CephBrokerRq object |
1227 | 579 | """ | 961 | """ |
1229 | 580 | states = get_request_states(request) | 962 | states = get_request_states(request, relation=relation) |
1230 | 581 | for rid in states.keys(): | 963 | for rid in states.keys(): |
1231 | 582 | if not states[rid]['sent']: | 964 | if not states[rid]['sent']: |
1232 | 583 | return False | 965 | return False |
1233 | @@ -585,7 +967,7 @@ | |||
1234 | 585 | return True | 967 | return True |
1235 | 586 | 968 | ||
1236 | 587 | 969 | ||
1238 | 588 | def is_request_complete(request): | 970 | def is_request_complete(request, relation='ceph'): |
1239 | 589 | """Check to see if a functionally equivalent request has already been | 971 | """Check to see if a functionally equivalent request has already been |
1240 | 590 | completed | 972 | completed |
1241 | 591 | 973 | ||
1242 | @@ -593,7 +975,7 @@ | |||
1243 | 593 | 975 | ||
1244 | 594 | @param request: A CephBrokerRq object | 976 | @param request: A CephBrokerRq object |
1245 | 595 | """ | 977 | """ |
1247 | 596 | states = get_request_states(request) | 978 | states = get_request_states(request, relation=relation) |
1248 | 597 | for rid in states.keys(): | 979 | for rid in states.keys(): |
1249 | 598 | if not states[rid]['complete']: | 980 | if not states[rid]['complete']: |
1250 | 599 | return False | 981 | return False |
1251 | @@ -643,15 +1025,15 @@ | |||
1252 | 643 | return 'broker-rsp-' + local_unit().replace('/', '-') | 1025 | return 'broker-rsp-' + local_unit().replace('/', '-') |
1253 | 644 | 1026 | ||
1254 | 645 | 1027 | ||
1256 | 646 | def send_request_if_needed(request): | 1028 | def send_request_if_needed(request, relation='ceph'): |
1257 | 647 | """Send broker request if an equivalent request has not already been sent | 1029 | """Send broker request if an equivalent request has not already been sent |
1258 | 648 | 1030 | ||
1259 | 649 | @param request: A CephBrokerRq object | 1031 | @param request: A CephBrokerRq object |
1260 | 650 | """ | 1032 | """ |
1262 | 651 | if is_request_sent(request): | 1033 | if is_request_sent(request, relation=relation): |
1263 | 652 | log('Request already sent but not complete, not sending new request', | 1034 | log('Request already sent but not complete, not sending new request', |
1264 | 653 | level=DEBUG) | 1035 | level=DEBUG) |
1265 | 654 | else: | 1036 | else: |
1267 | 655 | for rid in relation_ids('ceph'): | 1037 | for rid in relation_ids(relation): |
1268 | 656 | log('Sending request {}'.format(request.request_id), level=DEBUG) | 1038 | log('Sending request {}'.format(request.request_id), level=DEBUG) |
1269 | 657 | relation_set(relation_id=rid, broker_req=request.request) | 1039 | relation_set(relation_id=rid, broker_req=request.request) |
1270 | 658 | 1040 | ||
1271 | === modified file 'hooks/charmhelpers/contrib/storage/linux/loopback.py' | |||
1272 | --- hooks/charmhelpers/contrib/storage/linux/loopback.py 2015-02-19 22:08:13 +0000 | |||
1273 | +++ hooks/charmhelpers/contrib/storage/linux/loopback.py 2016-01-22 14:18:52 +0000 | |||
1274 | @@ -76,3 +76,13 @@ | |||
1275 | 76 | check_call(cmd) | 76 | check_call(cmd) |
1276 | 77 | 77 | ||
1277 | 78 | return create_loopback(path) | 78 | return create_loopback(path) |
1278 | 79 | |||
1279 | 80 | |||
1280 | 81 | def is_mapped_loopback_device(device): | ||
1281 | 82 | """ | ||
1282 | 83 | Checks if a given device name is an existing/mapped loopback device. | ||
1283 | 84 | :param device: str: Full path to the device (eg, /dev/loop1). | ||
1284 | 85 | :returns: str: Path to the backing file if is a loopback device | ||
1285 | 86 | empty string otherwise | ||
1286 | 87 | """ | ||
1287 | 88 | return loopback_devices().get(device, "") | ||
1288 | 79 | 89 | ||
1289 | === modified file 'hooks/charmhelpers/core/hookenv.py' | |||
1290 | --- hooks/charmhelpers/core/hookenv.py 2015-11-11 14:57:38 +0000 | |||
1291 | +++ hooks/charmhelpers/core/hookenv.py 2016-01-22 14:18:52 +0000 | |||
1292 | @@ -492,7 +492,7 @@ | |||
1293 | 492 | 492 | ||
1294 | 493 | @cached | 493 | @cached |
1295 | 494 | def peer_relation_id(): | 494 | def peer_relation_id(): |
1297 | 495 | '''Get a peer relation id if a peer relation has been joined, else None.''' | 495 | '''Get the peers relation id if a peers relation has been joined, else None.''' |
1298 | 496 | md = metadata() | 496 | md = metadata() |
1299 | 497 | section = md.get('peers') | 497 | section = md.get('peers') |
1300 | 498 | if section: | 498 | if section: |
1301 | @@ -517,12 +517,12 @@ | |||
1302 | 517 | def relation_to_role_and_interface(relation_name): | 517 | def relation_to_role_and_interface(relation_name): |
1303 | 518 | """ | 518 | """ |
1304 | 519 | Given the name of a relation, return the role and the name of the interface | 519 | Given the name of a relation, return the role and the name of the interface |
1306 | 520 | that relation uses (where role is one of ``provides``, ``requires``, or ``peer``). | 520 | that relation uses (where role is one of ``provides``, ``requires``, or ``peers``). |
1307 | 521 | 521 | ||
1308 | 522 | :returns: A tuple containing ``(role, interface)``, or ``(None, None)``. | 522 | :returns: A tuple containing ``(role, interface)``, or ``(None, None)``. |
1309 | 523 | """ | 523 | """ |
1310 | 524 | _metadata = metadata() | 524 | _metadata = metadata() |
1312 | 525 | for role in ('provides', 'requires', 'peer'): | 525 | for role in ('provides', 'requires', 'peers'): |
1313 | 526 | interface = _metadata.get(role, {}).get(relation_name, {}).get('interface') | 526 | interface = _metadata.get(role, {}).get(relation_name, {}).get('interface') |
1314 | 527 | if interface: | 527 | if interface: |
1315 | 528 | return role, interface | 528 | return role, interface |
1316 | @@ -534,7 +534,7 @@ | |||
1317 | 534 | """ | 534 | """ |
1318 | 535 | Given a role and interface name, return a list of relation names for the | 535 | Given a role and interface name, return a list of relation names for the |
1319 | 536 | current charm that use that interface under that role (where role is one | 536 | current charm that use that interface under that role (where role is one |
1321 | 537 | of ``provides``, ``requires``, or ``peer``). | 537 | of ``provides``, ``requires``, or ``peers``). |
1322 | 538 | 538 | ||
1323 | 539 | :returns: A list of relation names. | 539 | :returns: A list of relation names. |
1324 | 540 | """ | 540 | """ |
1325 | @@ -555,7 +555,7 @@ | |||
1326 | 555 | :returns: A list of relation names. | 555 | :returns: A list of relation names. |
1327 | 556 | """ | 556 | """ |
1328 | 557 | results = [] | 557 | results = [] |
1330 | 558 | for role in ('provides', 'requires', 'peer'): | 558 | for role in ('provides', 'requires', 'peers'): |
1331 | 559 | results.extend(role_and_interface_to_relations(role, interface_name)) | 559 | results.extend(role_and_interface_to_relations(role, interface_name)) |
1332 | 560 | return results | 560 | return results |
1333 | 561 | 561 | ||
1334 | @@ -637,7 +637,7 @@ | |||
1335 | 637 | 637 | ||
1336 | 638 | 638 | ||
1337 | 639 | @cached | 639 | @cached |
1339 | 640 | def storage_get(attribute="", storage_id=""): | 640 | def storage_get(attribute=None, storage_id=None): |
1340 | 641 | """Get storage attributes""" | 641 | """Get storage attributes""" |
1341 | 642 | _args = ['storage-get', '--format=json'] | 642 | _args = ['storage-get', '--format=json'] |
1342 | 643 | if storage_id: | 643 | if storage_id: |
1343 | @@ -651,7 +651,7 @@ | |||
1344 | 651 | 651 | ||
1345 | 652 | 652 | ||
1346 | 653 | @cached | 653 | @cached |
1348 | 654 | def storage_list(storage_name=""): | 654 | def storage_list(storage_name=None): |
1349 | 655 | """List the storage IDs for the unit""" | 655 | """List the storage IDs for the unit""" |
1350 | 656 | _args = ['storage-list', '--format=json'] | 656 | _args = ['storage-list', '--format=json'] |
1351 | 657 | if storage_name: | 657 | if storage_name: |
1352 | @@ -878,6 +878,40 @@ | |||
1353 | 878 | subprocess.check_call(cmd) | 878 | subprocess.check_call(cmd) |
1354 | 879 | 879 | ||
1355 | 880 | 880 | ||
1356 | 881 | @translate_exc(from_exc=OSError, to_exc=NotImplementedError) | ||
1357 | 882 | def payload_register(ptype, klass, pid): | ||
1358 | 883 | """ is used while a hook is running to let Juju know that a | ||
1359 | 884 | payload has been started.""" | ||
1360 | 885 | cmd = ['payload-register'] | ||
1361 | 886 | for x in [ptype, klass, pid]: | ||
1362 | 887 | cmd.append(x) | ||
1363 | 888 | subprocess.check_call(cmd) | ||
1364 | 889 | |||
1365 | 890 | |||
1366 | 891 | @translate_exc(from_exc=OSError, to_exc=NotImplementedError) | ||
1367 | 892 | def payload_unregister(klass, pid): | ||
1368 | 893 | """ is used while a hook is running to let Juju know | ||
1369 | 894 | that a payload has been manually stopped. The <class> and <id> provided | ||
1370 | 895 | must match a payload that has been previously registered with juju using | ||
1371 | 896 | payload-register.""" | ||
1372 | 897 | cmd = ['payload-unregister'] | ||
1373 | 898 | for x in [klass, pid]: | ||
1374 | 899 | cmd.append(x) | ||
1375 | 900 | subprocess.check_call(cmd) | ||
1376 | 901 | |||
1377 | 902 | |||
1378 | 903 | @translate_exc(from_exc=OSError, to_exc=NotImplementedError) | ||
1379 | 904 | def payload_status_set(klass, pid, status): | ||
1380 | 905 | """is used to update the current status of a registered payload. | ||
1381 | 906 | The <class> and <id> provided must match a payload that has been previously | ||
1382 | 907 | registered with juju using payload-register. The <status> must be one of the | ||
1383 | 908 | follow: starting, started, stopping, stopped""" | ||
1384 | 909 | cmd = ['payload-status-set'] | ||
1385 | 910 | for x in [klass, pid, status]: | ||
1386 | 911 | cmd.append(x) | ||
1387 | 912 | subprocess.check_call(cmd) | ||
1388 | 913 | |||
1389 | 914 | |||
1390 | 881 | @cached | 915 | @cached |
1391 | 882 | def juju_version(): | 916 | def juju_version(): |
1392 | 883 | """Full version string (eg. '1.23.3.1-trusty-amd64')""" | 917 | """Full version string (eg. '1.23.3.1-trusty-amd64')""" |
1393 | 884 | 918 | ||
1394 | === modified file 'hooks/charmhelpers/core/host.py' | |||
1395 | --- hooks/charmhelpers/core/host.py 2015-11-11 14:57:38 +0000 | |||
1396 | +++ hooks/charmhelpers/core/host.py 2016-01-22 14:18:52 +0000 | |||
1397 | @@ -67,10 +67,14 @@ | |||
1398 | 67 | """Pause a system service. | 67 | """Pause a system service. |
1399 | 68 | 68 | ||
1400 | 69 | Stop it, and prevent it from starting again at boot.""" | 69 | Stop it, and prevent it from starting again at boot.""" |
1402 | 70 | stopped = service_stop(service_name) | 70 | stopped = True |
1403 | 71 | if service_running(service_name): | ||
1404 | 72 | stopped = service_stop(service_name) | ||
1405 | 71 | upstart_file = os.path.join(init_dir, "{}.conf".format(service_name)) | 73 | upstart_file = os.path.join(init_dir, "{}.conf".format(service_name)) |
1406 | 72 | sysv_file = os.path.join(initd_dir, service_name) | 74 | sysv_file = os.path.join(initd_dir, service_name) |
1408 | 73 | if os.path.exists(upstart_file): | 75 | if init_is_systemd(): |
1409 | 76 | service('disable', service_name) | ||
1410 | 77 | elif os.path.exists(upstart_file): | ||
1411 | 74 | override_path = os.path.join( | 78 | override_path = os.path.join( |
1412 | 75 | init_dir, '{}.override'.format(service_name)) | 79 | init_dir, '{}.override'.format(service_name)) |
1413 | 76 | with open(override_path, 'w') as fh: | 80 | with open(override_path, 'w') as fh: |
1414 | @@ -78,9 +82,9 @@ | |||
1415 | 78 | elif os.path.exists(sysv_file): | 82 | elif os.path.exists(sysv_file): |
1416 | 79 | subprocess.check_call(["update-rc.d", service_name, "disable"]) | 83 | subprocess.check_call(["update-rc.d", service_name, "disable"]) |
1417 | 80 | else: | 84 | else: |
1418 | 81 | # XXX: Support SystemD too | ||
1419 | 82 | raise ValueError( | 85 | raise ValueError( |
1421 | 83 | "Unable to detect {0} as either Upstart {1} or SysV {2}".format( | 86 | "Unable to detect {0} as SystemD, Upstart {1} or" |
1422 | 87 | " SysV {2}".format( | ||
1423 | 84 | service_name, upstart_file, sysv_file)) | 88 | service_name, upstart_file, sysv_file)) |
1424 | 85 | return stopped | 89 | return stopped |
1425 | 86 | 90 | ||
1426 | @@ -92,7 +96,9 @@ | |||
1427 | 92 | Reenable starting again at boot. Start the service""" | 96 | Reenable starting again at boot. Start the service""" |
1428 | 93 | upstart_file = os.path.join(init_dir, "{}.conf".format(service_name)) | 97 | upstart_file = os.path.join(init_dir, "{}.conf".format(service_name)) |
1429 | 94 | sysv_file = os.path.join(initd_dir, service_name) | 98 | sysv_file = os.path.join(initd_dir, service_name) |
1431 | 95 | if os.path.exists(upstart_file): | 99 | if init_is_systemd(): |
1432 | 100 | service('enable', service_name) | ||
1433 | 101 | elif os.path.exists(upstart_file): | ||
1434 | 96 | override_path = os.path.join( | 102 | override_path = os.path.join( |
1435 | 97 | init_dir, '{}.override'.format(service_name)) | 103 | init_dir, '{}.override'.format(service_name)) |
1436 | 98 | if os.path.exists(override_path): | 104 | if os.path.exists(override_path): |
1437 | @@ -100,34 +106,43 @@ | |||
1438 | 100 | elif os.path.exists(sysv_file): | 106 | elif os.path.exists(sysv_file): |
1439 | 101 | subprocess.check_call(["update-rc.d", service_name, "enable"]) | 107 | subprocess.check_call(["update-rc.d", service_name, "enable"]) |
1440 | 102 | else: | 108 | else: |
1441 | 103 | # XXX: Support SystemD too | ||
1442 | 104 | raise ValueError( | 109 | raise ValueError( |
1444 | 105 | "Unable to detect {0} as either Upstart {1} or SysV {2}".format( | 110 | "Unable to detect {0} as SystemD, Upstart {1} or" |
1445 | 111 | " SysV {2}".format( | ||
1446 | 106 | service_name, upstart_file, sysv_file)) | 112 | service_name, upstart_file, sysv_file)) |
1447 | 107 | 113 | ||
1449 | 108 | started = service_start(service_name) | 114 | started = service_running(service_name) |
1450 | 115 | if not started: | ||
1451 | 116 | started = service_start(service_name) | ||
1452 | 109 | return started | 117 | return started |
1453 | 110 | 118 | ||
1454 | 111 | 119 | ||
1455 | 112 | def service(action, service_name): | 120 | def service(action, service_name): |
1456 | 113 | """Control a system service""" | 121 | """Control a system service""" |
1458 | 114 | cmd = ['service', service_name, action] | 122 | if init_is_systemd(): |
1459 | 123 | cmd = ['systemctl', action, service_name] | ||
1460 | 124 | else: | ||
1461 | 125 | cmd = ['service', service_name, action] | ||
1462 | 115 | return subprocess.call(cmd) == 0 | 126 | return subprocess.call(cmd) == 0 |
1463 | 116 | 127 | ||
1464 | 117 | 128 | ||
1466 | 118 | def service_running(service): | 129 | def service_running(service_name): |
1467 | 119 | """Determine whether a system service is running""" | 130 | """Determine whether a system service is running""" |
1474 | 120 | try: | 131 | if init_is_systemd(): |
1475 | 121 | output = subprocess.check_output( | 132 | return service('is-active', service_name) |
1470 | 122 | ['service', service, 'status'], | ||
1471 | 123 | stderr=subprocess.STDOUT).decode('UTF-8') | ||
1472 | 124 | except subprocess.CalledProcessError: | ||
1473 | 125 | return False | ||
1476 | 126 | else: | 133 | else: |
1480 | 127 | if ("start/running" in output or "is running" in output): | 134 | try: |
1481 | 128 | return True | 135 | output = subprocess.check_output( |
1482 | 129 | else: | 136 | ['service', service_name, 'status'], |
1483 | 137 | stderr=subprocess.STDOUT).decode('UTF-8') | ||
1484 | 138 | except subprocess.CalledProcessError: | ||
1485 | 130 | return False | 139 | return False |
1486 | 140 | else: | ||
1487 | 141 | if ("start/running" in output or "is running" in output or | ||
1488 | 142 | "up and running" in output): | ||
1489 | 143 | return True | ||
1490 | 144 | else: | ||
1491 | 145 | return False | ||
1492 | 131 | 146 | ||
1493 | 132 | 147 | ||
1494 | 133 | def service_available(service_name): | 148 | def service_available(service_name): |
1495 | @@ -142,8 +157,29 @@ | |||
1496 | 142 | return True | 157 | return True |
1497 | 143 | 158 | ||
1498 | 144 | 159 | ||
1501 | 145 | def adduser(username, password=None, shell='/bin/bash', system_user=False): | 160 | SYSTEMD_SYSTEM = '/run/systemd/system' |
1502 | 146 | """Add a user to the system""" | 161 | |
1503 | 162 | |||
1504 | 163 | def init_is_systemd(): | ||
1505 | 164 | """Return True if the host system uses systemd, False otherwise.""" | ||
1506 | 165 | return os.path.isdir(SYSTEMD_SYSTEM) | ||
1507 | 166 | |||
1508 | 167 | |||
1509 | 168 | def adduser(username, password=None, shell='/bin/bash', system_user=False, | ||
1510 | 169 | primary_group=None, secondary_groups=None): | ||
1511 | 170 | """Add a user to the system. | ||
1512 | 171 | |||
1513 | 172 | Will log but otherwise succeed if the user already exists. | ||
1514 | 173 | |||
1515 | 174 | :param str username: Username to create | ||
1516 | 175 | :param str password: Password for user; if ``None``, create a system user | ||
1517 | 176 | :param str shell: The default shell for the user | ||
1518 | 177 | :param bool system_user: Whether to create a login or system user | ||
1519 | 178 | :param str primary_group: Primary group for user; defaults to username | ||
1520 | 179 | :param list secondary_groups: Optional list of additional groups | ||
1521 | 180 | |||
1522 | 181 | :returns: The password database entry struct, as returned by `pwd.getpwnam` | ||
1523 | 182 | """ | ||
1524 | 147 | try: | 183 | try: |
1525 | 148 | user_info = pwd.getpwnam(username) | 184 | user_info = pwd.getpwnam(username) |
1526 | 149 | log('user {0} already exists!'.format(username)) | 185 | log('user {0} already exists!'.format(username)) |
1527 | @@ -158,6 +194,16 @@ | |||
1528 | 158 | '--shell', shell, | 194 | '--shell', shell, |
1529 | 159 | '--password', password, | 195 | '--password', password, |
1530 | 160 | ]) | 196 | ]) |
1531 | 197 | if not primary_group: | ||
1532 | 198 | try: | ||
1533 | 199 | grp.getgrnam(username) | ||
1534 | 200 | primary_group = username # avoid "group exists" error | ||
1535 | 201 | except KeyError: | ||
1536 | 202 | pass | ||
1537 | 203 | if primary_group: | ||
1538 | 204 | cmd.extend(['-g', primary_group]) | ||
1539 | 205 | if secondary_groups: | ||
1540 | 206 | cmd.extend(['-G', ','.join(secondary_groups)]) | ||
1541 | 161 | cmd.append(username) | 207 | cmd.append(username) |
1542 | 162 | subprocess.check_call(cmd) | 208 | subprocess.check_call(cmd) |
1543 | 163 | user_info = pwd.getpwnam(username) | 209 | user_info = pwd.getpwnam(username) |
1544 | @@ -255,14 +301,12 @@ | |||
1545 | 255 | 301 | ||
1546 | 256 | 302 | ||
1547 | 257 | def fstab_remove(mp): | 303 | def fstab_remove(mp): |
1550 | 258 | """Remove the given mountpoint entry from /etc/fstab | 304 | """Remove the given mountpoint entry from /etc/fstab""" |
1549 | 259 | """ | ||
1551 | 260 | return Fstab.remove_by_mountpoint(mp) | 305 | return Fstab.remove_by_mountpoint(mp) |
1552 | 261 | 306 | ||
1553 | 262 | 307 | ||
1554 | 263 | def fstab_add(dev, mp, fs, options=None): | 308 | def fstab_add(dev, mp, fs, options=None): |
1557 | 264 | """Adds the given device entry to the /etc/fstab file | 309 | """Adds the given device entry to the /etc/fstab file""" |
1556 | 265 | """ | ||
1558 | 266 | return Fstab.add(dev, mp, fs, options=options) | 310 | return Fstab.add(dev, mp, fs, options=options) |
1559 | 267 | 311 | ||
1560 | 268 | 312 | ||
1561 | @@ -318,8 +362,7 @@ | |||
1562 | 318 | 362 | ||
1563 | 319 | 363 | ||
1564 | 320 | def file_hash(path, hash_type='md5'): | 364 | def file_hash(path, hash_type='md5'): |
1567 | 321 | """ | 365 | """Generate a hash checksum of the contents of 'path' or None if not found. |
1566 | 322 | Generate a hash checksum of the contents of 'path' or None if not found. | ||
1568 | 323 | 366 | ||
1569 | 324 | :param str hash_type: Any hash alrgorithm supported by :mod:`hashlib`, | 367 | :param str hash_type: Any hash alrgorithm supported by :mod:`hashlib`, |
1570 | 325 | such as md5, sha1, sha256, sha512, etc. | 368 | such as md5, sha1, sha256, sha512, etc. |
1571 | @@ -334,10 +377,9 @@ | |||
1572 | 334 | 377 | ||
1573 | 335 | 378 | ||
1574 | 336 | def path_hash(path): | 379 | def path_hash(path): |
1579 | 337 | """ | 380 | """Generate a hash checksum of all files matching 'path'. Standard |
1580 | 338 | Generate a hash checksum of all files matching 'path'. Standard wildcards | 381 | wildcards like '*' and '?' are supported, see documentation for the 'glob' |
1581 | 339 | like '*' and '?' are supported, see documentation for the 'glob' module for | 382 | module for more information. |
1578 | 340 | more information. | ||
1582 | 341 | 383 | ||
1583 | 342 | :return: dict: A { filename: hash } dictionary for all matched files. | 384 | :return: dict: A { filename: hash } dictionary for all matched files. |
1584 | 343 | Empty if none found. | 385 | Empty if none found. |
1585 | @@ -349,8 +391,7 @@ | |||
1586 | 349 | 391 | ||
1587 | 350 | 392 | ||
1588 | 351 | def check_hash(path, checksum, hash_type='md5'): | 393 | def check_hash(path, checksum, hash_type='md5'): |
1591 | 352 | """ | 394 | """Validate a file using a cryptographic checksum. |
1590 | 353 | Validate a file using a cryptographic checksum. | ||
1592 | 354 | 395 | ||
1593 | 355 | :param str checksum: Value of the checksum used to validate the file. | 396 | :param str checksum: Value of the checksum used to validate the file. |
1594 | 356 | :param str hash_type: Hash algorithm used to generate `checksum`. | 397 | :param str hash_type: Hash algorithm used to generate `checksum`. |
1595 | @@ -365,6 +406,7 @@ | |||
1596 | 365 | 406 | ||
1597 | 366 | 407 | ||
1598 | 367 | class ChecksumError(ValueError): | 408 | class ChecksumError(ValueError): |
1599 | 409 | """A class derived from Value error to indicate the checksum failed.""" | ||
1600 | 368 | pass | 410 | pass |
1601 | 369 | 411 | ||
1602 | 370 | 412 | ||
1603 | @@ -470,7 +512,7 @@ | |||
1604 | 470 | 512 | ||
1605 | 471 | 513 | ||
1606 | 472 | def list_nics(nic_type=None): | 514 | def list_nics(nic_type=None): |
1608 | 473 | '''Return a list of nics of given type(s)''' | 515 | """Return a list of nics of given type(s)""" |
1609 | 474 | if isinstance(nic_type, six.string_types): | 516 | if isinstance(nic_type, six.string_types): |
1610 | 475 | int_types = [nic_type] | 517 | int_types = [nic_type] |
1611 | 476 | else: | 518 | else: |
1612 | @@ -512,12 +554,13 @@ | |||
1613 | 512 | 554 | ||
1614 | 513 | 555 | ||
1615 | 514 | def set_nic_mtu(nic, mtu): | 556 | def set_nic_mtu(nic, mtu): |
1617 | 515 | '''Set MTU on a network interface''' | 557 | """Set the Maximum Transmission Unit (MTU) on a network interface.""" |
1618 | 516 | cmd = ['ip', 'link', 'set', nic, 'mtu', mtu] | 558 | cmd = ['ip', 'link', 'set', nic, 'mtu', mtu] |
1619 | 517 | subprocess.check_call(cmd) | 559 | subprocess.check_call(cmd) |
1620 | 518 | 560 | ||
1621 | 519 | 561 | ||
1622 | 520 | def get_nic_mtu(nic): | 562 | def get_nic_mtu(nic): |
1623 | 563 | """Return the Maximum Transmission Unit (MTU) for a network interface.""" | ||
1624 | 521 | cmd = ['ip', 'addr', 'show', nic] | 564 | cmd = ['ip', 'addr', 'show', nic] |
1625 | 522 | ip_output = subprocess.check_output(cmd).decode('UTF-8').split('\n') | 565 | ip_output = subprocess.check_output(cmd).decode('UTF-8').split('\n') |
1626 | 523 | mtu = "" | 566 | mtu = "" |
1627 | @@ -529,6 +572,7 @@ | |||
1628 | 529 | 572 | ||
1629 | 530 | 573 | ||
1630 | 531 | def get_nic_hwaddr(nic): | 574 | def get_nic_hwaddr(nic): |
1631 | 575 | """Return the Media Access Control (MAC) for a network interface.""" | ||
1632 | 532 | cmd = ['ip', '-o', '-0', 'addr', 'show', nic] | 576 | cmd = ['ip', '-o', '-0', 'addr', 'show', nic] |
1633 | 533 | ip_output = subprocess.check_output(cmd).decode('UTF-8') | 577 | ip_output = subprocess.check_output(cmd).decode('UTF-8') |
1634 | 534 | hwaddr = "" | 578 | hwaddr = "" |
1635 | @@ -539,7 +583,7 @@ | |||
1636 | 539 | 583 | ||
1637 | 540 | 584 | ||
1638 | 541 | def cmp_pkgrevno(package, revno, pkgcache=None): | 585 | def cmp_pkgrevno(package, revno, pkgcache=None): |
1640 | 542 | '''Compare supplied revno with the revno of the installed package | 586 | """Compare supplied revno with the revno of the installed package |
1641 | 543 | 587 | ||
1642 | 544 | * 1 => Installed revno is greater than supplied arg | 588 | * 1 => Installed revno is greater than supplied arg |
1643 | 545 | * 0 => Installed revno is the same as supplied arg | 589 | * 0 => Installed revno is the same as supplied arg |
1644 | @@ -548,7 +592,7 @@ | |||
1645 | 548 | This function imports apt_cache function from charmhelpers.fetch if | 592 | This function imports apt_cache function from charmhelpers.fetch if |
1646 | 549 | the pkgcache argument is None. Be sure to add charmhelpers.fetch if | 593 | the pkgcache argument is None. Be sure to add charmhelpers.fetch if |
1647 | 550 | you call this function, or pass an apt_pkg.Cache() instance. | 594 | you call this function, or pass an apt_pkg.Cache() instance. |
1649 | 551 | ''' | 595 | """ |
1650 | 552 | import apt_pkg | 596 | import apt_pkg |
1651 | 553 | if not pkgcache: | 597 | if not pkgcache: |
1652 | 554 | from charmhelpers.fetch import apt_cache | 598 | from charmhelpers.fetch import apt_cache |
1653 | @@ -558,19 +602,27 @@ | |||
1654 | 558 | 602 | ||
1655 | 559 | 603 | ||
1656 | 560 | @contextmanager | 604 | @contextmanager |
1658 | 561 | def chdir(d): | 605 | def chdir(directory): |
1659 | 606 | """Change the current working directory to a different directory for a code | ||
1660 | 607 | block and return the previous directory after the block exits. Useful to | ||
1661 | 608 | run commands from a specificed directory. | ||
1662 | 609 | |||
1663 | 610 | :param str directory: The directory path to change to for this context. | ||
1664 | 611 | """ | ||
1665 | 562 | cur = os.getcwd() | 612 | cur = os.getcwd() |
1666 | 563 | try: | 613 | try: |
1668 | 564 | yield os.chdir(d) | 614 | yield os.chdir(directory) |
1669 | 565 | finally: | 615 | finally: |
1670 | 566 | os.chdir(cur) | 616 | os.chdir(cur) |
1671 | 567 | 617 | ||
1672 | 568 | 618 | ||
1673 | 569 | def chownr(path, owner, group, follow_links=True, chowntopdir=False): | 619 | def chownr(path, owner, group, follow_links=True, chowntopdir=False): |
1676 | 570 | """ | 620 | """Recursively change user and group ownership of files and directories |
1675 | 571 | Recursively change user and group ownership of files and directories | ||
1677 | 572 | in given path. Doesn't chown path itself by default, only its children. | 621 | in given path. Doesn't chown path itself by default, only its children. |
1678 | 573 | 622 | ||
1679 | 623 | :param str path: The string path to start changing ownership. | ||
1680 | 624 | :param str owner: The owner string to use when looking up the uid. | ||
1681 | 625 | :param str group: The group string to use when looking up the gid. | ||
1682 | 574 | :param bool follow_links: Also Chown links if True | 626 | :param bool follow_links: Also Chown links if True |
1683 | 575 | :param bool chowntopdir: Also chown path itself if True | 627 | :param bool chowntopdir: Also chown path itself if True |
1684 | 576 | """ | 628 | """ |
1685 | @@ -594,15 +646,23 @@ | |||
1686 | 594 | 646 | ||
1687 | 595 | 647 | ||
1688 | 596 | def lchownr(path, owner, group): | 648 | def lchownr(path, owner, group): |
1689 | 649 | """Recursively change user and group ownership of files and directories | ||
1690 | 650 | in a given path, not following symbolic links. See the documentation for | ||
1691 | 651 | 'os.lchown' for more information. | ||
1692 | 652 | |||
1693 | 653 | :param str path: The string path to start changing ownership. | ||
1694 | 654 | :param str owner: The owner string to use when looking up the uid. | ||
1695 | 655 | :param str group: The group string to use when looking up the gid. | ||
1696 | 656 | """ | ||
1697 | 597 | chownr(path, owner, group, follow_links=False) | 657 | chownr(path, owner, group, follow_links=False) |
1698 | 598 | 658 | ||
1699 | 599 | 659 | ||
1700 | 600 | def get_total_ram(): | 660 | def get_total_ram(): |
1702 | 601 | '''The total amount of system RAM in bytes. | 661 | """The total amount of system RAM in bytes. |
1703 | 602 | 662 | ||
1704 | 603 | This is what is reported by the OS, and may be overcommitted when | 663 | This is what is reported by the OS, and may be overcommitted when |
1705 | 604 | there are multiple containers hosted on the same machine. | 664 | there are multiple containers hosted on the same machine. |
1707 | 605 | ''' | 665 | """ |
1708 | 606 | with open('/proc/meminfo', 'r') as f: | 666 | with open('/proc/meminfo', 'r') as f: |
1709 | 607 | for line in f.readlines(): | 667 | for line in f.readlines(): |
1710 | 608 | if line: | 668 | if line: |
1711 | 609 | 669 | ||
1712 | === modified file 'hooks/charmhelpers/core/services/helpers.py' | |||
1713 | --- hooks/charmhelpers/core/services/helpers.py 2015-11-11 14:57:38 +0000 | |||
1714 | +++ hooks/charmhelpers/core/services/helpers.py 2016-01-22 14:18:52 +0000 | |||
1715 | @@ -243,13 +243,15 @@ | |||
1716 | 243 | :param str source: The template source file, relative to | 243 | :param str source: The template source file, relative to |
1717 | 244 | `$CHARM_DIR/templates` | 244 | `$CHARM_DIR/templates` |
1718 | 245 | 245 | ||
1720 | 246 | :param str target: The target to write the rendered template to | 246 | :param str target: The target to write the rendered template to (or None) |
1721 | 247 | :param str owner: The owner of the rendered file | 247 | :param str owner: The owner of the rendered file |
1722 | 248 | :param str group: The group of the rendered file | 248 | :param str group: The group of the rendered file |
1723 | 249 | :param int perms: The permissions of the rendered file | 249 | :param int perms: The permissions of the rendered file |
1724 | 250 | :param partial on_change_action: functools partial to be executed when | 250 | :param partial on_change_action: functools partial to be executed when |
1725 | 251 | rendered file changes | 251 | rendered file changes |
1726 | 252 | :param jinja2 loader template_loader: A jinja2 template loader | 252 | :param jinja2 loader template_loader: A jinja2 template loader |
1727 | 253 | |||
1728 | 254 | :return str: The rendered template | ||
1729 | 253 | """ | 255 | """ |
1730 | 254 | def __init__(self, source, target, | 256 | def __init__(self, source, target, |
1731 | 255 | owner='root', group='root', perms=0o444, | 257 | owner='root', group='root', perms=0o444, |
1732 | @@ -267,12 +269,14 @@ | |||
1733 | 267 | if self.on_change_action and os.path.isfile(self.target): | 269 | if self.on_change_action and os.path.isfile(self.target): |
1734 | 268 | pre_checksum = host.file_hash(self.target) | 270 | pre_checksum = host.file_hash(self.target) |
1735 | 269 | service = manager.get_service(service_name) | 271 | service = manager.get_service(service_name) |
1737 | 270 | context = {} | 272 | context = {'ctx': {}} |
1738 | 271 | for ctx in service.get('required_data', []): | 273 | for ctx in service.get('required_data', []): |
1739 | 272 | context.update(ctx) | 274 | context.update(ctx) |
1743 | 273 | templating.render(self.source, self.target, context, | 275 | context['ctx'].update(ctx) |
1744 | 274 | self.owner, self.group, self.perms, | 276 | |
1745 | 275 | template_loader=self.template_loader) | 277 | result = templating.render(self.source, self.target, context, |
1746 | 278 | self.owner, self.group, self.perms, | ||
1747 | 279 | template_loader=self.template_loader) | ||
1748 | 276 | if self.on_change_action: | 280 | if self.on_change_action: |
1749 | 277 | if pre_checksum == host.file_hash(self.target): | 281 | if pre_checksum == host.file_hash(self.target): |
1750 | 278 | hookenv.log( | 282 | hookenv.log( |
1751 | @@ -281,6 +285,8 @@ | |||
1752 | 281 | else: | 285 | else: |
1753 | 282 | self.on_change_action() | 286 | self.on_change_action() |
1754 | 283 | 287 | ||
1755 | 288 | return result | ||
1756 | 289 | |||
1757 | 284 | 290 | ||
1758 | 285 | # Convenience aliases for templates | 291 | # Convenience aliases for templates |
1759 | 286 | render_template = template = TemplateCallback | 292 | render_template = template = TemplateCallback |
1760 | 287 | 293 | ||
1761 | === modified file 'hooks/charmhelpers/core/templating.py' | |||
1762 | --- hooks/charmhelpers/core/templating.py 2015-11-11 14:57:38 +0000 | |||
1763 | +++ hooks/charmhelpers/core/templating.py 2016-01-22 14:18:52 +0000 | |||
1764 | @@ -27,7 +27,8 @@ | |||
1765 | 27 | 27 | ||
1766 | 28 | The `source` path, if not absolute, is relative to the `templates_dir`. | 28 | The `source` path, if not absolute, is relative to the `templates_dir`. |
1767 | 29 | 29 | ||
1769 | 30 | The `target` path should be absolute. | 30 | The `target` path should be absolute. It can also be `None`, in which |
1770 | 31 | case no file will be written. | ||
1771 | 31 | 32 | ||
1772 | 32 | The context should be a dict containing the values to be replaced in the | 33 | The context should be a dict containing the values to be replaced in the |
1773 | 33 | template. | 34 | template. |
1774 | @@ -36,6 +37,9 @@ | |||
1775 | 36 | 37 | ||
1776 | 37 | If omitted, `templates_dir` defaults to the `templates` folder in the charm. | 38 | If omitted, `templates_dir` defaults to the `templates` folder in the charm. |
1777 | 38 | 39 | ||
1778 | 40 | The rendered template will be written to the file as well as being returned | ||
1779 | 41 | as a string. | ||
1780 | 42 | |||
1781 | 39 | Note: Using this requires python-jinja2; if it is not installed, calling | 43 | Note: Using this requires python-jinja2; if it is not installed, calling |
1782 | 40 | this will attempt to use charmhelpers.fetch.apt_install to install it. | 44 | this will attempt to use charmhelpers.fetch.apt_install to install it. |
1783 | 41 | """ | 45 | """ |
1784 | @@ -67,9 +71,11 @@ | |||
1785 | 67 | level=hookenv.ERROR) | 71 | level=hookenv.ERROR) |
1786 | 68 | raise e | 72 | raise e |
1787 | 69 | content = template.render(context) | 73 | content = template.render(context) |
1794 | 70 | target_dir = os.path.dirname(target) | 74 | if target is not None: |
1795 | 71 | if not os.path.exists(target_dir): | 75 | target_dir = os.path.dirname(target) |
1796 | 72 | # This is a terrible default directory permission, as the file | 76 | if not os.path.exists(target_dir): |
1797 | 73 | # or its siblings will often contain secrets. | 77 | # This is a terrible default directory permission, as the file |
1798 | 74 | host.mkdir(os.path.dirname(target), owner, group, perms=0o755) | 78 | # or its siblings will often contain secrets. |
1799 | 75 | host.write_file(target, content.encode(encoding), owner, group, perms) | 79 | host.mkdir(os.path.dirname(target), owner, group, perms=0o755) |
1800 | 80 | host.write_file(target, content.encode(encoding), owner, group, perms) | ||
1801 | 81 | return content | ||
1802 | 76 | 82 | ||
1803 | === modified file 'hooks/charmhelpers/fetch/__init__.py' | |||
1804 | --- hooks/charmhelpers/fetch/__init__.py 2015-11-11 14:57:38 +0000 | |||
1805 | +++ hooks/charmhelpers/fetch/__init__.py 2016-01-22 14:18:52 +0000 | |||
1806 | @@ -98,6 +98,14 @@ | |||
1807 | 98 | 'liberty/proposed': 'trusty-proposed/liberty', | 98 | 'liberty/proposed': 'trusty-proposed/liberty', |
1808 | 99 | 'trusty-liberty/proposed': 'trusty-proposed/liberty', | 99 | 'trusty-liberty/proposed': 'trusty-proposed/liberty', |
1809 | 100 | 'trusty-proposed/liberty': 'trusty-proposed/liberty', | 100 | 'trusty-proposed/liberty': 'trusty-proposed/liberty', |
1810 | 101 | # Mitaka | ||
1811 | 102 | 'mitaka': 'trusty-updates/mitaka', | ||
1812 | 103 | 'trusty-mitaka': 'trusty-updates/mitaka', | ||
1813 | 104 | 'trusty-mitaka/updates': 'trusty-updates/mitaka', | ||
1814 | 105 | 'trusty-updates/mitaka': 'trusty-updates/mitaka', | ||
1815 | 106 | 'mitaka/proposed': 'trusty-proposed/mitaka', | ||
1816 | 107 | 'trusty-mitaka/proposed': 'trusty-proposed/mitaka', | ||
1817 | 108 | 'trusty-proposed/mitaka': 'trusty-proposed/mitaka', | ||
1818 | 101 | } | 109 | } |
1819 | 102 | 110 | ||
1820 | 103 | # The order of this list is very important. Handlers should be listed in from | 111 | # The order of this list is very important. Handlers should be listed in from |
1821 | @@ -411,7 +419,7 @@ | |||
1822 | 411 | importlib.import_module(package), | 419 | importlib.import_module(package), |
1823 | 412 | classname) | 420 | classname) |
1824 | 413 | plugin_list.append(handler_class()) | 421 | plugin_list.append(handler_class()) |
1826 | 414 | except (ImportError, AttributeError): | 422 | except NotImplementedError: |
1827 | 415 | # Skip missing plugins so that they can be ommitted from | 423 | # Skip missing plugins so that they can be ommitted from |
1828 | 416 | # installation if desired | 424 | # installation if desired |
1829 | 417 | log("FetchHandler {} not found, skipping plugin".format( | 425 | log("FetchHandler {} not found, skipping plugin".format( |
1830 | 418 | 426 | ||
1831 | === modified file 'hooks/charmhelpers/fetch/archiveurl.py' | |||
1832 | --- hooks/charmhelpers/fetch/archiveurl.py 2015-07-22 12:10:31 +0000 | |||
1833 | +++ hooks/charmhelpers/fetch/archiveurl.py 2016-01-22 14:18:52 +0000 | |||
1834 | @@ -108,7 +108,7 @@ | |||
1835 | 108 | install_opener(opener) | 108 | install_opener(opener) |
1836 | 109 | response = urlopen(source) | 109 | response = urlopen(source) |
1837 | 110 | try: | 110 | try: |
1839 | 111 | with open(dest, 'w') as dest_file: | 111 | with open(dest, 'wb') as dest_file: |
1840 | 112 | dest_file.write(response.read()) | 112 | dest_file.write(response.read()) |
1841 | 113 | except Exception as e: | 113 | except Exception as e: |
1842 | 114 | if os.path.isfile(dest): | 114 | if os.path.isfile(dest): |
1843 | 115 | 115 | ||
1844 | === modified file 'hooks/charmhelpers/fetch/bzrurl.py' | |||
1845 | --- hooks/charmhelpers/fetch/bzrurl.py 2015-02-19 22:08:13 +0000 | |||
1846 | +++ hooks/charmhelpers/fetch/bzrurl.py 2016-01-22 14:18:52 +0000 | |||
1847 | @@ -15,60 +15,50 @@ | |||
1848 | 15 | # along with charm-helpers. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with charm-helpers. If not, see <http://www.gnu.org/licenses/>. |
1849 | 16 | 16 | ||
1850 | 17 | import os | 17 | import os |
1851 | 18 | from subprocess import check_call | ||
1852 | 18 | from charmhelpers.fetch import ( | 19 | from charmhelpers.fetch import ( |
1853 | 19 | BaseFetchHandler, | 20 | BaseFetchHandler, |
1855 | 20 | UnhandledSource | 21 | UnhandledSource, |
1856 | 22 | filter_installed_packages, | ||
1857 | 23 | apt_install, | ||
1858 | 21 | ) | 24 | ) |
1859 | 22 | from charmhelpers.core.host import mkdir | 25 | from charmhelpers.core.host import mkdir |
1860 | 23 | 26 | ||
1861 | 24 | import six | ||
1862 | 25 | if six.PY3: | ||
1863 | 26 | raise ImportError('bzrlib does not support Python3') | ||
1864 | 27 | 27 | ||
1873 | 28 | try: | 28 | if filter_installed_packages(['bzr']) != []: |
1874 | 29 | from bzrlib.branch import Branch | 29 | apt_install(['bzr']) |
1875 | 30 | from bzrlib import bzrdir, workingtree, errors | 30 | if filter_installed_packages(['bzr']) != []: |
1876 | 31 | except ImportError: | 31 | raise NotImplementedError('Unable to install bzr') |
1869 | 32 | from charmhelpers.fetch import apt_install | ||
1870 | 33 | apt_install("python-bzrlib") | ||
1871 | 34 | from bzrlib.branch import Branch | ||
1872 | 35 | from bzrlib import bzrdir, workingtree, errors | ||
1877 | 36 | 32 | ||
1878 | 37 | 33 | ||
1879 | 38 | class BzrUrlFetchHandler(BaseFetchHandler): | 34 | class BzrUrlFetchHandler(BaseFetchHandler): |
1880 | 39 | """Handler for bazaar branches via generic and lp URLs""" | 35 | """Handler for bazaar branches via generic and lp URLs""" |
1881 | 40 | def can_handle(self, source): | 36 | def can_handle(self, source): |
1882 | 41 | url_parts = self.parse_url(source) | 37 | url_parts = self.parse_url(source) |
1884 | 42 | if url_parts.scheme not in ('bzr+ssh', 'lp'): | 38 | if url_parts.scheme not in ('bzr+ssh', 'lp', ''): |
1885 | 43 | return False | 39 | return False |
1886 | 40 | elif not url_parts.scheme: | ||
1887 | 41 | return os.path.exists(os.path.join(source, '.bzr')) | ||
1888 | 44 | else: | 42 | else: |
1889 | 45 | return True | 43 | return True |
1890 | 46 | 44 | ||
1891 | 47 | def branch(self, source, dest): | 45 | def branch(self, source, dest): |
1892 | 48 | url_parts = self.parse_url(source) | ||
1893 | 49 | # If we use lp:branchname scheme we need to load plugins | ||
1894 | 50 | if not self.can_handle(source): | 46 | if not self.can_handle(source): |
1895 | 51 | raise UnhandledSource("Cannot handle {}".format(source)) | 47 | raise UnhandledSource("Cannot handle {}".format(source)) |
1910 | 52 | if url_parts.scheme == "lp": | 48 | if os.path.exists(dest): |
1911 | 53 | from bzrlib.plugin import load_plugins | 49 | check_call(['bzr', 'pull', '--overwrite', '-d', dest, source]) |
1912 | 54 | load_plugins() | 50 | else: |
1913 | 55 | try: | 51 | check_call(['bzr', 'branch', source, dest]) |
1900 | 56 | local_branch = bzrdir.BzrDir.create_branch_convenience(dest) | ||
1901 | 57 | except errors.AlreadyControlDirError: | ||
1902 | 58 | local_branch = Branch.open(dest) | ||
1903 | 59 | try: | ||
1904 | 60 | remote_branch = Branch.open(source) | ||
1905 | 61 | remote_branch.push(local_branch) | ||
1906 | 62 | tree = workingtree.WorkingTree.open(dest) | ||
1907 | 63 | tree.update() | ||
1908 | 64 | except Exception as e: | ||
1909 | 65 | raise e | ||
1914 | 66 | 52 | ||
1916 | 67 | def install(self, source): | 53 | def install(self, source, dest=None): |
1917 | 68 | url_parts = self.parse_url(source) | 54 | url_parts = self.parse_url(source) |
1918 | 69 | branch_name = url_parts.path.strip("/").split("/")[-1] | 55 | branch_name = url_parts.path.strip("/").split("/")[-1] |
1921 | 70 | dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched", | 56 | if dest: |
1922 | 71 | branch_name) | 57 | dest_dir = os.path.join(dest, branch_name) |
1923 | 58 | else: | ||
1924 | 59 | dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched", | ||
1925 | 60 | branch_name) | ||
1926 | 61 | |||
1927 | 72 | if not os.path.exists(dest_dir): | 62 | if not os.path.exists(dest_dir): |
1928 | 73 | mkdir(dest_dir, perms=0o755) | 63 | mkdir(dest_dir, perms=0o755) |
1929 | 74 | try: | 64 | try: |
1930 | 75 | 65 | ||
1931 | === modified file 'hooks/charmhelpers/fetch/giturl.py' | |||
1932 | --- hooks/charmhelpers/fetch/giturl.py 2015-07-22 12:10:31 +0000 | |||
1933 | +++ hooks/charmhelpers/fetch/giturl.py 2016-01-22 14:18:52 +0000 | |||
1934 | @@ -15,24 +15,18 @@ | |||
1935 | 15 | # along with charm-helpers. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with charm-helpers. If not, see <http://www.gnu.org/licenses/>. |
1936 | 16 | 16 | ||
1937 | 17 | import os | 17 | import os |
1938 | 18 | from subprocess import check_call, CalledProcessError | ||
1939 | 18 | from charmhelpers.fetch import ( | 19 | from charmhelpers.fetch import ( |
1940 | 19 | BaseFetchHandler, | 20 | BaseFetchHandler, |
1942 | 20 | UnhandledSource | 21 | UnhandledSource, |
1943 | 22 | filter_installed_packages, | ||
1944 | 23 | apt_install, | ||
1945 | 21 | ) | 24 | ) |
1960 | 22 | from charmhelpers.core.host import mkdir | 25 | |
1961 | 23 | 26 | if filter_installed_packages(['git']) != []: | |
1962 | 24 | import six | 27 | apt_install(['git']) |
1963 | 25 | if six.PY3: | 28 | if filter_installed_packages(['git']) != []: |
1964 | 26 | raise ImportError('GitPython does not support Python 3') | 29 | raise NotImplementedError('Unable to install git') |
1951 | 27 | |||
1952 | 28 | try: | ||
1953 | 29 | from git import Repo | ||
1954 | 30 | except ImportError: | ||
1955 | 31 | from charmhelpers.fetch import apt_install | ||
1956 | 32 | apt_install("python-git") | ||
1957 | 33 | from git import Repo | ||
1958 | 34 | |||
1959 | 35 | from git.exc import GitCommandError # noqa E402 | ||
1965 | 36 | 30 | ||
1966 | 37 | 31 | ||
1967 | 38 | class GitUrlFetchHandler(BaseFetchHandler): | 32 | class GitUrlFetchHandler(BaseFetchHandler): |
1968 | @@ -40,19 +34,24 @@ | |||
1969 | 40 | def can_handle(self, source): | 34 | def can_handle(self, source): |
1970 | 41 | url_parts = self.parse_url(source) | 35 | url_parts = self.parse_url(source) |
1971 | 42 | # TODO (mattyw) no support for ssh git@ yet | 36 | # TODO (mattyw) no support for ssh git@ yet |
1973 | 43 | if url_parts.scheme not in ('http', 'https', 'git'): | 37 | if url_parts.scheme not in ('http', 'https', 'git', ''): |
1974 | 44 | return False | 38 | return False |
1975 | 39 | elif not url_parts.scheme: | ||
1976 | 40 | return os.path.exists(os.path.join(source, '.git')) | ||
1977 | 45 | else: | 41 | else: |
1978 | 46 | return True | 42 | return True |
1979 | 47 | 43 | ||
1981 | 48 | def clone(self, source, dest, branch, depth=None): | 44 | def clone(self, source, dest, branch="master", depth=None): |
1982 | 49 | if not self.can_handle(source): | 45 | if not self.can_handle(source): |
1983 | 50 | raise UnhandledSource("Cannot handle {}".format(source)) | 46 | raise UnhandledSource("Cannot handle {}".format(source)) |
1984 | 51 | 47 | ||
1987 | 52 | if depth: | 48 | if os.path.exists(dest): |
1988 | 53 | Repo.clone_from(source, dest, branch=branch, depth=depth) | 49 | cmd = ['git', '-C', dest, 'pull', source, branch] |
1989 | 54 | else: | 50 | else: |
1991 | 55 | Repo.clone_from(source, dest, branch=branch) | 51 | cmd = ['git', 'clone', source, dest, '--branch', branch] |
1992 | 52 | if depth: | ||
1993 | 53 | cmd.extend(['--depth', depth]) | ||
1994 | 54 | check_call(cmd) | ||
1995 | 56 | 55 | ||
1996 | 57 | def install(self, source, branch="master", dest=None, depth=None): | 56 | def install(self, source, branch="master", dest=None, depth=None): |
1997 | 58 | url_parts = self.parse_url(source) | 57 | url_parts = self.parse_url(source) |
1998 | @@ -62,11 +61,9 @@ | |||
1999 | 62 | else: | 61 | else: |
2000 | 63 | dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched", | 62 | dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched", |
2001 | 64 | branch_name) | 63 | branch_name) |
2002 | 65 | if not os.path.exists(dest_dir): | ||
2003 | 66 | mkdir(dest_dir, perms=0o755) | ||
2004 | 67 | try: | 64 | try: |
2005 | 68 | self.clone(source, dest_dir, branch, depth) | 65 | self.clone(source, dest_dir, branch, depth) |
2007 | 69 | except GitCommandError as e: | 66 | except CalledProcessError as e: |
2008 | 70 | raise UnhandledSource(e) | 67 | raise UnhandledSource(e) |
2009 | 71 | except OSError as e: | 68 | except OSError as e: |
2010 | 72 | raise UnhandledSource(e.strerror) | 69 | raise UnhandledSource(e.strerror) |
2011 | 73 | 70 | ||
2012 | === modified file 'tests/019-basic-trusty-mitaka' (properties changed: -x to +x) | |||
2013 | === modified file 'tests/020-basic-wily-liberty' (properties changed: -x to +x) | |||
2014 | === modified file 'tests/basic_deployment.py' | |||
2015 | --- tests/basic_deployment.py 2015-11-11 14:57:38 +0000 | |||
2016 | +++ tests/basic_deployment.py 2016-01-22 14:18:52 +0000 | |||
2017 | @@ -267,7 +267,7 @@ | |||
2018 | 267 | 'tenantId': u.not_null, | 267 | 'tenantId': u.not_null, |
2019 | 268 | 'id': u.not_null, | 268 | 'id': u.not_null, |
2020 | 269 | 'email': 'juju@localhost'}, | 269 | 'email': 'juju@localhost'}, |
2022 | 270 | {'name': 'quantum', | 270 | {'name': 'neutron', |
2023 | 271 | 'enabled': True, | 271 | 'enabled': True, |
2024 | 272 | 'tenantId': u.not_null, | 272 | 'tenantId': u.not_null, |
2025 | 273 | 'id': u.not_null, | 273 | 'id': u.not_null, |
2026 | 274 | 274 | ||
2027 | === modified file 'tests/charmhelpers/contrib/openstack/amulet/deployment.py' | |||
2028 | --- tests/charmhelpers/contrib/openstack/amulet/deployment.py 2015-11-11 19:54:58 +0000 | |||
2029 | +++ tests/charmhelpers/contrib/openstack/amulet/deployment.py 2016-01-22 14:18:52 +0000 | |||
2030 | @@ -125,7 +125,8 @@ | |||
2031 | 125 | 125 | ||
2032 | 126 | # Charms which can not use openstack-origin, ie. many subordinates | 126 | # Charms which can not use openstack-origin, ie. many subordinates |
2033 | 127 | no_origin = ['cinder-ceph', 'hacluster', 'neutron-openvswitch', 'nrpe', | 127 | no_origin = ['cinder-ceph', 'hacluster', 'neutron-openvswitch', 'nrpe', |
2035 | 128 | 'openvswitch-odl', 'neutron-api-odl', 'odl-controller'] | 128 | 'openvswitch-odl', 'neutron-api-odl', 'odl-controller', |
2036 | 129 | 'cinder-backup'] | ||
2037 | 129 | 130 | ||
2038 | 130 | if self.openstack: | 131 | if self.openstack: |
2039 | 131 | for svc in services: | 132 | for svc in services: |
2040 | @@ -225,7 +226,8 @@ | |||
2041 | 225 | self.precise_havana, self.precise_icehouse, | 226 | self.precise_havana, self.precise_icehouse, |
2042 | 226 | self.trusty_icehouse, self.trusty_juno, self.utopic_juno, | 227 | self.trusty_icehouse, self.trusty_juno, self.utopic_juno, |
2043 | 227 | self.trusty_kilo, self.vivid_kilo, self.trusty_liberty, | 228 | self.trusty_kilo, self.vivid_kilo, self.trusty_liberty, |
2045 | 228 | self.wily_liberty) = range(12) | 229 | self.wily_liberty, self.trusty_mitaka, |
2046 | 230 | self.xenial_mitaka) = range(14) | ||
2047 | 229 | 231 | ||
2048 | 230 | releases = { | 232 | releases = { |
2049 | 231 | ('precise', None): self.precise_essex, | 233 | ('precise', None): self.precise_essex, |
2050 | @@ -237,9 +239,11 @@ | |||
2051 | 237 | ('trusty', 'cloud:trusty-juno'): self.trusty_juno, | 239 | ('trusty', 'cloud:trusty-juno'): self.trusty_juno, |
2052 | 238 | ('trusty', 'cloud:trusty-kilo'): self.trusty_kilo, | 240 | ('trusty', 'cloud:trusty-kilo'): self.trusty_kilo, |
2053 | 239 | ('trusty', 'cloud:trusty-liberty'): self.trusty_liberty, | 241 | ('trusty', 'cloud:trusty-liberty'): self.trusty_liberty, |
2054 | 242 | ('trusty', 'cloud:trusty-mitaka'): self.trusty_mitaka, | ||
2055 | 240 | ('utopic', None): self.utopic_juno, | 243 | ('utopic', None): self.utopic_juno, |
2056 | 241 | ('vivid', None): self.vivid_kilo, | 244 | ('vivid', None): self.vivid_kilo, |
2058 | 242 | ('wily', None): self.wily_liberty} | 245 | ('wily', None): self.wily_liberty, |
2059 | 246 | ('xenial', None): self.xenial_mitaka} | ||
2060 | 243 | return releases[(self.series, self.openstack)] | 247 | return releases[(self.series, self.openstack)] |
2061 | 244 | 248 | ||
2062 | 245 | def _get_openstack_release_string(self): | 249 | def _get_openstack_release_string(self): |
2063 | @@ -256,6 +260,7 @@ | |||
2064 | 256 | ('utopic', 'juno'), | 260 | ('utopic', 'juno'), |
2065 | 257 | ('vivid', 'kilo'), | 261 | ('vivid', 'kilo'), |
2066 | 258 | ('wily', 'liberty'), | 262 | ('wily', 'liberty'), |
2067 | 263 | ('xenial', 'mitaka'), | ||
2068 | 259 | ]) | 264 | ]) |
2069 | 260 | if self.openstack: | 265 | if self.openstack: |
2070 | 261 | os_origin = self.openstack.split(':')[1] | 266 | os_origin = self.openstack.split(':')[1] |
charm_lint_check #17861 odl-controller-next for 1chb1n mp283530
LINT OK: passed
Build: http:// 10.245. 162.77: 8080/job/ charm_lint_ check/17861/