From c3849602196139ec61c27699b34f04825e565b44 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Wed, 8 Sep 2021 06:32:46 -0700 Subject: [PATCH] Change order of MP2P migration Ensure resources are migrated in the expected order. Address global-variable-not-assigned (W0602) im migration.py Also update .pylintrc for ignoring consider-using-f-string (C0209) Change-Id: Ie8361af6a5bcecea0757c8c04fef85f548db3a06 --- .pylintrc | 1 + .../admin/plugins/nsxv/resources/migration.py | 2 -- .../plugins/nsxv3/resources/migration.py | 23 ++++++++++++------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.pylintrc b/.pylintrc index 0e682dc790..d183d03d06 100644 --- a/.pylintrc +++ b/.pylintrc @@ -53,6 +53,7 @@ disable= # bad-continuation, consider-iterating-dictionary, consider-using-enumerate, + consider-using-f-string, invalid-name, len-as-condition, # misplaced-comparison-constant, diff --git a/vmware_nsx/shell/admin/plugins/nsxv/resources/migration.py b/vmware_nsx/shell/admin/plugins/nsxv/resources/migration.py index 77ea2fbb66..0084b287a7 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv/resources/migration.py +++ b/vmware_nsx/shell/admin/plugins/nsxv/resources/migration.py @@ -69,7 +69,6 @@ n_warnings = 0 def log_error(msg): - global all_errors global n_errors LOG.info("ERROR: %s", msg) all_errors.append(msg) @@ -77,7 +76,6 @@ def log_error(msg): def log_warning(msg): - global all_warnings global n_warnings LOG.info("WARNING: %s", msg) all_warnings.append(msg) diff --git a/vmware_nsx/shell/admin/plugins/nsxv3/resources/migration.py b/vmware_nsx/shell/admin/plugins/nsxv3/resources/migration.py index 8c81781d04..844a49b35b 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv3/resources/migration.py +++ b/vmware_nsx/shell/admin/plugins/nsxv3/resources/migration.py @@ -1159,7 +1159,6 @@ def migrate_edge_firewalls(nsxlib, nsxpolicy, plugin): plugin.nsxpolicy = nsxpolicy ctx = context.get_admin_context() routers = plugin.get_routers(ctx) - global NSX_ROUTER_SECTIONS for rtr in routers: nsx_router_id = db.get_nsx_router_id(ctx.session, rtr['id']) nsx_rtr = nsxlib.logical_router.get(nsx_router_id) @@ -1320,19 +1319,29 @@ def migrate_t_resources_2_p(nsxlib, nsxpolicy, plugin, start_migration_process(nsxlib) # Migration order derives from the dependencies between resources - public_switches, tier0s = migrate_tier0s(nsxlib, nsxpolicy, plugin) - migrate_md_proxies(nsxlib, nsxpolicy, plugin) - migrate_switch_profiles(nsxlib, nsxpolicy, plugin) - migrate_groups(nsxlib, nsxpolicy) + # Migrate DHCP server migrate_dhcp_servers(nsxlib, nsxpolicy) + # Migrate Tier0 routers + public_switches, tier0s = migrate_tier0s(nsxlib, nsxpolicy, plugin) + # Migrate Tier1 routers mp_routers = migrate_routers(nsxlib, nsxpolicy) + # Migrate switch profiles + migrate_switch_profiles(nsxlib, nsxpolicy, plugin) + # Migrate MD Proxies + migrate_md_proxies(nsxlib, nsxpolicy, plugin) + # Migrate logical switches mp_networks = migrate_networks(nsxlib, nsxpolicy, plugin, public_switches) + # Migrate logical ports including Tier1 router ports migrate_ports(nsxlib, nsxpolicy, plugin, mp_networks) + # Migrate static routes and NAT config migrate_routers_config(nsxlib, nsxpolicy, plugin, mp_routers) + # Migrate Tier0 router ports and configuration migrate_tier0_config(nsxlib, nsxpolicy, tier0s) + # Migrate NS groups + migrate_groups(nsxlib, nsxpolicy) + # Migrate Lb profiles, monitors, pools, virtual servers, and services migrate_lb_resources(nsxlib, nsxpolicy) - # Migrate firewall sections last as those take the longest to rollback # in case of error migrate_dfw_sections(nsxlib, nsxpolicy, plugin) @@ -1357,7 +1366,6 @@ def migrate_t_resources_2_p(nsxlib, nsxpolicy, plugin, except Exception as e: LOG.error("Abort migration failed: %s", e) - global ROLLBACK_DATA if ROLLBACK_DATA: LOG.info("Rolling migration back %s", ROLLBACK_DATA) send_rollback_request({'migration_data': ROLLBACK_DATA}) @@ -1539,7 +1547,6 @@ def post_migration_actions(nsxlib, nsxpolicy, nsxpolicy_admin, plugin): break # -- Delete MP edge firewall rules - global NSX_ROUTER_SECTIONS for section in NSX_ROUTER_SECTIONS: # make sure the policy section was already realized # with runtime_status=SUCESS