Add API tests for the reset_interfaces parameter

Depends-On: https://review.openstack.org/582951
Change-Id: Idd2c1a0104a0d0e349ccdc0599825b7492a94ba5
Story: #2002868
Task: #22829
This commit is contained in:
Dmitry Tantsur 2018-07-16 17:48:32 +02:00
parent f7c53ca295
commit e754805de1
3 changed files with 49 additions and 7 deletions

View File

@ -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)

View File

@ -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):

View File

@ -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'