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
=== modified file 'charmhelpers/contrib/storage/linux/utils.py'
--- charmhelpers/contrib/storage/linux/utils.py 2014-03-05 20:46:13 +0000
+++ charmhelpers/contrib/storage/linux/utils.py 2014-03-25 16:07:21 +0000
@@ -2,7 +2,8 @@
2from stat import S_ISBLK2from stat import S_ISBLK
33
4from subprocess import (4from subprocess import (
5 check_call5 check_call,
6 check_output,
6)7)
78
89
@@ -22,5 +23,12 @@
2223
23 :param block_device: str: Full path of block device to clean.24 :param block_device: str: Full path of block device to clean.
24 '''25 '''
25 check_call(['sgdisk', '--zap-all', '--clear',26 # sometimes sgdisk exits non-zero; this is OK, dd will clean up
26 '--mbrtogpt', block_device])27 check_output(['sgdisk', '--zap-all', '--mbrtogpt',
28 '--clear', block_device])
29 dev_end = check_output(['blockdev', '--getsz', block_device])
30 gpt_end = int(dev_end.split()[0]) - 100
31 check_call(['dd', 'if=/dev/zero', 'of=%s'%(block_device),
32 'bs=1M', 'count=1'])
33 check_call(['dd', 'if=/dev/zero', 'of=%s'%(block_device),
34 'bs=512', 'count=100', 'seek=%s'%(gpt_end)])
2735
=== modified file 'tests/contrib/storage/test_linux_storage_utils.py'
--- tests/contrib/storage/test_linux_storage_utils.py 2014-03-05 20:46:13 +0000
+++ tests/contrib/storage/test_linux_storage_utils.py 2014-03-25 16:07:21 +0000
@@ -8,12 +8,19 @@
88
99
10class MiscStorageUtilsTests(unittest.TestCase):10class MiscStorageUtilsTests(unittest.TestCase):
11 def test_zap_disk(self):11 @patch(STORAGE_LINUX_UTILS + '.check_call')
12 def test_zap_disk(self, check_call):
12 '''It calls sgdisk correctly to zap disk'''13 '''It calls sgdisk correctly to zap disk'''
13 with patch(STORAGE_LINUX_UTILS + '.check_call') as check_call:14 with patch(STORAGE_LINUX_UTILS + '.check_output') as check_output:
15 check_output.return_value = '200\n'
14 storage_utils.zap_disk('/dev/foo')16 storage_utils.zap_disk('/dev/foo')
15 check_call.assert_called_with(['sgdisk', '--zap-all', '--clear',17 check_output.assert_any_call(['sgdisk', '--zap-all', '--mbrtogpt',
16 '--mbrtogpt', '/dev/foo'])18 '--clear', '/dev/foo'])
19 check_output.assert_any_call(['blockdev', '--getsz', '/dev/foo'])
20 check_call.assert_any_call(['dd', 'if=/dev/zero', 'of=/dev/foo',
21 'bs=1M', 'count=1'])
22 check_call.assert_any_call(['dd', 'if=/dev/zero', 'of=/dev/foo',
23 'bs=512', 'count=100', 'seek=100'])
1724
18 @patch(STORAGE_LINUX_UTILS + '.stat')25 @patch(STORAGE_LINUX_UTILS + '.stat')
19 @patch(STORAGE_LINUX_UTILS + '.S_ISBLK')26 @patch(STORAGE_LINUX_UTILS + '.S_ISBLK')

Subscribers

People subscribed via source and target branches