Real errors were not being reported, and instead several error messages from umount would appear. To fix this, we print out *all* exceptions that occur, not just P2VErrors. Also, we don't try to umount when /source is not mounted
Signed-off-by: Ben Lipton <[email protected]> --- p2v-transfer/p2v_transfer.py | 11 ++++++++--- p2v-transfer/test/p2v_transfer_test.py | 19 +++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/p2v-transfer/p2v_transfer.py b/p2v-transfer/p2v_transfer.py index 871e056..5df5e71 100755 --- a/p2v-transfer/p2v_transfer.py +++ b/p2v-transfer/p2v_transfer.py @@ -106,8 +106,11 @@ def EstablishConnection(user, host, key): client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.WarningPolicy()) client.load_system_host_keys() - client.connect(host, username=user, pkey=key, - allow_agent=False, look_for_keys=False) + try: + client.connect(host, username=user, pkey=key, + allow_agent=False, look_for_keys=False) + except IOError, e: + raise P2VError("Problem connecting to instance: %s" % e) DisplayCommandEnd("done") return client @@ -359,6 +362,8 @@ def UnmountSourceFilesystems(): """ for trynum in range(3): + if not os.path.exists(SOURCE_MOUNT) or not os.path.ismount(SOURCE_MOUNT): + return errcode = subprocess.call(["umount", SOURCE_MOUNT]) if not errcode: return @@ -415,7 +420,7 @@ def main(argv): ShutDownTarget(client) else: raise P2VError("Instance kernel not present on source OS") - except P2VError, e: + except Exception, e: # Make sure any error gets printed out print e sys.exit(1) finally: diff --git a/p2v-transfer/test/p2v_transfer_test.py b/p2v-transfer/test/p2v_transfer_test.py index 8e521f4..52ee291 100755 --- a/p2v-transfer/test/p2v_transfer_test.py +++ b/p2v-transfer/test/p2v_transfer_test.py @@ -266,16 +266,27 @@ EOF self.mox.VerifyAll() def testUnmountSourceFilesystemsExitsOnError(self): + self.mox.StubOutWithMock(self.module.os.path, "exists") + self.mox.StubOutWithMock(self.module.os.path, "ismount") command_list = ["umount", self.module.SOURCE_MOUNT] - # Will retry twice before quitting - self._MockSubprocessCallFailure(command_list) - self._MockSubprocessCallFailure(command_list) - self._MockSubprocessCallFailure(command_list) + + for trynum in range(3): + self.module.os.path.exists(self.module.SOURCE_MOUNT).AndReturn(True) + self.module.os.path.ismount(self.module.SOURCE_MOUNT).AndReturn(True) + + # Will retry twice before quitting + self._MockSubprocessCallFailure(command_list) + self.mox.ReplayAll() self.assertRaises(SystemExit, self.module.UnmountSourceFilesystems) self.mox.VerifyAll() def testUnmountSourceFilesystemsCallsUmount(self): + self.mox.StubOutWithMock(self.module.os.path, "exists") + self.mox.StubOutWithMock(self.module.os.path, "ismount") + + self.module.os.path.exists(self.module.SOURCE_MOUNT).AndReturn(True) + self.module.os.path.ismount(self.module.SOURCE_MOUNT).AndReturn(True) command_list = ["umount", self.module.SOURCE_MOUNT] self._MockSubprocessCallSuccess(command_list) self.mox.ReplayAll() -- 1.7.3.1
