Merge lp:~tribaal/charms/trusty/ceph/backport-apt-cache-fixes into lp:~openstack-charmers-archive/charms/trusty/ceph/trunk

Proposed by Chris Glass
Status: Merged
Merge reported by: James Page
Merged at revision: not available
Proposed branch: lp:~tribaal/charms/trusty/ceph/backport-apt-cache-fixes
Merge into: lp:~openstack-charmers-archive/charms/trusty/ceph/trunk
Diff against target: 237 lines (+51/-43)
6 files modified
.bzrignore (+1/-0)
Makefile (+8/-2)
hooks/ceph.py (+25/-28)
hooks/charmhelpers/contrib/storage/linux/utils.py (+4/-0)
hooks/charmhelpers/core/host.py (+2/-6)
hooks/charmhelpers/fetch/__init__.py (+11/-7)
To merge this branch: bzr merge lp:~tribaal/charms/trusty/ceph/backport-apt-cache-fixes
Reviewer Review Type Date Requested Status
James Page Approve
Review via email: mp+236068@code.launchpad.net

Description of the change

This branch backports changes fixing https://bugs.launchpad.net/charms/+source/ceph/+bug/1346489 into the "main" branch from the "next" branch.

It also refreshes charm-helpers.

To post a comment you must log in.
Revision history for this message
James Page (james-page) wrote :

