Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from autotest_lib.client.bin import test, utils | 5 from autotest_lib.client.bin import test, utils |
| 6 from autotest_lib.client.common_lib import error | 6 from autotest_lib.client.common_lib import error |
| 7 | 7 |
| 8 import dbus | 8 import dbus |
| 9 | 9 |
| 10 class platform_CrosDisksDBus(test.test): | 10 class platform_CrosDisksDBus(test.test): |
| 11 version = 1 | 11 version = 1 |
| 12 | 12 |
| 13 def validate_disk(self, disk): | |
| 14 # Disk properties provided by the API | |
| 15 disk_properties = ( | |
| 16 ('DeviceFile', dbus.String), | |
| 17 ('DeviceIsDrive', dbus.Boolean), | |
| 18 ('DeviceIsMediaAvailable', dbus.Boolean), | |
| 19 ('DeviceIsMounted', dbus.Boolean), | |
| 20 ('DeviceIsOpticalDisc', dbus.Boolean), | |
| 21 ('DeviceIsReadOnly', dbus.Boolean), | |
| 22 ('DeviceMountPaths', dbus.String), | |
| 23 ('DevicePresentationHide', dbus.Boolean), | |
| 24 ('DeviceSize', dbus.Int64), | |
| 25 ('DriveIsRotational', dbus.Boolean), | |
| 26 ('DriveModel', dbus.String), | |
| 27 ('IdLabel', dbus.String), | |
| 28 ('NativePath', dbus.String), | |
| 29 ) | |
| 30 | |
| 31 for (prop_name, prop_value_type) in disk_properties: | |
| 32 # Check if all disk properties are set. | |
| 33 if prop_name not in disk: | |
| 34 raise error.TestFail("disk.%s not found" % prop_name) | |
| 35 | |
| 36 # Check if each disk property has the right data type. | |
| 37 prop_value = disk[prop_name] | |
| 38 if not isinstance(prop_value, prop_value_type): | |
| 39 raise error.TestFail( | |
| 40 "disk.%s is %s, but %s expected" | |
| 41 % (prop_name, type(prop_value), prop_value_type)) | |
| 42 | |
| 43 # Check if DeviceFile has a proper value. | |
| 44 if not disk['DeviceFile']: | |
| 45 raise error.TestFail( | |
| 46 "disk.DeviceFile should not be empty") | |
| 47 | |
| 48 # Check if the values of DeviceIsMounted and DeviceMountPaths | |
| 49 # are consistent. | |
| 50 if disk['DeviceIsMounted']: | |
| 51 if not disk['DeviceMountPaths']: | |
| 52 raise error.TestFail( | |
| 53 "disk.DeviceMountPaths should not be empty " | |
| 54 "if disk.DeviceIsMounted is true") | |
| 55 else: | |
| 56 if disk['DeviceMountPaths']: | |
| 57 raise error.TestFail( | |
| 58 "disk.DeviceMountPaths should be empty " | |
| 59 "if disk.DeviceIsMounted is false") | |
| 60 | |
| 13 def run_once(self): | 61 def run_once(self): |
| 14 # TODO(rtc): Excercise the whole API. | 62 # TODO(rtc): Excercise the whole API. |
| 15 bus = dbus.SystemBus() | 63 bus = dbus.SystemBus() |
| 16 proxy = bus.get_object('org.chromium.CrosDisks', | 64 proxy = bus.get_object('org.chromium.CrosDisks', |
| 17 '/org/chromium/CrosDisks') | 65 '/org/chromium/CrosDisks') |
| 18 cros_disks = dbus.Interface(proxy, 'org.chromium.CrosDisks') | 66 cros_disks = dbus.Interface(proxy, 'org.chromium.CrosDisks') |
| 67 | |
| 68 # Check if CrosDisks server is alive. | |
|
rtc
2011/04/18 20:29:13
Can you pull these checks into different methods?
| |
| 19 is_alive = cros_disks.IsAlive() | 69 is_alive = cros_disks.IsAlive() |
| 20 if not is_alive: | 70 if not is_alive: |
| 21 raise error.TestFail("Unable to talk to the disk daemon") | 71 raise error.TestFail("Unable to talk to the disk daemon") |
| 72 | |
| 73 # Check if EnumerateDevices method returns a list of devices. | |
| 74 devices = cros_disks.EnumerateDevices() | |
| 75 for device in devices: | |
| 76 if not device or not isinstance(device, dbus.String): | |
| 77 raise error.TestFail( | |
| 78 "device returned by EnumerateDevices " | |
| 79 "should be a non-empty string") | |
| 80 | |
| 81 # Check if GetAll method returns a list of disk properties. | |
| 82 disks = cros_disks.GetAll() | |
| 83 for disk in disks: | |
| 84 self.validate_disk(disk) | |
| 85 | |
| 86 # Check if GetAll and EnumerateDevices return the same number | |
| 87 # of entries. | |
| 88 if len(disks) != len(devices): | |
| 89 raise error.TestFail( | |
| 90 "GetAll returns %d entries, " | |
| 91 "but EnumerateDevices returns %d entries" | |
| 92 % (len(disks), len(devices))) | |
| 93 | |
| OLD | NEW |