Use importlib.util to replace imp

Since the imp module is deprecated and scheduled for removal in
Python 3.12 in favor of importlib, update the relevant libraries to
resolve any ModuleNotFoundError issues with Python 3.12.

Changes:
- use import importlib.util instead of import imp

Tested:
- Ran basic test pass with Python 3.10 and 3.12.

Change-Id: I25dde939dd25268b2ae329b0121858bec20ed03c
Signed-off-by: Brian Ma <chma0@nuvoton.com>
diff --git a/data/model.py b/data/model.py
index 78a7284..adeec17 100755
--- a/data/model.py
+++ b/data/model.py
@@ -1,12 +1,19 @@
 #!/usr/bin/env python3 -u
-import imp as imp
+import importlib.util
 import string as string
 
 from robot.libraries.BuiltIn import BuiltIn
 
 
+def load_source(name, module_path):
+    spec = importlib.util.spec_from_file_location(name, module_path)
+    module = importlib.util.module_from_spec(spec)
+    spec.loader.exec_module(module)
+    return module
+
+
 def get_sensor(module_name, value):
-    m = imp.load_source("module.name", module_name)
+    m = load_source("module.name", module_name)
 
     for i in m.ID_LOOKUP["SENSOR"]:
         if m.ID_LOOKUP["SENSOR"][i] == value:
@@ -16,7 +23,7 @@
 
 
 def get_inventory_sensor(module_name, value):
-    m = imp.load_source("module.name", module_name)
+    m = load_source("module.name", module_name)
 
     value = string.replace(value, m.INVENTORY_ROOT, "<inventory_root>")
 
@@ -29,7 +36,7 @@
 
 def get_inventory_list(module_name):
     inventory_list = []
-    m = imp.load_source("module.name", module_name)
+    m = load_source("module.name", module_name)
 
     for i in m.ID_LOOKUP["FRU"]:
         s = m.ID_LOOKUP["FRU"][i]
@@ -41,7 +48,7 @@
 
 def get_inventory_fru_type_list(module_name, fru_type):
     inventory_list = []
-    m = imp.load_source("module.name", module_name)
+    m = load_source("module.name", module_name)
 
     for i in m.FRU_INSTANCES.keys():
         if m.FRU_INSTANCES[i]["fru_type"] == fru_type:
@@ -57,7 +64,7 @@
 
 def get_FRU_component_name_list(module_name):
     name_list = []
-    m = imp.load_source("module.name", module_name)
+    m = load_source("module.name", module_name)
 
     for name in m.FRU_COMPONENT_NAME:
         name_list.append(name)
@@ -67,7 +74,7 @@
 
 
 def get_ipmi_rest_fru_field_map(module_name):
-    m = imp.load_source("module.name", module_name)
+    m = load_source("module.name", module_name)
 
     ipmi_rest_fru_field_map = dict.copy(m.ipmi_rest_fru_field_map)