Browse Source

Convert the charm to Python3

Change-Id: Ibdb9e582d75fd0c7cd130dddae9966aac5da3279
changes/38/634738/2
Alex Kavanagh 4 months ago
parent
commit
a53b14a19b

+ 1
- 0
.gitignore View File

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

+ 1
- 2
.zuul.yaml View File

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

+ 1
- 1
hooks/cinder_backup_hooks.py View File

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

+ 5
- 4
hooks/cinder_backup_utils.py View File

@@ -99,7 +99,7 @@ def restart_map():
99 99
                     that should be restarted when file changes.
100 100
     """
101 101
     _map = []
102
-    for f, ctxt in CONFIG_FILES.iteritems():
102
+    for f, ctxt in CONFIG_FILES.items():
103 103
         svcs = []
104 104
         for svc in ctxt['services']:
105 105
             svcs.append(svc)
@@ -111,9 +111,10 @@ def restart_map():
111 111
 def set_ceph_env_variables(service):
112 112
     # XXX: Horrid kludge to make cinder-backup use
113 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 116
     if 'CEPH_ARGS' not in env:
116
-        with open('/etc/environment', 'a') as out:
117
+        with open('/etc/environment', 'at') as out:
117 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 120
         out.write('env CEPH_ARGS="--id %s"\n' % service)

+ 5
- 5
tests/basic_deployment.py View File

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

+ 2
- 1
tox.ini View File

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

+ 1
- 0
unit_tests/__init__.py View File

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

+ 2
- 2
unit_tests/test_utils.py View File

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

Loading…
Cancel
Save