Make getPciConfigAddress an utility function
authorReto Buerki <reet@codelabs.ch>
Mon, 11 Sep 2017 09:40:02 +0000 (11:40 +0200)
committerReto Buerki <reet@codelabs.ch>
Fri, 15 Sep 2017 11:16:20 +0000 (13:16 +0200)
src/creator.py
test/test_creator.py

index f75853b..39bdc05 100644 (file)
@@ -55,6 +55,21 @@ WELL_KNOWN_IOPORTS = {
 }
 
 
+def getPciConfigAddress(path):
+    pciconfigaddr = ""
+    key = "PCI MMCONFIG"
+    try:
+        iomemdata = extractor.extractData(path)
+        keyline = parseutil.findLines(iomemdata, key)[0]
+        pciconfigaddr = keyline.split("-")[0].lstrip()
+
+    except (customExceptions.KeyNotFound, IOError):
+        message.addWarning(
+            "Could not obtain pciConfigAddress from %s." % path)
+
+    return pciconfigaddr
+
+
 class ProcessorCreator():
 
     def createElem(self, cpuinfopath, msrpaths, dmesgpath):
@@ -245,7 +260,7 @@ class DevicesCreator():
         print "> Creating element: devices"
         devices = schemadata.schema.devicesType(
             pciConfigAddress=util.toWord64(
-                self.getPciConfigAddress(paths.IOMEM)))
+                getPciConfigAddress(paths.IOMEM)))
 
         # Add system board
         print "> Extracting system board information..."
@@ -272,20 +287,6 @@ class DevicesCreator():
 
         return devices
 
-    def getPciConfigAddress(self, path):
-        pciconfigaddr = ""
-        key = "PCI MMCONFIG"
-        try:
-            iomemdata = extractor.extractData(path)
-            keyline = parseutil.findLines(iomemdata, key)[0]
-            pciconfigaddr = keyline.split("-")[0].lstrip()
-
-        except (customExceptions.KeyNotFound, IOError):
-            message.addWarning(
-                "Could not obtain pciConfigAddress from %s." % path)
-
-        return pciconfigaddr
-
 
 class PciDevicesCreator():
 
index 060c444..4d8f14a 100644 (file)
@@ -280,9 +280,9 @@ class TestDevicesCreator:
         testnokey = os.path.join(testdir, "test_iomem_nopciconfig")
 
         devcreator = creator.DevicesCreator()
-        assert devcreator.getPciConfigAddress(testiomem) == "e0000000"
-        assert not devcreator.getPciConfigAddress(testinvalidloc)
-        assert not devcreator.getPciConfigAddress(testnokey)
+        assert creator.getPciConfigAddress(testiomem) == "e0000000"
+        assert not creator.getPciConfigAddress(testinvalidloc)
+        assert not creator.getPciConfigAddress(testnokey)
 
 
 class TestPciDevicesCreator: