baremetal: Adds list node firmware support
Added support to list the firmware components of a node under the baremetal service. - Created new functions `list_node_firmware` in baremetal proxy and `list_firmware` in baremetal node resource. - Added new release note to describe the new feature. - Added unit and functional tests for the new functions. Change-Id: Ib4b1584f24b0d4beb1594f97e1bbb8c81f5a84d5
This commit is contained in:
parent
dbf5c975ce
commit
c6281c5bc7
@ -88,6 +88,9 @@ DEPLOY_STEPS_VERSION = '1.69'
|
||||
CHANGE_BOOT_MODE_VERSION = '1.76'
|
||||
"""API version in which boot_mode and secure_boot states can be changed"""
|
||||
|
||||
FIRMWARE_VERSION = '1.86'
|
||||
"""API version in which firmware components of a node can be accessed"""
|
||||
|
||||
|
||||
class Resource(resource.Resource):
|
||||
base_path: str
|
||||
|
@ -1243,6 +1243,16 @@ class Proxy(proxy.Proxy):
|
||||
res = self._get_resource(_node.Node, node)
|
||||
return res.set_traits(self, traits)
|
||||
|
||||
def list_node_firmware(self, node):
|
||||
"""Lists firmware components for a node.
|
||||
|
||||
:param node: The value can be the name or ID of a node or a
|
||||
:class:`~openstack.baremetal.v1.node.Node` instance.
|
||||
:returns: A list of the node's firmware components.
|
||||
"""
|
||||
res = self._get_resource(_node.Node, node)
|
||||
return res.list_firmware(self)
|
||||
|
||||
def volume_connectors(self, details=False, **query):
|
||||
"""Retrieve a generator of volume_connector.
|
||||
|
||||
|
@ -1397,6 +1397,37 @@ class Node(_common.Resource):
|
||||
exceptions.raise_from_response(response, error_message=msg)
|
||||
return response.json()
|
||||
|
||||
def list_firmware(self, session):
|
||||
"""List firmware components associated with the node.
|
||||
|
||||
:param session: The session to use for making this request.
|
||||
:returns: The HTTP response.
|
||||
"""
|
||||
session = self._get_session(session)
|
||||
version = self._assert_microversion_for(
|
||||
session,
|
||||
'fetch',
|
||||
_common.FIRMWARE_VERSION,
|
||||
error_message=("Cannot use node list firmware components API"),
|
||||
)
|
||||
|
||||
request = self._prepare_request(requires_id=True)
|
||||
request.url = utils.urljoin(request.url, 'firmware')
|
||||
|
||||
response = session.get(
|
||||
request.url,
|
||||
headers=request.headers,
|
||||
microversion=version,
|
||||
retriable_status_codes=_common.RETRIABLE_STATUS_CODES,
|
||||
)
|
||||
|
||||
msg = "Failed to list firmware components for node {node}".format(
|
||||
node=self.id
|
||||
)
|
||||
exceptions.raise_from_response(response, error_message=msg)
|
||||
|
||||
return response.json()
|
||||
|
||||
def patch(
|
||||
self,
|
||||
session,
|
||||
|
@ -489,3 +489,13 @@ class TestTraits(base.BaseBaremetalTest):
|
||||
self.assertEqual(['CUSTOM_FOOBAR'], self.node.traits)
|
||||
node = self.conn.baremetal.get_node(self.node)
|
||||
self.assertEqual(['CUSTOM_FOOBAR'], node.traits)
|
||||
|
||||
|
||||
class TestBareMetalNodeListFirmware(base.BaseBaremetalTest):
|
||||
min_microversion = '1.86'
|
||||
|
||||
def test_list_firmware(self):
|
||||
node = self.create_node(firmware_interface="no-firmware")
|
||||
self.assertEqual("no-firmware", node.firmware_interface)
|
||||
result = self.conn.baremetal.list_node_firmware(node)
|
||||
self.assertEqual({'firmware': []}, result)
|
||||
|
@ -1293,3 +1293,48 @@ class TestNodeInventory(base.TestCase):
|
||||
microversion='1.81',
|
||||
retriable_status_codes=_common.RETRIABLE_STATUS_CODES,
|
||||
)
|
||||
|
||||
|
||||
@mock.patch.object(node.Node, 'fetch', lambda self, session: self)
|
||||
@mock.patch.object(exceptions, 'raise_from_response', mock.Mock())
|
||||
class TestNodeFirmware(base.TestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.node = node.Node(**FAKE)
|
||||
self.session = mock.Mock(
|
||||
spec=adapter.Adapter,
|
||||
default_microversion='1.86',
|
||||
)
|
||||
|
||||
def test_list_firmware(self):
|
||||
node_firmware = {
|
||||
"firmware": [
|
||||
{
|
||||
"created_at": "2016-08-18T22:28:49.653974+00:00",
|
||||
"updated_at": "2016-08-18T22:28:49.653974+00:00",
|
||||
"component": "BMC",
|
||||
"initial_version": "v1.0.0",
|
||||
"current_version": "v1.2.0",
|
||||
"last_version_flashed": "v1.2.0",
|
||||
},
|
||||
{
|
||||
"created_at": "2016-08-18T22:28:49.653974+00:00",
|
||||
"updated_at": "2016-08-18T22:28:49.653974+00:00",
|
||||
"component": "BIOS",
|
||||
"initial_version": "v1.0.0",
|
||||
"current_version": "v1.1.5",
|
||||
"last_version_flashed": "v1.1.5",
|
||||
},
|
||||
]
|
||||
}
|
||||
self.session.get.return_value.json.return_value = node_firmware
|
||||
|
||||
res = self.node.list_firmware(self.session)
|
||||
self.assertEqual(node_firmware, res)
|
||||
|
||||
self.session.get.assert_called_once_with(
|
||||
'nodes/%s/firmware' % self.node.id,
|
||||
headers=mock.ANY,
|
||||
microversion='1.86',
|
||||
retriable_status_codes=_common.RETRIABLE_STATUS_CODES,
|
||||
)
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Adds support for querying a bare-metal node's firmware as per functionality
|
||||
introduced in API 1.86.
|
Loading…
Reference in New Issue
Block a user