Instead of using a dictionary, which iterates through its items in an
arbitrary order, return the filesystems in a list of device, mount point
pairs. Add a unit test to verify this behavior.

Signed-off-by: Ben Lipton <[email protected]>
---
 p2v-transfer/p2v_transfer.py           |   12 +++++-------
 p2v-transfer/test/p2v_transfer_test.py |   19 ++++++++++++++++++-
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/p2v-transfer/p2v_transfer.py b/p2v-transfer/p2v_transfer.py
index 446673c..20fd500 100755
--- a/p2v-transfer/p2v_transfer.py
+++ b/p2v-transfer/p2v_transfer.py
@@ -173,14 +173,13 @@ def MountSourceFilesystems(fs_devs):
   make sure it's empty (though it really should be, since we're probably
   running off LiveCD/PXE)
 
-  @type fs_devs: dict
-  @param fs_devs: Dictionary mapping devices with normal filesystems to mount
-    points
+  @type fs_devs: list
+  @param fs_devs: List of device, mount point tuples.
 
   """
   DisplayCommandStart("Mounting filesystems to copy...")
 
-  for dev, mount_point in fs_devs.iteritems():
+  for dev, mount_point in fs_devs:
     if mount_point == "/":
       continue
 
@@ -443,11 +442,10 @@ def UnmountSourceFilesystems(fs_devs):
   of times in case the filesystem is busy the first time.
 
   @type fs_devs: dict
-  @param fs_devs: Dictionary mapping devices with normal filesystems to mount
-    points
+  @param fs_devs: List of device, mount point tuples.
 
   """
-  for mount in reversed(fs_devs.values()):
+  for _, mount in reversed(fs_devs):
     if mount == "/":
       mount = SOURCE_MOUNT
     elif mount[0] == os.sep:
diff --git a/p2v-transfer/test/p2v_transfer_test.py 
b/p2v-transfer/test/p2v_transfer_test.py
index 27fc1d3..5b0b0d7 100755
--- a/p2v-transfer/test/p2v_transfer_test.py
+++ b/p2v-transfer/test/p2v_transfer_test.py
@@ -70,7 +70,7 @@ class P2vtransferTest(unittest.TestCase):
     self.swapsize = 1024
     self.totsize = 102400
 
-    self.fs_devs = { self.root_dev: "/" }
+    self.fs_devs = [(self.root_dev, "/")]
     self.swap_devs = ["/dev/sda5"]
 
     self.opts = self.module.optparse.Values()
@@ -421,6 +421,23 @@ EOF
     self.assertTrue(res is self.client)
     self.mox.VerifyAll()
 
+  def testMountSourceFilesystemsMountsFilesystemsInOrder(self):
+    dev1 = "/dev/sda2"
+    dev2 = "/dev/sda5"
+    fs_devs1 = [("/dev/sda1", "/"), (dev1, "/usr"), (dev2, "/usr/local")]
+    fs_devs2 = [("/dev/sda1", "/"), (dev2, "/usr"), (dev1, "/usr/local")]
+    for devpair in fs_devs1[1:]:
+      self._MockSubprocessCallSuccess(["mount", devpair[0],
+                                       self.module.SOURCE_MOUNT + devpair[1]])
+    for devpair in fs_devs2[1:]:
+      self._MockSubprocessCallSuccess(["mount", devpair[0],
+                                       self.module.SOURCE_MOUNT + devpair[1]])
+
+    self.mox.ReplayAll()
+    self.module.MountSourceFilesystems(fs_devs1)
+    self.module.MountSourceFilesystems(fs_devs2)
+    self.mox.VerifyAll()
+
 
 if __name__ == "__main__":
   unittest.main()
-- 
1.7.3.1

Reply via email to