Merge "Provide proper error message if interface name is invalid"

This commit is contained in:
Zuul 2018-07-11 15:01:21 +00:00 committed by Gerrit Code Review
commit 5a7535252d
3 changed files with 14 additions and 6 deletions

View File

@ -434,8 +434,7 @@ class TestInterfaceApi(BaseTest):
self.uuid, "em1", fields)
self.assertEqual(expected_values, iface_dict)
# Test interface name not in 'all_interfaces'
expected_values = collections.OrderedDict()
iface_dict = self.get_client().get_interface_data(
self.uuid, "em55", fields)
self.assertEqual(expected_values, iface_dict)
def test_invalid_interface(self, mock_req):
mock_req.return_value.json.return_value = self.inspector_db
self.assertRaises(ValueError, self.get_client().get_interface_data,
self.uuid, "em55", ["node_ident", "interface"])

View File

@ -294,6 +294,7 @@ class ClientV1(http.BaseClient):
:param interface: interface name
:param field_sel: list of all fields for which to get data
:returns: interface data in OrderedDict
:raises: ValueError if interface is not found.
"""
# Use OrderedDict to maintain order of user-entered fields
iface_data = collections.OrderedDict()
@ -303,7 +304,9 @@ class ClientV1(http.BaseClient):
# Make sure interface name is valid
if interface not in all_interfaces:
return iface_data
raise ValueError(
_("Interface %s was not found on this node")
% interface)
# If lldp data not available this will still return interface,
# mac, node_ident etc.

View File

@ -0,0 +1,6 @@
---
fixes:
- The error message returned when running the
`openstack baremetal introspection interface show`
command with an interface not associated with the node has been fixed.
It now indicates that the interface was invalid.