aeb2010
From 115ea0749bb0bb2fdcc31be845fbc39d9f04f796 Mon Sep 17 00:00:00 2001
aeb2010
From: Adam Williamson <awilliam@redhat.com>
aeb2010
Date: Sat, 10 Feb 2024 08:50:19 -0800
aeb2010
Subject: [PATCH 2/2] Python 3.12: adjust for removal of SafeConfigParser
aeb2010
aeb2010
Signed-off-by: Adam Williamson <awilliam@redhat.com>
aeb2010
---
aeb2010
 imagefactory_plugins/EC2/EC2.py                           | 6 +++++-
aeb2010
 imagefactory_plugins/IndirectionCloud/IndirectionCloud.py | 6 +++++-
aeb2010
 imagefactory_plugins/Nova/Nova.py                         | 8 ++++++--
aeb2010
 imagefactory_plugins/Rackspace/Rackspace.py               | 6 +++++-
aeb2010
 imagefactory_plugins/TinMan/TinMan.py                     | 6 +++++-
aeb2010
 5 files changed, 26 insertions(+), 6 deletions(-)
aeb2010
aeb2010
diff --git a/imagefactory_plugins/EC2/EC2.py b/imagefactory_plugins/EC2/EC2.py
aeb2010
index 9e927f9..bac6d89 100644
aeb2010
--- a/imagefactory_plugins/EC2/EC2.py
aeb2010
+++ b/imagefactory_plugins/EC2/EC2.py
aeb2010
@@ -61,7 +61,11 @@ class EC2(object):
aeb2010
         self.log = logging.getLogger('%s.%s' % (__name__, self.__class__.__name__))
aeb2010
         config_obj = ApplicationConfiguration()
aeb2010
         self.app_config = config_obj.configuration
aeb2010
-        self.oz_config = configparser.SafeConfigParser()
aeb2010
+        try:
aeb2010
+            self.oz_config = configparser.SafeConfigParser()
aeb2010
+        except AttributeError:
aeb2010
+            # SafeConfigParser was deprecated in Python 3.2
aeb2010
+            self.oz_config = configparser.ConfigParser()
aeb2010
         self.oz_config.read("/etc/oz/oz.cfg")
aeb2010
         self.oz_config.set('paths', 'output_dir', self.app_config["imgdir"])
aeb2010
         self.guest = None
aeb2010
diff --git a/imagefactory_plugins/IndirectionCloud/IndirectionCloud.py b/imagefactory_plugins/IndirectionCloud/IndirectionCloud.py
aeb2010
index ff364db..a41dc74 100644
aeb2010
--- a/imagefactory_plugins/IndirectionCloud/IndirectionCloud.py
aeb2010
+++ b/imagefactory_plugins/IndirectionCloud/IndirectionCloud.py
aeb2010
@@ -282,7 +282,11 @@ class IndirectionCloud(object):
aeb2010
     def _init_oz(self):
aeb2010
         # populate a config object to pass to OZ; this allows us to specify our
aeb2010
         # own output dir but inherit other Oz behavior
aeb2010
-        self.oz_config = configparser.SafeConfigParser()
aeb2010
+        try:
aeb2010
+            self.oz_config = configparser.SafeConfigParser()
aeb2010
+        except AttributeError:
aeb2010
+            # SafeConfigParser was deprecated in Python 3.2
aeb2010
+            self.oz_config = configparser.ConfigParser()
aeb2010
         if self.oz_config.read("/etc/oz/oz.cfg") != []:
aeb2010
             self.oz_config.set('paths', 'output_dir', self.app_config["imgdir"])
aeb2010
             if "oz_data_dir" in self.app_config:
