Merge lp:~gnuoy/charm-helpers/add-apt-hold into lp:charm-helpers

Proposed by Liam Young
Status: Merged
Merged at revision: 81
Proposed branch: lp:~gnuoy/charm-helpers/add-apt-hold
Merge into: lp:charm-helpers
Diff against target: 120 lines (+63/-6)
2 files modified
charmhelpers/fetch/__init__.py (+14/-0)
tests/fetch/test_fetch.py (+49/-6)
To merge this branch: bzr merge lp:~gnuoy/charm-helpers/add-apt-hold
Reviewer Review Type Date Requested Status
James Page Approve
Review via email: mp+183398@code.launchpad.net

Description of the change

Added ability to hold packages and tidied up some old lint from the fetch tests

To post a comment you must log in.
Revision history for this message
James Page (james-page) :
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 2013-08-21 11:45:37 +0000
3+++ charmhelpers/fetch/__init__.py 2013-09-02 08:47:58 +0000
4@@ -79,6 +79,20 @@
5 subprocess.call(cmd)
6
7
8+def apt_hold(packages, fatal=False):
9+ """Hold one or more packages"""
10+ cmd = ['apt-mark', 'hold']
11+ if isinstance(packages, basestring):
12+ cmd.append(packages)
13+ else:
14+ cmd.extend(packages)
15+ log("Holding {}".format(packages))
16+ if fatal:
17+ subprocess.check_call(cmd)
18+ else:
19+ subprocess.call(cmd)
20+
21+
22 def add_source(source, key=None):
23 if ((source.startswith('ppa:') or
24 source.startswith('http:'))):
25
26=== modified file 'tests/fetch/test_fetch.py'
27--- tests/fetch/test_fetch.py 2013-08-21 15:45:53 +0000
28+++ tests/fetch/test_fetch.py 2013-09-02 08:47:58 +0000
29@@ -352,27 +352,24 @@
30 check_call.assert_called_with(['apt-get', '-y', '--foo', '--bar',
31 'install', 'foo', 'bar'])
32
33-
34 @patch('subprocess.check_call')
35 @patch.object(fetch, 'log')
36 def test_purges_apt_packages_as_string_fatal(self, log, mock_call):
37 packages = 'irrelevant names'
38 mock_call.side_effect = OSError('fail')
39
40- mock_call.assertRaises(OSError, fetch.apt_purge, packages, fatal=True )
41+ mock_call.assertRaises(OSError, fetch.apt_purge, packages, fatal=True)
42 log.assert_called()
43
44-
45 @patch('subprocess.check_call')
46 @patch.object(fetch, 'log')
47 def test_purges_apt_packages_fatal(self, log, mock_call):
48 packages = ['irrelevant', 'names']
49 mock_call.side_effect = OSError('fail')
50
51- mock_call.assertRaises(OSError, fetch.apt_purge, packages, fatal=True )
52+ mock_call.assertRaises(OSError, fetch.apt_purge, packages, fatal=True)
53 log.assert_called()
54
55-
56 @patch('subprocess.call')
57 @patch.object(fetch, 'log')
58 def test_purges_apt_packages_as_string_nofatal(self, log, mock_call):
59@@ -383,7 +380,6 @@
60 log.assert_called()
61 mock_call.assert_called_with(['apt-get', '-y', 'purge', 'foo bar'])
62
63-
64 @patch('subprocess.call')
65 @patch.object(fetch, 'log')
66 def test_purges_apt_packages_nofatal(self, log, mock_call):
67@@ -395,6 +391,53 @@
68 mock_call.assert_called_with(['apt-get', '-y', 'purge', 'foo',
69 'bar'])
70
71+ @patch('subprocess.check_call')
72+ @patch.object(fetch, 'log')
73+ def test_hold_apt_packages_as_string_fatal(self, log, mock_call):
74+ packages = 'irrelevant names'
75+ mock_call.side_effect = OSError('fail')
76+
77+ mock_call.assertRaises(OSError, fetch.apt_hold, packages, fatal=True)
78+ log.assert_called()
79+
80+ @patch('subprocess.check_call')
81+ @patch.object(fetch, 'log')
82+ def test_hold_apt_packages_fatal(self, log, mock_call):
83+ packages = ['irrelevant', 'names']
84+ mock_call.side_effect = OSError('fail')
85+
86+ mock_call.assertRaises(OSError, fetch.apt_hold, packages, fatal=True)
87+ log.assert_called()
88+
89+ @patch('subprocess.call')
90+ @patch.object(fetch, 'log')
91+ def test_hold_apt_packages_as_string_nofatal(self, log, mock_call):
92+ packages = 'foo bar'
93+
94+ fetch.apt_hold(packages)
95+
96+ log.assert_called()
97+ mock_call.assert_called_with(['apt-mark', 'hold', 'foo bar'])
98+
99+ @patch('subprocess.call')
100+ @patch.object(fetch, 'log')
101+ def test_hold_apt_packages_nofatal(self, log, mock_call):
102+ packages = ['foo', 'bar']
103+
104+ fetch.apt_hold(packages)
105+
106+ log.assert_called()
107+ mock_call.assert_called_with(['apt-mark', 'hold', 'foo', 'bar'])
108+
109+ @patch('subprocess.call')
110+ @patch.object(fetch, 'log')
111+ def test_hold_apt_packages_nofatal_abortonfatal(self, log, mock_call):
112+ packages = ['foo', 'bar']
113+
114+ fetch.apt_hold(packages, fatal=True)
115+
116+ log.assert_called()
117+ mock_call.assert_called_with(['apt-mark', 'hold', 'foo', 'bar'])
118
119 @patch('subprocess.check_call')
120 def test_apt_update_fatal(self, check_call):

Subscribers

People subscribed via source and target branches