From patchwork Thu Dec 22 14:39:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georgy Redkozubov X-Patchwork-Id: 5955 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 80D2423E2D for ; Thu, 22 Dec 2011 14:39:15 +0000 (UTC) Received: from mail-ey0-f180.google.com (mail-ey0-f180.google.com [209.85.215.180]) by fiordland.canonical.com (Postfix) with ESMTP id 5A026A1864A for ; Thu, 22 Dec 2011 14:39:15 +0000 (UTC) Received: by eaac11 with SMTP id c11so5827787eaa.11 for ; Thu, 22 Dec 2011 06:39:15 -0800 (PST) Received: by 10.205.138.136 with SMTP id is8mr3150543bkc.35.1324564755103; Thu, 22 Dec 2011 06:39:15 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.205.82.144 with SMTP id ac16cs67025bkc; Thu, 22 Dec 2011 06:39:14 -0800 (PST) Received: by 10.205.119.139 with SMTP id fu11mr3177322bkc.56.1324564753316; Thu, 22 Dec 2011 06:39:13 -0800 (PST) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id cr8si16696964wib.12.2011.12.22.06.39.13 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 22 Dec 2011 06:39:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1Rdjnc-0003Pr-Uz for ; Thu, 22 Dec 2011 14:39:12 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id E01C6E0444 for ; Thu, 22 Dec 2011 14:39:12 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: linaro-image-tools X-Launchpad-Branch: ~linaro-image-tools/linaro-image-tools/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 479 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-image-tools/linaro-image-tools/trunk] Rev 479: [r=mabac] Add the ability to check for appearance of partitions to the UDisks service for the dev... Message-Id: <20111222143912.4764.41694.launchpad@ackee.canonical.com> Date: Thu, 22 Dec 2011 14:39:12 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="14487"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: c0b39bbe2cddb758bff2d6cddaade35dd46875fa Merge authors: Georgy Redkozubov (georgy-redkozubov) Related merge proposals: https://code.launchpad.net/~georgy-redkozubov/linaro-image-tools/717129/+merge/85478 proposed by: Georgy Redkozubov (georgy-redkozubov) review: Approve - Mattias Backman (mabac) ------------------------------------------------------------ revno: 479 [merge] committer: Georgy Redkozubov branch nick: lit-trunk timestamp: Thu 2011-12-22 18:36:11 +0400 message: [r=mabac] Add the ability to check for appearance of partitions to the UDisks service for the device being partitioned. Fixes bug 717129 modified: linaro_image_tools/media_create/partitions.py linaro_image_tools/media_create/tests/test_media_create.py --- lp:linaro-image-tools https://code.launchpad.net/~linaro-image-tools/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-image-tools/linaro-image-tools/trunk/+edit-subscription === modified file 'linaro_image_tools/media_create/partitions.py' --- linaro_image_tools/media_create/partitions.py 2011-07-28 01:24:21 +0000 +++ linaro_image_tools/media_create/partitions.py 2011-12-22 08:30:57 +0000 @@ -42,6 +42,9 @@ CYLINDER_SIZE = HEADS * SECTORS * SECTOR_SIZE DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties' UDISKS = "org.freedesktop.UDisks" +# Max number of attempts to sleep (total sleep time in seconds = +# 1+2+...+MAX_TTS) +MAX_TTS = 10 def setup_android_partitions(board_config, media, image_size, bootfs_label, @@ -428,14 +431,32 @@ """ # This could be simpler but UDisks doesn't make it easy for us: # https://bugs.freedesktop.org/show_bug.cgi?id=33113. - for dev_file in glob.glob("%s?*" % device): - device_path = _get_udisks_device_path(dev_file) - udisks_dev = dbus.SystemBus().get_object(UDISKS, device_path) - part_number = udisks_dev.Get( - device_path, 'PartitionNumber', dbus_interface=DBUS_PROPERTIES) - if part_number == partition: - return str(udisks_dev.Get( - device_path, 'DeviceFile', dbus_interface=DBUS_PROPERTIES)) + time_to_sleep = 1 + dev_files = glob.glob("%s?*" % device) + i = 0 + while i < len(dev_files): + dev_file = dev_files[i] + try: + device_path = _get_udisks_device_path(dev_file) + partition_str = _get_udisks_device_file(device_path, partition) + if partition_str: + return partition_str + i += 1 + except dbus.exceptions.DBusException, e: + if time_to_sleep > MAX_TTS: + print "We've waited long enough..." + raise + print "*" * 60 + print "UDisks doesn't know about %s: %s" % (dev_file, e) + bus = dbus.SystemBus() + manager = dbus.Interface( + bus.get_object(UDISKS, "/org/freedesktop/UDisks"), UDISKS) + print "This is what UDisks know about: %s" % ( + manager.EnumerateDevices()) + print "Sleeping for %d seconds" % time_to_sleep + time.sleep(time_to_sleep) + time_to_sleep += 1 + print "*" * 60 return None @@ -447,6 +468,16 @@ return udisks.get_dbus_method('FindDeviceByDeviceFile')(device) +def _get_udisks_device_file(path, part): + """Return the UNIX special device file for the given partition.""" + udisks_dev = dbus.SystemBus().get_object(UDISKS, path) + part_number = udisks_dev.Get( + path, 'PartitionNumber', dbus_interface=DBUS_PROPERTIES) + if part_number == part: + return str(udisks_dev.Get( + path, 'DeviceFile', dbus_interface=DBUS_PROPERTIES)) + + def convert_size_to_bytes(size): """Convert a size string in Kbytes, Mbytes or Gbytes to bytes.""" unit = size[-1].upper() === modified file 'linaro_image_tools/media_create/tests/test_media_create.py' --- linaro_image_tools/media_create/tests/test_media_create.py 2011-12-19 13:51:23 +0000 +++ linaro_image_tools/media_create/tests/test_media_create.py 2011-12-22 14:36:11 +0000 @@ -30,6 +30,7 @@ import types import struct import tarfile +import dbus from StringIO import StringIO from testtools import TestCase @@ -92,6 +93,7 @@ setup_partitions, get_uuid, _parse_blkid_output, + _get_device_file_for_partition_number, ) from linaro_image_tools.media_create.rootfs import ( append_to_fstab, @@ -2210,6 +2212,71 @@ '%s mkfs.ext3 %s -L root' % (sudo_args, rootfs_dev)], popen_fixture.mock.commands_executed) + def test_get_device_file_for_partition_number_raises_DBusException(self): + def mock_get_udisks_device_path(d): + raise dbus.exceptions.DBusException + + self.useFixture(MockSomethingFixture( + partitions, '_get_udisks_device_path', + mock_get_udisks_device_path)) + + tmpfile = self.createTempFileAsFixture() + partition = board_configs['beagle'].mmc_part_offset + + self.useFixture(MockSomethingFixture( + glob, 'glob', + lambda pathname: ['%s%d' % (tmpfile, partition)])) + + self.useFixture(MockSomethingFixture( + sys, 'stdout', open('/dev/null', 'w'))) + + media = Media(tmpfile) + media.is_block_device = True + self.assertRaises(dbus.exceptions.DBusException, + _get_device_file_for_partition_number, + media.path, partition) + + def test_get_device_file_for_partition_number(self): + class Namespace: pass + ns = Namespace() + ns.count = 0 + + def mock_get_udisks_device_path(dev): + ns.count += 1 + if ns.count < 5: + raise dbus.exceptions.DBusException + else: + return '/abc/123' + + def mock_get_udisks_device_file(dev, part): + if ns.count < 5: + raise dbus.exceptions.DBusException + else: + return '/abc/123' + + self.useFixture(MockSomethingFixture( + partitions, '_get_udisks_device_path', + mock_get_udisks_device_path)) + + self.useFixture(MockSomethingFixture( + partitions, '_get_udisks_device_file', + mock_get_udisks_device_file)) + + tmpfile = self.createTempFileAsFixture() + partition = board_configs['beagle'].mmc_part_offset + + self.useFixture(MockSomethingFixture( + glob, 'glob', + lambda pathname: ['%s%d' % (tmpfile, partition)])) + + self.useFixture(MockSomethingFixture( + sys, 'stdout', open('/dev/null', 'w'))) + + media = Media(tmpfile) + media.is_block_device = True + self.assertIsNotNone(_get_device_file_for_partition_number( + media.path, partition)) + class TestException(Exception): """Just a test exception."""