Append IOMMU group element in getPci function
authorReto Buerki <reet@codelabs.ch>
Fri, 8 Sep 2017 13:43:28 +0000 (15:43 +0200)
committerReto Buerki <reet@codelabs.ch>
Fri, 8 Sep 2017 15:44:03 +0000 (17:44 +0200)
data/creator/iommu_groups/2/devices/0000:01:02.3/.keep [new file with mode: 0644]
src/creator.py
test/test_creator.py

diff --git a/data/creator/iommu_groups/2/devices/0000:01:02.3/.keep b/data/creator/iommu_groups/2/devices/0000:01:02.3/.keep
new file mode 100644 (file)
index 0000000..e69de29
index 60c07a1..2e457cc 100644 (file)
@@ -492,7 +492,7 @@ class PciDevicesCreator():
 
     def getPci(self, devicepath, devicecapmgr, devicespec, iommugrpdir):
         pcistr = os.path.basename(devicepath)
-        return schemadata.schema.pciType(
+        pci = schemadata.schema.pciType(
             bus=util.wrap16(self.getDeviceBus(pcistr)),
             device=util.wrap16(self.getDeviceNo(pcistr)),
             function=self.getDeviceFunction(pcistr),
@@ -503,6 +503,15 @@ class PciDevicesCreator():
                     deviceId=devicespec.deviceId,
                     revisionId=devicespec.revisionId))
 
+        if iommugrpdir:
+            for root, dirs, files in os.walk(iommugrpdir):
+                if pcistr in dirs:
+                    tokens = root.split("/")
+                    pci.append(schemadata.schema.iommuGroupType
+                               (id=tokens[len(tokens) - 2]))
+
+        return pci
+
     def getPci_MSI(self, devicepath, devicecapmgr):
         msi = "false"
         if devicecap.CAP_MSI in devicecapmgr.getCapList(devicepath):
index 8b32b68..baaa406 100644 (file)
@@ -448,6 +448,7 @@ class TestPciDevicesCreator:
         assert dev_pci.identification.vendorId == "16#2222#"
         assert dev_pci.identification.deviceId == "16#1112#"
         assert dev_pci.identification.revisionId == "16#a1#"
+        assert dev_pci.iommuGroup.id == 2
 
     def test_getPci_MSI(self):
         testloc = os.path.join(self.testdir, "devices_testcap")