Merge "Get inventory from Inspector"
This commit is contained in:
commit
4d66609e95
@ -36,6 +36,7 @@ from ironic.conf import CONF
|
||||
from ironic.drivers import base
|
||||
from ironic.drivers.modules import deploy_utils
|
||||
from ironic.drivers.modules import inspect_utils
|
||||
from ironic.objects import node_inventory
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -339,7 +340,8 @@ def _check_status(task):
|
||||
task.node.uuid)
|
||||
|
||||
try:
|
||||
status = _get_client(task.context).get_introspection(node.uuid)
|
||||
inspector_client = _get_client(task.context)
|
||||
status = inspector_client.get_introspection(node.uuid)
|
||||
except Exception:
|
||||
# NOTE(dtantsur): get_status should not normally raise
|
||||
# let's assume it's a transient failure and retry later
|
||||
@ -363,6 +365,14 @@ def _check_status(task):
|
||||
_inspection_error_handler(task, error)
|
||||
elif status.is_finished:
|
||||
_clean_up(task)
|
||||
introspection_data = inspector_client.get_introspection_data(
|
||||
node.uuid, processed=True)
|
||||
inventory_data = introspection_data.pop("inventory")
|
||||
plugin_data = introspection_data
|
||||
node_inventory.NodeInventory(
|
||||
node_id=node.id,
|
||||
inventory_data=inventory_data,
|
||||
plugin_data=plugin_data).create()
|
||||
|
||||
|
||||
def _clean_up(task):
|
||||
|
@ -24,6 +24,7 @@ from ironic.conductor import task_manager
|
||||
from ironic.drivers.modules import inspect_utils
|
||||
from ironic.drivers.modules import inspector
|
||||
from ironic.drivers.modules.redfish import utils as redfish_utils
|
||||
from ironic import objects
|
||||
from ironic.tests.unit.db import base as db_base
|
||||
from ironic.tests.unit.objects import utils as obj_utils
|
||||
|
||||
@ -552,6 +553,34 @@ class CheckStatusTestCase(BaseTestCase):
|
||||
self.task)
|
||||
self.driver.boot.clean_up_ramdisk.assert_called_once_with(self.task)
|
||||
|
||||
def test_status_ok_store_inventory(self, mock_client):
|
||||
mock_get = mock_client.return_value.get_introspection
|
||||
mock_get.return_value = mock.Mock(is_finished=True,
|
||||
error=None,
|
||||
spec=['is_finished', 'error'])
|
||||
mock_get_data = mock_client.return_value.get_introspection_data
|
||||
mock_get_data.return_value = {
|
||||
"inventory": {"cpu": "amd"}, "disks": [{"name": "/dev/vda"}]}
|
||||
inspector._check_status(self.task)
|
||||
mock_get.assert_called_once_with(self.node.uuid)
|
||||
mock_get_data.assert_called_once_with(self.node.uuid, processed=True)
|
||||
|
||||
stored = objects.NodeInventory.get_by_node_id(self.context,
|
||||
self.node.id)
|
||||
self.assertEqual({"cpu": "amd"}, stored["inventory_data"])
|
||||
self.assertEqual({"disks": [{"name": "/dev/vda"}]},
|
||||
stored["plugin_data"])
|
||||
|
||||
def test_status_error_dont_store_inventory(self, mock_client):
|
||||
mock_get = mock_client.return_value.get_introspection
|
||||
mock_get.return_value = mock.Mock(is_finished=True,
|
||||
error='boom',
|
||||
spec=['is_finished', 'error'])
|
||||
mock_get_data = mock_client.return_value.get_introspection_data
|
||||
inspector._check_status(self.task)
|
||||
mock_get.assert_called_once_with(self.node.uuid)
|
||||
mock_get_data.assert_not_called()
|
||||
|
||||
|
||||
@mock.patch('ironic.drivers.modules.inspector._get_client', autospec=True)
|
||||
class InspectHardwareAbortTestCase(BaseTestCase):
|
||||
|
Loading…
Reference in New Issue
Block a user