Dispatch the call to erase_block_device

There is no way for two hardware managers to handle erasing two disks
in two different ways. dispatch_to_managers was designed specifically
for this case, and the default behavior will remain the same for the
GenericHardwareManager (erase_block_device will pick up each disk).

Also return the result of the dispatch calls, so they'll be logged by
Ironic and give more cleaning insight.

Change-Id: I19e9dc8539a0729fbb96cae92fe633e24608fc68
This commit is contained in:
Josh Gachnang 2015-08-17 09:51:21 -07:00 committed by Jay Faulkner
parent 3de3ca3b22
commit cd6f15dffe
2 changed files with 22 additions and 1 deletions
ironic_python_agent

@ -161,10 +161,15 @@ class HardwareManager(object):
:param node: Ironic node object
:param ports: list of Ironic port objects
:return: a dictionary in the form {device.name: erasure output}
"""
erase_results = {}
block_devices = self.list_block_devices()
for block_device in block_devices:
self.erase_block_device(node, block_device)
result = dispatch_to_managers(
'erase_block_device', node=node, block_device=block_device)
erase_results[block_device.name] = result
return erase_results
def list_hardware_info(self):
hardware_info = {}

@ -426,6 +426,22 @@ class TestGenericHardwareManager(test_base.BaseTestCase):
self.assertEqual(getattr(expected, attr),
getattr(device, attr))
@mock.patch.object(hardware, 'dispatch_to_managers')
def test_erase_devices(self, mocked_dispatch):
mocked_dispatch.return_value = 'erased device'
self.hardware.list_block_devices = mock.Mock()
self.hardware.list_block_devices.return_value = [
hardware.BlockDevice('/dev/sdj', 'big', 1073741824, True),
hardware.BlockDevice('/dev/hdaa', 'small', 65535, False),
]
expected = {'/dev/hdaa': 'erased device', '/dev/sdj': 'erased device'}
result = self.hardware.erase_devices({}, [])
self.assertEqual(expected, result)
@mock.patch.object(utils, 'execute')
def test_erase_block_device_ata_success(self, mocked_execute):
hdparm_info_fields = {