summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Kavanagh <alex@ajkavanagh.co.uk>2019-02-04 16:36:55 +0000
committerAlex Kavanagh <alex@ajkavanagh.co.uk>2019-02-13 16:24:29 +0000
commita53b14a19be3cd6742f1df35ee8d0b233c8bd08e (patch)
tree5142a3e6e4028e35e3d286384ebbf64c0dbb0e8c
parent98a5f35b1d7f9fb417ca148cedb32d4e574417fc (diff)
Convert the charm to Python3
Notes
Notes (review): Code-Review+1: sahid <sahid.ferdjaoui@canonical.com> Verified+1: Canonical CI <uosci-testing-bot@ubuntu.com> Code-Review+2: David Ames <david.ames@canonical.com> Workflow+1: David Ames <david.ames@canonical.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 13 Feb 2019 18:33:23 +0000 Reviewed-on: https://review.openstack.org/634738 Project: openstack/charm-cinder-backup Branch: refs/heads/master
-rw-r--r--.gitignore1
-rw-r--r--.zuul.yaml3
-rwxr-xr-xhooks/cinder_backup_hooks.py2
-rw-r--r--hooks/cinder_backup_utils.py9
-rw-r--r--tests/basic_deployment.py10
-rw-r--r--tox.ini3
-rw-r--r--unit_tests/__init__.py1
-rw-r--r--unit_tests/test_utils.py4
8 files changed, 18 insertions, 15 deletions
diff --git a/.gitignore b/.gitignore
index 7947e2f..c94de0a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@ bin
6*.py[oc] 6*.py[oc]
7*.pyc 7*.pyc
8func-results.json 8func-results.json
9.stestr
diff --git a/.zuul.yaml b/.zuul.yaml
index aa9c508..7051aee 100644
--- a/.zuul.yaml
+++ b/.zuul.yaml
@@ -1,4 +1,3 @@
1- project: 1- project:
2 templates: 2 templates:
3 - python-charm-jobs 3 - python35-charm-jobs
4 - openstack-python35-jobs-nonvoting
diff --git a/hooks/cinder_backup_hooks.py b/hooks/cinder_backup_hooks.py
index 083b19e..aa2ac3e 100755
--- a/hooks/cinder_backup_hooks.py
+++ b/hooks/cinder_backup_hooks.py
@@ -1,4 +1,4 @@
1#!/usr/bin/python 1#!/usr/bin/env python3
2# 2#
3# Copyright 2016 Canonical Ltd 3# Copyright 2016 Canonical Ltd
4# 4#
diff --git a/hooks/cinder_backup_utils.py b/hooks/cinder_backup_utils.py
index 9621a0f..ce413d4 100644
--- a/hooks/cinder_backup_utils.py
+++ b/hooks/cinder_backup_utils.py
@@ -99,7 +99,7 @@ def restart_map():
99 that should be restarted when file changes. 99 that should be restarted when file changes.
100 """ 100 """
101 _map = [] 101 _map = []
102 for f, ctxt in CONFIG_FILES.iteritems(): 102 for f, ctxt in CONFIG_FILES.items():
103 svcs = [] 103 svcs = []
104 for svc in ctxt['services']: 104 for svc in ctxt['services']:
105 svcs.append(svc) 105 svcs.append(svc)
@@ -111,9 +111,10 @@ def restart_map():
111def set_ceph_env_variables(service): 111def set_ceph_env_variables(service):
112 # XXX: Horrid kludge to make cinder-backup use 112 # XXX: Horrid kludge to make cinder-backup use
113 # a different ceph username than admin 113 # a different ceph username than admin
114 env = open('/etc/environment', 'r').read() 114 with open('/etc/environment', 'rt') as f:
115 env = f.read()
115 if 'CEPH_ARGS' not in env: 116 if 'CEPH_ARGS' not in env:
116 with open('/etc/environment', 'a') as out: 117 with open('/etc/environment', 'at') as out:
117 out.write('CEPH_ARGS="--id %s"\n' % service) 118 out.write('CEPH_ARGS="--id %s"\n' % service)
118 with open('/etc/init/cinder-backup.override', 'w') as out: 119 with open('/etc/init/cinder-backup.override', 'wt') as out:
119 out.write('env CEPH_ARGS="--id %s"\n' % service) 120 out.write('env CEPH_ARGS="--id %s"\n' % service)
diff --git a/tests/basic_deployment.py b/tests/basic_deployment.py
index 29ce31b..d28f784 100644
--- a/tests/basic_deployment.py
+++ b/tests/basic_deployment.py
@@ -745,7 +745,7 @@ class CinderBackupBasicDeployment(OpenStackAmuletDeployment):
745 # NOTE(hopem): it appears that at some point cinder-backup stopped 745 # NOTE(hopem): it appears that at some point cinder-backup stopped
746 # restoring volume metadata properly so revert to default name if 746 # restoring volume metadata properly so revert to default name if
747 # original is not found 747 # original is not found
748 name = "restore_backup_%s" % (vol_backup.id) 748 name = "restore_backup_{}".format(vol_backup.id)
749 try: 749 try:
750 cinder_vols = [v for v in vols if v.name == name] 750 cinder_vols = [v for v in vols if v.name == name]
751 except AttributeError: 751 except AttributeError:
@@ -753,11 +753,11 @@ class CinderBackupBasicDeployment(OpenStackAmuletDeployment):
753 753
754 if not cinder_vols: 754 if not cinder_vols:
755 try: 755 try:
756 msg = ("Could not find restore vol '%s' in %s" % 756 msg = ("Could not find restore vol '{}' in {}"
757 (name, [v.name for v in vols])) 757 .format(name, [v.name for v in vols]))
758 except AttributeError: 758 except AttributeError:
759 msg = ("Could not find restore vol '%s' in %s" % 759 msg = ("Could not find restore vol '{}' in {}"
760 (name, [v.display_name for v in vols])) 760 .format(name, [v.display_name for v in vols]))
761 u.log.error(msg) 761 u.log.error(msg)
762 amulet.raise_status(amulet.FAIL, msg=msg) 762 amulet.raise_status(amulet.FAIL, msg=msg)
763 763
diff --git a/tox.ini b/tox.ini
index 0b72fa9..1457901 100644
--- a/tox.ini
+++ b/tox.ini
@@ -2,7 +2,7 @@
2# This file is managed centrally by release-tools and should not be modified 2# This file is managed centrally by release-tools and should not be modified
3# within individual charm repos. 3# within individual charm repos.
4[tox] 4[tox]
5envlist = pep8,py27 5envlist = pep8,py3{5,6}
6skipsdist = True 6skipsdist = True
7 7
8[testenv] 8[testenv]
@@ -20,6 +20,7 @@ passenv = HOME TERM AMULET_* CS_API_*
20basepython = python2.7 20basepython = python2.7
21deps = -r{toxinidir}/requirements.txt 21deps = -r{toxinidir}/requirements.txt
22 -r{toxinidir}/test-requirements.txt 22 -r{toxinidir}/test-requirements.txt
23commands = /bin/true
23 24
24[testenv:py35] 25[testenv:py35]
25basepython = python3.5 26basepython = python3.5
diff --git a/unit_tests/__init__.py b/unit_tests/__init__.py
index b7fe4e1..524cb9e 100644
--- a/unit_tests/__init__.py
+++ b/unit_tests/__init__.py
@@ -14,3 +14,4 @@
14 14
15import sys 15import sys
16sys.path.append('hooks') 16sys.path.append('hooks')
17sys.path.append('unit_tests')
diff --git a/unit_tests/test_utils.py b/unit_tests/test_utils.py
index 74b57c8..a5cf7f7 100644
--- a/unit_tests/test_utils.py
+++ b/unit_tests/test_utils.py
@@ -35,7 +35,7 @@ def load_config():
35 35
36 if not config: 36 if not config:
37 logging.error('Could not find config.yaml in any parent directory ' 37 logging.error('Could not find config.yaml in any parent directory '
38 'of %s. ' % __file__) 38 'of %s.'.format(__file__))
39 raise Exception 39 raise Exception
40 40
41 return yaml.safe_load(open(config).read())['options'] 41 return yaml.safe_load(open(config).read())['options']
@@ -47,7 +47,7 @@ def get_default_config():
47 """ 47 """
48 default_config = {} 48 default_config = {}
49 config = load_config() 49 config = load_config()
50 for k, v in config.iteritems(): 50 for k, v in config.items():
51 if 'default' in v: 51 if 'default' in v:
52 default_config[k] = v['default'] 52 default_config[k] = v['default']
53 else: 53 else: