Skip to content

Commit efba46a

Browse files
committed
Fix inband disk erase using agent_ilo driver
In-band disk erase using shred fails for agent_ilo driver as it tries to erase the virtual floppy device attached.This fix is to skip the virtual media devices and continue with other disks. Change-Id: I26745985382d440f7d4b3fbfffb14545067fcca6 Closes-Bug:#1450298
1 parent 1394771 commit efba46a

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

ironic_python_agent/hardware.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,13 @@ def match(hint, current_value, device):
427427
"deployment using these hints %s" % root_device_hints)
428428

429429
def erase_block_device(self, block_device):
430+
431+
# Check if the block device is virtual media and skip the device.
432+
if self._is_virtual_media_device(block_device):
433+
LOG.info("Skipping the erase of virtual media device %s",
434+
block_device.name)
435+
return
436+
430437
if self._ata_erase(block_device):
431438
return
432439

@@ -452,6 +459,21 @@ def _shred_block_device(self, block_device):
452459

453460
return True
454461

462+
def _is_virtual_media_device(self, block_device):
463+
"""Check if the block device corresponds to Virtual Media device.
464+
465+
:param block_device: a BlockDevice object
466+
:returns: True if it's a virtual media device, else False
467+
"""
468+
vm_device_label = '/dev/disk/by-label/ir-vfd-dev'
469+
if os.path.exists(vm_device_label):
470+
link = os.readlink(vm_device_label)
471+
device = os.path.normpath(os.path.join(os.path.dirname(
472+
vm_device_label), link))
473+
if block_device.name == device:
474+
return True
475+
return False
476+
455477
def _get_ata_security_lines(self, block_device):
456478
output = utils.execute('hdparm', '-I', block_device.name)[0]
457479

ironic_python_agent/tests/hardware.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import mock
16+
import os
1617
from oslotest import base as test_base
1718
import pyudev
1819
import six
@@ -454,6 +455,53 @@ def test_erase_block_device_notsupported_shred(self, mocked_execute):
454455
'--iterations', '1', '/dev/sda')
455456
])
456457

458+
@mock.patch.object(hardware.GenericHardwareManager,
459+
'_is_virtual_media_device', autospec=True)
460+
def test_erase_block_device_virtual_media(self, vm_mock):
461+
vm_mock.return_value = True
462+
block_device = hardware.BlockDevice('/dev/sda', 'big', 1073741824,
463+
True)
464+
self.hardware.erase_block_device(block_device)
465+
vm_mock.assert_called_once_with(self.hardware, block_device)
466+
467+
@mock.patch.object(os, 'readlink', autospec=True)
468+
@mock.patch.object(os.path, 'exists', autospec=True)
469+
def test__is_virtual_media_device_exists(self, mocked_exists,
470+
mocked_link):
471+
mocked_exists.return_value = True
472+
mocked_link.return_value = '../../sda'
473+
block_device = hardware.BlockDevice('/dev/sda', 'big', 1073741824,
474+
True)
475+
res = self.hardware._is_virtual_media_device(block_device)
476+
self.assertTrue(res)
477+
mocked_exists.assert_called_once_with('/dev/disk/by-label/ir-vfd-dev')
478+
mocked_link.assert_called_once_with('/dev/disk/by-label/ir-vfd-dev')
479+
480+
@mock.patch.object(os, 'readlink', autospec=True)
481+
@mock.patch.object(os.path, 'exists', autospec=True)
482+
def test__is_virtual_media_device_exists_no_match(self, mocked_exists,
483+
mocked_link):
484+
mocked_exists.return_value = True
485+
mocked_link.return_value = '../../sdb'
486+
block_device = hardware.BlockDevice('/dev/sda', 'big', 1073741824,
487+
True)
488+
res = self.hardware._is_virtual_media_device(block_device)
489+
self.assertFalse(res)
490+
mocked_exists.assert_called_once_with('/dev/disk/by-label/ir-vfd-dev')
491+
mocked_link.assert_called_once_with('/dev/disk/by-label/ir-vfd-dev')
492+
493+
@mock.patch.object(os, 'readlink', autospec=True)
494+
@mock.patch.object(os.path, 'exists', autospec=True)
495+
def test__is_virtual_media_device_path_doesnt_exist(self, mocked_exists,
496+
mocked_link):
497+
mocked_exists.return_value = False
498+
block_device = hardware.BlockDevice('/dev/sda', 'big', 1073741824,
499+
True)
500+
res = self.hardware._is_virtual_media_device(block_device)
501+
self.assertFalse(res)
502+
mocked_exists.assert_called_once_with('/dev/disk/by-label/ir-vfd-dev')
503+
self.assertFalse(mocked_link.called)
504+
457505
@mock.patch.object(utils, 'execute')
458506
def test_erase_block_device_ata_security_enabled(self, mocked_execute):
459507
hdparm_output = HDPARM_INFO_TEMPLATE % {

0 commit comments

Comments
 (0)