Get the tests working under Python 3
Fix non-py3k-compatible syntax and add a Python 3.5 test job. Change-Id: I33195c70d134c004bdc21fbfb3d30f66c2deeb4e Story: #2002586 Task: #24298
This commit is contained in:
parent
20e3165c1d
commit
47bd699e45
|
@ -1,3 +1,4 @@
|
|||
- project:
|
||||
templates:
|
||||
- openstack-python-jobs
|
||||
- openstack-python35-jobs
|
||||
|
|
36
bin/heat-cfn
36
bin/heat-cfn
|
@ -27,7 +27,7 @@ import sys
|
|||
import time
|
||||
import logging
|
||||
|
||||
import httplib
|
||||
import six.moves.http_client as httplib
|
||||
|
||||
import oslo_i18n
|
||||
from six.moves.urllib.parse import urlparse
|
||||
|
@ -131,7 +131,7 @@ def template_validate(options, arguments):
|
|||
c = get_client(options)
|
||||
parameters.update(c.format_parameters(options))
|
||||
result = c.validate_template(**parameters)
|
||||
print c.format_template(result)
|
||||
print(c.format_template(result))
|
||||
|
||||
|
||||
@utils.catch_error('estimatetemplatecost')
|
||||
|
@ -154,7 +154,7 @@ def estimate_template_cost(options, arguments):
|
|||
c = get_client(options)
|
||||
parameters.update(c.format_parameters(options))
|
||||
result = c.estimate_template_cost(**parameters)
|
||||
print result
|
||||
print(result)
|
||||
|
||||
|
||||
@utils.catch_error('gettemplate')
|
||||
|
@ -172,7 +172,7 @@ def get_template(options, arguments):
|
|||
|
||||
c = get_client(options)
|
||||
result = c.get_template(**parameters)
|
||||
print result
|
||||
print(result)
|
||||
|
||||
|
||||
@utils.catch_error('create')
|
||||
|
@ -215,7 +215,7 @@ def stack_create(options, arguments):
|
|||
c = get_client(options)
|
||||
parameters.update(c.format_parameters(options))
|
||||
result = c.create_stack(**parameters)
|
||||
print result
|
||||
print(result)
|
||||
|
||||
|
||||
@utils.catch_error('update')
|
||||
|
@ -256,7 +256,7 @@ def stack_update(options, arguments):
|
|||
c = get_client(options)
|
||||
parameters.update(c.format_parameters(options))
|
||||
result = c.update_stack(**parameters)
|
||||
print result
|
||||
print(result)
|
||||
|
||||
|
||||
@utils.catch_error('delete')
|
||||
|
@ -278,7 +278,7 @@ def stack_delete(options, arguments):
|
|||
|
||||
c = get_client(options)
|
||||
result = c.delete_stack(**parameters)
|
||||
print result
|
||||
print(result)
|
||||
|
||||
|
||||
@utils.catch_error('describe')
|
||||
|
@ -296,7 +296,7 @@ def stack_describe(options, arguments):
|
|||
|
||||
c = get_client(options)
|
||||
result = c.describe_stacks(**parameters)
|
||||
print c.format_stack(result)
|
||||
print(c.format_stack(result))
|
||||
|
||||
|
||||
@utils.catch_error('event-list')
|
||||
|
@ -314,7 +314,7 @@ def stack_events_list(options, arguments):
|
|||
|
||||
c = get_client(options)
|
||||
result = c.list_stack_events(**parameters)
|
||||
print c.format_stack_event(result)
|
||||
print(c.format_stack_event(result))
|
||||
|
||||
|
||||
@utils.catch_error('resource')
|
||||
|
@ -326,7 +326,7 @@ def stack_resource_show(options, arguments):
|
|||
try:
|
||||
stack_name, resource_name = arguments
|
||||
except ValueError:
|
||||
print 'Enter stack name and logical resource id'
|
||||
print('Enter stack name and logical resource id')
|
||||
return
|
||||
|
||||
parameters = {
|
||||
|
@ -334,7 +334,7 @@ def stack_resource_show(options, arguments):
|
|||
'LogicalResourceId': resource_name,
|
||||
}
|
||||
result = c.describe_stack_resource(**parameters)
|
||||
print c.format_stack_resource_detail(result)
|
||||
print(c.format_stack_resource_detail(result))
|
||||
|
||||
|
||||
@utils.catch_error('resource-list')
|
||||
|
@ -346,14 +346,14 @@ def stack_resources_list(options, arguments):
|
|||
try:
|
||||
stack_name = arguments.pop(0)
|
||||
except IndexError:
|
||||
print 'Enter stack name'
|
||||
print('Enter stack name')
|
||||
return
|
||||
|
||||
parameters = {
|
||||
'StackName': stack_name,
|
||||
}
|
||||
result = c.list_stack_resources(**parameters)
|
||||
print c.format_stack_resource_summary(result)
|
||||
print(c.format_stack_resource_summary(result))
|
||||
|
||||
|
||||
@utils.catch_error('resource-list-details')
|
||||
|
@ -376,7 +376,7 @@ def stack_resources_list_details(options, arguments):
|
|||
name_or_pid = arguments.pop(0)
|
||||
except IndexError:
|
||||
logging.error("Must pass a stack_name or physical_resource_id")
|
||||
print usage
|
||||
print(usage)
|
||||
return
|
||||
|
||||
logical_resource_id = arguments.pop(0) if arguments else None
|
||||
|
@ -388,11 +388,11 @@ def stack_resources_list_details(options, arguments):
|
|||
result = c.describe_stack_resources(**parameters)
|
||||
|
||||
if result:
|
||||
print c.format_stack_resource(result)
|
||||
print(c.format_stack_resource(result))
|
||||
else:
|
||||
logging.error("Invalid stack_name, physical_resource_id " +
|
||||
"or logical_resource_id")
|
||||
print usage
|
||||
print(usage)
|
||||
|
||||
|
||||
@utils.catch_error('list')
|
||||
|
@ -404,7 +404,7 @@ def stack_list(options, arguments):
|
|||
'''
|
||||
c = get_client(options)
|
||||
result = c.list_stacks()
|
||||
print c.format_stack_summary(result)
|
||||
print(c.format_stack_summary(result))
|
||||
|
||||
|
||||
def get_client(options):
|
||||
|
@ -595,7 +595,7 @@ def print_help(options, args):
|
|||
|
||||
subst = {'prog': os.path.basename(sys.argv[0])}
|
||||
docs = [lookup_command(parser, cmd).__doc__ % subst for cmd in args]
|
||||
print '\n\n'.join(docs)
|
||||
print('\n\n'.join(docs))
|
||||
|
||||
|
||||
def lookup_command(parser, command_name):
|
||||
|
|
|
@ -64,7 +64,7 @@ def alarm_describe(options, arguments):
|
|||
|
||||
c = heat_client.get_client(options.port)
|
||||
result = c.describe_alarm(**parameters)
|
||||
print c.format_metric_alarm(result)
|
||||
print(c.format_metric_alarm(result))
|
||||
|
||||
|
||||
@utils.catch_error('alarm-set-state')
|
||||
|
@ -82,9 +82,9 @@ def alarm_set_state(options, arguments):
|
|||
parameters['StateValue'] = arguments.pop(0)
|
||||
except IndexError:
|
||||
logging.error("Must specify AlarmName and StateValue")
|
||||
print usage
|
||||
print "StateValue must be one of %s, %s or %s" % (
|
||||
heat_client.BotoCWClient.ALARM_STATES)
|
||||
print(usage)
|
||||
print("StateValue must be one of %s, %s or %s" % (
|
||||
heat_client.BotoCWClient.ALARM_STATES))
|
||||
return utils.FAILURE
|
||||
try:
|
||||
parameters['StateReason'] = arguments.pop(0)
|
||||
|
@ -96,7 +96,7 @@ def alarm_set_state(options, arguments):
|
|||
|
||||
c = heat_client.get_client(options.port)
|
||||
result = c.set_alarm_state(**parameters)
|
||||
print result
|
||||
print(result)
|
||||
|
||||
|
||||
@utils.catch_error('metric-list')
|
||||
|
@ -112,7 +112,7 @@ def metric_list(options, arguments):
|
|||
|
||||
c = heat_client.get_client(options.port)
|
||||
result = c.list_metrics(**parameters)
|
||||
print c.format_metric(result)
|
||||
print(c.format_metric(result))
|
||||
|
||||
|
||||
@utils.catch_error('metric-put-data')
|
||||
|
@ -139,12 +139,12 @@ e.g
|
|||
parameters['MetricValue'] = arguments.pop(0)
|
||||
except IndexError:
|
||||
logging.error("Please specify the alarm, metric, unit and value")
|
||||
print usage
|
||||
print(usage)
|
||||
return utils.FAILURE
|
||||
|
||||
c = heat_client.get_client(options.port)
|
||||
result = c.put_metric_data(**parameters)
|
||||
print result
|
||||
print(result)
|
||||
|
||||
|
||||
def create_options(parser):
|
||||
|
@ -214,7 +214,7 @@ def print_help(options, args):
|
|||
|
||||
subst = {'prog': os.path.basename(sys.argv[0])}
|
||||
docs = [lookup_command(parser, cmd).__doc__ % subst for cmd in args]
|
||||
print '\n\n'.join(docs)
|
||||
print('\n\n'.join(docs))
|
||||
|
||||
|
||||
def lookup_command(parser, command_name):
|
||||
|
|
|
@ -19,11 +19,12 @@
|
|||
|
||||
import collections
|
||||
import functools
|
||||
import httplib
|
||||
import os
|
||||
import urllib
|
||||
|
||||
import six
|
||||
import six.moves.urllib.parse as urlparse
|
||||
import six.moves.http_client as httplib
|
||||
try:
|
||||
from eventlet.green import socket
|
||||
from eventlet.green import ssl
|
||||
|
@ -64,7 +65,7 @@ def handle_redirects(func):
|
|||
|
||||
@functools.wraps(func)
|
||||
def wrapped(self, method, url, body, headers):
|
||||
for _dum in xrange(MAX_REDIRECTS):
|
||||
for _dum in range(MAX_REDIRECTS):
|
||||
try:
|
||||
return func(self, method, url, body, headers)
|
||||
except exception.RedirectException as redirect:
|
||||
|
@ -434,7 +435,7 @@ class BaseClient(object):
|
|||
return method.lower() in ('post', 'put')
|
||||
|
||||
def _simple(body):
|
||||
return body is None or isinstance(body, basestring)
|
||||
return body is None or isinstance(body, six.string_types)
|
||||
|
||||
def _filelike(body):
|
||||
return hasattr(body, 'read')
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
import functools
|
||||
import sys
|
||||
|
||||
import six
|
||||
import six.moves.urllib.parse as urlparse
|
||||
|
||||
from heat_cfnclient._i18n import _
|
||||
|
@ -118,7 +119,7 @@ def wrap_exception(notifier=None, publisher_id=None, event_type=None,
|
|||
payload)
|
||||
|
||||
# re-raise original exception since it may have been clobbered
|
||||
raise exc_info[0], exc_info[1], exc_info[2]
|
||||
six.reraise(*exc_info)
|
||||
|
||||
return functools.wraps(f)(wrapped)
|
||||
return inner
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
# See http://code.google.com/p/python-nose/issues/detail?id=373
|
||||
# The code below enables nosetests to work with i18n _() blocks
|
||||
import __builtin__
|
||||
setattr(__builtin__, '_', lambda x: x)
|
|
@ -40,6 +40,6 @@ class CliTest(testtools.TestCase):
|
|||
stderr=subprocess.PIPE)
|
||||
stdout, stderr = proc.communicate()
|
||||
|
||||
if proc.returncode:
|
||||
print('Error executing %s:\n %s %s ' % (bin, stdout, stderr))
|
||||
raise subprocess.CalledProcessError(proc.returncode, bin)
|
||||
self.assertFalse(proc.returncode,
|
||||
'Error executing %s:\n %s %s ' % (bin,
|
||||
stdout, stderr))
|
||||
|
|
|
@ -14,6 +14,9 @@
|
|||
# under the License.
|
||||
|
||||
import functools
|
||||
|
||||
import six
|
||||
|
||||
from heat_cfnclient.common import exception
|
||||
from oslo_log import log as logging
|
||||
|
||||
|
@ -47,7 +50,7 @@ def catch_error(action):
|
|||
if options.debug:
|
||||
raise
|
||||
LOG.error("Failed to %s. Got error:" % action)
|
||||
pieces = unicode(e).split('\n')
|
||||
pieces = six.text_type(e).split('\n')
|
||||
for piece in pieces:
|
||||
LOG.error(piece)
|
||||
return FAILURE
|
||||
|
|
Loading…
Reference in New Issue