diff mbox

[Branch,~linaro-maintainers/linaro-image-tools/trunk] Rev 264: Add a test to make sure ensure_partition_is_not_mounted is not called when generating image files

Message ID 20110127184329.25975.3615.launchpad@loganberry.canonical.com
State Accepted
Headers show

Commit Message

Guilherme Salgado Jan. 27, 2011, 6:43 p.m. UTC
Merge authors:
  Guilherme Salgado (salgado)
Related merge proposals:
  https://code.launchpad.net/~salgado/linaro-image-tools/bug-701678/+merge/47688
  proposed by: Guilherme Salgado (salgado)
  review: Approve - James Westby (james-w)
------------------------------------------------------------
revno: 264 [merge]
fixes bug(s): https://launchpad.net/bugs/701678 https://launchpad.net/bugs/705571
committer: Guilherme Salgado <salgado@canonical.com>
branch nick: trunk
timestamp: Thu 2011-01-27 16:41:26 -0200
message:
  Add a test to make sure ensure_partition_is_not_mounted is not called when generating image files
modified:
  linaro_media_create/partitions.py
  linaro_media_create/tests/test_media_create.py


--
lp:linaro-image-tools
https://code.launchpad.net/~linaro-maintainers/linaro-image-tools/trunk

You are subscribed to branch lp:linaro-image-tools.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-maintainers/linaro-image-tools/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'linaro_media_create/partitions.py'
--- linaro_media_create/partitions.py	2011-01-26 18:03:50 +0000
+++ linaro_media_create/partitions.py	2011-01-27 16:39:37 +0000
@@ -54,15 +54,16 @@ 
     if media.is_block_device:
         bootfs, rootfs = get_boot_and_root_partitions_for_media(
             media, board_config)
-    else:
-        bootfs, rootfs = get_boot_and_root_loopback_devices(media.path)
-
-    if should_format_bootfs:
-        print "\nFormating boot partition\n"
         # It looks like KDE somehow automounts the partitions after you
         # repartition a disk so we need to unmount them here to create the
         # filesystem.
         ensure_partition_is_not_mounted(bootfs)
+        ensure_partition_is_not_mounted(rootfs)
+    else:
+        bootfs, rootfs = get_boot_and_root_loopback_devices(media.path)
+
+    if should_format_bootfs:
+        print "\nFormating boot partition\n"
         proc = cmd_runner.run(
             ['mkfs.vfat', '-F', str(board_config.fat_size), bootfs, '-n',
              bootfs_label],
@@ -72,7 +73,6 @@ 
     if should_format_rootfs:
         print "\nFormating root partition\n"
         mkfs = 'mkfs.%s' % rootfs_type
-        ensure_partition_is_not_mounted(rootfs)
         proc = cmd_runner.run(
             [mkfs, rootfs, '-L', rootfs_label],
             as_root=True)

=== modified file 'linaro_media_create/tests/test_media_create.py'
--- linaro_media_create/tests/test_media_create.py	2011-01-26 18:03:50 +0000
+++ linaro_media_create/tests/test_media_create.py	2011-01-27 17:19:03 +0000
@@ -161,7 +161,7 @@ 
         self.mock_all_boards_funcs()
 
     def mock_all_boards_funcs(self):
-        """Mock all functions of linaro_media_create.boards with a call tracer."""
+        """Mock functions of linaro_media_create.boards with a call tracer."""
 
         def mock_func_creator(name):
             return lambda *args, **kwargs: self.funcs_calls.append(name)
@@ -680,8 +680,15 @@ 
         popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())
         self.useFixture(MockSomethingFixture(
             sys, 'stdout', open('/dev/null', 'w')))
+        def ensure_partition_not_mounted(part):
+            raise AssertionError(
+                "ensure_partition_is_not_mounted must not be called when "
+                "generating image files. It makes no sense to do that and "
+                "it depends on UDisks, thus making it hard to run on a "
+                "chroot")
         self.useFixture(MockSomethingFixture(
-            partitions, 'is_partition_mounted', lambda part: False))
+            partitions,
+            'ensure_partition_is_not_mounted', ensure_partition_not_mounted))
         self.useFixture(MockSomethingFixture(
             partitions, 'get_boot_and_root_loopback_devices',
             lambda image: ('/dev/loop99', '/dev/loop98')))
@@ -724,8 +731,8 @@ 
              # Since the partitions are mounted, setup_partitions will umount
              # them before running mkfs.
              ['sudo', 'umount', bootfs_dev],
-             ['sudo', 'mkfs.vfat', '-F', '32', bootfs_dev, '-n', 'boot'],
              ['sudo', 'umount', rootfs_dev],
+             ['sudo', 'mkfs.vfat', '-F', '32', bootfs_dev, '-n', 'boot'],
              ['sudo', 'mkfs.ext3', rootfs_dev, '-L', 'root']],
             popen_fixture.mock.calls)