Merge lp:~gnuoy/charms/trusty/openstack-dashboard/stable-charmhelper-sync into lp:~openstack-charmers-archive/charms/trusty/openstack-dashboard/trunk

Proposed by Liam Young
Status: Merged
Approved by: Chris Glass
Approved revision: 33
Merged at revision: 33
Proposed branch: lp:~gnuoy/charms/trusty/openstack-dashboard/stable-charmhelper-sync
Merge into: lp:~openstack-charmers-archive/charms/trusty/openstack-dashboard/trunk
Diff against target: 84 lines (+16/-22)
3 files modified
hooks/charmhelpers/contrib/openstack/utils.py (+3/-8)
hooks/charmhelpers/core/host.py (+2/-6)
hooks/charmhelpers/fetch/__init__.py (+11/-8)
To merge this branch: bzr merge lp:~gnuoy/charms/trusty/openstack-dashboard/stable-charmhelper-sync
Reviewer Review Type Date Requested Status
Chris Glass (community) Approve
Review via email: mp+232358@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Chris Glass (tribaal) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/charmhelpers/contrib/openstack/utils.py'
2--- hooks/charmhelpers/contrib/openstack/utils.py 2014-05-19 11:42:57 +0000
3+++ hooks/charmhelpers/contrib/openstack/utils.py 2014-08-27 07:23:31 +0000
4@@ -24,7 +24,7 @@
5 )
6
7 from charmhelpers.core.host import lsb_release, mounts, umount
8-from charmhelpers.fetch import apt_install
9+from charmhelpers.fetch import apt_install, apt_cache
10 from charmhelpers.contrib.storage.linux.utils import is_block_device, zap_disk
11 from charmhelpers.contrib.storage.linux.loopback import ensure_loopback_device
12
13@@ -130,13 +130,8 @@
14
15 def get_os_codename_package(package, fatal=True):
16 '''Derive OpenStack release codename from an installed package.'''
17- apt.init()
18-
19- # Tell apt to build an in-memory cache to prevent race conditions (if
20- # another process is already building the cache).
21- apt.config.set("Dir::Cache::pkgcache", "")
22-
23- cache = apt.Cache()
24+
25+ cache = apt_cache()
26
27 try:
28 pkg = cache[package]
29
30=== modified file 'hooks/charmhelpers/core/host.py'
31--- hooks/charmhelpers/core/host.py 2014-08-13 15:55:59 +0000
32+++ hooks/charmhelpers/core/host.py 2014-08-27 07:23:31 +0000
33@@ -318,12 +318,8 @@
34 0 => Installed revno is the same as supplied arg
35 -1 => Installed revno is less than supplied arg
36 '''
37+ from charmhelpers.fetch import apt_cache
38 if not pkgcache:
39- apt_pkg.init()
40- # Force Apt to build its cache in memory. That way we avoid race
41- # conditions with other applications building the cache in the same
42- # place.
43- apt_pkg.config.set("Dir::Cache::pkgcache", "")
44- pkgcache = apt_pkg.Cache()
45+ pkgcache = apt_cache()
46 pkg = pkgcache[package]
47 return apt_pkg.version_compare(pkg.current_ver.ver_str, revno)
48
49=== modified file 'hooks/charmhelpers/fetch/__init__.py'
50--- hooks/charmhelpers/fetch/__init__.py 2014-08-13 15:55:59 +0000
51+++ hooks/charmhelpers/fetch/__init__.py 2014-08-27 07:23:31 +0000
52@@ -108,14 +108,8 @@
53
54 def filter_installed_packages(packages):
55 """Returns a list of packages that require installation"""
56- apt_pkg.init()
57-
58- # Tell apt to build an in-memory cache to prevent race conditions (if
59- # another process is already building the cache).
60- apt_pkg.config.set("Dir::Cache::pkgcache", "")
61- apt_pkg.config.set("Dir::Cache::srcpkgcache", "")
62-
63- cache = apt_pkg.Cache()
64+
65+ cache = apt_cache()
66 _pkgs = []
67 for package in packages:
68 try:
69@@ -128,6 +122,15 @@
70 return _pkgs
71
72
73+def apt_cache(in_memory=True):
74+ """Build and return an apt cache"""
75+ apt_pkg.init()
76+ if in_memory:
77+ apt_pkg.config.set("Dir::Cache::pkgcache", "")
78+ apt_pkg.config.set("Dir::Cache::srcpkgcache", "")
79+ return apt_pkg.Cache()
80+
81+
82 def apt_install(packages, options=None, fatal=False):
83 """Install one or more packages"""
84 if options is None:

Subscribers

People subscribed via source and target branches