Merge "Remove six and python 2.7 full support"

This commit is contained in:
Zuul 2020-05-03 05:41:58 +00:00 committed by Gerrit Code Review
commit e8c843cc63
10 changed files with 37 additions and 51 deletions

View File

@ -18,7 +18,6 @@ import mock
from oslo_messaging.rpc import dispatcher
from oslo_serialization import jsonutils as json
from oslo_utils import timeutils
import six
from heat.common import crypt
from heat.common import exception
@ -202,7 +201,7 @@ class SoftwareConfigServiceTest(common.HeatTestCase):
try:
stack.validate()
except exception.StackValidationFailed as exc:
self.fail("Validation should have passed: %s" % six.text_type(exc))
self.fail("Validation should have passed: %s" % str(exc))
def _create_software_deployment(self, config_id=None, input_values=None,
action='INIT',
@ -600,7 +599,7 @@ class SoftwareConfigServiceTest(common.HeatTestCase):
values.update(kwargs)
updated = self.engine.update_software_deployment(
self.ctx, deployment_id, updated_at=None, **values)
for key, value in six.iteritems(kwargs):
for key, value in kwargs.items():
self.assertEqual(value, updated[key])
check_software_deployment_updated(config_id=config_id)
@ -822,7 +821,7 @@ class SoftwareConfigServiceTest(common.HeatTestCase):
deployment = self._create_software_deployment(
status='IN_PROGRESS', config_id=config['id'])
deployment_id = six.text_type(deployment['id'])
deployment_id = str(deployment['id'])
sd = software_deployment_object.SoftwareDeployment.get_by_id(
self.ctx, deployment_id)

View File

@ -14,7 +14,6 @@
import mock
from oslo_config import cfg
from oslo_messaging.rpc import dispatcher
import six
from heat.common import exception
from heat.engine import service
@ -168,4 +167,4 @@ class StackServiceAdoptTest(common.HeatTestCase):
template, {}, None,
{'adopt_stack_data': str(adopt_data)})
self.assertEqual(exception.NotSupported, ex.exc_info[0])
self.assertIn('Stack Adopt', six.text_type(ex.exc_info[1]))
self.assertIn('Stack Adopt', str(ex.exc_info[1]))

View File

@ -15,7 +15,6 @@ import mock
from oslo_config import cfg
from oslo_messaging.rpc import dispatcher
from oslo_service import threadgroup
import six
from swiftclient import exceptions
from heat.common import environment_util as env_util
@ -94,7 +93,7 @@ class StackCreateTest(common.HeatTestCase):
self.assertEqual(exception.NotFound, ex.exc_info[0])
self.assertIn('Could not fetch files from container '
'test_container, reason: error.',
six.text_type(ex.exc_info[1]))
str(ex.exc_info[1]))
def test_stack_create(self):
stack_name = 'service_create_test_stack'
@ -153,7 +152,7 @@ class StackCreateTest(common.HeatTestCase):
self._test_stack_create, stack_name)
self.assertEqual(exception.RequestLimitExceeded, ex.exc_info[0])
self.assertIn("You have reached the maximum stacks per tenant",
six.text_type(ex.exc_info[1]))
str(ex.exc_info[1]))
@mock.patch.object(stack.Stack, 'validate')
def test_stack_create_verify_err(self, mock_validate):
@ -238,7 +237,7 @@ class StackCreateTest(common.HeatTestCase):
template, params, None, {}, None)
self.assertEqual(exception.MissingCredentialError, ex.exc_info[0])
self.assertEqual('Missing required credential: X-Auth-Key',
six.text_type(ex.exc_info[1]))
str(ex.exc_info[1]))
mock_tmpl.assert_called_once_with(template, files=None)
mock_env.assert_called_once_with(params)
@ -259,7 +258,7 @@ class StackCreateTest(common.HeatTestCase):
template, params, None, {})
self.assertEqual(exception.MissingCredentialError, ex.exc_info[0])
self.assertEqual('Missing required credential: X-Auth-User',
six.text_type(ex.exc_info[1]))
str(ex.exc_info[1]))
mock_tmpl.assert_called_once_with(template, files=None)
mock_env.assert_called_once_with(params)
@ -326,7 +325,7 @@ class StackCreateTest(common.HeatTestCase):
tpl, params, None, {})
self.assertEqual(exception.RequestLimitExceeded, ex.exc_info[0])
self.assertIn(exception.StackResourceLimitExceeded.msg_fmt,
six.text_type(ex.exc_info[1]))
str(ex.exc_info[1]))
@mock.patch.object(threadgroup, 'ThreadGroup')
@mock.patch.object(stack.Stack, 'validate')
@ -421,7 +420,7 @@ class StackCreateTest(common.HeatTestCase):
self.man._validate_deferred_auth_context,
ctx, stk)
self.assertEqual('Missing required credential: X-Auth-User',
six.text_type(ex))
str(ex))
# missing password
ctx = utils.dummy_context(password=None)
@ -429,7 +428,7 @@ class StackCreateTest(common.HeatTestCase):
self.man._validate_deferred_auth_context,
ctx, stk)
self.assertEqual('Missing required credential: X-Auth-Key',
six.text_type(ex))
str(ex))
@mock.patch.object(instances.Instance, 'validate')
@mock.patch.object(stack.Stack, 'total_resources')

