From 6fef03c7ce71fb8d5aa8f81d0fa04c3fd7f51a79 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Tue, 30 Oct 2018 09:47:14 -0500 Subject: [PATCH] Apply list filter fix to servers and floating ips too Servers and floating ips use the same batching/caching logic that ports to - and suffer from the same issue in their push-down code. Let's fix them too. Change-Id: Ia5c40ef333d3084ec026ef1ddbe41aa7c64da610 --- openstack/cloud/openstackcloud.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/openstack/cloud/openstackcloud.py b/openstack/cloud/openstackcloud.py index 34954297b..898c71da5 100755 --- a/openstack/cloud/openstackcloud.py +++ b/openstack/cloud/openstackcloud.py @@ -2101,6 +2101,16 @@ class _OpenStackCloudMixin(_normalize.Normalizer): :returns: A list of server ``munch.Munch``. """ + # If pushdown filters are specified and we do not have batched caching + # enabled, bypass local caching and push down the filters. + if filters and self._SERVER_AGE == 0: + return self._list_servers( + detailed=detailed, + all_projects=all_projects, + bare=bare, + filters=filters, + ) + if (time.time() - self._servers_time) >= self._SERVER_AGE: # Since we're using cached data anyway, we don't need to # have more than one thread actually submit the list @@ -2116,12 +2126,14 @@ class _OpenStackCloudMixin(_normalize.Normalizer): self._servers = self._list_servers( detailed=detailed, all_projects=all_projects, - bare=bare, - filters=filters) + bare=bare) self._servers_time = time.time() finally: self._servers_lock.release() - return self._servers + # Wrap the return with filter_list so that if filters were passed + # but we were batching/caching and thus always fetching the whole + # list from the cloud, we still return a filtered list. + return _utils._filter_list(self._servers, None, filters) def _list_servers(self, detailed=False, all_projects=False, bare=False, filters=None): @@ -2333,7 +2345,10 @@ class _OpenStackCloudMixin(_normalize.Normalizer): self._floating_ips_time = time.time() finally: self._floating_ips_lock.release() - return self._floating_ips + # Wrap the return with filter_list so that if filters were passed + # but we were batching/caching and thus always fetching the whole + # list from the cloud, we still return a filtered list. + return _utils._filter_list(self._floating_ips, None, filters) def _neutron_list_floating_ips(self, filters=None): if not filters: