Merge lp:~chris.macnaughton/openstack-mojo-specs/py3 into lp:openstack-mojo-specs

Proposed by Chris MacNaughton
Status: Needs review
Proposed branch: lp:~chris.macnaughton/openstack-mojo-specs/py3
Merge into: lp:openstack-mojo-specs
Diff against target: 301 lines (+62/-32)
3 files modified
helper/utils/kiki.py (+7/-2)
helper/utils/mojo_os_utils.py (+14/-7)
helper/utils/mojo_utils.py (+41/-23)
To merge this branch: bzr merge lp:~chris.macnaughton/openstack-mojo-specs/py3
Reviewer Review Type Date Requested Status
OpenStack Charm Testing Maintainers Pending
Review via email: mp+336590@code.launchpad.net
To post a comment you must log in.
328. By Chris MacNaughton

fix indent

329. By Chris MacNaughton

updates to support py3

330. By Chris MacNaughton

Merge upstream

Unmerged revisions

330. By Chris MacNaughton

Merge upstream

329. By Chris MacNaughton

updates to support py3

328. By Chris MacNaughton

fix indent

327. By Chris MacNaughton

update to support py3

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'helper/utils/kiki.py'
2--- helper/utils/kiki.py 2017-09-21 14:10:57 +0000
3+++ helper/utils/kiki.py 2018-02-05 16:27:09 +0000
4@@ -18,7 +18,7 @@
5
6 Usage:
7
8-import kiki
9+import utils.kiki as kiki
10
11 cmd = [kiki.cmd(), kiki.remove_unit(), unit]
12 subprocess.check_call(cmd)
13@@ -33,6 +33,8 @@
14 import os
15 import subprocess
16
17+import six
18+
19 __author__ = 'David Ames <david.ames@canonical.com>'
20
21 cache = {}
22@@ -120,7 +122,10 @@
23 @returns string Juju version
24 """
25 try:
26- return subprocess.check_output([cmd(), 'version']).rstrip()
27+ output = subprocess.check_output([cmd(), 'version']).rstrip()
28+ if six.PY3:
29+ output = output.decode('utf-8')
30+ return output
31 except OSError as e:
32 raise JujuBinaryNotFound("Juju is not installed at {}. Error: {}"
33 "".format(cmd(), e))
34
35=== modified file 'helper/utils/mojo_os_utils.py'
36--- helper/utils/mojo_os_utils.py 2018-01-23 13:23:09 +0000
37+++ helper/utils/mojo_os_utils.py 2018-02-05 16:27:09 +0000
38@@ -1,6 +1,6 @@
39 #!/usr/bin/env python
40
41-from os_versions import (
42+from utils.os_versions import (
43 OPENSTACK_CODENAMES,
44 SWIFT_CODENAMES,
45 PACKAGE_CODENAMES,
46@@ -15,7 +15,7 @@
47 v3,
48 v2,
49 )
50-import mojo_utils
51+import utils.mojo_utils as mojo_utils
52 from novaclient import client as novaclient_client
53 from neutronclient.v2_0 import client as neutronclient
54
55@@ -25,12 +25,19 @@
56 import re
57 import sys
58 import tempfile
59-import urllib
60+import six
61+if six.PY3:
62+ from urllib.request import urlretrieve
63+else:
64+ from urllib import urlretrieve
65 import os
66 import time
67 import subprocess
68 import paramiko
69-import StringIO
70+try:
71+ from StringIO import StringIO
72+except ImportError:
73+ from io import StringIO
74 import dns.resolver
75
76 CHARM_TYPES = {
77@@ -217,14 +224,14 @@
78 if not image_glance_name:
79 image_glance_name = image.split('/')[-1]
80 local_file = os.path.join(tmp_dir, image_glance_name)
81- urllib.urlretrieve(image, local_file)
82+ urlretrieve(image, local_file)
83 return local_file
84
85
86 def upload_image(gclient, ifile, image_name, public, disk_format,
87 container_format):
88 logging.info('Uploading %s to glance ' % (image_name))
89- with open(ifile) as fimage:
90+ with open(ifile, 'rb') as fimage:
91 gclient.images.create(
92 name=image_name,
93 is_public=public,
94@@ -815,7 +822,7 @@
95 ssh = paramiko.SSHClient()
96 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
97 if privkey:
98- key = paramiko.RSAKey.from_private_key(StringIO.StringIO(privkey))
99+ key = paramiko.RSAKey.from_private_key(StringIO(privkey))
100 ssh.connect(ip, username=username, password='', pkey=key)
101 else:
102 ssh.connect(ip, username=username, password=password)
103
104=== modified file 'helper/utils/mojo_utils.py'
105--- helper/utils/mojo_utils.py 2018-01-19 12:15:27 +0000
106+++ helper/utils/mojo_utils.py 2018-02-05 16:27:09 +0000
107@@ -6,10 +6,11 @@
108 import subprocess
109 import time
110 import yaml
111+import six
112 import utils.juju_wait as juju_wait
113 from collections import Counter
114
115-import kiki
116+import utils.kiki as kiki
117
118
119 JUJU_STATUSES = {
120@@ -80,7 +81,7 @@
121
122 def convert_unit_to_machineno(unit):
123 juju_status = get_juju_status(unit)
124- return juju_status['machines'].itervalues().next()['instance-id']
125+ return iter(juju_status['machines'].values()).next()['instance-id']
126
127
128 def convert_unit_to_machinename(unit):
129@@ -124,6 +125,8 @@
130 cmd.append('uname -a')
131 p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
132 output = p.communicate()
133+ if six.PY3:
134+ output = (output[0].decode('utf-8'), output[1])
135 if p.returncode != 0 and fatal:
136 raise Exception('Error running remote command')
137 return output
138@@ -244,14 +247,14 @@
139
140 def juju_get_config_keys(service):
141 cmd = [kiki.cmd(), kiki.get_config(), service]
142- juju_get_output = subprocess.Popen(cmd, stdout=subprocess.PIPE).stdout
143+ juju_get_output = subprocess.Popen(cmd, stdout=subprocess.PIPE)
144 service_config = yaml.load(juju_get_output)
145- return service_config['settings'].keys()
146+ return list(service_config['settings'].keys())
147
148
149 def juju_get(service, option):
150 cmd = [kiki.cmd(), kiki.get_config(), service]
151- juju_get_output = subprocess.Popen(cmd, stdout=subprocess.PIPE).stdout
152+ juju_get_output = subprocess.Popen(cmd, stdout=subprocess.PIPE)
153 service_config = yaml.load(juju_get_output)
154
155 if (option in service_config['settings'] and
156@@ -277,12 +280,15 @@
157 @returns String name of the cloud for the current Juju 2.x controller
158 """
159 cmd = [kiki.cmd(), 'show-controller', '--format=yaml']
160- cloud_config = yaml.load(subprocess.check_output(cmd))
161+ output = subprocess.check_output(cmd)
162+ if six.PY3:
163+ output = output.decode('utf-8')
164+ cloud_config = yaml.load(output)
165 # There will only be one top level controller from show-controller,
166 # but we do not know its name.
167 assert len(cloud_config) == 1
168 try:
169- return cloud_config.values()[0]['details']['cloud']
170+ return list(cloud_config.values())[0]['details']['cloud']
171 except KeyError:
172 raise KeyError("Failed to get cloud information from the controller")
173
174@@ -292,8 +298,11 @@
175
176 @returns String name of the undercloud type
177 """
178- juju_env = subprocess.check_output([kiki.cmd(), 'switch']).strip('\n')
179- if kiki.version() < 2:
180+ juju_env = subprocess.check_output([kiki.cmd(), 'switch'])
181+ if six.PY3:
182+ juju_env = juju_env.decode('utf-8')
183+ juju_env = juju_env.strip('\n')
184+ if kiki.version()[0] == "1":
185 juju_env_contents = get_juju_environments_yaml()
186 return juju_env_contents['environments'][juju_env]['type']
187 else:
188@@ -303,7 +312,10 @@
189 # the cloud configured in ~/.local/share/juju/clouds.yaml
190 # Determine the cloud type directly
191 cmd = [kiki.cmd(), 'show-cloud', cloud, '--format=yaml']
192- return yaml.load(subprocess.check_output(cmd))['type']
193+ output = subprocess.check_output(cmd)
194+ if six.PY3:
195+ output = output.decode('utf-8')
196+ return yaml.load(output)['type']
197 else:
198 # If the controller was deployed elsewhere
199 # show-controllers unhelpfully returns an empty string for cloud
200@@ -326,7 +338,7 @@
201
202 os_auth_url = os.environ.get('OS_AUTH_URL')
203 if os_auth_url:
204- api_version = os_auth_url.split('/')[-1].translate(None, 'v')
205+ api_version = os_auth_url.split('/')[-1].replace('v', '')
206 else:
207 logging.error('Missing OS authentication setting: OS_AUTH_URL')
208 raise MissingOSAthenticationException(
209@@ -372,7 +384,7 @@
210 auth_settings['OS_PROJECT_ID'] = os_project_id
211
212 # Validate settings
213- for key, settings in auth_settings.items():
214+ for key, settings in list(auth_settings.items()):
215 if settings is None:
216 logging.error('Missing OS authentication setting: {}'
217 ''.format(key))
218@@ -390,9 +402,7 @@
219 return juju_get('keystone', 'vip')
220 if not juju_status:
221 juju_status = get_juju_status()
222- unit = (juju_status[kiki.applications()]['keystone']['units']
223- .itervalues()
224- .next())
225+ unit = (next(iter(juju_status[kiki.applications()]['keystone']['units'].values())))
226 return unit['public-address']
227
228
229@@ -467,7 +477,7 @@
230 def get_mojo_config(filename):
231 config_file = get_mojo_file(filename)
232 logging.info('Using config %s' % (config_file))
233- return yaml.load(file(config_file, 'r'))
234+ return yaml.load(open(config_file, 'r').read())
235
236
237 def get_charm_dir():
238@@ -477,7 +487,9 @@
239
240 def sync_charmhelpers(charmdir):
241 p = subprocess.Popen(['make', 'sync'], cwd=charmdir)
242- p.communicate()
243+ output = p.communicate()
244+ if six.PY3:
245+ output = (output[0].decode('utf-8'), output[1])
246
247
248 def wipe_charm_dir():
249@@ -650,7 +662,7 @@
250 while False in stable_state:
251 juju_status = get_juju_status()
252 stable_state = []
253- for juju_objtype, check_info in checks.iteritems():
254+ for juju_objtype, check_info in checks.items():
255 for check in check_info:
256 check_function = check['check_func']
257 states = check_function(juju_status)
258@@ -658,7 +670,7 @@
259 raise Exception("Error in juju status")
260 stable_state.append(juju_status_all_stable(states))
261 time.sleep(5)
262- for juju_objtype, check_info in checks.iteritems():
263+ for juju_objtype, check_info in checks.items():
264 for check in check_info:
265 check_function = check['check_func']
266 states = check_function(juju_status)
267@@ -743,8 +755,8 @@
268 _vars[_key] = _val
269
270 # Remove keys and items with a None value
271- _vars['vips'] = filter(None, _vips)
272- for k, v in _vars.items():
273+ _vars['vips'] = [_f for _f in _vips if _f]
274+ for k, v in list(_vars.items()):
275 if not v:
276 del _vars[k]
277
278@@ -799,7 +811,10 @@
279
280 def action_get_output(action_id):
281 cmd = kiki.show_action_output_cmd() + ['--format=yaml', action_id]
282- return yaml.load(subprocess.check_output(cmd))
283+ output = subprocess.check_output(cmd)
284+ if six.PY3:
285+ output = output.decode('utf-8')
286+ return yaml.load(output)
287
288
289 def action_get_status(action_id):
290@@ -821,7 +836,10 @@
291 cmd = kiki.run_action_cmd() + ['--format=yaml', unit, action_name]
292 if action_args:
293 cmd.extend(action_args)
294- action_out = yaml.load(subprocess.check_output(cmd))
295+ output = subprocess.check_output(cmd)
296+ if six.PY3:
297+ output = output.decode('utf-8')
298+ action_out = yaml.load(output)
299 action_id = action_out['Action queued with id']
300 if timeout:
301 action_wait(action_id, timeout)

Subscribers

People subscribed via source and target branches