I think this or an equiv was already been merged.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file '.bzrignore'
2--- .bzrignore 1970-01-01 00:00:00 +0000
3+++ .bzrignore 2014-09-26 07:27:46 +0000
4@@ -0,0 +1,1 @@
5+bin/
6
7=== modified file 'Makefile'
8--- Makefile 2014-05-21 10:09:21 +0000
9+++ Makefile 2014-09-26 07:27:46 +0000
10@@ -1,11 +1,17 @@
11 #!/usr/bin/make
12+PYTHON := /usr/bin/env python
13
14 lint:
15 @flake8 --exclude hooks/charmhelpers hooks
16 @charm proof
17
18-sync:
19- @charm-helper-sync -c charm-helpers-sync.yaml
20+bin/charm_helpers_sync.py:
21+ @mkdir -p bin
22+ @bzr cat lp:charm-helpers/tools/charm_helpers_sync/charm_helpers_sync.py \
23+ > bin/charm_helpers_sync.py
24+
25+sync: bin/charm_helpers_sync.py
26+ $(PYTHON) bin/charm_helpers_sync.py -c charm-helpers-sync.yaml
27
28 publish: lint
29 bzr push lp:charms/ceph
30
31=== modified file 'hooks/ceph.py'
32--- hooks/ceph.py 2014-05-19 12:15:38 +0000
33+++ hooks/ceph.py 2014-09-26 07:27:46 +0000
34@@ -11,19 +11,20 @@
35 import subprocess
36 import time
37 import os
38-import apt_pkg as apt
39 from charmhelpers.core.host import (
40 mkdir,
41 service_restart,
42+ cmp_pkgrevno,
43 )
44 from charmhelpers.core.hookenv import (
45 log,
46 ERROR,
47+ WARNING,
48 )
49 from charmhelpers.contrib.storage.linux.utils import (
50 zap_disk,
51 is_block_device,
52- is_device_mounted
53+ is_device_mounted,
54 )
55 from utils import (
56 get_unit_hostname,
57@@ -126,7 +127,7 @@
58 def start_osds(devices):
59 # Scan for ceph block devices
60 rescan_osd_devices()
61- if get_ceph_version() >= "0.56.6":
62+ if cmp_pkgrevno('ceph', "0.56.6") >= 0:
63 # Use ceph-disk-activate for directory based OSD's
64 for dev_or_path in devices:
65 if os.path.exists(dev_or_path) and os.path.isdir(dev_or_path):
66@@ -284,7 +285,7 @@
67 log('bootstrap_monitor_cluster: mon already initialized.')
68 else:
69 # Ceph >= 0.61.3 needs this for ceph-mon fs creation
70- mkdir('/var/run/ceph', perms=0755)
71+ mkdir('/var/run/ceph', perms=0o755)
72 mkdir(path)
73 # end changes for Ceph >= 0.61.3
74 try:
75@@ -309,20 +310,6 @@
76 os.unlink(keyring)
77
78
79-def get_ceph_version():
80- apt.init()
81- cache = apt.Cache()
82- pkg = cache['ceph']
83- if pkg.current_ver:
84- return apt.upstream_version(pkg.current_ver.ver_str)
85- else:
86- return None
87-
88-
89-def version_compare(a, b):
90- return apt.version_compare(a, b)
91-
92-
93 def update_monfs():
94 hostname = get_unit_hostname()
95 monfs = '/var/lib/ceph/mon/ceph-{}'.format(hostname)
96@@ -334,14 +321,16 @@
97 pass
98
99
100-def osdize(dev, osd_format, osd_journal, reformat_osd=False):
101+def osdize(dev, osd_format, osd_journal, reformat_osd=False,
102+ ignore_errors=False):
103 if dev.startswith('/dev'):
104- osdize_dev(dev, osd_format, osd_journal, reformat_osd)
105+ osdize_dev(dev, osd_format, osd_journal, reformat_osd, ignore_errors)
106 else:
107 osdize_dir(dev)
108
109
110-def osdize_dev(dev, osd_format, osd_journal, reformat_osd=False):
111+def osdize_dev(dev, osd_format, osd_journal, reformat_osd=False,
112+ ignore_errors=False):
113 if not os.path.exists(dev):
114 log('Path {} does not exist - bailing'.format(dev))
115 return
116@@ -360,10 +349,12 @@
117
118 cmd = ['ceph-disk-prepare']
119 # Later versions of ceph support more options
120- if get_ceph_version() >= "0.48.3":
121+ if cmp_pkgrevno('ceph', '0.48.3') >= 0:
122 if osd_format:
123 cmd.append('--fs-type')
124 cmd.append(osd_format)
125+ if reformat_osd:
126+ cmd.append('--zap-disk')
127 cmd.append(dev)
128 if osd_journal and os.path.exists(osd_journal):
129 cmd.append(osd_journal)
130@@ -371,11 +362,17 @@
131 # Just provide the device - no other options
132 # for older versions of ceph
133 cmd.append(dev)
134-
135- if reformat_osd:
136- zap_disk(dev)
137-
138- subprocess.check_call(cmd)
139+ if reformat_osd:
140+ zap_disk(dev)
141+
142+ try:
143+ subprocess.check_call(cmd)
144+ except subprocess.CalledProcessError as e:
145+ if ignore_errors:
146+ log('Unable to initialize device: {}'.format(dev), WARNING)
147+ else:
148+ log('Unable to initialize device: {}'.format(dev), ERROR)
149+ raise e
150
151
152 def osdize_dir(path):
153@@ -383,7 +380,7 @@
154 log('Path {} is already configured as an OSD - bailing'.format(path))
155 return
156
157- if get_ceph_version() < "0.56.6":
158+ if cmp_pkgrevno('ceph', "0.56.6") < 0:
159 log('Unable to use directories for OSDs with ceph < 0.56.6',
160 level=ERROR)
161 raise
162
163=== modified file 'hooks/charmhelpers/contrib/storage/linux/utils.py'
164--- hooks/charmhelpers/contrib/storage/linux/utils.py 2014-05-19 11:38:45 +0000
165+++ hooks/charmhelpers/contrib/storage/linux/utils.py 2014-09-26 07:27:46 +0000
166@@ -37,6 +37,7 @@
167 check_call(['dd', 'if=/dev/zero', 'of=%s' % (block_device),
168 'bs=512', 'count=100', 'seek=%s' % (gpt_end)])
169
170+
171 def is_device_mounted(device):
172 '''Given a device path, return True if that device is mounted, and False
173 if it isn't.
174@@ -45,5 +46,8 @@
175 :returns: boolean: True if the path represents a mounted device, False if
176 it doesn't.
177 '''
178+ is_partition = bool(re.search(r".*[0-9]+\b", device))
179 out = check_output(['mount'])
180+ if is_partition:
181+ return bool(re.search(device + r"\b", out))
182 return bool(re.search(device + r"[0-9]+\b", out))
183
184=== modified file 'hooks/charmhelpers/core/host.py'
185--- hooks/charmhelpers/core/host.py 2014-07-24 09:59:35 +0000
186+++ hooks/charmhelpers/core/host.py 2014-09-26 07:27:46 +0000
187@@ -318,12 +318,8 @@
188 0 => Installed revno is the same as supplied arg
189 -1 => Installed revno is less than supplied arg
190 '''
191+ from charmhelpers.fetch import apt_cache
192 if not pkgcache:
193- apt_pkg.init()
194- # Force Apt to build its cache in memory. That way we avoid race
195- # conditions with other applications building the cache in the same
196- # place.
197- apt_pkg.config.set("Dir::Cache::pkgcache", "")
198- pkgcache = apt_pkg.Cache()
199+ pkgcache = apt_cache()
200 pkg = pkgcache[package]
201 return apt_pkg.version_compare(pkg.current_ver.ver_str, revno)
202
203=== modified file 'hooks/charmhelpers/fetch/__init__.py'
204--- hooks/charmhelpers/fetch/__init__.py 2014-05-19 11:38:45 +0000
205+++ hooks/charmhelpers/fetch/__init__.py 2014-09-26 07:27:46 +0000
206@@ -108,13 +108,8 @@
207
208 def filter_installed_packages(packages):
209 """Returns a list of packages that require installation"""
210- apt_pkg.init()
211-
212- # Tell apt to build an in-memory cache to prevent race conditions (if
213- # another process is already building the cache).
214- apt_pkg.config.set("Dir::Cache::pkgcache", "")
215-
216- cache = apt_pkg.Cache()
217+
218+ cache = apt_cache()
219 _pkgs = []
220 for package in packages:
221 try:
222@@ -127,6 +122,15 @@
223 return _pkgs
224
225
226+def apt_cache(in_memory=True):
227+ """Build and return an apt cache"""
228+ apt_pkg.init()
229+ if in_memory:
230+ apt_pkg.config.set("Dir::Cache::pkgcache", "")
231+ apt_pkg.config.set("Dir::Cache::srcpkgcache", "")
232+ return apt_pkg.Cache()
233+
234+
235 def apt_install(packages, options=None, fatal=False):
236 """Install one or more packages"""
237 if options is None:

Subscribers

People subscribed via source and target branches