diff options
-rw-r--r-- | ironic/api/controllers/v1/port.py | 6 | ||||
-rw-r--r-- | ironic/tests/unit/api/controllers/v1/test_port.py | 9 |
2 files changed, 12 insertions, 3 deletions
diff --git a/ironic/api/controllers/v1/port.py b/ironic/api/controllers/v1/port.py index 141771e11..449c18ca2 100644 --- a/ironic/api/controllers/v1/port.py +++ b/ironic/api/controllers/v1/port.py @@ -443,10 +443,10 @@ class PortsController(rest.RestController): if ('local_link_connection/network_type' in fields and not api_utils.allow_local_link_connection_network_type()): raise exception.NotAcceptable() - if isinstance(fields, dict): + if (isinstance(fields, dict) + and fields.get('local_link_connection') is not None): if (not api_utils.allow_local_link_connection_network_type() - and 'network_type' in fields.get('local_link_connection', - {}).keys()): + and 'network_type' in fields['local_link_connection']): raise exception.NotAcceptable() @METRICS.timer('PortsController.get_all') diff --git a/ironic/tests/unit/api/controllers/v1/test_port.py b/ironic/tests/unit/api/controllers/v1/test_port.py index 620b79b2f..1d0de01f1 100644 --- a/ironic/tests/unit/api/controllers/v1/test_port.py +++ b/ironic/tests/unit/api/controllers/v1/test_port.py @@ -185,6 +185,15 @@ class TestPortsController__CheckAllowedPortFields(base.TestCase): self.assertFalse(mock_allow_portgroup.called) mock_allow_physnet.assert_called_once_with() + def test__check_allowed_port_fields_local_link_connection_none_type( + self, mock_allow_port, mock_allow_portgroup, mock_allow_physnet): + mock_allow_port.return_value = True + mock_allow_physnet.return_value = True + self.assertIsNone( + self.controller._check_allowed_port_fields( + {'local_link_connection': None})) + mock_allow_port.assert_called_once_with() + class TestListPorts(test_api_base.BaseApiTest): |