Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: client/site_tests/platform_CrosDisksDBus/platform_CrosDisksDBus.py

Issue 6873021: Test CrosDisks DBus API (Closed) Base URL: ssh://gitrw.chromium.org:9222/autotest.git@master
Patch Set: Update tests based on changes in CrosDisks DBus API Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_properties(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.Array),
23 ('DevicePresentationHide', dbus.Boolean),
24 ('DeviceSize', dbus.UInt64),
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 mount_paths = disk['DeviceMountPaths']
51 if disk['DeviceIsMounted']:
52 if len(mount_paths) == 0:
53 raise error.TestFail(
54 "disk.DeviceMountPaths should not be empty "
55 "if disk.DeviceIsMounted is true")
56 else:
57 if len(mount_paths) != 0:
58 raise error.TestFail(
59 "disk.DeviceMountPaths should be empty "
60 "if disk.DeviceIsMounted is false")
61
62 if mount_paths.signature != dbus.Signature('s'):
63 raise error.TestFail(
64 "disk.DeviceMountPaths should contain only strings")
65
66 for mount_path in mount_paths:
67 if not mount_path:
68 raise error.TestFail(
69 "disk.DeviceMountPaths should not contain any "
70 "empty string")
71
72 def test_is_alive(self):
73 # Check if CrosDisks server is alive.
74 is_alive = self.cros_disks.IsAlive()
75 if not is_alive:
76 raise error.TestFail("Unable to talk to the disk daemon")
77
78 def test_enumerate_device_files(self):
79 # Check if EnumerateDeviceFiles method returns a list of devices.
80 devices = self.cros_disks.EnumerateDeviceFiles()
81 for device in devices:
82 if not device or not isinstance(device, dbus.String):
83 raise error.TestFail(
84 "device returned by EnumerateDeviceFiles "
85 "should be a non-empty string")
86
87 def test_get_device_properties(self):
88 # Check if GetDeviceProperties method returns valid properties.
89 devices = self.cros_disks.EnumerateDeviceFiles()
90 for device in devices:
91 properties = self.cros_disks.GetDeviceProperties(device)
92 self.validate_disk_properties(properties)
93
94 def test_get_device_properties_of_nonexistent_device(self):
95 try:
96 properties = self.cros_disks.GetDeviceProperties('/nonexistent')
97 except dbus.DBusException:
98 return
99 raise error.TestFail(
100 "GetDeviceProperties of a nonexistent device should fail")
101
102 def test_mount_nonexistent_device(self):
103 try:
104 path = self.cros_disks.FilesystemMount('/nonexistent', '', [])
105 except dbus.DBusException:
106 return
107 raise error.TestFail("Mounting a nonexistent device should fail")
108
109 def test_unmount_nonexistent_device(self):
110 try:
111 self.cros_disks.FilesystemUnmount('/nonexistent', [])
112 except dbus.DBusException:
113 return
114 raise error.TestFail("Unmounting a nonexistent device should fail")
115
13 def run_once(self): 116 def run_once(self):
14 # TODO(rtc): Excercise the whole API.
15 bus = dbus.SystemBus() 117 bus = dbus.SystemBus()
16 proxy = bus.get_object('org.chromium.CrosDisks', 118 proxy = bus.get_object('org.chromium.CrosDisks',
17 '/org/chromium/CrosDisks') 119 '/org/chromium/CrosDisks')
18 cros_disks = dbus.Interface(proxy, 'org.chromium.CrosDisks') 120 self.cros_disks = dbus.Interface(proxy, 'org.chromium.CrosDisks')
19 is_alive = cros_disks.IsAlive() 121 self.test_is_alive()
20 if not is_alive: 122 self.test_enumerate_device_files()
21 raise error.TestFail("Unable to talk to the disk daemon") 123 self.test_get_device_properties()
124 self.test_get_device_properties_of_nonexistent_device()
125 self.test_mount_nonexistent_device()
126 self.test_unmount_nonexistent_device()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698