Merge "Support IPA in raid_device plugin"

This commit is contained in:
Jenkins 2015-09-24 16:13:28 +00:00 committed by Gerrit Code Review
commit d4e97877e9
2 changed files with 54 additions and 8 deletions

View File

@ -44,6 +44,13 @@ class RaidDeviceDetection(base.ProcessingHook):
the plugin needs to take precedence over the standard plugin.
"""
def _get_serials(self, data):
if 'inventory' in data:
return [x['serial'] for x in data['inventory'].get('disks', ())
if x.get('serial')]
elif 'block_devices' in data:
return data['block_devices'].get('serials', ())
def before_processing(self, introspection_data, **kwargs):
"""Adds fake local_gb value if it's missing from introspection_data."""
if not introspection_data.get('local_gb'):
@ -52,7 +59,8 @@ class RaidDeviceDetection(base.ProcessingHook):
introspection_data['local_gb'] = 1
def before_update(self, introspection_data, node_info, **kwargs):
if 'block_devices' not in introspection_data:
current_devices = self._get_serials(introspection_data)
if not current_devices:
LOG.warning(_LW('No block device was received from ramdisk'))
return
@ -65,7 +73,6 @@ class RaidDeviceDetection(base.ProcessingHook):
if 'block_devices' in node.extra:
# Compare previously discovered devices with the current ones
previous_devices = node.extra['block_devices']['serials']
current_devices = introspection_data['block_devices']['serials']
new_devices = [device for device in current_devices
if device not in previous_devices]
@ -90,4 +97,4 @@ class RaidDeviceDetection(base.ProcessingHook):
# devices in node.extra
node_info.patch([{'op': 'add',
'path': '/extra/block_devices',
'value': introspection_data['block_devices']}])
'value': {'serials': current_devices}}])

View File

@ -53,12 +53,37 @@ class TestRaidDeviceDetectionUpdate(test_base.NodeTest):
self.assertCalledWithPatch(patch, mock_patch)
def test_no_previous_block_devices(self):
introspection_data = {'inventory': {
'disks': [
{'name': '/dev/sda', 'serial': 'foo'},
{'name': '/dev/sdb', 'serial': 'bar'},
]
}}
expected = [{'op': 'add', 'path': '/extra/block_devices',
'value': {'serials': ['foo', 'bar']}}]
self._check(introspection_data, expected)
def test_no_previous_block_devices_old_ramdisk(self):
introspection_data = {'block_devices': {'serials': ['foo', 'bar']}}
expected = [{'op': 'add', 'path': '/extra/block_devices',
'value': introspection_data['block_devices']}]
self._check(introspection_data, expected)
def test_root_device_found(self):
self.node.extra['block_devices'] = {'serials': ['foo', 'bar']}
introspection_data = {'inventory': {
'disks': [
{'name': '/dev/sda', 'serial': 'foo'},
{'name': '/dev/sdb', 'serial': 'baz'},
]
}}
expected = [{'op': 'remove', 'path': '/extra/block_devices'},
{'op': 'add', 'path': '/properties/root_device',
'value': {'serial': 'baz'}}]
self._check(introspection_data, expected)
def test_root_device_found_old_ramdisk(self):
self.node.extra['block_devices'] = {'serials': ['foo', 'bar']}
introspection_data = {'block_devices': {'serials': ['foo', 'baz']}}
expected = [{'op': 'remove', 'path': '/extra/block_devices'},
@ -69,21 +94,35 @@ class TestRaidDeviceDetectionUpdate(test_base.NodeTest):
def test_root_device_already_exposed(self):
self.node.properties['root_device'] = {'serial': 'foo'}
introspection_data = {'block_devices': {'serials': ['foo', 'baz']}}
introspection_data = {'inventory': {
'disks': [
{'name': '/dev/sda', 'serial': 'foo'},
{'name': '/dev/sdb', 'serial': 'baz'},
]
}}
self._check(introspection_data, [])
def test_multiple_new_devices(self):
self.node.extra['block_devices'] = {'serials': ['foo', 'bar']}
introspection_data = {
'block_devices': {'serials': ['foo', 'baz', 'qux']}
}
introspection_data = {'inventory': {
'disks': [
{'name': '/dev/sda', 'serial': 'foo'},
{'name': '/dev/sdb', 'serial': 'baz'},
{'name': '/dev/sdc', 'serial': 'qux'},
]
}}
self._check(introspection_data, [])
def test_no_new_devices(self):
self.node.extra['block_devices'] = {'serials': ['foo', 'bar']}
introspection_data = {'block_devices': {'serials': ['foo', 'bar']}}
introspection_data = {'inventory': {
'disks': [
{'name': '/dev/sda', 'serial': 'foo'},
{'name': '/dev/sdb', 'serial': 'bar'},
]
}}
self._check(introspection_data, [])