From 785016eb742206d89aae2898fc4af77e19c581fa Mon Sep 17 00:00:00 2001 From: Fernando Ferraz Date: Thu, 17 Mar 2022 06:38:18 +0000 Subject: [PATCH] Fix Dummy driver fails to get subnet_allocations With the addition of support to multiple subnets per AZ, backend_details structure was changed in Dummy driver to store multiple subnet primary and secondary public ips in a subnet_allocations list dumped to a json string, breaking upgrading environments that already contains pre-existent share servers in old format. This change fixes the issue by checking if subnet_allocations does exist, otherwise ensure backward compatibility by reading public ips information in the old format. Change-Id: I547de2f4cd82744ecc1cc8180f8cefdf5ec485b4 --- manila/tests/share/drivers/dummy.py | 40 +++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/manila/tests/share/drivers/dummy.py b/manila/tests/share/drivers/dummy.py index e517e2754e..601827af65 100644 --- a/manila/tests/share/drivers/dummy.py +++ b/manila/tests/share/drivers/dummy.py @@ -195,11 +195,31 @@ class DummyDriver(driver.ShareDriver): "is_admin_only": is_admin_only, } + def _get_subnet_allocations_from_backend_details(self, backend_details): + """Reads subnet_allocations info from backend details""" + # NOTE(sfernand): Ensure backward compatibility for share servers + # created prior to the addition of support to multiple subnets per AZ, + # by read ip information using the old format in case + # subnet_allocations does not exist. + if 'subnet_allocations' in backend_details: + subnet_allocations = jsonutils.loads( + backend_details['subnet_allocations']) + else: + subnet_allocations = [{ + 'primary_public_ip': + backend_details['primary_public_ip'], + 'secondary_public_ip': + backend_details['secondary_public_ip'] + }] + return subnet_allocations + def _generate_export_locations(self, mountpoint, share_server=None): if share_server: - subnet_allocations = jsonutils.loads( - share_server["backend_details"]["subnet_allocations"]) - service_ip = share_server["backend_details"]["service_ip"] + backend_details = share_server['backend_details'] + subnet_allocations = ( + self._get_subnet_allocations_from_backend_details( + backend_details)) + service_ip = backend_details["service_ip"] else: subnet_allocations = [{ "primary_public_ip": "10.0.0.10", @@ -857,8 +877,10 @@ class DummyDriver(driver.ShareDriver): raise exception.ShareBackendException(msg=msg) ips = [server_details['service_ip']] - subnet_allocations = jsonutils.loads( - server_details['subnet_allocations']) + + subnet_allocations = ( + self._get_subnet_allocations_from_backend_details(server_details)) + for subnet_allocation in subnet_allocations: ips += list(subnet_allocation.values()) return ips @@ -934,8 +956,10 @@ class DummyDriver(driver.ShareDriver): self, context, share_server, current_network_allocations, new_network_allocations, security_services, shares, snapshots): - subnet_allocations = jsonutils.loads( - share_server['backend_details']['subnet_allocations']) + backend_details = share_server['backend_details'] + subnet_allocations = ( + self._get_subnet_allocations_from_backend_details(backend_details)) + subnet_allocations.append({ 'primary_public_ip': new_network_allocations[ 'network_allocations'][0]['ip_address'], @@ -945,7 +969,7 @@ class DummyDriver(driver.ShareDriver): new_server = { "backend_details": { "subnet_allocations": jsonutils.dumps(subnet_allocations), - "service_ip": share_server["backend_details"]["service_ip"], + "service_ip": backend_details["service_ip"], } } shares_updates = {}