Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Futurize the codebase for Python 3 support #424

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions imagefactory.spec
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ BuildArch: noarch
%if 0%{?rhel} == 6
ExcludeArch: i386 ppc64
%endif
Requires: python-future
Requires: python-pycurl
Requires: python-libguestfs
Requires: python-zope-interface
Expand All @@ -44,6 +45,7 @@ Requires(preun): initscripts

BuildRequires: python2
BuildRequires: python-setuptools
BuildRequires: python-future
# TODO: Any changes to the _internal_ API must increment this version or, in
# the case of backwards compatible changes, add a new version (RPM
# allows multiple version "=" lines for the same package or
Expand Down
2 changes: 2 additions & 0 deletions imagefactory.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ BuildArch: noarch
%if 0%{?rhel} == 6
ExcludeArch: i386 ppc64
%endif
Requires: python-future
Requires: python-pycurl
Requires: python-libguestfs
Requires: python-zope-interface
Expand All @@ -44,6 +45,7 @@ Requires(preun): initscripts

BuildRequires: python2
BuildRequires: python-setuptools
BuildRequires: python-future
# TODO: Any changes to the _internal_ API must increment this version or, in
# the case of backwards compatible changes, add a new version (RPM
# allows multiple version "=" lines for the same package or
Expand Down
1 change: 1 addition & 0 deletions imagefactory_plugins/Atlas/Atlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from builtins import object
import zope
import os
import logging
Expand Down
3 changes: 2 additions & 1 deletion imagefactory_plugins/Atlas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from Atlas import Atlas as delegate_class
from __future__ import absolute_import
from .Atlas import Atlas as delegate_class
9 changes: 6 additions & 3 deletions imagefactory_plugins/Docker/Docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from builtins import str
from builtins import range
from builtins import object
import logging
import zope
import libxml2
Expand Down Expand Up @@ -305,7 +308,7 @@ def builder_should_create_target_image(self, builder, target, image_id, template
wrap_metadata = parameter_cast_to_bool(parameters.get('create_docker_metadata', True))
compress_type = parameters.get('compress', None)
if compress_type:
if compress_type in self.compress_commands.keys():
if compress_type in list(self.compress_commands.keys()):
compress_command = self.compress_commands[compress_type]
else:
raise Exception("Passed unknown compression type (%s) for Docker plugin" % (compress_type))
Expand Down Expand Up @@ -359,15 +362,15 @@ def _run_guestmount(g):
if os.path.isfile(fp) and not os.path.islink(fp):
size += os.path.getsize(fp)
self.log.debug("Total real file content size (%d)" % (size))
except Exception, e:
except Exception as e:
self.log.exception(e)
raise
finally:
if tempdir:
try:
subprocess.check_call( ['umount', '-f', tempdir] )
os.rmdir(tempdir)
except Exception, e:
except Exception as e:
self.log.exception(e)
self.log.error("WARNING: Could not unmount guest at (%s) - may still be mounted" % (tempdir) )
if fuse_thread:
Expand Down
3 changes: 2 additions & 1 deletion imagefactory_plugins/Docker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from Docker import Docker as delegate_class
from __future__ import absolute_import
from .Docker import Docker as delegate_class

36 changes: 22 additions & 14 deletions imagefactory_plugins/EC2/EC2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import division
from future import standard_library
standard_library.install_aliases()
from builtins import map
from builtins import str
from builtins import range
from builtins import object
from past.utils import old_div
import logging
import zope
import oz.Fedora
Expand All @@ -24,7 +32,7 @@
import string
import libxml2
import traceback
import ConfigParser
import configparser
import boto.ec2
import sys
import json
Expand Down Expand Up @@ -61,7 +69,7 @@ def __init__(self):
self.log = logging.getLogger('%s.%s' % (__name__, self.__class__.__name__))
config_obj = ApplicationConfiguration()
self.app_config = config_obj.configuration
self.oz_config = ConfigParser.SafeConfigParser()
self.oz_config = configparser.SafeConfigParser()
self.oz_config.read("/etc/oz/oz.cfg")
self.oz_config.set('paths', 'output_dir', self.app_config["imgdir"])
self.guest = None
Expand Down Expand Up @@ -118,7 +126,7 @@ def builder_did_create_target_image(self, builder, target, image_id, template, p

# populate a config object to pass to OZ; this allows us to specify our
# own output dir but inherit other Oz behavior
self.oz_config = ConfigParser.SafeConfigParser()
self.oz_config = configparser.SafeConfigParser()
self.oz_config.read("/etc/oz/oz.cfg")
self.oz_config.set('paths', 'output_dir', self.app_config["imgdir"])

Expand Down Expand Up @@ -304,7 +312,7 @@ def ec2_copy_filesystem(self):
input_size = disk_image_capacity(self.image)
GIGABYTE = 2 ** 30
# This rounds up to the nearest GiB and correctly deals with exact number of GB files
flat_size = int((input_size + GIGABYTE - 1)/GIGABYTE) * GIGABYTE
flat_size = int(old_div((input_size + GIGABYTE - 1),GIGABYTE)) * GIGABYTE

self.log.debug("create target image of size %d bytes" % (flat_size))
# /dev/sdb
Expand Down Expand Up @@ -529,7 +537,7 @@ def wait_for_ec2_instance_start(self, instance):
self.log.debug("Waiting for EC2 instance to start: %d/300" % (i))
try:
instance.update()
except EC2ResponseError, e:
except EC2ResponseError as e:
# We occasionally get errors when querying an instance that has just started - ignore them and hope for the best
self.log.warning("EC2ResponseError encountered when querying EC2 instance (%s) - trying to continue" % (instance.id), exc_info = True)
except:
Expand Down Expand Up @@ -794,7 +802,7 @@ def replace(item):
'--ec2cert', '/tmp/cert-ec2.pem',
'-a', self.ec2_access_key, '-s', self.ec2_secret_key,
'-U', upload_url]
command_log = map(replace, command)
command_log = list(map(replace, command))
self.activity("Uploading bundle to S3")
self.log.debug("Executing upload bundle command: %s" % (command_log))
stdout, stderr, retcode = self.guest.guest_execute_command(guestaddr, ' '.join(command))
Expand All @@ -806,7 +814,7 @@ def replace(item):
'-A', self.ec2_access_key, '-S', self.ec2_secret_key, '-a', self.tdlobj.arch,
#'-n', image_name, '-d', image_desc,
manifest_s3_loc]
command_log = map(replace, command)
command_log = list(map(replace, command))
self.activity("Registering bundle as a new AMI")
self.log.debug("Executing register command: %s" % (command_log))
stdout, stderr, retcode = self.guest.guest_execute_command(guestaddr,
Expand Down Expand Up @@ -867,7 +875,7 @@ def replace(item):
sleep(interval)
else:
raise Exception("Timeout waiting for instance to terminate.")
except Exception, e:
except Exception as e:
self.log.debug("Unable to delete temporary security group (%s) due to exception: %s" % (factory_security_group_name, e))

self.log.debug("Fedora_ec2_Builder successfully pushed image with uuid %s as %s" % (self.new_image_id, new_ami_id))
Expand Down Expand Up @@ -1060,7 +1068,7 @@ def ec2_push_image_upload_ebs(self, target_image_id, provider, credentials, virt

GIGABYTE = 2 ** 30
# This rounds up to the nearest GiB and correctly deals with exact number of GB files
ami_size =int((os.path.getsize(input_image) + GIGABYTE - 1)/GIGABYTE)
ami_size =int(old_div((os.path.getsize(input_image) + GIGABYTE - 1),GIGABYTE))
self.activity("Creating %d GiB volume in (%s) to hold new image" % (ami_size,self.instance.placement))
volume = conn.create_volume(ami_size, self.instance.placement)

Expand Down Expand Up @@ -1216,7 +1224,7 @@ def ec2_push_image_upload_ebs(self, target_image_id, provider, credentials, virt
try:
volume.delete()
break
except Exception, e:
except Exception as e:
if tries<7:
tries += 1
self.log.debug("Volume delete failed - waiting 10 seconds and trying again (%d/6 tries)" % (tries))
Expand Down Expand Up @@ -1292,7 +1300,7 @@ def replace(item):
if virt_type == "paravirtual":
bundle_command.extend( [ "--kernel", aki ] )

bundle_command_log = map(replace, bundle_command)
bundle_command_log = list(map(replace, bundle_command))

self.activity("Bundling image locally")
self.log.debug("Executing bundle command: %s " % (bundle_command_log))
Expand All @@ -1310,7 +1318,7 @@ def replace(item):
"-a", self.ec2_access_key, "-s", self.ec2_secret_key,
"-U" , upload_url ]

upload_command_log = map(replace, upload_command)
upload_command_log = list(map(replace, upload_command))

self.activity("Uploading image to EC2")
self.log.debug("Executing upload command: %s " % (upload_command_log))
Expand All @@ -1330,7 +1338,7 @@ def replace(item):
"--root-device-name", root_dev,
"--virtualization-type", virt_type,
s3_path ]
register_command_log = map(replace, register_command)
register_command_log = list(map(replace, register_command))
self.activity("Registering image")
self.log.debug("Executing register command: %s with environment %s " % (register_command_log, repr(register_env)))
register_output = subprocess_check_output(register_command, env=register_env)
Expand Down Expand Up @@ -1361,7 +1369,7 @@ def abort(self):
instance_id = self.instance.id
try:
self.terminate_instance(self.instance)
except Exception, e:
except Exception as e:
self.log.warning("Warning, encountered - Instance %s may not be terminated ******** " % (instance_id))
self.log.exception(e)

Expand Down
1 change: 1 addition & 0 deletions imagefactory_plugins/EC2/EC2CloudOSHelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from builtins import object
import logging
from imgfac.ImageFactoryException import ImageFactoryException
import oz.RHEL_5
Expand Down
3 changes: 2 additions & 1 deletion imagefactory_plugins/EC2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from EC2 import EC2 as delegate_class
from __future__ import absolute_import
from .EC2 import EC2 as delegate_class
1 change: 1 addition & 0 deletions imagefactory_plugins/GCE/GCE.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from builtins import object
import zope
import os
import traceback
Expand Down
3 changes: 2 additions & 1 deletion imagefactory_plugins/GCE/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from GCE import GCE as delegate_class
from __future__ import absolute_import
from .GCE import GCE as delegate_class
5 changes: 4 additions & 1 deletion imagefactory_plugins/HyperV/HyperV.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from future import standard_library
standard_library.install_aliases()
from builtins import object
import zope
import oz.GuestFactory
import oz.TDL
Expand All @@ -21,7 +24,7 @@
import libxml2
import traceback
import json
import ConfigParser
import configparser
import logging
import subprocess
from xml.etree.ElementTree import fromstring
Expand Down
3 changes: 2 additions & 1 deletion imagefactory_plugins/HyperV/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from HyperV import HyperV as delegate_class
from __future__ import absolute_import
from .HyperV import HyperV as delegate_class
12 changes: 8 additions & 4 deletions imagefactory_plugins/IndirectionCloud/IndirectionCloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from future import standard_library
standard_library.install_aliases()
from builtins import str
from builtins import object
import logging
import zope
import oz.TDL
Expand All @@ -26,7 +30,7 @@
# For now we import both
import libxml2
import lxml
import ConfigParser
import configparser
import tempfile
import base64
import os
Expand Down Expand Up @@ -282,7 +286,7 @@ def oz_refresh_customizations(self, partial_tdl):
def _init_oz(self):
# populate a config object to pass to OZ; this allows us to specify our
# own output dir but inherit other Oz behavior
self.oz_config = ConfigParser.SafeConfigParser()
self.oz_config = configparser.SafeConfigParser()
if self.oz_config.read("/etc/oz/oz.cfg") != []:
self.oz_config.set('paths', 'output_dir', self.app_config["imgdir"])
if "oz_data_dir" in self.app_config:
Expand All @@ -299,9 +303,9 @@ def _init_oz(self):
self.guest = oz.GuestFactory.guest_factory(self.tdlobj, self.oz_config, None)
# Oz just selects a random port here - This could potentially collide if we are unlucky
self.guest.listen_port = self.res_mgr.get_next_listen_port()
except libvirtError, e:
except libvirtError as e:
raise ImageFactoryException("Cannot connect to libvirt. Make sure libvirt is running. [Original message: %s]" % e.message)
except OzException, e:
except OzException as e:
if "Unsupported" in e.message:
raise ImageFactoryException("TinMan plugin does not support distro (%s) update (%s) in TDL" % (self.tdlobj.distro, self.tdlobj.update) )
else:
Expand Down
3 changes: 2 additions & 1 deletion imagefactory_plugins/IndirectionCloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from IndirectionCloud import IndirectionCloud as delegate_class
from __future__ import absolute_import
from .IndirectionCloud import IndirectionCloud as delegate_class
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
# This is important since ks files typically have characters that may need
# to be escaped - even newlines need this

from __future__ import print_function
import sys
import json

kickstart = open(sys.argv[1]).read()

parameters = { "install_script": kickstart, "generate_icicle": False }

print json.dumps(parameters)
print(json.dumps(parameters))
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/python

from __future__ import print_function
import sys
import json

Expand All @@ -9,4 +10,4 @@

parameters = { "utility_image": utility_image, "utility_customizations": utility_tdl }

print json.dumps(parameters)
print(json.dumps(parameters))
2 changes: 2 additions & 0 deletions imagefactory_plugins/MockCloud/MockCloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from builtins import str
from builtins import object
import logging
import uuid
import zope
Expand Down
3 changes: 2 additions & 1 deletion imagefactory_plugins/MockCloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from MockCloud import MockCloud as delegate_class
from __future__ import absolute_import
from .MockCloud import MockCloud as delegate_class
1 change: 1 addition & 0 deletions imagefactory_plugins/MockOS/MockOS.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from builtins import object
import logging
import zope
from imgfac.OSDelegate import OSDelegate
Expand Down
3 changes: 2 additions & 1 deletion imagefactory_plugins/MockOS/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from MockOS import MockOS as delegate_class
from __future__ import absolute_import
from .MockOS import MockOS as delegate_class
Loading