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
=== modified file 'hooks/lib/utils.py'
--- hooks/lib/utils.py 2013-03-21 18:28:05 +0000
+++ hooks/lib/utils.py 2013-05-03 19:37:23 +0000
@@ -9,6 +9,7 @@
9# Adam Gandelman <adamg@ubuntu.com>9# Adam Gandelman <adamg@ubuntu.com>
10#10#
1111
12import apt_pkg as apt
12import json13import json
13import os14import os
14import subprocess15import subprocess
@@ -29,12 +30,25 @@
2930
3031
31def install(*pkgs):32def install(*pkgs):
33 apt.init()
34 cache = apt.Cache()
35 _pkgs = []
36 # Ensure we only attempt to install packages that are actually needed.
37 for pkg in pkgs:
38 try:
39 p = cache[pkg]
40 p.current_ver or _pkgs.append(pkg)
41 except KeyError:
42 juju_log('ERROR', 'Attempting to install %s but there is no '\
43 'installation candidate.')
44 sys.exit(1)
45
32 cmd = [46 cmd = [
33 'apt-get',47 'apt-get',
34 '-y',48 '-y',
35 'install'49 'install'
36 ]50 ]
37 for pkg in pkgs:51 for pkg in _pkgs:
38 cmd.append(pkg)52 cmd.append(pkg)
39 subprocess.check_call(cmd)53 subprocess.check_call(cmd)
4054
4155
=== modified file 'revision'
--- revision 2013-04-25 16:57:49 +0000
+++ revision 2013-05-03 19:37:23 +0000
@@ -1,1 +1,1 @@
12191220

Subscribers

People subscribed via source and target branches