You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ironic-inspector/ironic_inspector/test/unit/test_plugins_raid_device.py

133 lines
4.8 KiB

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
from ironic_inspector import node_cache
from ironic_inspector.plugins import base
from ironic_inspector.plugins import raid_device
from ironic_inspector.test import base as test_base
class TestRaidDeviceDetection(test_base.NodeTest):
hook = raid_device.RaidDeviceDetection()
def test_loadable_by_name(self):
names = ('raid_device', 'root_device_hint')
base.CONF.set_override('processing_hooks', ','.join(names),
'processing')
for name in names:
ext = base.processing_hooks_manager()[name]
self.assertIsInstance(ext.obj, raid_device.RaidDeviceDetection)
def test_missing_local_gb(self):
introspection_data = {}
self.hook.before_processing(introspection_data)
self.assertEqual(1, introspection_data['local_gb'])
def test_local_gb_not_changed(self):
introspection_data = {'local_gb': 42}
self.hook.before_processing(introspection_data)
self.assertEqual(42, introspection_data['local_gb'])
class TestRaidDeviceDetectionUpdate(test_base.NodeTest):
hook = raid_device.RaidDeviceDetection()
@mock.patch.object(node_cache.NodeInfo, 'patch')
def _check(self, data, patch, mock_patch):
self.hook.before_processing(data)
self.hook.before_update(data, self.node_info)
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'},
{'op': 'add', 'path': '/properties/root_device',
'value': {'serial': 'baz'}}]
self._check(introspection_data, expected)
def test_root_device_already_exposed(self):
self.node.properties['root_device'] = {'serial': 'foo'}
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 = {'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 = {'inventory': {
'disks': [
{'name': '/dev/sda', 'serial': 'foo'},
{'name': '/dev/sdb', 'serial': 'bar'},
]
}}
self._check(introspection_data, [])
def test_no_block_devices_from_ramdisk(self):
introspection_data = {}
self._check(introspection_data, [])