[MP2P] Avoid starting migration while component is in progress

In some cases the migration code might move to the next bunch of objects
while the MP_TO_POLICY_MIGRATION component is still progressing.
This will cause the process to fail as the code will refuse to proceed to
the next migration and the whole process will be aborted.

This change ensures the MP_TO_POLICY_MIGRATION component is in SUCCESS
state before moving on to the next bunch of objects.

Change-Id: Id357538f2a38891dda32386f8da945a5b1d2f4a1
This commit is contained in:
Salvatore Orlando 2021-08-20 08:15:20 -07:00 committed by Salvatore Orlando
parent 435294cdae
commit e5e0808cfd
1 changed files with 21 additions and 2 deletions

View File

@ -213,6 +213,22 @@ def verify_component_status(nsxlib, component_number):
return COMPONENT_STATUS_OK
def wait_for_component_success(nsxlib, component_number):
while True:
status = get_migration_status(nsxlib)
try:
component_status = (
status['component_status'][component_number].get('status'))
except IndexError:
LOG.error("Unable to fetch component #%d. Migrator status: %s",
component_number, status)
if component_status == POLICY_API_STATUS_SUCCESS:
return
LOG.debug("Component #%d status is %s. Waiting 5 seconds",
component_number, component_status)
time.sleep(5)
def wait_on_overall_migration_status_to_pause(nsxlib):
while True:
status = get_migration_status(nsxlib)
@ -220,7 +236,7 @@ def wait_on_overall_migration_status_to_pause(nsxlib):
if (migration_status == POLICY_API_STATUS_PAUSED or
migration_status == POLICY_API_STATUS_SUCCESS):
break
time.sleep(1)
time.sleep(5)
def printable_resource_name(resource):
@ -378,7 +394,10 @@ def migrate_objects(nsxlib, data, use_admin=False):
global ROLLBACK_DATA
# rollback should be done in the reverse order
ROLLBACK_DATA = [data] + ROLLBACK_DATA
LOG.debug("Ensuring MP_TO_POLICY_MIGRATION component is success "
"before moving on to next migration")
wait_for_component_success(nsxlib, 1)
LOG.debug("Migration completed for %d objects", len(data['resource_ids']))
return True