Convert the charm to Python3

Change-Id: Ibdb9e582d75fd0c7cd130dddae9966aac5da3279
This commit is contained in:
Alex Kavanagh 2019-02-04 16:36:55 +00:00
parent 98a5f35b1d
commit a53b14a19b
8 changed files with 18 additions and 15 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ bin
*.py[oc] *.py[oc]
*.pyc *.pyc
func-results.json func-results.json
.stestr

View File

@ -1,4 +1,3 @@
- project: - project:
templates: templates:
- python-charm-jobs - python35-charm-jobs
- openstack-python35-jobs-nonvoting

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/env python3
# #
# Copyright 2016 Canonical Ltd # Copyright 2016 Canonical Ltd
# #

View File

@ -99,7 +99,7 @@ def restart_map():
that should be restarted when file changes. that should be restarted when file changes.
""" """
_map = [] _map = []
for f, ctxt in CONFIG_FILES.iteritems(): for f, ctxt in CONFIG_FILES.items():
svcs = [] svcs = []
for svc in ctxt['services']: for svc in ctxt['services']:
svcs.append(svc) svcs.append(svc)
@ -111,9 +111,10 @@ def restart_map():
def set_ceph_env_variables(service): def set_ceph_env_variables(service):
# XXX: Horrid kludge to make cinder-backup use # XXX: Horrid kludge to make cinder-backup use
# a different ceph username than admin # a different ceph username than admin
env = open('/etc/environment', 'r').read() with open('/etc/environment', 'rt') as f:
env = f.read()
if 'CEPH_ARGS' not in env: if 'CEPH_ARGS' not in env:
with open('/etc/environment', 'a') as out: with open('/etc/environment', 'at') as out:
out.write('CEPH_ARGS="--id %s"\n' % service) out.write('CEPH_ARGS="--id %s"\n' % service)
with open('/etc/init/cinder-backup.override', 'w') as out: with open('/etc/init/cinder-backup.override', 'wt') as out:
out.write('env CEPH_ARGS="--id %s"\n' % service) out.write('env CEPH_ARGS="--id %s"\n' % service)

View File

@ -745,7 +745,7 @@ class CinderBackupBasicDeployment(OpenStackAmuletDeployment):
# NOTE(hopem): it appears that at some point cinder-backup stopped # NOTE(hopem): it appears that at some point cinder-backup stopped
# restoring volume metadata properly so revert to default name if # restoring volume metadata properly so revert to default name if
# original is not found # original is not found
name = "restore_backup_%s" % (vol_backup.id) name = "restore_backup_{}".format(vol_backup.id)
try: try:
cinder_vols = [v for v in vols if v.name == name] cinder_vols = [v for v in vols if v.name == name]
except AttributeError: except AttributeError:
@ -753,11 +753,11 @@ class CinderBackupBasicDeployment(OpenStackAmuletDeployment):
if not cinder_vols: if not cinder_vols:
try: try:
msg = ("Could not find restore vol '%s' in %s" % msg = ("Could not find restore vol '{}' in {}"
(name, [v.name for v in vols])) .format(name, [v.name for v in vols]))
except AttributeError: except AttributeError:
msg = ("Could not find restore vol '%s' in %s" % msg = ("Could not find restore vol '{}' in {}"
(name, [v.display_name for v in vols])) .format(name, [v.display_name for v in vols]))
u.log.error(msg) u.log.error(msg)
amulet.raise_status(amulet.FAIL, msg=msg) amulet.raise_status(amulet.FAIL, msg=msg)

View File

@ -2,7 +2,7 @@
# This file is managed centrally by release-tools and should not be modified # This file is managed centrally by release-tools and should not be modified
# within individual charm repos. # within individual charm repos.
[tox] [tox]
envlist = pep8,py27 envlist = pep8,py3{5,6}
skipsdist = True skipsdist = True
[testenv] [testenv]
@ -20,6 +20,7 @@ passenv = HOME TERM AMULET_* CS_API_*
basepython = python2.7 basepython = python2.7
deps = -r{toxinidir}/requirements.txt deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt -r{toxinidir}/test-requirements.txt
commands = /bin/true
[testenv:py35] [testenv:py35]
basepython = python3.5 basepython = python3.5

View File

@ -14,3 +14,4 @@
import sys import sys
sys.path.append('hooks') sys.path.append('hooks')
sys.path.append('unit_tests')

View File

@ -35,7 +35,7 @@ def load_config():
if not config: if not config:
logging.error('Could not find config.yaml in any parent directory ' logging.error('Could not find config.yaml in any parent directory '
'of %s. ' % __file__) 'of %s.'.format(__file__))
raise Exception raise Exception
return yaml.safe_load(open(config).read())['options'] return yaml.safe_load(open(config).read())['options']
@ -47,7 +47,7 @@ def get_default_config():
""" """
default_config = {} default_config = {}
config = load_config() config = load_config()
for k, v in config.iteritems(): for k, v in config.items():
if 'default' in v: if 'default' in v:
default_config[k] = v['default'] default_config[k] = v['default']
else: else: