From 4b7d6d5099ea7d944a03c4cb0e61b00a3bed3db8 Mon Sep 17 00:00:00 2001 From: meow Date: Mon, 30 Dec 2019 21:14:08 +0500 Subject: [PATCH] Bug fixed in migration code --- ucloud/vmm/__init__.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/ucloud/vmm/__init__.py b/ucloud/vmm/__init__.py index 3d3c304..d64473b 100644 --- a/ucloud/vmm/__init__.py +++ b/ucloud/vmm/__init__.py @@ -57,6 +57,7 @@ class TransferVM(Process): os.remove(self.src_sock_path) command = [ + "sudo" "ssh", "-nNT", "-L", @@ -73,9 +74,7 @@ class TransferVM(Process): else: time.sleep(2) vmm = VMM() - logger.debug( - "Executing: ssh forwarding command: %s", command - ) + logger.debug("Executing: ssh forwarding command: %s", command) vmm.execute_command( self.src_uuid, command="migrate", @@ -83,22 +82,20 @@ class TransferVM(Process): ) while p.poll() is None: - success, output = vmm.execute_command( - self.src_uuid, command="query-migrate" - ) + success, output = vmm.execute_command(self.src_uuid, command="query-migrate") if success: status = output["return"]["status"] - - if status != "active": - print("Migration Status: ", status) - if status == "completed": - vmm.stop(self.src_uuid) + logger.info('Migration Status: {}'.format(status)) + if status == "completed": + vmm.stop(self.src_uuid) + return + elif status in ['failed', 'cancelled']: return - else: - print("Migration Status: ", status) else: + logger.error("Couldn't be able to query VM {} that was in migration".format(self.src_uuid)) return - time.sleep(0.2) + + time.sleep(2) class VMM: