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
=== added file '.bzrignore'
--- .bzrignore 1970-01-01 00:00:00 +0000
+++ .bzrignore 2014-09-26 07:27:46 +0000
@@ -0,0 +1,1 @@
1bin/
02
=== modified file 'Makefile'
--- Makefile 2014-05-21 10:09:21 +0000
+++ Makefile 2014-09-26 07:27:46 +0000
@@ -1,11 +1,17 @@
1#!/usr/bin/make1#!/usr/bin/make
2PYTHON := /usr/bin/env python
23
3lint:4lint:
4 @flake8 --exclude hooks/charmhelpers hooks5 @flake8 --exclude hooks/charmhelpers hooks
5 @charm proof6 @charm proof
67
7sync:8bin/charm_helpers_sync.py:
8 @charm-helper-sync -c charm-helpers-sync.yaml9 @mkdir -p bin
10 @bzr cat lp:charm-helpers/tools/charm_helpers_sync/charm_helpers_sync.py \
11 > bin/charm_helpers_sync.py
12
13sync: bin/charm_helpers_sync.py
14 $(PYTHON) bin/charm_helpers_sync.py -c charm-helpers-sync.yaml
915
10publish: lint16publish: lint
11 bzr push lp:charms/ceph17 bzr push lp:charms/ceph
1218
=== modified file 'hooks/ceph.py'
--- hooks/ceph.py 2014-05-19 12:15:38 +0000
+++ hooks/ceph.py 2014-09-26 07:27:46 +0000
@@ -11,19 +11,20 @@
11import subprocess11import subprocess
12import time12import time
13import os13import os
14import apt_pkg as apt
15from charmhelpers.core.host import (14from charmhelpers.core.host import (
16 mkdir,15 mkdir,
17 service_restart,16 service_restart,
17 cmp_pkgrevno,
18)18)
19from charmhelpers.core.hookenv import (19from charmhelpers.core.hookenv import (
20 log,20 log,
21 ERROR,21 ERROR,
22 WARNING,
22)23)
23from charmhelpers.contrib.storage.linux.utils import (24from charmhelpers.contrib.storage.linux.utils import (
24 zap_disk,25 zap_disk,
25 is_block_device,26 is_block_device,
26 is_device_mounted27 is_device_mounted,
27)28)
28from utils import (29from utils import (
29 get_unit_hostname,30 get_unit_hostname,
@@ -126,7 +127,7 @@
126def start_osds(devices):127def start_osds(devices):
127 # Scan for ceph block devices128 # Scan for ceph block devices
128 rescan_osd_devices()129 rescan_osd_devices()
129 if get_ceph_version() >= "0.56.6":130 if cmp_pkgrevno('ceph', "0.56.6") >= 0:
130 # Use ceph-disk-activate for directory based OSD's131 # Use ceph-disk-activate for directory based OSD's
131 for dev_or_path in devices:132 for dev_or_path in devices:
132 if os.path.exists(dev_or_path) and os.path.isdir(dev_or_path):133 if os.path.exists(dev_or_path) and os.path.isdir(dev_or_path):
@@ -284,7 +285,7 @@
284 log('bootstrap_monitor_cluster: mon already initialized.')285 log('bootstrap_monitor_cluster: mon already initialized.')
285 else:286 else:
286 # Ceph >= 0.61.3 needs this for ceph-mon fs creation287 # Ceph >= 0.61.3 needs this for ceph-mon fs creation
287 mkdir('/var/run/ceph', perms=0755)288 mkdir('/var/run/ceph', perms=0o755)
288 mkdir(path)289 mkdir(path)
289 # end changes for Ceph >= 0.61.3290 # end changes for Ceph >= 0.61.3
290 try:291 try:
@@ -309,20 +310,6 @@
309 os.unlink(keyring)310 os.unlink(keyring)
310311
311312
312def get_ceph_version():
313 apt.init()
314 cache = apt.Cache()
315 pkg = cache['ceph']
316 if pkg.current_ver:
317 return apt.upstream_version(pkg.current_ver.ver_str)
318 else:
319 return None
320
321
322def version_compare(a, b):
323 return apt.version_compare(a, b)
324
325
326def update_monfs():313def update_monfs():
327 hostname = get_unit_hostname()314 hostname = get_unit_hostname()
328 monfs = '/var/lib/ceph/mon/ceph-{}'.format(hostname)315 monfs = '/var/lib/ceph/mon/ceph-{}'.format(hostname)
@@ -334,14 +321,16 @@
334 pass321 pass
335322
336323
337def osdize(dev, osd_format, osd_journal, reformat_osd=False):324def osdize(dev, osd_format, osd_journal, reformat_osd=False,
325 ignore_errors=False):
338 if dev.startswith('/dev'):326 if dev.startswith('/dev'):
339 osdize_dev(dev, osd_format, osd_journal, reformat_osd)327 osdize_dev(dev, osd_format, osd_journal, reformat_osd, ignore_errors)
340 else:328 else:
341 osdize_dir(dev)329 osdize_dir(dev)
342330
343331
344def osdize_dev(dev, osd_format, osd_journal, reformat_osd=False):332def osdize_dev(dev, osd_format, osd_journal, reformat_osd=False,
333 ignore_errors=False):
345 if not os.path.exists(dev):334 if not os.path.exists(dev):
346 log('Path {} does not exist - bailing'.format(dev))335 log('Path {} does not exist - bailing'.format(dev))
347 return336 return
@@ -360,10 +349,12 @@
360349
361 cmd = ['ceph-disk-prepare']350 cmd = ['ceph-disk-prepare']
362 # Later versions of ceph support more options351 # Later versions of ceph support more options
363 if get_ceph_version() >= "0.48.3":352 if cmp_pkgrevno('ceph', '0.48.3') >= 0:
364 if osd_format:353 if osd_format:
365 cmd.append('--fs-type')354 cmd.append('--fs-type')
366 cmd.append(osd_format)355 cmd.append(osd_format)
356 if reformat_osd:
357 cmd.append('--zap-disk')
367 cmd.append(dev)358 cmd.append(dev)
368 if osd_journal and os.path.exists(osd_journal):359 if osd_journal and os.path.exists(osd_journal):
369 cmd.append(osd_journal)360 cmd.append(osd_journal)
@@ -371,11 +362,17 @@
371 # Just provide the device - no other options362 # Just provide the device - no other options
372 # for older versions of ceph363 # for older versions of ceph
373 cmd.append(dev)364 cmd.append(dev)
374365 if reformat_osd:
375 if reformat_osd:366 zap_disk(dev)
376 zap_disk(dev)367
377368 try:
378 subprocess.check_call(cmd)369 subprocess.check_call(cmd)
370 except subprocess.CalledProcessError as e:
371 if ignore_errors:
372 log('Unable to initialize device: {}'.format(dev), WARNING)
373 else:
374 log('Unable to initialize device: {}'.format(dev), ERROR)
375 raise e
379376
380377
381def osdize_dir(path):378def osdize_dir(path):
@@ -383,7 +380,7 @@
383 log('Path {} is already configured as an OSD - bailing'.format(path))380 log('Path {} is already configured as an OSD - bailing'.format(path))
384 return381 return
385382
386 if get_ceph_version() < "0.56.6":383 if cmp_pkgrevno('ceph', "0.56.6") < 0:
387 log('Unable to use directories for OSDs with ceph < 0.56.6',384 log('Unable to use directories for OSDs with ceph < 0.56.6',
388 level=ERROR)385 level=ERROR)
389 raise386 raise
390387
=== modified file 'hooks/charmhelpers/contrib/storage/linux/utils.py'
--- hooks/charmhelpers/contrib/storage/linux/utils.py 2014-05-19 11:38:45 +0000
+++ hooks/charmhelpers/contrib/storage/linux/utils.py 2014-09-26 07:27:46 +0000
@@ -37,6 +37,7 @@
37 check_call(['dd', 'if=/dev/zero', 'of=%s' % (block_device),37 check_call(['dd', 'if=/dev/zero', 'of=%s' % (block_device),
38 'bs=512', 'count=100', 'seek=%s' % (gpt_end)])38 'bs=512', 'count=100', 'seek=%s' % (gpt_end)])
3939
40
40def is_device_mounted(device):41def is_device_mounted(device):
41 '''Given a device path, return True if that device is mounted, and False42 '''Given a device path, return True if that device is mounted, and False
42 if it isn't.43 if it isn't.
@@ -45,5 +46,8 @@
45 :returns: boolean: True if the path represents a mounted device, False if46 :returns: boolean: True if the path represents a mounted device, False if
46 it doesn't.47 it doesn't.
47 '''48 '''
49 is_partition = bool(re.search(r".*[0-9]+\b", device))
48 out = check_output(['mount'])50 out = check_output(['mount'])
51 if is_partition:
52 return bool(re.search(device + r"\b", out))
49 return bool(re.search(device + r"[0-9]+\b", out))53 return bool(re.search(device + r"[0-9]+\b", out))
5054
=== modified file 'hooks/charmhelpers/core/host.py'
--- hooks/charmhelpers/core/host.py 2014-07-24 09:59:35 +0000
+++ hooks/charmhelpers/core/host.py 2014-09-26 07:27:46 +0000
@@ -318,12 +318,8 @@
318 0 => Installed revno is the same as supplied arg318 0 => Installed revno is the same as supplied arg
319 -1 => Installed revno is less than supplied arg319 -1 => Installed revno is less than supplied arg
320 '''320 '''
321 from charmhelpers.fetch import apt_cache
321 if not pkgcache:322 if not pkgcache:
322 apt_pkg.init()323 pkgcache = apt_cache()
323 # Force Apt to build its cache in memory. That way we avoid race
324 # conditions with other applications building the cache in the same
325 # place.
326 apt_pkg.config.set("Dir::Cache::pkgcache", "")
327 pkgcache = apt_pkg.Cache()
328 pkg = pkgcache[package]324 pkg = pkgcache[package]
329 return apt_pkg.version_compare(pkg.current_ver.ver_str, revno)325 return apt_pkg.version_compare(pkg.current_ver.ver_str, revno)
330326
=== modified file 'hooks/charmhelpers/fetch/__init__.py'
--- hooks/charmhelpers/fetch/__init__.py 2014-05-19 11:38:45 +0000
+++ hooks/charmhelpers/fetch/__init__.py 2014-09-26 07:27:46 +0000
@@ -108,13 +108,8 @@
108108
109def filter_installed_packages(packages):109def filter_installed_packages(packages):
110 """Returns a list of packages that require installation"""110 """Returns a list of packages that require installation"""
111 apt_pkg.init()111
112112 cache = apt_cache()
113 # Tell apt to build an in-memory cache to prevent race conditions (if
114 # another process is already building the cache).
115 apt_pkg.config.set("Dir::Cache::pkgcache", "")
116
117 cache = apt_pkg.Cache()
118 _pkgs = []113 _pkgs = []
119 for package in packages:114 for package in packages:
120 try:115 try:
@@ -127,6 +122,15 @@
127 return _pkgs122 return _pkgs
128123
129124
125def apt_cache(in_memory=True):
126 """Build and return an apt cache"""
127 apt_pkg.init()
128 if in_memory:
129 apt_pkg.config.set("Dir::Cache::pkgcache", "")
130 apt_pkg.config.set("Dir::Cache::srcpkgcache", "")
131 return apt_pkg.Cache()
132
133
130def apt_install(packages, options=None, fatal=False):134def apt_install(packages, options=None, fatal=False):
131 """Install one or more packages"""135 """Install one or more packages"""
132 if options is None:136 if options is None:

Subscribers

People subscribed via source and target branches