~niedbalski/charm-helpers/fix-test_requirements

« back to all changes in this revision

Viewing changes to tests/contrib/storage/test_linux_storage_utils.py

  • Committer: James Page
  • Date: 2014-04-14 14:39:03 UTC
  • mfrom: (133.1.1 use-dd-in-zap-disk)
  • Revision ID: james.page@canonical.com-20140414143903-rsryogzedxacqtal
[rharper,r=james-page] sgdisk is sometimes unreliable;  add in calls to dd to completely wipe MBR and GPT end tables to ensure a 'clean' disk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
 
10
10
class MiscStorageUtilsTests(unittest.TestCase):
11
 
    def test_zap_disk(self):
 
11
 
 
12
    @patch(STORAGE_LINUX_UTILS + '.check_output')
 
13
    @patch(STORAGE_LINUX_UTILS + '.call')
 
14
    @patch(STORAGE_LINUX_UTILS + '.check_call')
 
15
    def test_zap_disk(self, check_call, call, check_output):
12
16
        '''It calls sgdisk correctly to zap disk'''
13
 
        with patch(STORAGE_LINUX_UTILS + '.check_call') as check_call:
14
 
            storage_utils.zap_disk('/dev/foo')
15
 
            check_call.assert_called_with(['sgdisk', '--zap-all', '--clear',
16
 
                                           '--mbrtogpt', '/dev/foo'])
 
17
        check_output.return_value = '200\n'
 
18
        storage_utils.zap_disk('/dev/foo')
 
19
        call.assert_any_call(['sgdisk', '--zap-all', '--mbrtogpt',
 
20
                              '--clear', '/dev/foo'])
 
21
        check_output.assert_any_call(['blockdev', '--getsz', '/dev/foo'])
 
22
        check_call.assert_any_call(['dd', 'if=/dev/zero', 'of=/dev/foo',
 
23
                                    'bs=1M', 'count=1'])
 
24
        check_call.assert_any_call(['dd', 'if=/dev/zero', 'of=/dev/foo',
 
25
                                    'bs=512', 'count=100', 'seek=100'])
17
26
 
18
27
    @patch(STORAGE_LINUX_UTILS + '.stat')
19
28
    @patch(STORAGE_LINUX_UTILS + '.S_ISBLK')