Merge "Create [inventory]"

This commit is contained in:
Zuul 2023-01-20 20:34:37 +00:00 committed by Gerrit Code Review
commit 2e1477f433
8 changed files with 53 additions and 27 deletions

View File

@ -1966,7 +1966,7 @@ class NodeInventoryController(rest.RestController):
"""
node = api_utils.check_node_policy_and_retrieve(
'baremetal:node:inventory:get', self.node_ident)
store_data = CONF.inspector.inventory_data_backend
store_data = CONF.inventory.data_backend
if store_data == 'none':
raise exception.NotFound(
(_("Cannot obtain node inventory because it was not stored")))

View File

@ -34,6 +34,7 @@ from ironic.conf import healthcheck
from ironic.conf import ibmc
from ironic.conf import ilo
from ironic.conf import inspector
from ironic.conf import inventory
from ironic.conf import ipmi
from ironic.conf import irmc
from ironic.conf import metrics
@ -69,6 +70,7 @@ healthcheck.register_opts(CONF)
ibmc.register_opts(CONF)
ilo.register_opts(CONF)
inspector.register_opts(CONF)
inventory.register_opts(CONF)
ipmi.register_opts(CONF)
irmc.register_opts(CONF)
metrics.register_opts(CONF)

View File

@ -39,17 +39,6 @@ opts = [
'managed by ironic. Set this to True if your '
'installation of ironic-inspector does not have a '
'separate PXE boot environment.')),
cfg.StrOpt('inventory_data_backend',
help=_('The storage backend for storing introspection data.'),
choices=[('none', _('introspection data will not be stored')),
('database', _('introspection data stored in an SQL '
'database')),
('swift', _('introspection data stored in Swift'))],
default='database'),
cfg.StrOpt('swift_inventory_data_container',
default='introspection_data_container',
help=_('The Swift introspection data container to store '
'the inventory data.')),
]

34
ironic/conf/inventory.py Normal file
View File

@ -0,0 +1,34 @@
#
# 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.
from oslo_config import cfg
from ironic.common.i18n import _
opts = [
cfg.StrOpt('data_backend',
help=_('The storage backend for storing introspection data.'),
choices=[('none', _('introspection data will not be stored')),
('database', _('introspection data stored in an SQL '
'database')),
('swift', _('introspection data stored in Swift'))],
default='database'),
cfg.StrOpt('swift_data_container',
default='introspection_data_container',
help=_('The Swift introspection data container to store '
'the inventory data.')),
]
def register_opts(conf):
conf.register_opts(opts, group='inventory')

View File

@ -32,6 +32,7 @@ _opts = [
('healthcheck', ironic.conf.healthcheck.opts),
('ilo', ironic.conf.ilo.opts),
('inspector', ironic.conf.inspector.list_opts()),
('inventory', ironic.conf.inventory.opts),
('ipmi', ironic.conf.ipmi.opts),
('irmc', ironic.conf.irmc.opts),
('anaconda', ironic.conf.anaconda.opts),

View File

@ -368,7 +368,7 @@ def _check_status(task):
elif status.is_finished:
_clean_up(task)
# If store_data == 'none', do not store the data
store_data = CONF.inspector.inventory_data_backend
store_data = CONF.inventory.data_backend
if store_data == 'none':
LOG.debug('Introspection data storage is disabled, the data will '
'not be saved for node %(node)s', {'node': node.uuid})
@ -417,7 +417,7 @@ def store_introspection_data(node_uuid, inventory_data, plugin_data):
"""
swift_api = swift.SwiftAPI()
swift_object_name = '%s-%s' % (_OBJECT_NAME_PREFIX, node_uuid)
container = CONF.inspector.swift_inventory_data_container
container = CONF.inventory.swift_data_container
swift_api.create_object_from_data(swift_object_name + '-inventory',
inventory_data,
container)
@ -436,7 +436,7 @@ def get_introspection_data(node_uuid):
"""
swift_api = swift.SwiftAPI()
swift_object_name = '%s-%s' % (_OBJECT_NAME_PREFIX, node_uuid)
container = CONF.inspector.swift_inventory_data_container
container = CONF.inventory.swift_data_container
inventory_data = swift_api.get_object(swift_object_name + '-inventory',
container)
plugin_data = swift_api.get_object(swift_object_name + '-plugin',

View File

@ -7949,8 +7949,8 @@ class TestNodeInventory(test_api_base.BaseApiTest):
def test_get_inventory(self):
self._add_inventory()
CONF.set_override('inventory_data_backend', 'database',
group='inspector')
CONF.set_override('data_backend', 'database',
group='inventory')
ret = self.get_json('/nodes/%s/inventory' % self.node.uuid,
headers={api_base.Version.string: self.version})
self.assertEqual({'inventory': self.fake_inventory_data,
@ -7958,8 +7958,8 @@ class TestNodeInventory(test_api_base.BaseApiTest):
@mock.patch.object(inspector, 'get_introspection_data', autospec=True)
def test_get_inventory_swift(self, mock_get_data):
CONF.set_override('inventory_data_backend', 'swift',
group='inspector')
CONF.set_override('data_backend', 'swift',
group='inventory')
mock_get_data.return_value = {"inventory": self.fake_inventory_data,
"plugin_data": self.fake_plugin_data}
ret = self.get_json('/nodes/%s/inventory' % self.node.uuid,

View File

@ -555,8 +555,8 @@ class CheckStatusTestCase(BaseTestCase):
self.driver.boot.clean_up_ramdisk.assert_called_once_with(self.task)
def test_status_ok_store_inventory_in_db(self, mock_client):
CONF.set_override('inventory_data_backend', 'database',
group='inspector')
CONF.set_override('data_backend', 'database',
group='inventory')
mock_get = mock_client.return_value.get_introspection
mock_get.return_value = mock.Mock(is_finished=True,
error=None,
@ -577,10 +577,10 @@ class CheckStatusTestCase(BaseTestCase):
@mock.patch.object(swift, 'SwiftAPI', autospec=True)
def test_status_ok_store_inventory_in_swift(self,
swift_api_mock, mock_client):
CONF.set_override('inventory_data_backend', 'swift', group='inspector')
CONF.set_override('data_backend', 'swift', group='inventory')
CONF.set_override(
'swift_inventory_data_container', 'introspection_data',
group='inspector')
'swift_data_container', 'introspection_data',
group='inventory')
mock_get = mock_client.return_value.get_introspection
mock_get.return_value = mock.Mock(is_finished=True,
error=None,
@ -602,7 +602,7 @@ class CheckStatusTestCase(BaseTestCase):
mock.call(object_name + '-plugin', fake_plugin_data, container)])
def test_status_ok_store_inventory_nostore(self, mock_client):
CONF.set_override('inventory_data_backend', 'none', group='inspector')
CONF.set_override('data_backend', 'none', group='inventory')
mock_get = mock_client.return_value.get_introspection
mock_get.return_value = mock.Mock(is_finished=True,
error=None,
@ -613,8 +613,8 @@ class CheckStatusTestCase(BaseTestCase):
mock_get_data.assert_not_called()
def test_status_error_dont_store_inventory(self, mock_client):
CONF.set_override('inventory_data_backend', 'database',
group='inspector')
CONF.set_override('data_backend', 'database',
group='inventory')
mock_get = mock_client.return_value.get_introspection
mock_get.return_value = mock.Mock(is_finished=True,
error='boom',