Author: gnichols
Date: 2012-01-20 17:45:36 +0000 (Fri, 20 Jan 2012)
New Revision: 1156
Added:
trunk/v7/dbusDevice.py
trunk/v7/udisksDeviceDetector.py
Modified:
trunk/v7/certificationtest.py
trunk/v7/device.py
trunk/v7/deviceclassdocument.py
trunk/v7/tags.py
Log:
Bug 782197 - FEAT: v7 should support dbus udisks in place of hal/kudzu/hardware.py for storage test
Modified: trunk/v7/certificationtest.py
===================================================================
--- trunk/v7/certificationtest.py 2012-01-20 17:41:14 UTC (rev 1155)
+++ trunk/v7/certificationtest.py 2012-01-20 17:45:36 UTC (rev 1156)
@@ -134,7 +134,7 @@
def appendDevice(self, device):
for name in self.deviceClasses:
if self.deviceClasses[name].registerDevice(device):
- # print "%s registered device %s" % (name, device.getUDI())
+ print "%s registered device %s" % (name, device.getUDI())
pass
def setOS(self, tag, value):
Added: trunk/v7/dbusDevice.py
===================================================================
--- trunk/v7/dbusDevice.py (rev 0)
+++ trunk/v7/dbusDevice.py 2012-01-20 17:45:36 UTC (rev 1156)
@@ -0,0 +1,111 @@
+# Copyright (c) 2012 Red Hat, Inc. All rights reserved. This copyrighted material
+# is made available to anyone wishing to use, modify, copy, or
+# redistribute it subject to the terms and conditions of the GNU General
+# Public License v.2.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# Author: Greg Nichols
+#
+import string
+import os
+import sys
+import dbus
+
+from tags import Constants
+from device import Device
+
+class DBusDevice(Device):
+ def __init__(self, dbusClass, dbusObject):
+ Device.__init__(self)
+ self.dbusClass = dbusClass
+ self.dbusObject = dbusObject
+ self.dbusInterface = dbus.Interface(self.dbusObject, dbus.PROPERTIES_IFACE)
+ self.getProperties()
+
+ def dump(self):
+ print "\nUDI: " + self.getUDI() + "\n----------------------------------------"
+ # print self.dbusObject.Introspect()
+ for (name, value) in self.getProperties().iteritems():
+ print "%s: %s" % (name, value)
+
+
+ def getProperty(self, name):
+ try:
+ return self.dbusObject.Get(self.dbusClass, name)
+ except:
+ return ""
+
+ def getProperties(self):
+ # refresh them
+ self.properties = dict()
+ for (property, value) in self.dbusObject.GetAll(self.dbusClass).iteritems():
+ # skip binary blobs alltogether
+ if "Blob" in property:
+ continue
+ # convert list values to strings with comma separation
+ try:
+ if isinstance(value, dbus.Array):
+ value = ", ".join(value)
+ except TypeError:
+ pass
+ self.properties[property] = value
+ return self.properties
+
+
+class UDisksDevice(DBusDevice):
+
+ def __init__(self, object):
+ DBusDevice.__init__(self, dbusClass="org.freedesktop.UDisks.Device", dbusObject=object)
+ self.setUDI(self.getProperty("NativePath"))
+
+ def dump(self):
+ DBusDevice.dump(self)
+ for attribute in ["DeviceFile", "NativePath", "IdLabel", "IdUsage", "IdUuid", "DeviceSize"]:
+ print attribute + ": " + str(self.getProperty(attribute))
+
+ def getMountPaths(self):
+ paths = list()
+ if self.getProperty("DeviceIsMounted"):
+ paths = self.getProperty("DeviceMountPaths")
+ return paths
+
+ def getSource(self):
+ return Constants.udisks
+
+
+
+class UDisksDrive(UDisksDevice):
+
+ def __init__(self, object):
+ UDisksDevice.__init__(self, object)
+
+ def dump(self):
+ UDisksDevice.dump(self)
+
+ def getProduct(self):
+ return self.getProperty("DriveModel")
+
+class UDisksPartition(UDisksDevice):
+
+ def __init__(self, object):
+ UDisksDevice.__init__(self, object)
+
+class UDisksAdapter(DBusDevice):
+
+ def __init__(self, object):
+ DBusDevice.__init__(self, dbusClass="org.freedesktop.UDisks.Adapter", dbusObject=object)
+ self.setUDI(self.getProperty("NativePath"))
+
+ def getSource(self):
+ return Constants.udisks
+
+ def getProduct(self):
+ return self.getProperty("Model")
+
Modified: trunk/v7/device.py
===================================================================
--- trunk/v7/device.py 2012-01-20 17:41:14 UTC (rev 1155)
+++ trunk/v7/device.py 2012-01-20 17:45:36 UTC (rev 1156)
@@ -37,10 +37,10 @@
return None
def getUDI(self):
- return self.getProperty(Constants.info_dot_udi)
+ return self.udi
def setUDI(self, udi):
- self.properties[Constants.info_dot_udi] = udi
+ self.udi = udi
def getClass(self):
return self.deviceClass
Modified: trunk/v7/deviceclassdocument.py
===================================================================
--- trunk/v7/deviceclassdocument.py 2012-01-20 17:41:14 UTC (rev 1155)
+++ trunk/v7/deviceclassdocument.py 2012-01-20 17:45:36 UTC (rev 1156)
@@ -24,6 +24,7 @@
from testdocument import TestDocument
import version
from deviceDetector import DeviceDetector
+from dbusDevice import UDisksDevice, UDisksDrive
# A DeviceClassDocument is a collection of devices and tests for those devices
@@ -45,9 +46,9 @@
def registerDevice(self, device):
if self.hasDevice(device):
- self.appendDevice(device)
if self.getName() != "system":
device.setClass(self.getName())
+ self.appendDevice(device)
return True
return False
@@ -245,6 +246,9 @@
self.setFunction(SystemFunction.storage)
def hasDevice(self, device):
+
+ if device.getSource() == Constants.udisks and isinstance(device, UDisksDrive) and device.getProperty("DeviceIsSystemInternal"):
+ return True
if (device.getSource() == Constants.hal
and ('storage' in device.getProperty("info.capabilities")
or device.getProperty("info.linux.driver") == "cciss"
Modified: trunk/v7/tags.py
===================================================================
--- trunk/v7/tags.py 2012-01-20 17:41:14 UTC (rev 1155)
+++ trunk/v7/tags.py 2012-01-20 17:45:36 UTC (rev 1156)
@@ -31,6 +31,7 @@
arch="arch"
test="test"
hal="hal"
+ udisks="udisks"
kudzu="kudzu"
system="system"
output="output"
@@ -135,6 +136,7 @@
forced = "forced"
ALL = "ALL"
hal = "hal"
+ udisks="udisks"
kudzu = "kudzu"
proc = "proc"
user = "user"
Added: trunk/v7/udisksDeviceDetector.py
===================================================================
--- trunk/v7/udisksDeviceDetector.py (rev 0)
+++ trunk/v7/udisksDeviceDetector.py 2012-01-20 17:45:36 UTC (rev 1156)
@@ -0,0 +1,85 @@
+#!/usr/bin/python
+# Copyright (c) 2012 Red Hat, Inc. All rights reserved. This copyrighted material
+# is made available to anyone wishing to use, modify, copy, or
+# redistribute it subject to the terms and conditions of the GNU General
+# Public License v.2.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# Authors: Greg Nichols
+#
+# A v7 DeviceDetector generalized from HAL to add udisks and upower
+
+import dbus
+import re
+import string
+import sys
+
+from v7.device import Device
+from v7.dbusDevice import UDisksDevice, UDisksDrive, UDisksPartition, UDisksAdapter
+from v7.deviceDetector import DeviceDetector
+from v7.tags import Constants
+
+class UDisksDeviceDetector(DeviceDetector):
+ def __init__(self):
+ DeviceDetector.__init__(self, name=Constants.udisks)
+ self.debugging = True
+ self.rootObject ='org.freedesktop.UDisks'
+ self.rootPath = '/org/freedesktop/UDisks'
+ self.interface = None
+ try:
+ self.bus = dbus.SystemBus()
+ dbusObject = self.bus.get_object(self.rootObject, self.rootPath)
+ self.interface = dbus.Interface(dbusObject, self.rootObject)
+ if self.interface and self.debugging:
+ print "found interface for " + self.name
+ except Exception, exception:
+ if self.debugging:
+ print "Warning: "
+ print exception
+
+ def getDevices(self):
+ devices = list()
+ for devicePath in self.interface.EnumerateDevices():
+ device = self.bus.get_object(self.rootObject, devicePath)
+ deviceProperties = dbus.Interface(device, dbus.PROPERTIES_IFACE)
+ #try:
+ if True:
+ if deviceProperties.Get("org.freedesktop.UDisks.Device", "DeviceIsDrive"):
+ devices.append(UDisksDrive(device))
+ elif deviceProperties.Get("org.freedesktop.UDisks.Device", "DeviceIsPartition"):
+ devices.append(UDisksPartition(device))
+ else:
+ devices.append(UDisksDevice(device))
+ #except Exception, e:
+ #print e
+
+ for adapterPath in self.interface.EnumerateAdapters():
+ adapter = self.bus.get_object(self.rootObject, adapterPath)
+ devices.append(UDisksAdapter(adapter))
+
+ return devices
+
+
+ def dump(self):
+ print "--------------------------------------------------------------"
+ print " Devices:"
+ for device in self.getDevices():
+ device.dump()
+ device.getProduct()
+
+def unit_test():
+
+ udisks=UDisksDeviceDetector()
+ udisks.dump()
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(unit_test())