Merge "Support per-call version: set_provision_state"

This commit is contained in:
Zuul 2018-06-12 10:10:07 +00:00 committed by Gerrit Code Review
commit 5448011fdf
3 changed files with 28 additions and 5 deletions

View File

@ -185,18 +185,24 @@ class Manager(object):
def _list_primitives(self, url, response_key=None): def _list_primitives(self, url, response_key=None):
return self.__list(url, response_key=response_key) return self.__list(url, response_key=response_key)
def _update(self, resource_id, patch, method='PATCH'): def _update(self, resource_id, patch, method='PATCH',
os_ironic_api_version=None):
"""Update a resource. """Update a resource.
:param resource_id: Resource identifier. :param resource_id: Resource identifier.
:param patch: New version of a given resource, a dictionary or None. :param patch: New version of a given resource, a dictionary or None.
:param method: Name of the method for the request. :param method: Name of the method for the request.
:param os_ironic_api_version: String version (e.g. "1.35") to use for
the request. If not specified, the client's default is used.
""" """
url = self._path(resource_id) url = self._path(resource_id)
kwargs = {} kwargs = {}
if patch is not None: if patch is not None:
kwargs['body'] = patch kwargs['body'] = patch
if os_ironic_api_version is not None:
kwargs['headers'] = {'X-OpenStack-Ironic-API-Version':
os_ironic_api_version}
resp, body = self.api.json_request(method, url, **kwargs) resp, body = self.api.json_request(method, url, **kwargs)
# PATCH/PUT requests may not return a body # PATCH/PUT requests may not return a body
if body: if body:

View File

@ -1298,6 +1298,17 @@ class NodeManagerTest(testtools.TestCase):
] ]
self.assertEqual(expect, self.api.calls) self.assertEqual(expect, self.api.calls)
def test_node_set_provision_state_microversion_override(self):
target_state = 'active'
self.mgr.set_provision_state(NODE1['uuid'], target_state,
os_ironic_api_version="1.35")
body = {'target': target_state}
expect = [
('PUT', '/v1/nodes/%s/states/provision' % NODE1['uuid'],
{'X-OpenStack-Ironic-API-Version': '1.35'}, body),
]
self.assertEqual(expect, self.api.calls)
def test_node_set_provision_state_with_configdrive(self): def test_node_set_provision_state_with_configdrive(self):
target_state = 'active' target_state = 'active'
self.mgr.set_provision_state(NODE1['uuid'], target_state, self.mgr.set_provision_state(NODE1['uuid'], target_state,

View File

@ -336,9 +336,11 @@ class NodeManager(base.CreateManager):
def delete(self, node_id): def delete(self, node_id):
return self._delete(resource_id=node_id) return self._delete(resource_id=node_id)
def update(self, node_id, patch, http_method='PATCH'): def update(self, node_id, patch, http_method='PATCH',
os_ironic_api_version=None):
return self._update(resource_id=node_id, patch=patch, return self._update(resource_id=node_id, patch=patch,
method=http_method) method=http_method,
os_ironic_api_version=os_ironic_api_version)
def vendor_passthru(self, node_id, method, args=None, def vendor_passthru(self, node_id, method, args=None,
http_method=None): http_method=None):
@ -483,7 +485,8 @@ class NodeManager(base.CreateManager):
return self.get(path) return self.get(path)
def set_provision_state(self, node_uuid, state, configdrive=None, def set_provision_state(self, node_uuid, state, configdrive=None,
cleansteps=None, rescue_password=None): cleansteps=None, rescue_password=None,
os_ironic_api_version=None):
"""Set the provision state for the node. """Set the provision state for the node.
:param node_uuid: The UUID or name of the node. :param node_uuid: The UUID or name of the node.
@ -502,6 +505,8 @@ class NodeManager(base.CreateManager):
:param rescue_password: A string to be used as the login password :param rescue_password: A string to be used as the login password
inside the rescue ramdisk once a node is rescued. This must be inside the rescue ramdisk once a node is rescued. This must be
specified (and is only valid) when setting 'state' to 'rescue'. specified (and is only valid) when setting 'state' to 'rescue'.
:param os_ironic_api_version: String version (e.g. "1.35") to use for
the request. If not specified, the client's default is used.
:raises: InvalidAttribute if there was an error with the clean steps :raises: InvalidAttribute if there was an error with the clean steps
:returns: The status of the request :returns: The status of the request
""" """
@ -521,7 +526,8 @@ class NodeManager(base.CreateManager):
elif rescue_password: elif rescue_password:
body['rescue_password'] = rescue_password body['rescue_password'] = rescue_password
return self.update(path, body, http_method='PUT') return self.update(path, body, http_method='PUT',
os_ironic_api_version=os_ironic_api_version)
def states(self, node_uuid): def states(self, node_uuid):
path = "%s/states" % node_uuid path = "%s/states" % node_uuid