MP2P migration: enhance pre-migration checks

- Add a utility that can run the pre-checks separatly with:
nsxadmin -r nsx-migrate-t2p -o validate
- Add the nsx version check
- Verify no DHCP relay config
- Add unit tests to the migration utilities

Change-Id: I49b7402c38ade40df97a2aabc84a41fe29f23731
This commit is contained in:
asarfaty 2020-07-19 07:08:30 +02:00 committed by Adit Sarfaty
parent f73cd449a9
commit 88701ce4aa
4 changed files with 73 additions and 30 deletions

View File

@ -595,6 +595,10 @@ Config
T2P migration T2P migration
~~~~~~~~~~~~~ ~~~~~~~~~~~~~
- Verify the current configuration can be migrated to Policy::
nsxadmin -r nsx-migrate-t2p -o validate
- Migrate NSX resources and neutron DB from NSX-T (MP) to Policy:: - Migrate NSX resources and neutron DB from NSX-T (MP) to Policy::
nsxadmin -r nsx-migrate-t2p -o import --property logfile=<> (--verbose) nsxadmin -r nsx-migrate-t2p -o import --property logfile=<> (--verbose)

View File

@ -1101,11 +1101,6 @@ def migrate_lb_services(nsxlib, nsxpolicy):
def migrate_t_resources_2_p(nsxlib, nsxpolicy, plugin): def migrate_t_resources_2_p(nsxlib, nsxpolicy, plugin):
"""Create policy resources for all MP resources used by neutron""" """Create policy resources for all MP resources used by neutron"""
nsx_version = nsxlib.get_version()
if not nsx_utils.is_nsx_version_3_1_0(nsx_version):
LOG.error("Migration not supported for NSX %s", nsx_version)
return False
# Initialize the migration process # Initialize the migration process
if not ensure_migration_state_ready(nsxlib, with_abort=True): if not ensure_migration_state_ready(nsxlib, with_abort=True):
return False return False
@ -1376,8 +1371,12 @@ def edge_firewall_migration_cond(resource):
def pre_migration_checks(nsxlib, plugin): def pre_migration_checks(nsxlib, plugin):
"""Check for unsupported configuration that will block the migration """Check for unsupported configuration that will fail the migration"""
""" nsx_version = nsxlib.get_version()
if not nsx_utils.is_nsx_version_3_1_0(nsx_version):
LOG.error("Pre migration check failed: Migration not supported for "
"NSX %s", nsx_version)
return False
# Cannot migrate with unsupported services # Cannot migrate with unsupported services
service_plugins = cfg.CONF.service_plugins service_plugins = cfg.CONF.service_plugins
@ -1420,11 +1419,31 @@ def pre_migration_checks(nsxlib, plugin):
MIGRATE_LIMIT_SECTION_AND_RULES) MIGRATE_LIMIT_SECTION_AND_RULES)
return False return False
# DHCP relay is unsupported
if plugin._availability_zones_data.dhcp_relay_configured():
LOG.error("Pre migration check failed: DHCP relay configuration "
"cannot be migrated. Please remove it from the plugin "
"configuration and from all NSX logical router ports and "
"try again.")
return False
return True return True
@admin_utils.output_header @admin_utils.output_header
def t_2_p_migration(resource, event, trigger, **kwargs): def MP2Policy_pre_migration_check(resource, event, trigger, **kwargs):
"""Verify if the current configuration can be migrated to Policy"""
nsxlib = utils.get_connected_nsxlib()
with utils.NsxV3PluginWrapper() as plugin:
if not pre_migration_checks(nsxlib, plugin):
# Failed
LOG.error("T2P migration cannot run. Please fix the configuration "
"and try again\n\n")
exit(1)
@admin_utils.output_header
def MP2Policy_migration(resource, event, trigger, **kwargs):
"""Migrate NSX resources and neutron DB from NSX-T (MP) to Policy""" """Migrate NSX resources and neutron DB from NSX-T (MP) to Policy"""
verbose = kwargs.get('verbose', False) verbose = kwargs.get('verbose', False)
@ -1452,20 +1471,21 @@ def t_2_p_migration(resource, event, trigger, **kwargs):
'nsx_api_managers', 'nsx_api_managers',
[cfg.CONF.nsx_v3.nsx_api_managers[0]], [cfg.CONF.nsx_v3.nsx_api_managers[0]],
'nsx_v3') 'nsx_v3')
if (len(cfg.CONF.nsx_v3.nsx_api_user) and # Make sure user & password are set in the config
len(cfg.CONF.nsx_v3.nsx_api_password)): if (len(cfg.CONF.nsx_v3.nsx_api_user) and
cfg.CONF.set_override( len(cfg.CONF.nsx_v3.nsx_api_password)):
'nsx_api_user', cfg.CONF.set_override(
[cfg.CONF.nsx_v3.nsx_api_user[0]], 'nsx_api_user',
'nsx_v3') [cfg.CONF.nsx_v3.nsx_api_user[0]],
cfg.CONF.set_override( 'nsx_v3')
'nsx_api_password', cfg.CONF.set_override(
[cfg.CONF.nsx_v3.nsx_api_password[0]], 'nsx_api_password',
'nsx_v3') [cfg.CONF.nsx_v3.nsx_api_password[0]],
else: 'nsx_v3')
LOG.error("Please provide nsx_api_user and nsx_api_password " else:
"in the configuration") LOG.error("Please provide nsx_api_user and nsx_api_password "
return "in the configuration")
exit(1)
retriables = [nsxlib_exc.APITransactionAborted, retriables = [nsxlib_exc.APITransactionAborted,
nsxlib_exc.ServerBusy] nsxlib_exc.ServerBusy]
@ -1492,7 +1512,7 @@ def t_2_p_migration(resource, event, trigger, **kwargs):
# Failed # Failed
LOG.error("T2P migration cannot run. Please fix the configuration " LOG.error("T2P migration cannot run. Please fix the configuration "
"and try again\n\n") "and try again\n\n")
return exit(1)
elapsed_time = time.time() - start_time elapsed_time = time.time() - start_time
LOG.debug("Pre-migration took %s seconds", elapsed_time) LOG.debug("Pre-migration took %s seconds", elapsed_time)
@ -1500,7 +1520,7 @@ def t_2_p_migration(resource, event, trigger, **kwargs):
if not migrate_t_resources_2_p(nsxlib, nsxpolicy, plugin): if not migrate_t_resources_2_p(nsxlib, nsxpolicy, plugin):
# Failed # Failed
LOG.error("T2P migration failed. Aborting\n\n") LOG.error("T2P migration failed. Aborting\n\n")
return exit(1)
elapsed_time = time.time() - start_time elapsed_time = time.time() - start_time
LOG.debug("Migration took %s seconds", elapsed_time) LOG.debug("Migration took %s seconds", elapsed_time)
@ -1513,7 +1533,7 @@ def t_2_p_migration(resource, event, trigger, **kwargs):
@admin_utils.output_header @admin_utils.output_header
def cleanup_db_mappings(resource, event, trigger, **kwargs): def MP2Policy_cleanup_db_mappings(resource, event, trigger, **kwargs):
"""Delete all entries from nsx-t mapping tables in DB""" """Delete all entries from nsx-t mapping tables in DB"""
confirm = admin_utils.query_yes_no( confirm = admin_utils.query_yes_no(
"Are you sure you want to delete all MP plugin mapping DB tables?", "Are you sure you want to delete all MP plugin mapping DB tables?",
@ -1543,10 +1563,14 @@ def cleanup_db_mappings(resource, event, trigger, **kwargs):
LOG.info("Deleted all MP plugin mapping DB tables.") LOG.info("Deleted all MP plugin mapping DB tables.")
registry.subscribe(t_2_p_migration, registry.subscribe(MP2Policy_migration,
constants.NSX_MIGRATE_T_P, constants.NSX_MIGRATE_T_P,
shell.Operations.IMPORT.value) shell.Operations.IMPORT.value)
registry.subscribe(cleanup_db_mappings, registry.subscribe(MP2Policy_pre_migration_check,
constants.NSX_MIGRATE_T_P,
shell.Operations.VALIDATE.value)
registry.subscribe(MP2Policy_cleanup_db_mappings,
constants.NSX_MIGRATE_T_P, constants.NSX_MIGRATE_T_P,
shell.Operations.CLEAN_ALL.value) shell.Operations.CLEAN_ALL.value)

View File

@ -157,7 +157,8 @@ nsxv3_resources = {
[Operations.SHOW.value]), [Operations.SHOW.value]),
constants.NSX_MIGRATE_T_P: Resource(constants.NSX_MIGRATE_T_P, constants.NSX_MIGRATE_T_P: Resource(constants.NSX_MIGRATE_T_P,
[Operations.IMPORT.value, [Operations.IMPORT.value,
Operations.CLEAN_ALL.value]), Operations.CLEAN_ALL.value,
Operations.VALIDATE.value]),
} }
# Add supported NSX-V resources in this dictionary # Add supported NSX-V resources in this dictionary

