Merge lp:~stub/charm-helpers/packagestatus into lp:charm-helpers

Proposed by Stuart Bishop
Status: Merged
Merged at revision: 398
Proposed branch: lp:~stub/charm-helpers/packagestatus
Merge into: lp:charm-helpers
Diff against target: 151 lines (+65/-25)
2 files modified
charmhelpers/fetch/__init__.py (+20/-12)
tests/fetch/test_fetch.py (+45/-13)
To merge this branch: bzr merge lp:~stub/charm-helpers/packagestatus
Reviewer Review Type Date Requested Status
Tim Van Steenburgh Approve
Review via email: mp+263630@code.launchpad.net

Description of the change

I need to unhold packages, not just hold them.

Rework apt_hold into apt_hold, apt_unhold and general apt_mark.

To post a comment you must log in.
Revision history for this message
Tim Van Steenburgh (tvansteenburgh) wrote :

+1, LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/fetch/__init__.py'
2--- charmhelpers/fetch/__init__.py 2015-04-29 12:52:18 +0000
3+++ charmhelpers/fetch/__init__.py 2015-07-02 10:22:38 +0000
4@@ -215,19 +215,27 @@
5 _run_apt_command(cmd, fatal)
6
7
8+def apt_mark(packages, mark, fatal=False):
9+ """Flag one or more packages using apt-mark"""
10+ cmd = ['apt-mark', mark]
11+ if isinstance(packages, six.string_types):
12+ cmd.append(packages)
13+ else:
14+ cmd.extend(packages)
15+ log("Holding {}".format(packages))
16+
17+ if fatal:
18+ subprocess.check_call(cmd, universal_newlines=True)
19+ else:
20+ subprocess.call(cmd, universal_newlines=True)
21+
22+
23 def apt_hold(packages, fatal=False):
24- """Hold one or more packages"""
25- cmd = ['apt-mark', 'hold']
26- if isinstance(packages, six.string_types):
27- cmd.append(packages)
28- else:
29- cmd.extend(packages)
30- log("Holding {}".format(packages))
31-
32- if fatal:
33- subprocess.check_call(cmd)
34- else:
35- subprocess.call(cmd)
36+ return apt_mark(packages, 'hold', fatal=fatal)
37+
38+
39+def apt_unhold(packages, fatal=False):
40+ return apt_mark(packages, 'unhold', fatal=fatal)
41
42
43 def add_source(source, key=None):
44
45=== modified file 'tests/fetch/test_fetch.py'
46--- tests/fetch/test_fetch.py 2014-11-25 15:07:02 +0000
47+++ tests/fetch/test_fetch.py 2015-07-02 10:22:38 +0000
48@@ -6,6 +6,7 @@
49 patch,
50 MagicMock,
51 call,
52+ sentinel,
53 )
54 from charmhelpers import fetch
55 import os
56@@ -581,51 +582,82 @@
57
58 @patch('subprocess.check_call')
59 @patch.object(fetch, 'log')
60- def test_hold_apt_packages_as_string_fatal(self, log, mock_call):
61+ def test_mark_apt_packages_as_string_fatal(self, log, mock_call):
62 packages = 'irrelevant names'
63 mock_call.side_effect = OSError('fail')
64
65- mock_call.assertRaises(OSError, fetch.apt_hold, packages, fatal=True)
66+ mock_call.assertRaises(OSError,
67+ fetch.apt_mark, packages,
68+ sentinel.mark, fatal=True)
69 log.assert_called()
70
71 @patch('subprocess.check_call')
72 @patch.object(fetch, 'log')
73- def test_hold_apt_packages_fatal(self, log, mock_call):
74+ def test_mark_apt_packages_fatal(self, log, mock_call):
75 packages = ['irrelevant', 'names']
76 mock_call.side_effect = OSError('fail')
77
78- mock_call.assertRaises(OSError, fetch.apt_hold, packages, fatal=True)
79+ mock_call.assertRaises(OSError,
80+ fetch.apt_mark, packages,
81+ sentinel.mark, fatal=True)
82 log.assert_called()
83
84 @patch('subprocess.call')
85 @patch.object(fetch, 'log')
86- def test_hold_apt_packages_as_string_nofatal(self, log, mock_call):
87+ def test_mark_apt_packages_as_string_nofatal(self, log, mock_call):
88 packages = 'foo bar'
89
90- fetch.apt_hold(packages)
91+ fetch.apt_mark(packages, sentinel.mark)
92
93 log.assert_called()
94- mock_call.assert_called_with(['apt-mark', 'hold', 'foo bar'])
95+ mock_call.assert_called_with(['apt-mark', sentinel.mark, 'foo bar'],
96+ universal_newlines=True)
97
98 @patch('subprocess.call')
99 @patch.object(fetch, 'log')
100- def test_hold_apt_packages_nofatal(self, log, mock_call):
101+ def test_mark_apt_packages_nofatal(self, log, mock_call):
102 packages = ['foo', 'bar']
103
104- fetch.apt_hold(packages)
105+ fetch.apt_mark(packages, sentinel.mark)
106
107 log.assert_called()
108- mock_call.assert_called_with(['apt-mark', 'hold', 'foo', 'bar'])
109+ mock_call.assert_called_with(['apt-mark', sentinel.mark, 'foo', 'bar'],
110+ universal_newlines=True)
111
112 @patch('subprocess.check_call')
113 @patch.object(fetch, 'log')
114- def test_hold_apt_packages_nofatal_abortonfatal(self, log, mock_call):
115+ def test_mark_apt_packages_nofatal_abortonfatal(self, log, mock_call):
116 packages = ['foo', 'bar']
117
118- fetch.apt_hold(packages, fatal=True)
119+ fetch.apt_mark(packages, sentinel.mark, fatal=True)
120
121 log.assert_called()
122- mock_call.assert_called_with(['apt-mark', 'hold', 'foo', 'bar'])
123+ mock_call.assert_called_with(['apt-mark', sentinel.mark, 'foo', 'bar'],
124+ universal_newlines=True)
125+
126+ @patch.object(fetch, 'apt_mark')
127+ def test_apt_hold(self, apt_mark):
128+ fetch.apt_hold(sentinel.packages)
129+ apt_mark.assert_called_once_with(sentinel.packages, 'hold',
130+ fatal=False)
131+
132+ @patch.object(fetch, 'apt_mark')
133+ def test_apt_hold_fatal(self, apt_mark):
134+ fetch.apt_hold(sentinel.packages, fatal=sentinel.fatal)
135+ apt_mark.assert_called_once_with(sentinel.packages, 'hold',
136+ fatal=sentinel.fatal)
137+
138+ @patch.object(fetch, 'apt_mark')
139+ def test_apt_unhold(self, apt_mark):
140+ fetch.apt_unhold(sentinel.packages)
141+ apt_mark.assert_called_once_with(sentinel.packages, 'unhold',
142+ fatal=False)
143+
144+ @patch.object(fetch, 'apt_mark')
145+ def test_apt_unhold_fatal(self, apt_mark):
146+ fetch.apt_unhold(sentinel.packages, fatal=sentinel.fatal)
147+ apt_mark.assert_called_once_with(sentinel.packages, 'unhold',
148+ fatal=sentinel.fatal)
149
150 @patch('subprocess.check_call')
151 def test_apt_update_fatal(self, check_call):

Subscribers

People subscribed via source and target branches