From b5af694793c050c872b519ee28ecddc5ea0b3efa Mon Sep 17 00:00:00 2001 From: asarfaty Date: Sun, 10 Jan 2021 11:38:13 +0200 Subject: [PATCH] V2T migration: Fix issues with api-replay 1. Add subnet host routes when enabling the dhcp 2. Add empty listeners to Lb objects Change-Id: I1754bf565ebbc90889e2f04e124fc7c08eedbad6 --- vmware_nsx/api_replay/client.py | 14 +++++++++++--- vmware_nsx/api_replay/utils.py | 3 +++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/vmware_nsx/api_replay/client.py b/vmware_nsx/api_replay/client.py index 70cc017726..0b737916ee 100644 --- a/vmware_nsx/api_replay/client.py +++ b/vmware_nsx/api_replay/client.py @@ -565,6 +565,7 @@ class ApiReplayClient(utils.PrepareObjectForMigration): # Handle DHCP enabled subnets enable_dhcp = False + sub_host_routes = None if body['enable_dhcp']: count_dhcp_subnet = count_dhcp_subnet + 1 # disable dhcp on subnet: we will enable it after creating @@ -586,13 +587,17 @@ class ApiReplayClient(utils.PrepareObjectForMigration): enable_dhcp = False else: enable_dhcp = True + if body.get('host_routes'): + # Should be added when dhcp is enabled + sub_host_routes = body.pop('host_routes') try: created_subnet = self.dest_neutron.create_subnet( {'subnet': body})['subnet'] LOG.info("Created subnet: %s", created_subnet['id']) subnets_map[subnet_id] = created_subnet['id'] if enable_dhcp: - dhcp_subnets.append(created_subnet) + dhcp_subnets.append({'id': created_subnet['id'], + 'host_routes': sub_host_routes}) except n_exc.BadRequest as e: LOG.error("Failed to create subnet: %(subnet)s: %(e)s", {'subnet': subnet, 'e': e}) @@ -715,11 +720,14 @@ class ApiReplayClient(utils.PrepareObjectForMigration): 'ip': ip_addr, 'mac': created_port['mac_address']}) - # Enable dhcp on the relevant subnets: + # Enable dhcp on the relevant subnets, and re-add host routes: for subnet in dhcp_subnets: try: + data = {'enable_dhcp': True} + if subnet['host_routes']: + data['host_routes'] = subnet['host_routes'] self.dest_neutron.update_subnet(subnet['id'], - {'subnet': {'enable_dhcp': True}}) + {'subnet': data}) except Exception as e: LOG.error("Failed to enable DHCP on subnet %(subnet)s: " "%(e)s", diff --git a/vmware_nsx/api_replay/utils.py b/vmware_nsx/api_replay/utils.py index 58bbe468c1..b128a54fcc 100644 --- a/vmware_nsx/api_replay/utils.py +++ b/vmware_nsx/api_replay/utils.py @@ -315,18 +315,21 @@ class PrepareObjectForMigration(object): def prepare_lb_listener(self, listener_obj, lb_body): body = self.drop_fields(listener_obj, self.drop_lb_listener_fields) body['loadbalancer'] = lb_body + body['loadbalancer']['listeners'] = [] body['loadbalancer_id'] = lb_body['id'] return body def prepare_lb_pool(self, pool_obj, lb_body): body = self.drop_fields(pool_obj, self.drop_lb_pool_fields) body['loadbalancer'] = lb_body + body['loadbalancer']['listeners'] = [] body['loadbalancer_id'] = lb_body['id'] return body def prepare_lb_member(self, mem_obj, lb_body): body = self.drop_fields(mem_obj, self.drop_lb_member_fields) body['loadbalancer'] = lb_body + body['loadbalancer']['listeners'] = [] body['loadbalancer_id'] = lb_body['id'] return body