Merge "Add set-boot-device to baremetal"
This commit is contained in:
commit
a88328e90e
|
@ -326,6 +326,19 @@ class Proxy(proxy.Proxy):
|
||||||
rescue_password=rescue_password,
|
rescue_password=rescue_password,
|
||||||
wait=wait, timeout=timeout)
|
wait=wait, timeout=timeout)
|
||||||
|
|
||||||
|
def set_node_boot_device(self, node, boot_device, persistent=False):
|
||||||
|
"""Set node boot device
|
||||||
|
|
||||||
|
:param node: The value can be the name or ID of a node or a
|
||||||
|
:class:`~openstack.baremetal.v1.node.Node` instance.
|
||||||
|
:param boot_device: Boot device to assign to the node.
|
||||||
|
:param persistent: If the boot device change is maintained after node
|
||||||
|
reboot
|
||||||
|
:return: The updated :class:`~openstack.baremetal.v1.node.Node`
|
||||||
|
"""
|
||||||
|
res = self._get_resource(_node.Node, node)
|
||||||
|
return res.set_boot_device(self, boot_device, persistent=persistent)
|
||||||
|
|
||||||
def wait_for_nodes_provision_state(self, nodes, expected_state,
|
def wait_for_nodes_provision_state(self, nodes, expected_state,
|
||||||
timeout=None,
|
timeout=None,
|
||||||
abort_on_failed_state=True):
|
abort_on_failed_state=True):
|
||||||
|
|
|
@ -720,5 +720,30 @@ class Node(_common.ListMixin, resource.Resource):
|
||||||
.format(node=self.id))
|
.format(node=self.id))
|
||||||
exceptions.raise_from_response(response, error_message=msg)
|
exceptions.raise_from_response(response, error_message=msg)
|
||||||
|
|
||||||
|
def set_boot_device(self, session, boot_device, persistent=False):
|
||||||
|
"""Set node boot device
|
||||||
|
|
||||||
|
:param session: The session to use for making this request.
|
||||||
|
:param boot_device: Boot device to assign to the node.
|
||||||
|
:param persistent: If the boot device change is maintained after node
|
||||||
|
reboot
|
||||||
|
:return: The updated :class:`~openstack.baremetal.v1.node.Node`
|
||||||
|
"""
|
||||||
|
session = self._get_session(session)
|
||||||
|
version = self._get_microversion_for(session, 'commit')
|
||||||
|
request = self._prepare_request(requires_id=True)
|
||||||
|
request.url = utils.urljoin(request.url, 'management', 'boot_device')
|
||||||
|
|
||||||
|
body = {'boot_device': boot_device, 'persistent': persistent}
|
||||||
|
|
||||||
|
response = session.put(
|
||||||
|
request.url, json=body,
|
||||||
|
headers=request.headers, microversion=version,
|
||||||
|
retriable_status_codes=_common.RETRIABLE_STATUS_CODES)
|
||||||
|
|
||||||
|
msg = ("Failed to set boot device for node {node}"
|
||||||
|
.format(node=self.id))
|
||||||
|
exceptions.raise_from_response(response, error_message=msg)
|
||||||
|
|
||||||
|
|
||||||
NodeDetail = Node
|
NodeDetail = Node
|
||||||
|
|
|
@ -683,3 +683,22 @@ class TestNodeMaintenance(base.TestCase):
|
||||||
json=None,
|
json=None,
|
||||||
headers=mock.ANY,
|
headers=mock.ANY,
|
||||||
microversion=mock.ANY)
|
microversion=mock.ANY)
|
||||||
|
|
||||||
|
|
||||||
|
@mock.patch.object(node.Node, 'fetch', lambda self, session: self)
|
||||||
|
@mock.patch.object(exceptions, 'raise_from_response', mock.Mock())
|
||||||
|
class TestNodeSetBootDevice(base.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestNodeSetBootDevice, self).setUp()
|
||||||
|
self.node = node.Node(**FAKE)
|
||||||
|
self.session = mock.Mock(spec=adapter.Adapter,
|
||||||
|
default_microversion='1.1')
|
||||||
|
|
||||||
|
def test_node_set_boot_device(self):
|
||||||
|
self.node.set_boot_device(self.session, 'pxe', persistent=False)
|
||||||
|
self.session.put.assert_called_once_with(
|
||||||
|
'nodes/%s/management/boot_device' % self.node.id,
|
||||||
|
json={'boot_device': 'pxe', 'persistent': False},
|
||||||
|
headers=mock.ANY, microversion=mock.ANY,
|
||||||
|
retriable_status_codes=_common.RETRIABLE_STATUS_CODES)
|
||||||
|
|
Loading…
Reference in New Issue