View File

@ -13,7 +13,6 @@
import mock
from oslo_config import cfg
from oslo_messaging.rpc import dispatcher
import six
from heat.common import exception
from heat.common import identifier
@ -244,7 +243,7 @@ class StackResourcesServiceTest(common.HeatTestCase):
@tools.stack_context('service_resources_list_test_stack_with_depth')
def test_stack_resources_list_with_depth(self, mock_load):
mock_load.return_value = self.stack
resources = six.itervalues(self.stack)
resources = self.stack.values()
self.stack.iter_resources = mock.Mock(return_value=resources)
self.eng.list_stack_resources(self.ctx,
self.stack.identifier(),
@ -256,7 +255,7 @@ class StackResourcesServiceTest(common.HeatTestCase):
@tools.stack_context('service_resources_list_test_stack_with_max_depth')
def test_stack_resources_list_with_max_depth(self, mock_load):
mock_load.return_value = self.stack
resources = six.itervalues(self.stack)
resources = self.stack.values()
self.stack.iter_resources = mock.Mock(return_value=resources)
self.eng.list_stack_resources(self.ctx,
self.stack.identifier(),
@ -269,7 +268,7 @@ class StackResourcesServiceTest(common.HeatTestCase):
@tools.stack_context('service_resources_list_test_stack')
def test_stack_resources_filter_type(self, mock_load):
mock_load.return_value = self.stack
resources = six.itervalues(self.stack)
resources = self.stack.values()
self.stack.iter_resources = mock.Mock(return_value=resources)
filters = {'type': 'AWS::EC2::Instance'}
resources = self.eng.list_stack_resources(self.ctx,
@ -283,7 +282,7 @@ class StackResourcesServiceTest(common.HeatTestCase):
@tools.stack_context('service_resources_list_test_stack')
def test_stack_resources_filter_type_not_found(self, mock_load):
mock_load.return_value = self.stack
resources = six.itervalues(self.stack)
resources = self.stack.values()
self.stack.iter_resources = mock.Mock(return_value=resources)
filters = {'type': 'NonExisted'}
resources = self.eng.list_stack_resources(self.ctx,
@ -432,7 +431,7 @@ class StackResourcesServiceTest(common.HeatTestCase):
'WebServerScaleDownPolicy',
details)
msg = 'Invalid hook type "invalid_hook"'
self.assertIn(msg, six.text_type(ex.exc_info[1]))
self.assertIn(msg, str(ex.exc_info[1]))
self.assertEqual(exception.InvalidBreakPointHook,
ex.exc_info[0])
@ -447,7 +446,7 @@ class StackResourcesServiceTest(common.HeatTestCase):
details)
msg = ('The "pre-update" hook is not defined on '
'AWSScalingPolicy "WebServerScaleDownPolicy"')
self.assertIn(msg, six.text_type(ex.exc_info[1]))
self.assertIn(msg, str(ex.exc_info[1]))
self.assertEqual(exception.InvalidBreakPointHook,
ex.exc_info[0])

View File

@ -14,7 +14,6 @@ import uuid
import mock
from oslo_messaging.rpc import dispatcher
import six
from heat.common import exception
from heat.common import template_format
@ -52,7 +51,7 @@ class SnapshotServiceTest(common.HeatTestCase):
snapshot_id)
expected = 'Snapshot with id %s not found' % snapshot_id
self.assertEqual(exception.NotFound, ex.exc_info[0])
self.assertIn(expected, six.text_type(ex.exc_info[1]))
self.assertIn(expected, str(ex.exc_info[1]))
def test_show_snapshot_not_belong_to_stack(self):
stk1 = self._create_stack('stack_snaphot_not_belong_to_stack_1')
@ -72,7 +71,7 @@ class SnapshotServiceTest(common.HeatTestCase):
'could not be found') % {'snapshot': snapshot_id,
'stack': stk2.name}
self.assertEqual(exception.SnapshotNotFound, ex.exc_info[0])
self.assertIn(expected, six.text_type(ex.exc_info[1]))
self.assertIn(expected, str(ex.exc_info[1]))
@mock.patch.object(stack.Stack, 'load')
def test_create_snapshot(self, mock_load):
@ -111,7 +110,7 @@ class SnapshotServiceTest(common.HeatTestCase):
self.assertEqual(exception.ActionInProgress, ex.exc_info[0])
msg = ("Stack %(stack)s already has an action (%(action)s) "
"in progress.") % {'stack': stack_name, 'action': stk.action}
self.assertEqual(msg, six.text_type(ex.exc_info[1]))
self.assertEqual(msg, str(ex.exc_info[1]))
mock_load.assert_called_once_with(self.ctx, stack=mock.ANY)
@ -153,7 +152,7 @@ class SnapshotServiceTest(common.HeatTestCase):
'could not be found') % {'snapshot': snapshot_id,
'stack': stk2.name}
self.assertEqual(exception.SnapshotNotFound, ex.exc_info[0])
self.assertIn(expected, six.text_type(ex.exc_info[1]))
self.assertIn(expected, str(ex.exc_info[1]))
mock_load.assert_called_once_with(self.ctx, stack=mock.ANY)
mock_load.reset_mock()
@ -172,7 +171,7 @@ class SnapshotServiceTest(common.HeatTestCase):
self.engine.delete_snapshot,
self.ctx, stk.identifier(), snapshot.id)
msg = 'Deleting in-progress snapshot is not supported'
self.assertIn(msg, six.text_type(ex.exc_info[1]))
self.assertIn(msg, str(ex.exc_info[1]))
self.assertEqual(exception.NotSupported, ex.exc_info[0])
@mock.patch.object(stack.Stack, 'load')
@ -256,6 +255,6 @@ class SnapshotServiceTest(common.HeatTestCase):
'could not be found') % {'snapshot': snapshot_id,
'stack': stk2.name}
self.assertEqual(exception.SnapshotNotFound, ex.exc_info[0])
self.assertIn(expected, six.text_type(ex.exc_info[1]))
self.assertIn(expected, str(ex.exc_info[1]))
mock_load.assert_called_once_with(self.ctx, stack=mock.ANY)

