** Description changed:
- -----------
- Description
- -----------
+ [ Impact ]
- When listing the port bindings, neutronclient uses the "port_bindings"
- key to access the API response from Neutron [1]. However, as stated on
- Neutron's v2 API reference page [2], the client should use "bindings":
+ A bug in python-neutronclient causes a KeyError when attempting to list
+ port bindings via the client. Specifically, calling the list_port_bindings
+ method triggers a KeyError: 'port_bindings'. This occurs because the client
+ expects the Neutron API response to contain the "port_bindings" key.
- ```
- {
- "bindings" : [
- {
- "host" : "jammy",
- ...
- }
- ]
- }
+ This affects any service or tool that calls this method, and as such can
+ cause functional failures in Openstack deployments. Upstream has fixed this
+ by adjusting the parsing of the API response to use the correct key "bindings"
+ instead of "port_bindings". The attached debdiffs apply this same fix to
+ affected Ubuntu and Ubuntu Cloud Archive series.
+
+ [ Test Plan ]
+
+ Deploy an OpenStack environment on the target series.
+
+ 1. Ensure you have administrative access to the deployed cloud and source
+ credentials.
+
+ 2. Create a test network and a port to run the query against.
+
+ ```sh
+ openstack network create test-net
+
+ openstack subnet create --network test-net --subnet-range 10.10.99.0/24
+ test-subnet
+
+ PORT_ID=$(openstack port create --network test-net test-port -c id -f value)
```
- ------------------
- Reproduction Steps
- ------------------
+ 3. Verify the failure exists using the following python script. It attempts
+ to call the problematic API method.
- Write a simple function in Nova to reproduce this:
+ Create a file named reproduce.py with the following contents:
- ```
- def test_function(self, context, instance):
- client = get_client(context, admin=True)
- bindings = None
+ ```py
+ import os
+ import sys
+ from keystoneauth1 import identity, session
+ from neutronclient.v2_0 import client
- for vif in instance.get_network_info():
- try:
- bindings = client.list_port_bindings(
- vif['id']
- )
- except Exception as e:
- LOG.exception("Encountered errors when listing bindings")
+ # Authenticate using environment variables
+ auth = identity.v3.Password(
+ auth_url=os.environ['OS_AUTH_URL'],
+ username=os.environ['OS_USERNAME'],
+ password=os.environ['OS_PASSWORD'],
+ project_name=os.environ['OS_PROJECT_NAME'],
+ user_domain_name=os.environ.get('OS_USER_DOMAIN_NAME', 'Default'),
+ project_domain_name=os.environ.get('OS_PROJECT_DOMAIN_NAME', 'Default')
+ )
+ sess = session.Session(auth=auth)
+ neutron = client.Client(session=sess)
- if bindings is not None:
- LOG.info("list port bindings ok, %s", bindings)
+ # Get the port ID
+ port_id = sys.argv[1]
+
+ print(f"Attempting list_port_bindings for {port_id}...")
+ try:
+ bindings = neutron.list_port_bindings(port_id)
+ print("SUCCESS: Bindings retrieved:", bindings)
+ except Exception as e:
+ print(f"FAILURE: error: {e}")
+ sys.exit(1)
```
- And we got the following error:
+ Run this script with the newly created port:
- ```
- 2025-10-31 20:12:16.782 3057724 ERROR nova.network.neutron [None
req-44d656db-4880-4976-8faa-a00ba70f67ed 5d22d29167e540c1b3b26b8e66cce21d
9ff8c74250054cf6be30d94c19a7a0d6 - - default default] Encountered errors when
listing bindings: KeyError: 'port_bindings'
- 2025-10-31 20:12:16.782 3057724 ERROR nova.network.neutron Traceback (most
recent call last):
- 2025-10-31 20:12:16.782 3057724 ERROR nova.network.neutron File
"/usr/lib/python3/dist-packages/nova/network/neutron.py", line 3115, in
test_function
- 2025-10-31 20:12:16.782 3057724 ERROR nova.network.neutron bindings =
client.list_port_bindings(
- 2025-10-31 20:12:16.782 3057724 ERROR nova.network.neutron File
"/usr/lib/python3/dist-packages/nova/network/neutron.py", line 197, in wrapper
- 2025-10-31 20:12:16.782 3057724 ERROR nova.network.neutron ret =
obj(*args, **kwargs)
- 2025-10-31 20:12:16.782 3057724 ERROR nova.network.neutron File
"/usr/lib/python3/dist-packages/neutronclient/v2_0/client.py", line 851, in
list_port_bindings
- 2025-10-31 20:12:16.782 3057724 ERROR nova.network.neutron return
self.list('port_bindings', self.port_bindings_path % port_id,
- 2025-10-31 20:12:16.782 3057724 ERROR nova.network.neutron File
"/usr/lib/python3/dist-packages/nova/network/neutron.py", line 197, in wrapper
- 2025-10-31 20:12:16.782 3057724 ERROR nova.network.neutron ret =
obj(*args, **kwargs)
- 2025-10-31 20:12:16.782 3057724 ERROR nova.network.neutron File
"/usr/lib/python3/dist-packages/neutronclient/v2_0/client.py", line 374, in list
- 2025-10-31 20:12:16.782 3057724 ERROR nova.network.neutron
res.extend(r[collection])
- 2025-10-31 20:12:16.782 3057724 ERROR nova.network.neutron KeyError:
'port_bindings'
- 2025-10-31 20:12:16.782 3057724 ERROR nova.network.neutron
+ ```sh
+ python3 reproduce.py $PORT_ID
```
- Changing "port_bindings" -> "bindings" in neutronclient's
- `list_port_bindings` function and re-run the function:
+ The expected result before applying the fix is that the script will
+ fail with FAILURE: error: KeyError: 'port_bindings'.
- ```
- 2025-10-31 20:16:44.081 3058851 INFO nova.network.neutron [None
req-25ee330d-0d81-4ee0-bf6b-5a15208351dc 5d22d29167e540c1b3b26b8e66cce21d
9ff8c74250054cf6be30d94c19a7a0d6 - - default default] list port bindings ok,
{'bindings': [{'host': 'example-host', 'vif_type': ...}]}
- ```
+ The expected result after applying the fix is that the script will
+ run successfully.
- -----------
- Environment
- -----------
- OpenStack: Caracal (2024.1)
- nova: 29.2.0
- neutronclient: 11.2.0
+ [ Where problems could occur ]
+ API response mismatch: The patch changes the key lookup from "port_bindings"
+ to "bindings". If there are non-standard Neutron API implementations that
+ only "port_bindings" and not the expected structure, this fix could
theoretically
+ prevent usage of this method that was previously working.
- ----------
- References
- ----------
- [1]:
https://github.com/openstack/python-neutronclient/blob/master/neutronclient/v2_0/client.py#L853
- [2]:
https://docs.openstack.org/api-ref/network/v2/index.html#show-port-binding-of-a-port
+ [ Other Info ]
+
+ This backports the merged upstream fix which corrects the JSON key. The
+ description / message from the original commit message is provided
+ below:
+
+ v2_0: Use 'bindings' when listing port bindings
+ This commit fixes a bug in v2_0 client's "list_port_bindings"
+ function, where it uses "port_bindings" to access Neutron's
+ response, instead of "bindings" [0].
+
+ [0]: https://docs.openstack.org/api-ref/network/v2/index.html#show-port-
+ binding-of-a-port
+
+ Closes-Bug: #2130459
+ Change-Id: I32ef753ec212b55f698e3844e043f68b22992ead
+ Signed-off-by: Zhan Zhang <[email protected]>
--
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2130459
Title:
neutronclient uses the wrong key when listing port bindings
To manage notifications about this bug go to:
https://bugs.launchpad.net/cloud-archive/+bug/2130459/+subscriptions
--
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs