Merge lp:~gandelman-a/charms/precise/keystone/avoid_upgrade_in_install into lp:~openstack-charmers/charms/precise/keystone/ha-support

Proposed by Adam Gandelman
Status: Merged
Merge reported by: James Page
Merged at revision: not available
Proposed branch: lp:~gandelman-a/charms/precise/keystone/avoid_upgrade_in_install
Merge into: lp:~openstack-charmers/charms/precise/keystone/ha-support
Diff against target: 45 lines (+16/-2)
2 files modified
hooks/lib/utils.py (+15/-1)
revision (+1/-1)
To merge this branch: bzr merge lp:~gandelman-a/charms/precise/keystone/avoid_upgrade_in_install
Reviewer Review Type Date Requested Status
James Page Approve
Review via email: mp+162456@code.launchpad.net

Description of the change

Updates utils.install to check if a package is installed before attempting to install it. This should help avoid unwanted upgrades when re-calling utils.install(*pkgs) from upgrade hooks. Should be merged into the helpers library after here.

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

Works for me

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/lib/utils.py'
2--- hooks/lib/utils.py 2013-03-21 18:28:05 +0000
3+++ hooks/lib/utils.py 2013-05-03 19:37:23 +0000
4@@ -9,6 +9,7 @@
5 # Adam Gandelman <adamg@ubuntu.com>
6 #
7
8+import apt_pkg as apt
9 import json
10 import os
11 import subprocess
12@@ -29,12 +30,25 @@
13
14
15 def install(*pkgs):
16+ apt.init()
17+ cache = apt.Cache()
18+ _pkgs = []
19+ # Ensure we only attempt to install packages that are actually needed.
20+ for pkg in pkgs:
21+ try:
22+ p = cache[pkg]
23+ p.current_ver or _pkgs.append(pkg)
24+ except KeyError:
25+ juju_log('ERROR', 'Attempting to install %s but there is no '\
26+ 'installation candidate.')
27+ sys.exit(1)
28+
29 cmd = [
30 'apt-get',
31 '-y',
32 'install'
33 ]
34- for pkg in pkgs:
35+ for pkg in _pkgs:
36 cmd.append(pkg)
37 subprocess.check_call(cmd)
38
39
40=== modified file 'revision'
41--- revision 2013-04-25 16:57:49 +0000
42+++ revision 2013-05-03 19:37:23 +0000
43@@ -1,1 +1,1 @@
44-219
45+220

Subscribers

People subscribed via source and target branches