Skip to content

Commit 8cef029

Browse files
committed
Fix error in in-band disk erase using shred
in-band disk erase using shred fails with error "'module' object has no attribute 'ProcessExecutionError'". This commit is to fix the issue. Change-Id: Ia0c426074b2f0e9d534ed96a3e213933160edc61 Closes-Bug:#144799
1 parent efba46a commit 8cef029

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

ironic_python_agent/hardware.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import shlex
1919

2020
import netifaces
21+
from oslo_concurrency import processutils
2122
from oslo_log import log
2223
from oslo_utils import units
2324
import psutil
@@ -454,7 +455,10 @@ def _shred_block_device(self, block_device):
454455
try:
455456
utils.execute('shred', '--force', '--zero', '--verbose',
456457
'--iterations', '1', block_device.name)
457-
except errors.ProcessExecutionError:
458+
except (processutils.ProcessExecutionError, OSError) as e:
459+
msg = ("Erasing block device %(dev)s failed with error %(err)s ",
460+
{'dev': block_device.name, 'err': e})
461+
LOG.error(msg)
458462
return False
459463

460464
return True

ironic_python_agent/tests/hardware.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import mock
1616
import os
17+
from oslo_concurrency import processutils
1718
from oslotest import base as test_base
1819
import pyudev
1920
import six
@@ -502,6 +503,26 @@ def test__is_virtual_media_device_path_doesnt_exist(self, mocked_exists,
502503
mocked_exists.assert_called_once_with('/dev/disk/by-label/ir-vfd-dev')
503504
self.assertFalse(mocked_link.called)
504505

506+
@mock.patch.object(utils, 'execute')
507+
def test_erase_block_device_shred_fail_oserror(self, mocked_execute):
508+
mocked_execute.side_effect = OSError
509+
block_device = hardware.BlockDevice('/dev/sda', 'big', 1073741824,
510+
True)
511+
res = self.hardware._shred_block_device(block_device)
512+
self.assertFalse(res)
513+
mocked_execute.assert_called_once_with('shred', '--force', '--zero',
514+
'--verbose', '--iterations', '1', '/dev/sda')
515+
516+
@mock.patch.object(utils, 'execute')
517+
def test_erase_block_device_shred_fail_processerror(self, mocked_execute):
518+
mocked_execute.side_effect = processutils.ProcessExecutionError
519+
block_device = hardware.BlockDevice('/dev/sda', 'big', 1073741824,
520+
True)
521+
res = self.hardware._shred_block_device(block_device)
522+
self.assertFalse(res)
523+
mocked_execute.assert_called_once_with('shred', '--force', '--zero',
524+
'--verbose', '--iterations', '1', '/dev/sda')
525+
505526
@mock.patch.object(utils, 'execute')
506527
def test_erase_block_device_ata_security_enabled(self, mocked_execute):
507528
hdparm_output = HDPARM_INFO_TEMPLATE % {

0 commit comments

Comments
 (0)