aeb2010
diff --git a/imagefactory_plugins/Nova/Nova.py b/imagefactory_plugins/Nova/Nova.py
aeb2010
index ff7cc08..9a8c777 100644
aeb2010
--- a/imagefactory_plugins/Nova/Nova.py
aeb2010
+++ b/imagefactory_plugins/Nova/Nova.py
aeb2010
@@ -28,7 +28,11 @@ from novaimagebuilder.StackEnvironment import StackEnvironment
aeb2010
 from time import sleep
aeb2010
 from base64 import b64decode
aeb2010
 #TODO: remove dependency on Oz
aeb2010
-from configparser import SafeConfigParser
aeb2010
+try:
aeb2010
+    from configparser import SafeConfigParser as ConfigParser
aeb2010
+except AttributeError:
aeb2010
+    # SafeConfigParser was deprecated in Python 3.2
aeb2010
+    from configparser import ConfigParser
aeb2010
 from oz.TDL import TDL
aeb2010
 import oz.GuestFactory
aeb2010
 
aeb2010
@@ -438,7 +442,7 @@ class Nova(object):
aeb2010
         return confirmation
aeb2010
 
aeb2010
     def _oz_config(self, private_key_file):
aeb2010
-        config = SafeConfigParser()
aeb2010
+        config = ConfigParser()
aeb2010
         if config.read("/etc/oz/oz.cfg"):
aeb2010
             config.set('paths', 'output_dir', self.app_config['imgdir'])
aeb2010
             config.set('paths', 'sshprivkey', private_key_file)
aeb2010
diff --git a/imagefactory_plugins/Rackspace/Rackspace.py b/imagefactory_plugins/Rackspace/Rackspace.py
aeb2010
index e045d14..ae7fe99 100644
aeb2010
--- a/imagefactory_plugins/Rackspace/Rackspace.py
aeb2010
+++ b/imagefactory_plugins/Rackspace/Rackspace.py
aeb2010
@@ -64,7 +64,11 @@ class Rackspace(object):
aeb2010
         self.log = logging.getLogger('%s.%s' % (__name__, self.__class__.__name__))
aeb2010
         config_obj = ApplicationConfiguration()
aeb2010
         self.app_config = config_obj.configuration
aeb2010
-        self.oz_config = configparser.SafeConfigParser()
aeb2010
+        try:
aeb2010
+            self.oz_config = configparser.SafeConfigParser()
aeb2010
+        except AttributeError:
aeb2010
+            # SafeConfigParser was deprecated in Python 3.2
aeb2010
+            self.oz_config = configparser.ConfigParser()
aeb2010
         self.oz_config.read("/etc/oz/oz.cfg")
aeb2010
         self.oz_config.set('paths', 'output_dir', self.app_config["imgdir"])
aeb2010
         self.active_image = None
aeb2010
diff --git a/imagefactory_plugins/TinMan/TinMan.py b/imagefactory_plugins/TinMan/TinMan.py
aeb2010
index 219a78e..27b3d23 100644
aeb2010
--- a/imagefactory_plugins/TinMan/TinMan.py
aeb2010
+++ b/imagefactory_plugins/TinMan/TinMan.py
aeb2010
@@ -269,7 +269,11 @@ class TinMan(object):
aeb2010
 
aeb2010
         # populate a config object to pass to OZ; this allows us to specify our
aeb2010
         # own output dir but inherit other Oz behavior
aeb2010
-        self.oz_config = configparser.SafeConfigParser()
aeb2010
+        try:
aeb2010
+            self.oz_config = configparser.SafeConfigParser()
aeb2010
+        except AttributeError:
aeb2010
+            # SafeConfigParser was deprecated in Python 3.2
aeb2010
+            self.oz_config = configparser.ConfigParser()
aeb2010
         if self.oz_config.read("/etc/oz/oz.cfg") != []:
aeb2010
             if self.parameters.get("oz_overrides", None) != None:
aeb2010
                 oz_overrides = json.loads(self.parameters.get("oz_overrides",None).replace("'", "\""))
aeb2010
-- 
aeb2010
2.43.0
aeb2010