View File

@ -17,7 +17,6 @@ import mock
from oslo_config import cfg
from oslo_messaging import conffixture
from oslo_messaging.rpc import dispatcher
import six
from heat.common import environment_util as env_util
from heat.common import exception
@ -644,7 +643,7 @@ resources:
self.assertEqual(exception.NotSupported, ex.exc_info[0])
self.assertIn("Cancelling update when stack is "
"UPDATE_COMPLETE",
six.text_type(ex.exc_info[1]))
str(ex.exc_info[1]))
@mock.patch.object(stack_object.Stack, 'count_total_resources')
def test_stack_update_equals(self, ctr):
@ -775,7 +774,7 @@ resources:
None, {rpc_api.PARAM_CONVERGE: False})
self.assertEqual(exception.RequestLimitExceeded, ex.exc_info[0])
self.assertIn(exception.StackResourceLimitExceeded.msg_fmt,
six.text_type(ex.exc_info[1]))
str(ex.exc_info[1]))
def test_stack_update_verify_err(self):
stack_name = 'service_update_verify_err_test_stack'
@ -869,7 +868,7 @@ resources:
template, params, None, api_args)
self.assertEqual(exception.MissingCredentialError, ex.exc_info[0])
self.assertEqual('Missing required credential: X-Auth-Key',
six.text_type(ex.exc_info[1]))
str(ex.exc_info[1]))
mock_get.assert_called_once_with(self.ctx, stk.identifier())
@ -950,7 +949,7 @@ resources:
self.assertEqual(exception.NotSupported, ex.exc_info[0])
self.assertIn("PATCH update to non-COMPLETE stack",
six.text_type(ex.exc_info[1]))
str(ex.exc_info[1]))
def test_update_immutable_parameter_disallowed(self):

