Merge lp:~bjornt/charms/trusty/ceph-radosgw/apt-cache-memonly into lp:~openstack-charmers-archive/charms/trusty/ceph-radosgw/trunk

Proposed by Björn Tillenius
Status: Superseded
Proposed branch: lp:~bjornt/charms/trusty/ceph-radosgw/apt-cache-memonly
Merge into: lp:~openstack-charmers-archive/charms/trusty/ceph-radosgw/trunk
Diff against target: 35 lines (+9/-5)
1 file modified
hooks/ceph.py (+9/-5)
To merge this branch: bzr merge lp:~bjornt/charms/trusty/ceph-radosgw/apt-cache-memonly
Reviewer Review Type Date Requested Status
OpenStack Charmers Pending
Review via email: mp+227873@code.launchpad.net

This proposal has been superseded by a proposal from 2014-07-23.

Description of the change

Build the Apt cache in memory when checking the ceph version.

This avoids a race condition where something else is rebuilding
the Apt cache in the same directory.

I also changed the imports, so it's clear that it's the apt_pkg
that is being used. There's another module called apt, which
provides a different API, and importing apt_pkg as apt has
fooled me more than once.

To post a comment you must log in.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'hooks/ceph.py'
--- hooks/ceph.py 2014-01-24 16:04:49 +0000
+++ hooks/ceph.py 2014-07-23 08:51:00 +0000
@@ -11,7 +11,7 @@
11import subprocess11import subprocess
12import time12import time
13import os13import os
14import apt_pkg as apt14import apt_pkg
1515
16from socket import gethostname as get_unit_hostname16from socket import gethostname as get_unit_hostname
1717
@@ -223,14 +223,18 @@
223223
224224
225def get_ceph_version(package=None):225def get_ceph_version(package=None):
226 apt.init()226 apt_pkg.init()
227 cache = apt.Cache()227 # Force Apt to build its cache in memory. That way we avoid race
228 # conditions with other applications building the cache in the same
229 # place.
230 apt_pkg.config.set("Dir::Cache::pkgcache", "")
231 cache = apt_pkg.Cache()
228 pkg = cache[package or 'ceph']232 pkg = cache[package or 'ceph']
229 if pkg.current_ver:233 if pkg.current_ver:
230 return apt.upstream_version(pkg.current_ver.ver_str)234 return apt_pkg.upstream_version(pkg.current_ver.ver_str)
231 else:235 else:
232 return None236 return None
233237
234238
235def version_compare(a, b):239def version_compare(a, b):
236 return apt.version_compare(a, b)240 return apt_pkg.version_compare(a, b)

Subscribers

People subscribed via source and target branches