Fix python3 compatibility
Change-Id: I01a142cab62253719f2534b0eda8e5954db76730
This commit is contained in:
parent
3ffcc0c657
commit
89558a7202
|
@ -2,7 +2,6 @@
|
|||
templates:
|
||||
- check-requirements
|
||||
- openstack-lower-constraints-jobs
|
||||
- openstack-python-jobs
|
||||
- openstack-python3-ussuri-jobs
|
||||
- publish-openstack-docs-pti
|
||||
- release-notes-jobs-python3
|
||||
|
|
|
@ -624,7 +624,7 @@ def get_backup_args():
|
|||
def __init__(self, args):
|
||||
self.__dict__.update(args)
|
||||
|
||||
cli_options = dict([(x, y) for x, y in CONF.iteritems() if y is not None])
|
||||
cli_options = dict([(x, y) for x, y in CONF.items() if y is not None])
|
||||
|
||||
defaults.update(cli_options)
|
||||
|
||||
|
|
|
@ -35,7 +35,6 @@ if six.PY3:
|
|||
else:
|
||||
from multiprocessing.queues import SimpleQueue
|
||||
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -190,7 +189,8 @@ class BackupEngine(object):
|
|||
"Engine error. Failed to backup.")
|
||||
|
||||
with open(freezer_meta, mode='wb') as b_file:
|
||||
b_file.write(json.dumps(self.metadata(backup_resource)))
|
||||
b_file.write(
|
||||
json.dumps(self.metadata(backup_resource)).encode())
|
||||
self.storage.put_metadata(engine_meta, freezer_meta, backup)
|
||||
finally:
|
||||
shutil.rmtree(tmpdir)
|
||||
|
|
|
@ -121,7 +121,7 @@ class NovaEngine(engine.BackupEngine):
|
|||
nova_networks = self.neutron.list_networks()['networks']
|
||||
|
||||
net_names = [network for network, _ in
|
||||
available_networks.iteritems()]
|
||||
available_networks.items()]
|
||||
match_networks = [{"net-id": network.get('id')} for network in
|
||||
nova_networks
|
||||
if network.get('name') in net_names]
|
||||
|
|
|
@ -336,7 +336,8 @@ class Job(object):
|
|||
max_retries_interval = job_action.get('max_retries_interval', 60)
|
||||
action_name = freezer_action.get('action', '')
|
||||
while tries:
|
||||
with tempfile.NamedTemporaryFile(delete=False) as config_file:
|
||||
with tempfile.NamedTemporaryFile(mode='w',
|
||||
delete=False) as config_file:
|
||||
self.save_action_to_file(freezer_action, config_file)
|
||||
config_file_name = config_file.name
|
||||
freezer_command = '{0} --metadata-out - --config {1}'.\
|
||||
|
|
|
@ -105,7 +105,7 @@ class Storage(object):
|
|||
|
||||
increments = backup.get_increments()
|
||||
|
||||
return {level: backup for level, backup in increments.iteritems()
|
||||
return {level: backup for level, backup in increments.items()
|
||||
if not recent_to_date or backup.timestamp <= recent_to_date}
|
||||
|
||||
def remove_older_than(self, engine, remove_older_timestamp,
|
||||
|
|
|
@ -62,10 +62,10 @@ class FsLikeStorage(physical.PhysicalStorage):
|
|||
with self.open(backup.data_path, 'rb') as backup_file:
|
||||
while True:
|
||||
chunk = backup_file.read(self.max_segment_size)
|
||||
if chunk == '':
|
||||
break
|
||||
if len(chunk):
|
||||
yield chunk
|
||||
else:
|
||||
break
|
||||
|
||||
@abc.abstractmethod
|
||||
def open(self, filename, mode):
|
||||
|
|
|
@ -46,7 +46,7 @@ class SwiftStorage(physical.PhysicalStorage):
|
|||
def put_file(self, from_path, to_path):
|
||||
split = to_path.rsplit('/', 1)
|
||||
file_size = os.path.getsize(from_path)
|
||||
with open(from_path, 'r') as meta_fd:
|
||||
with open(from_path, 'rb') as meta_fd:
|
||||
self.swift().put_object(split[0], split[1], meta_fd,
|
||||
content_length=file_size)
|
||||
|
||||
|
|
|
@ -75,7 +75,9 @@ def execute(args, must_fail=False, merge_stderr=False):
|
|||
"""
|
||||
stdout = subprocess.PIPE
|
||||
stderr = subprocess.STDOUT if merge_stderr else subprocess.PIPE
|
||||
proc = subprocess.Popen(args, stdout=stdout, stderr=stderr)
|
||||
proc = subprocess.Popen(args,
|
||||
stdout=stdout,
|
||||
stderr=stderr, universal_newlines=True)
|
||||
result, result_err = proc.communicate()
|
||||
|
||||
if not must_fail and proc.returncode != 0:
|
||||
|
|
|
@ -121,7 +121,9 @@ class CheckSum(object):
|
|||
# unicode-escape. The effect of them is the same.
|
||||
if six.PY2 and isinstance(buf, str):
|
||||
buf = buf.encode('string-escape')
|
||||
else:
|
||||
elif six.PY2 and not isinstance(buf, str):
|
||||
buf = buf.encode('unicode-escape')
|
||||
elif six.PY3 and isinstance(buf, six.string_types):
|
||||
buf = buf.encode('unicode-escape')
|
||||
|
||||
self.hasher.update(buf)
|
||||
|
|
|
@ -53,8 +53,10 @@ class Config(object):
|
|||
dict = {}
|
||||
for option in config.options(section):
|
||||
option_value = config.get(section, option)
|
||||
if option_value in ('False', 'None'):
|
||||
if option_value in ('False', 'false', 'None'):
|
||||
option_value = False
|
||||
if option_value in ('True', 'true', 'None'):
|
||||
option_value = True
|
||||
dict[option] = option_value
|
||||
if section.startswith("storage:"):
|
||||
storages.append(dict)
|
||||
|
|
Loading…
Reference in New Issue