Skip to content

Commit 4c1d2cd

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "IPA:'shred' utility to use configured iterations"
2 parents 63851b7 + 02f7845 commit 4c1d2cd

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

ironic_python_agent/hardware.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def erase_devices(self, node, ports):
151151
"""
152152
block_devices = self.list_block_devices()
153153
for block_device in block_devices:
154-
self.erase_block_device(block_device)
154+
self.erase_block_device(node, block_device)
155155

156156
def list_hardware_info(self):
157157
hardware_info = {}
@@ -427,7 +427,7 @@ def match(hint, current_value, device):
427427
raise errors.DeviceNotFound("No suitable device was found for "
428428
"deployment using these hints %s" % root_device_hints)
429429

430-
def erase_block_device(self, block_device):
430+
def erase_block_device(self, node, block_device):
431431

432432
# Check if the block device is virtual media and skip the device.
433433
if self._is_virtual_media_device(block_device):
@@ -438,23 +438,26 @@ def erase_block_device(self, block_device):
438438
if self._ata_erase(block_device):
439439
return
440440

441-
if self._shred_block_device(block_device):
441+
if self._shred_block_device(node, block_device):
442442
return
443443

444444
msg = ('Unable to erase block device {0}: device is unsupported.'
445445
).format(block_device.name)
446446
LOG.error(msg)
447447
raise errors.IncompatibleHardwareMethodError(msg)
448448

449-
def _shred_block_device(self, block_device):
449+
def _shred_block_device(self, node, block_device):
450450
"""Erase a block device using shred.
451451
452+
:param node: Ironic node info.
452453
:param block_device: a BlockDevice object to be erased
453454
:returns: True if the erase succeeds, False if it fails for any reason
454455
"""
456+
info = node.get('driver_internal_info', {})
457+
npasses = info.get('agent_erase_devices_iterations', 1)
455458
try:
456459
utils.execute('shred', '--force', '--zero', '--verbose',
457-
'--iterations', '1', block_device.name)
460+
'--iterations', npasses, block_device.name)
458461
except (processutils.ProcessExecutionError, OSError) as e:
459462
msg = ("Erasing block device %(dev)s failed with error %(err)s ",
460463
{'dev': block_device.name, 'err': e})

ironic_python_agent/tests/hardware.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ class TestGenericHardwareManager(test_base.BaseTestCase):
182182
def setUp(self):
183183
super(TestGenericHardwareManager, self).setUp()
184184
self.hardware = hardware.GenericHardwareManager()
185+
self.node = {'uuid': 'dda135fb-732d-4742-8e72-df8f3199d244',
186+
'driver_internal_info': {}}
185187

186188
@mock.patch('os.listdir')
187189
@mock.patch('os.path.exists')
@@ -409,7 +411,7 @@ def test_erase_block_device_ata_success(self, mocked_execute):
409411

410412
block_device = hardware.BlockDevice('/dev/sda', 'big', 1073741824,
411413
True)
412-
self.hardware.erase_block_device(block_device)
414+
self.hardware.erase_block_device(self.node, block_device)
413415
mocked_execute.assert_has_calls([
414416
mock.call('hdparm', '-I', '/dev/sda'),
415417
mock.call('hdparm', '--user-master', 'u', '--security-set-pass',
@@ -422,6 +424,8 @@ def test_erase_block_device_ata_success(self, mocked_execute):
422424
@mock.patch.object(utils, 'execute')
423425
def test_erase_block_device_nosecurity_shred(self, mocked_execute):
424426
hdparm_output = HDPARM_INFO_TEMPLATE.split('\nSecurity:')[0]
427+
info = self.node.get('driver_internal_info')
428+
info['agent_erase_devices_iterations'] = 2
425429

426430
mocked_execute.side_effect = [
427431
(hdparm_output, ''),
@@ -430,11 +434,11 @@ def test_erase_block_device_nosecurity_shred(self, mocked_execute):
430434

431435
block_device = hardware.BlockDevice('/dev/sda', 'big', 1073741824,
432436
True)
433-
self.hardware.erase_block_device(block_device)
437+
self.hardware.erase_block_device(self.node, block_device)
434438
mocked_execute.assert_has_calls([
435439
mock.call('hdparm', '-I', '/dev/sda'),
436440
mock.call('shred', '--force', '--zero', '--verbose',
437-
'--iterations', '1', '/dev/sda')
441+
'--iterations', 2, '/dev/sda')
438442
])
439443

440444
@mock.patch.object(utils, 'execute')
@@ -453,11 +457,11 @@ def test_erase_block_device_notsupported_shred(self, mocked_execute):
453457

454458
block_device = hardware.BlockDevice('/dev/sda', 'big', 1073741824,
455459
True)
456-
self.hardware.erase_block_device(block_device)
460+
self.hardware.erase_block_device(self.node, block_device)
457461
mocked_execute.assert_has_calls([
458462
mock.call('hdparm', '-I', '/dev/sda'),
459463
mock.call('shred', '--force', '--zero', '--verbose',
460-
'--iterations', '1', '/dev/sda')
464+
'--iterations', 1, '/dev/sda')
461465
])
462466

463467
@mock.patch.object(hardware.GenericHardwareManager,
@@ -466,7 +470,7 @@ def test_erase_block_device_virtual_media(self, vm_mock):
466470
vm_mock.return_value = True
467471
block_device = hardware.BlockDevice('/dev/sda', 'big', 1073741824,
468472
True)
469-
self.hardware.erase_block_device(block_device)
473+
self.hardware.erase_block_device(self.node, block_device)
470474
vm_mock.assert_called_once_with(self.hardware, block_device)
471475

472476
@mock.patch.object(os, 'readlink', autospec=True)
@@ -512,20 +516,20 @@ def test_erase_block_device_shred_fail_oserror(self, mocked_execute):
512516
mocked_execute.side_effect = OSError
513517
block_device = hardware.BlockDevice('/dev/sda', 'big', 1073741824,
514518
True)
515-
res = self.hardware._shred_block_device(block_device)
519+
res = self.hardware._shred_block_device(self.node, block_device)
516520
self.assertFalse(res)
517521
mocked_execute.assert_called_once_with('shred', '--force', '--zero',
518-
'--verbose', '--iterations', '1', '/dev/sda')
522+
'--verbose', '--iterations', 1, '/dev/sda')
519523

520524
@mock.patch.object(utils, 'execute')
521525
def test_erase_block_device_shred_fail_processerror(self, mocked_execute):
522526
mocked_execute.side_effect = processutils.ProcessExecutionError
523527
block_device = hardware.BlockDevice('/dev/sda', 'big', 1073741824,
524528
True)
525-
res = self.hardware._shred_block_device(block_device)
529+
res = self.hardware._shred_block_device(self.node, block_device)
526530
self.assertFalse(res)
527531
mocked_execute.assert_called_once_with('shred', '--force', '--zero',
528-
'--verbose', '--iterations', '1', '/dev/sda')
532+
'--verbose', '--iterations', 1, '/dev/sda')
529533

530534
@mock.patch.object(utils, 'execute')
531535
def test_erase_block_device_ata_security_enabled(self, mocked_execute):
@@ -544,7 +548,7 @@ def test_erase_block_device_ata_security_enabled(self, mocked_execute):
544548
True)
545549
self.assertRaises(errors.BlockDeviceEraseError,
546550
self.hardware.erase_block_device,
547-
block_device)
551+
self.node, block_device)
548552

549553
@mock.patch.object(utils, 'execute')
550554
def test_erase_block_device_ata_frozen(self, mocked_execute):
@@ -563,7 +567,7 @@ def test_erase_block_device_ata_frozen(self, mocked_execute):
563567
True)
564568
self.assertRaises(errors.BlockDeviceEraseError,
565569
self.hardware.erase_block_device,
566-
block_device)
570+
self.node, block_device)
567571

568572
@mock.patch.object(utils, 'execute')
569573
def test_erase_block_device_ata_failed(self, mocked_execute):
@@ -594,7 +598,7 @@ def test_erase_block_device_ata_failed(self, mocked_execute):
594598
True)
595599
self.assertRaises(errors.BlockDeviceEraseError,
596600
self.hardware.erase_block_device,
597-
block_device)
601+
self.node, block_device)
598602

599603
def test_normal_vs_enhanced_security_erase(self):
600604
@mock.patch.object(utils, 'execute')
@@ -617,7 +621,7 @@ def test_security_erase_option(test_case,
617621

618622
block_device = hardware.BlockDevice('/dev/sda', 'big', 1073741824,
619623
True)
620-
test_case.hardware.erase_block_device(block_device)
624+
test_case.hardware.erase_block_device(self.node, block_device)
621625
mocked_execute.assert_any_call('hdparm', '--user-master', 'u',
622626
expected_option,
623627
'NULL', '/dev/sda')

0 commit comments

Comments
 (0)