Merge "Add API tests for the reset_interfaces parameter"
This commit is contained in:
commit
f5792d1f8f
|
@ -85,7 +85,8 @@ class BaremetalClient(rest_client.RestClient):
|
|||
|
||||
return json.loads(object_str)
|
||||
|
||||
def _get_uri(self, resource_name, uuid=None, permanent=False):
|
||||
def _get_uri(self, resource_name, uuid=None, permanent=False,
|
||||
params=None):
|
||||
"""Get URI for a specific resource or object.
|
||||
|
||||
:param resource_name: The name of the REST resource, e.g., 'nodes'.
|
||||
|
@ -94,10 +95,15 @@ class BaremetalClient(rest_client.RestClient):
|
|||
|
||||
"""
|
||||
prefix = self.uri_prefix if not permanent else ''
|
||||
if params:
|
||||
params = '?' + '&'.join('%s=%s' % tpl for tpl in params.items())
|
||||
else:
|
||||
params = ''
|
||||
|
||||
return '{pref}/{res}{uuid}'.format(pref=prefix,
|
||||
res=resource_name,
|
||||
uuid='/%s' % uuid if uuid else '')
|
||||
return '{pref}/{res}{uuid}{params}'.format(
|
||||
pref=prefix, res=resource_name,
|
||||
uuid='/%s' % uuid if uuid else '',
|
||||
params=params)
|
||||
|
||||
def _make_patch(self, allowed_attributes, **kwargs):
|
||||
"""Create a JSON patch according to RFC 6902.
|
||||
|
@ -229,16 +235,17 @@ class BaremetalClient(rest_client.RestClient):
|
|||
self.expected_success(expected_status, resp.status)
|
||||
return resp, body
|
||||
|
||||
def _patch_request(self, resource, uuid, patch_object):
|
||||
def _patch_request(self, resource, uuid, patch_object, params=None):
|
||||
"""Update specified object with JSON-patch.
|
||||
|
||||
:param resource: The name of the REST resource, e.g., 'nodes'.
|
||||
:param uuid: The unique identifier of an object in UUID format.
|
||||
:param params: query parameters to pass.
|
||||
:returns: A tuple with the server response and the serialized patched
|
||||
object.
|
||||
|
||||
"""
|
||||
uri = self._get_uri(resource, uuid)
|
||||
uri = self._get_uri(resource, uuid, params=params)
|
||||
patch_body = json.dumps(patch_object)
|
||||
|
||||
resp, body = self.patch(uri, body=patch_body)
|
||||
|
|
|
@ -410,6 +410,11 @@ class BaremetalClient(base.BaremetalClient):
|
|||
:return: A tuple with the server response and the updated node.
|
||||
|
||||
"""
|
||||
if 'reset_interfaces' in kwargs:
|
||||
params = {'reset_interfaces': str(kwargs.pop('reset_interfaces'))}
|
||||
else:
|
||||
params = {}
|
||||
|
||||
node_attributes = ('properties/cpu_arch',
|
||||
'properties/cpus',
|
||||
'properties/local_gb',
|
||||
|
@ -423,7 +428,7 @@ class BaremetalClient(base.BaremetalClient):
|
|||
if not patch:
|
||||
patch = self._make_patch(node_attributes, **kwargs)
|
||||
|
||||
return self._patch_request('nodes', uuid, patch)
|
||||
return self._patch_request('nodes', uuid, patch, params=params)
|
||||
|
||||
@base.handle_errors
|
||||
def update_chassis(self, uuid, **kwargs):
|
||||
|
|
|
@ -469,6 +469,36 @@ class TestHardwareInterfaces(base.BaseBaremetalTest):
|
|||
self.assertEqual('fake', node[field])
|
||||
|
||||
|
||||
class TestResetInterfaces(TestHardwareInterfaces):
|
||||
|
||||
min_microversion = '1.45'
|
||||
|
||||
@classmethod
|
||||
def skip_checks(cls):
|
||||
super(TestResetInterfaces, cls).skip_checks()
|
||||
if 'ipmi' not in CONF.baremetal.enabled_hardware_types:
|
||||
raise cls.skipException('These tests rely on ipmi enabled')
|
||||
|
||||
def test_no_reset_by_default(self):
|
||||
self.assertRaises(
|
||||
lib_exc.BadRequest,
|
||||
self.client.update_node,
|
||||
self.node['uuid'],
|
||||
[{'path': '/driver', 'value': 'ipmi', 'op': 'replace'}])
|
||||
_, node = self.client.show_node(self.node['uuid'])
|
||||
self.assertEqual('fake-hardware', node['driver'])
|
||||
|
||||
def test_reset_all_interfaces(self):
|
||||
self.client.update_node(self.node['uuid'],
|
||||
[{'path': '/driver',
|
||||
'value': 'ipmi',
|
||||
'op': 'replace'}],
|
||||
reset_interfaces=True)
|
||||
_, node = self.client.show_node(self.node['uuid'])
|
||||
for iface in self.hardware_interfaces:
|
||||
self.assertNotEqual('fake', node['%s_interface' % iface])
|
||||
|
||||
|
||||
class TestNodesTraits(base.BaseBaremetalTest):
|
||||
|
||||
min_microversion = '1.37'
|
||||
|
|
Loading…
Reference in New Issue