Merge lp:~raharper/charm-helpers/use-dd-in-zap-disk into lp:charm-helpers

Proposed by Ryan Harper
Status: Merged
Merged at revision: 141
Proposed branch: lp:~raharper/charm-helpers/use-dd-in-zap-disk
Merge into: lp:charm-helpers
Diff against target: 56 lines (+22/-7)
2 files modified
charmhelpers/contrib/storage/linux/utils.py (+11/-3)
tests/contrib/storage/test_linux_storage_utils.py (+11/-4)
To merge this branch: bzr merge lp:~raharper/charm-helpers/use-dd-in-zap-disk
Reviewer Review Type Date Requested Status
James Page Pending
Review via email: mp+212660@code.launchpad.net

Description of the change

Update zap_disk to use dd to ensure complete wipe of MBR and GPT data on a disk; sgdisk doesn't always remove the data from the disk even if the command returns without error. This was observed on a cinder install which attempts to pvcreate on a disk, but refuses if there is any GPT related partition table (as observed via fdisk -l /dev/XXX which will complain about GPT tables). This patch has been in use in branches of the cinder/ceph charm here:

lp:~raharper/charms/precise/ceph/use-dd-zap-disk
lp:~raharper/charms/precise/cinder/use-dd-zap-disk

and I've successfully deployed each charm hundreds of times since the change.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/storage/linux/utils.py'
2--- charmhelpers/contrib/storage/linux/utils.py 2014-03-05 20:46:13 +0000
3+++ charmhelpers/contrib/storage/linux/utils.py 2014-03-25 16:07:21 +0000
4@@ -2,7 +2,8 @@
5 from stat import S_ISBLK
6
7 from subprocess import (
8- check_call
9+ check_call,
10+ check_output,
11 )
12
13
14@@ -22,5 +23,12 @@
15
16 :param block_device: str: Full path of block device to clean.
17 '''
18- check_call(['sgdisk', '--zap-all', '--clear',
19- '--mbrtogpt', block_device])
20+ # sometimes sgdisk exits non-zero; this is OK, dd will clean up
21+ check_output(['sgdisk', '--zap-all', '--mbrtogpt',
22+ '--clear', block_device])
23+ dev_end = check_output(['blockdev', '--getsz', block_device])
24+ gpt_end = int(dev_end.split()[0]) - 100
25+ check_call(['dd', 'if=/dev/zero', 'of=%s'%(block_device),
26+ 'bs=1M', 'count=1'])
27+ check_call(['dd', 'if=/dev/zero', 'of=%s'%(block_device),
28+ 'bs=512', 'count=100', 'seek=%s'%(gpt_end)])
29
30=== modified file 'tests/contrib/storage/test_linux_storage_utils.py'
31--- tests/contrib/storage/test_linux_storage_utils.py 2014-03-05 20:46:13 +0000
32+++ tests/contrib/storage/test_linux_storage_utils.py 2014-03-25 16:07:21 +0000
33@@ -8,12 +8,19 @@
34
35
36 class MiscStorageUtilsTests(unittest.TestCase):
37- def test_zap_disk(self):
38+ @patch(STORAGE_LINUX_UTILS + '.check_call')
39+ def test_zap_disk(self, check_call):
40 '''It calls sgdisk correctly to zap disk'''
41- with patch(STORAGE_LINUX_UTILS + '.check_call') as check_call:
42+ with patch(STORAGE_LINUX_UTILS + '.check_output') as check_output:
43+ check_output.return_value = '200\n'
44 storage_utils.zap_disk('/dev/foo')
45- check_call.assert_called_with(['sgdisk', '--zap-all', '--clear',
46- '--mbrtogpt', '/dev/foo'])
47+ check_output.assert_any_call(['sgdisk', '--zap-all', '--mbrtogpt',
48+ '--clear', '/dev/foo'])
49+ check_output.assert_any_call(['blockdev', '--getsz', '/dev/foo'])
50+ check_call.assert_any_call(['dd', 'if=/dev/zero', 'of=/dev/foo',
51+ 'bs=1M', 'count=1'])
52+ check_call.assert_any_call(['dd', 'if=/dev/zero', 'of=/dev/foo',
53+ 'bs=512', 'count=100', 'seek=100'])
54
55 @patch(STORAGE_LINUX_UTILS + '.stat')
56 @patch(STORAGE_LINUX_UTILS + '.S_ISBLK')

Subscribers

People subscribed via source and target branches