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
=== modified file 'charmhelpers/fetch/__init__.py'
--- charmhelpers/fetch/__init__.py 2013-08-21 11:45:37 +0000
+++ charmhelpers/fetch/__init__.py 2013-09-02 08:47:58 +0000
@@ -79,6 +79,20 @@
79 subprocess.call(cmd)79 subprocess.call(cmd)
8080
8181
82def apt_hold(packages, fatal=False):
83 """Hold one or more packages"""
84 cmd = ['apt-mark', 'hold']
85 if isinstance(packages, basestring):
86 cmd.append(packages)
87 else:
88 cmd.extend(packages)
89 log("Holding {}".format(packages))
90 if fatal:
91 subprocess.check_call(cmd)
92 else:
93 subprocess.call(cmd)
94
95
82def add_source(source, key=None):96def add_source(source, key=None):
83 if ((source.startswith('ppa:') or97 if ((source.startswith('ppa:') or
84 source.startswith('http:'))):98 source.startswith('http:'))):
8599
=== modified file 'tests/fetch/test_fetch.py'
--- tests/fetch/test_fetch.py 2013-08-21 15:45:53 +0000
+++ tests/fetch/test_fetch.py 2013-09-02 08:47:58 +0000
@@ -352,27 +352,24 @@
352 check_call.assert_called_with(['apt-get', '-y', '--foo', '--bar',352 check_call.assert_called_with(['apt-get', '-y', '--foo', '--bar',
353 'install', 'foo', 'bar'])353 'install', 'foo', 'bar'])
354354
355
356 @patch('subprocess.check_call')355 @patch('subprocess.check_call')
357 @patch.object(fetch, 'log')356 @patch.object(fetch, 'log')
358 def test_purges_apt_packages_as_string_fatal(self, log, mock_call):357 def test_purges_apt_packages_as_string_fatal(self, log, mock_call):
359 packages = 'irrelevant names'358 packages = 'irrelevant names'
360 mock_call.side_effect = OSError('fail')359 mock_call.side_effect = OSError('fail')
361360
362 mock_call.assertRaises(OSError, fetch.apt_purge, packages, fatal=True )361 mock_call.assertRaises(OSError, fetch.apt_purge, packages, fatal=True)
363 log.assert_called()362 log.assert_called()
364363
365
366 @patch('subprocess.check_call')364 @patch('subprocess.check_call')
367 @patch.object(fetch, 'log')365 @patch.object(fetch, 'log')
368 def test_purges_apt_packages_fatal(self, log, mock_call):366 def test_purges_apt_packages_fatal(self, log, mock_call):
369 packages = ['irrelevant', 'names']367 packages = ['irrelevant', 'names']
370 mock_call.side_effect = OSError('fail')368 mock_call.side_effect = OSError('fail')
371369
372 mock_call.assertRaises(OSError, fetch.apt_purge, packages, fatal=True )370 mock_call.assertRaises(OSError, fetch.apt_purge, packages, fatal=True)
373 log.assert_called()371 log.assert_called()
374372
375
376 @patch('subprocess.call')373 @patch('subprocess.call')
377 @patch.object(fetch, 'log')374 @patch.object(fetch, 'log')
378 def test_purges_apt_packages_as_string_nofatal(self, log, mock_call):375 def test_purges_apt_packages_as_string_nofatal(self, log, mock_call):
@@ -383,7 +380,6 @@
383 log.assert_called()380 log.assert_called()
384 mock_call.assert_called_with(['apt-get', '-y', 'purge', 'foo bar'])381 mock_call.assert_called_with(['apt-get', '-y', 'purge', 'foo bar'])
385382
386
387 @patch('subprocess.call')383 @patch('subprocess.call')
388 @patch.object(fetch, 'log')384 @patch.object(fetch, 'log')
389 def test_purges_apt_packages_nofatal(self, log, mock_call):385 def test_purges_apt_packages_nofatal(self, log, mock_call):
@@ -395,6 +391,53 @@
395 mock_call.assert_called_with(['apt-get', '-y', 'purge', 'foo',391 mock_call.assert_called_with(['apt-get', '-y', 'purge', 'foo',
396 'bar'])392 'bar'])
397393
394 @patch('subprocess.check_call')
395 @patch.object(fetch, 'log')
396 def test_hold_apt_packages_as_string_fatal(self, log, mock_call):
397 packages = 'irrelevant names'
398 mock_call.side_effect = OSError('fail')
399
400 mock_call.assertRaises(OSError, fetch.apt_hold, packages, fatal=True)
401 log.assert_called()
402
403 @patch('subprocess.check_call')
404 @patch.object(fetch, 'log')
405 def test_hold_apt_packages_fatal(self, log, mock_call):
406 packages = ['irrelevant', 'names']
407 mock_call.side_effect = OSError('fail')
408
409 mock_call.assertRaises(OSError, fetch.apt_hold, packages, fatal=True)
410 log.assert_called()
411
412 @patch('subprocess.call')
413 @patch.object(fetch, 'log')
414 def test_hold_apt_packages_as_string_nofatal(self, log, mock_call):
415 packages = 'foo bar'
416
417 fetch.apt_hold(packages)
418
419 log.assert_called()
420 mock_call.assert_called_with(['apt-mark', 'hold', 'foo bar'])
421
422 @patch('subprocess.call')
423 @patch.object(fetch, 'log')
424 def test_hold_apt_packages_nofatal(self, log, mock_call):
425 packages = ['foo', 'bar']
426
427 fetch.apt_hold(packages)
428
429 log.assert_called()
430 mock_call.assert_called_with(['apt-mark', 'hold', 'foo', 'bar'])
431
432 @patch('subprocess.call')
433 @patch.object(fetch, 'log')
434 def test_hold_apt_packages_nofatal_abortonfatal(self, log, mock_call):
435 packages = ['foo', 'bar']
436
437 fetch.apt_hold(packages, fatal=True)
438
439 log.assert_called()
440 mock_call.assert_called_with(['apt-mark', 'hold', 'foo', 'bar'])
398441
399 @patch('subprocess.check_call')442 @patch('subprocess.check_call')
400 def test_apt_update_fatal(self, check_call):443 def test_apt_update_fatal(self, check_call):

Subscribers

People subscribed via source and target branches