[sdk] possible bug in the openstacksdk/cloud?
Hello, Recently, I was debugging an issue related to the ansible openstack.cloud.server module while creating an instance with floating ip attached. A part of stack trace goes below: ... File "/home/user/venv/lib/python3.11/site-packages/openstack/cloud/_compute.py", line 1013, in create_server server = self.wait_for_server( File "/home/user/venv/lib/python3.11/site-packages/openstack/cloud/_compute.py", line 1153, in wait_for_server server = self.get_active_server( File "/home/user/venv/lib/python3.11/site-packages/openstack/cloud/_compute.py", line 1200, in get_active_server return self.add_ips_to_server( File "/home/user/venv/lib/python3.11/site-packages/openstack/cloud/_network_common.py", line 1412, in add_ips_to_server server = self._add_ip_from_pool( File "/home/user/venv/lib/python3.11/site-packages/openstack/cloud/_network_common.py", line 1247, in _add_ip_from_pool f_ip = self.create_floating_ip( File "/home/user/venv/lib/python3.11/site-packages/openstack/cloud/_network_common.py", line 765, in create_floating_ip return self._neutron_create_floating_ip( File "/home/user/venv/lib/python3.11/site-packages/openstack/cloud/_network_common.py", line 824, in _neutron_create_floating_ip network_id = network['id'] ~~~~~~~^^^^^^ TypeError: 'NoneType' object is not subscriptable Tracing this down to openstacksdk python module I have found a suspicious place in the openstacksdk code: if network_name_or_id: try: network = self.network.find_network(network_name_or_id) except exceptions.NotFoundException: raise exceptions.NotFoundException( "unable to find network for floating ips with ID " "{}".format(network_name_or_id) ) network_id = network['id'] https://github.com/openstack/openstacksdk/blob/de07fd02639eb565f10956b612ed2... I suppose that this call to self.network.find_network lacks "ignore_missing=True" param. E.g.: network = self.network.find_network(network_name_or_id, ignore_missing=True) This fixed my issue with floating ips, but I'm not sure such patch is suitable for the mainline code of the openstacksdk. Am I correct? Regards, Alexander.
Hi ! This looks like a valid bug in openstacksdk and it may be helpful if you can report the bug in https://bugs.launchpad.net/openstacksdk . I think the problem is not 'lack of ignore_missing=True' but 'lack of ignore_missing=False'. If my reading of openstack sdk code is correct then ignore_missing=True is default, which currently makes the find_network function return None instead of raising NotFoundException. Because we already have that try-except block catching NotFoundException adding ignore_missing=False to that find_network call sounds like a reasonable solution. If you are interested in proposing a fix then please feel free to do so or I (or anyone in the SDK team) can submit it on behalf of you. On 9/14/24 00:23, astepanov2007@gmail.com wrote:
Hello,
Recently, I was debugging an issue related to the ansible openstack.cloud.server module while creating an instance with floating ip attached. A part of stack trace goes below:
... File "/home/user/venv/lib/python3.11/site-packages/openstack/cloud/_compute.py", line 1013, in create_server server = self.wait_for_server( File "/home/user/venv/lib/python3.11/site-packages/openstack/cloud/_compute.py", line 1153, in wait_for_server server = self.get_active_server( File "/home/user/venv/lib/python3.11/site-packages/openstack/cloud/_compute.py", line 1200, in get_active_server return self.add_ips_to_server( File "/home/user/venv/lib/python3.11/site-packages/openstack/cloud/_network_common.py", line 1412, in add_ips_to_server server = self._add_ip_from_pool( File "/home/user/venv/lib/python3.11/site-packages/openstack/cloud/_network_common.py", line 1247, in _add_ip_from_pool f_ip = self.create_floating_ip( File "/home/user/venv/lib/python3.11/site-packages/openstack/cloud/_network_common.py", line 765, in create_floating_ip return self._neutron_create_floating_ip( File "/home/user/venv/lib/python3.11/site-packages/openstack/cloud/_network_common.py", line 824, in _neutron_create_floating_ip network_id = network['id'] ~~~~~~~^^^^^^ TypeError: 'NoneType' object is not subscriptable
Tracing this down to openstacksdk python module I have found a suspicious place in the openstacksdk code:
if network_name_or_id: try: network = self.network.find_network(network_name_or_id) except exceptions.NotFoundException: raise exceptions.NotFoundException( "unable to find network for floating ips with ID " "{}".format(network_name_or_id) ) network_id = network['id']
https://github.com/openstack/openstacksdk/blob/de07fd02639eb565f10956b612ed2...
I suppose that this call to self.network.find_network lacks "ignore_missing=True" param. E.g.: network = self.network.find_network(network_name_or_id, ignore_missing=True) This fixed my issue with floating ips, but I'm not sure such patch is suitable for the mainline code of the openstacksdk. Am I correct?
Regards, Alexander.
Hi, Takashi Thanks for a quick response!
This looks like a valid bug in openstacksdk and it may be helpful if you can report the bug in https://bugs.launchpad.net/openstacksdk .
I've reported it here https://bugs.launchpad.net/openstacksdk/+bug/2080859
I think the problem is not 'lack of ignore_missing=True' but 'lack of ignore_missing=False'.
Yep, the fix should contain "ignore_missing=False" indeed. I can confirm this fixes my issue. Using True in the provided example code was my copy-pasted mistake while describing the problem here.
If you are interested in proposing a fix then please feel free to do so or I (or anyone in the SDK team) can submit it on behalf of you.
Please submit this patch on behalf of me: diff --git a/openstack/cloud/_network_common.py b/openstack/cloud/_network_common.py index 43633d7cd..16fd7f35c 100644 --- a/openstack/cloud/_network_common.py +++ b/openstack/cloud/_network_common.py @@ -806,7 +806,7 @@ class NetworkCommonCloudMixin(openstackcloud._OpenStackCloudMixin): if not network_id: if network_name_or_id: try: - network = self.network.find_network(network_name_or_id) + network = self.network.find_network(network_name_or_id, ignore_missing=False) except exceptions.NotFoundException: raise exceptions.NotFoundException( "unable to find network for floating ips with ID " Regards, Alexander.
participants (2)
-
astepanov2007@gmail.com
-
Takashi Kajinami