View File

@ -42,6 +42,7 @@ from vmware_nsx.tests import unit as vmware
from vmware_nsx.tests.unit.nsx_p import test_plugin as test_p_plugin from vmware_nsx.tests.unit.nsx_p import test_plugin as test_p_plugin
from vmware_nsx.tests.unit.nsx_v import test_plugin as test_v_plugin from vmware_nsx.tests.unit.nsx_v import test_plugin as test_v_plugin
from vmware_nsx.tests.unit.nsx_v3 import test_plugin as test_v3_plugin from vmware_nsx.tests.unit.nsx_v3 import test_plugin as test_v3_plugin
from vmware_nsxlib.v3 import client as v3_client
from vmware_nsxlib.v3 import core_resources from vmware_nsxlib.v3 import core_resources
from vmware_nsxlib.v3 import resources as nsx_v3_resources from vmware_nsxlib.v3 import resources as nsx_v3_resources
from vmware_nsxlib.v3 import security as nsx_v3_security from vmware_nsxlib.v3 import security as nsx_v3_security
@ -306,8 +307,8 @@ class TestNsxv3AdminUtils(AbstractTestAdminUtils,
for cls in (nsx_v3_resources.LogicalPort, for cls in (nsx_v3_resources.LogicalPort,
nsx_v3_resources.LogicalDhcpServer, nsx_v3_resources.LogicalDhcpServer,
core_resources.NsxLibLogicalRouter, core_resources.NsxLibLogicalRouter,
core_resources.NsxLibSwitchingProfile): core_resources.NsxLibSwitchingProfile,
v3_client.RESTClient):
self._patch_object(cls, 'list', return_value={'results': []}) self._patch_object(cls, 'list', return_value={'results': []})
self._patch_object(cls, 'get', self._patch_object(cls, 'get',
return_value={'id': uuidutils.generate_uuid()}) return_value={'id': uuidutils.generate_uuid()})
@ -321,6 +322,19 @@ class TestNsxv3AdminUtils(AbstractTestAdminUtils,
return_value={'members': [{ return_value={'members': [{
'target_type': 'LogicalPort', 'target_type': 'LogicalPort',
'target_id': 'port_id'}]}) 'target_id': 'port_id'}]})
# Mocks for MP2P migration
mock.patch("vmware_nsxlib.v3.NsxLib.get_version",
return_value='3.1.0').start()
mock.patch("vmware_nsx.shell.admin.plugins.nsxv3.resources.migration."
"ensure_migration_state_ready", return_value=True).start()
mock.patch("vmware_nsx.shell.admin.plugins.nsxv3.resources.migration."
"change_migration_service_status").start()
cfg.CONF.set_override('nsx_api_managers', ['1.1.1.1'], 'nsx_v3')
cfg.CONF.set_override('nsx_api_user', ['admin'], 'nsx_v3')
cfg.CONF.set_override('nsx_api_password', ['dummy'], 'nsx_v3')
super(TestNsxv3AdminUtils, self)._init_mock_plugin() super(TestNsxv3AdminUtils, self)._init_mock_plugin()
self._plugin = nsxv3_utils.NsxV3PluginWrapper() self._plugin = nsxv3_utils.NsxV3PluginWrapper()