View File

@ -14,8 +14,6 @@
import sys
import types
import six
from heat.engine import plugin_manager
from heat.tests import common
@ -122,7 +120,7 @@ class TestPluginManager(common.HeatTestCase):
all_items = pm.load_all(mgr)
for item in six.iteritems(current_test_mapping()):
for item in current_test_mapping().items():
self.assertNotIn(item, all_items)
def test_load_all(self):
@ -138,5 +136,5 @@ class TestPluginManager(common.HeatTestCase):
all_items = pm.load_all(mgr)
for item in six.iteritems(current_test_mapping()):
for item in current_test_mapping().items():
self.assertIn(item, all_items)

View File

@ -12,7 +12,6 @@
# under the License.
import mock
import six
from heat.common import exception
from heat.engine import environment
@ -196,7 +195,7 @@ class ResourceTypeTest(common.HeatTestCase):
type_name='ResourceWithWrongRefOnFile')
msg = ('There was an error loading the definition of the global '
'resource type ResourceWithWrongRefOnFile.')
self.assertIn(msg, six.text_type(ex))
self.assertIn(msg, str(ex))
def test_resource_schema_no_template_file(self):
self._no_template_file(self.eng.resource_schema)
@ -209,7 +208,7 @@ class ResourceTypeTest(common.HeatTestCase):
self.eng.resource_schema,
self.ctx, type_name='Bogus')
msg = 'The Resource Type (Bogus) could not be found.'
self.assertEqual(msg, six.text_type(ex))
self.assertEqual(msg, str(ex))
def test_resource_schema_unavailable(self):
type_name = 'ResourceWithDefaultClientName'
@ -227,7 +226,7 @@ class ResourceTypeTest(common.HeatTestCase):
'type ResourceWithDefaultClientName, reason: '
'Service endpoint not in service catalog.')
self.assertEqual(msg,
six.text_type(ex),
str(ex),
'invalid exception message')
mock_is_service_available.assert_called_once_with(self.ctx)

View File

@ -16,7 +16,6 @@ import itertools
import eventlet
import mock
import six
from heat.common import timeutils
from heat.engine import dependencies
@ -67,7 +66,7 @@ class ExceptionGroupTest(common.HeatTestCase):
ex2 = Exception("ex 2")
exception_group = scheduler.ExceptionGroup([ex1, ex2])
self.assertEqual("['ex 1', 'ex 2']", six.text_type(exception_group))
self.assertEqual("['ex 1', 'ex 2']", str(exception_group))
class StepTracker(object):
@ -1272,7 +1271,6 @@ class DescriptionTest(common.HeatTestCase):
self.assertEqual('o', scheduler.task_description(C()))
def test_unicode(self):
@six.python_2_unicode_compatible
class C(object):
def __str__(self):
return u'C "\u2665"'

View File

@ -10,9 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import sys
import six
import functools
from heat.common import template_format
from heat.engine.clients.os import glance
@ -268,7 +266,7 @@ def stack_context(stack_name, create_res=True, convergence=False):
of test success/failure.
"""
def stack_delete(test_fn):
@six.wraps(test_fn)
@functools.wraps(test_fn)
def wrapped_test(test_case, *args, **kwargs):
def create_stack():
ctx = getattr(test_case, 'ctx', None)
@ -285,12 +283,11 @@ def stack_context(stack_name, create_res=True, convergence=False):
create_stack()
try:
test_fn(test_case, *args, **kwargs)
except Exception:
exc_class, exc_val, exc_tb = sys.exc_info()
except Exception as err:
try:
delete_stack()
finally:
six.reraise(exc_class, exc_val, exc_tb)
raise err from None
else:
delete_stack()