py34: heat.tests.client/openstack

* importutils.import_object results in a cfg.NoSuchOptError than
  a RuntimeError, handle the cfg.NoSuchOptError too.
* text.MIMEText content cannot be None in python3, use an empty
  string instead if the content is None.
* convert to bytes before using hashlib.sha256
* add a message keyword argument along with the cinder exception
  because self.__class__.message doesn't exist for exceptions in py34
* assert whether the string is against exception.args instead of the
  exception object itself.
* assert against a dictionary rather than a flattened string
  for consistent checking
* convert json strings to json before asserting/comparing

Change-Id: I5bbbc75373ce8009f0791cd2c7df1ba4c2d473b2
This commit is contained in:
Sirushti Murugesan 2015-08-07 14:30:29 +05:30
parent ee563bd6f1
commit 1023b6262f
8 changed files with 24 additions and 10 deletions

View File

@ -89,9 +89,9 @@ class ClientBackend(object):
try:
return importutils.import_object(cfg.CONF.cloud_backend,
context)
except (ImportError, RuntimeError) as err:
except (ImportError, RuntimeError, cfg.NoSuchOptError) as err:
msg = _('Invalid cloud_backend setting in heat.conf '
'detected - %s') % six.text_type(err)
'detected - %s') % six.text_type(err)
LOG.error(msg)
raise exception.Invalid(reason=msg)

View File

@ -297,6 +297,8 @@ class NovaClientPlugin(client_plugin.ClientPlugin):
def make_subpart(content, filename, subtype=None):
if subtype is None:
subtype = os.path.splitext(filename)[0]
if content is None:
content = ''
msg = text.MIMEText(content, _subtype=subtype)
msg.add_header('Content-Disposition', 'attachment',
filename=filename)

View File

@ -17,6 +17,7 @@ import hashlib
import random
import time
import six
from six.moves.urllib import parse
from swiftclient import client as sc
from swiftclient import exceptions
@ -98,7 +99,8 @@ class SwiftClientPlugin(client_plugin.ClientPlugin):
if key_header not in self.client().head_account():
self.client().post_account({
key_header: hashlib.sha224(
str(random.getrandbits(256))).hexdigest()[:32]})
six.b(six.text_type(
random.getrandbits(256)))).hexdigest()[:32]})
key = self.client().head_account()[key_header]

View File

@ -425,7 +425,8 @@ class TestIsNotFound(common.HeatTestCase):
is_client_exception=True,
is_conflict=True,
plugin='cinder',
exception=lambda: cinder_exc.ClientException(code=409),
exception=lambda: cinder_exc.ClientException(
code=409, message='conflict'),
)),
('glance_not_found', dict(
is_not_found=True,

View File

@ -357,7 +357,7 @@ class KeystoneClientTest(common.HeatTestCase):
err = self.assertRaises(ValueError,
heat_ks_client.delete_stack_domain_user,
user_id='duser123', project_id='aproject')
self.assertIn('User delete in invalid domain', err)
self.assertIn('User delete in invalid domain', err.args)
def test_delete_stack_domain_user_error_project(self):
"""Test deleting a stack domain user, wrong project."""
@ -379,7 +379,7 @@ class KeystoneClientTest(common.HeatTestCase):
err = self.assertRaises(ValueError,
heat_ks_client.delete_stack_domain_user,
user_id='duser123', project_id='aproject')
self.assertIn('User delete in invalid project', err)
self.assertIn('User delete in invalid project', err.args)
def test_delete_stack_user(self):

View File

@ -18,6 +18,7 @@ import uuid
import mock
from novaclient import exceptions as nova_exceptions
from oslo_config import cfg
from oslo_serialization import jsonutils as json
import six
from heat.common import exception
@ -386,7 +387,9 @@ class NovaClientPluginMetadataTests(NovaClientPluginTestCase):
def test_serialize_dict(self):
original = {'test_key': {'a': 'b', 'c': 'd'}}
expected = {'test_key': '{"a": "b", "c": "d"}'}
self.assertEqual(expected, self.nova_plugin.meta_serialize(original))
actual = self.nova_plugin.meta_serialize(original)
self.assertEqual(json.loads(expected['test_key']),
json.loads(actual['test_key']))
def test_serialize_none(self):
original = {'test_key': None}

View File

@ -14,6 +14,7 @@
import datetime
import uuid
from oslo_serialization import jsonutils as json
from oslo_utils import timeutils
import six
@ -230,7 +231,8 @@ class HeatWaitConditionTest(common.HeatTestCase):
'status': 'SUCCESS'}
ret = handle.handle_signal(details=test_metadata)
wc_att = rsrc.FnGetAtt('data')
self.assertEqual(u'{"1": "foo", "2": "dog"}', wc_att)
self.assertEqual(json.loads(u'{"1": "foo", "2": "dog"}'),
json.loads(wc_att))
self.assertEqual('status:SUCCESS reason:cat', ret)
self.m.VerifyAll()
@ -244,7 +246,8 @@ class HeatWaitConditionTest(common.HeatTestCase):
handle.handle_signal()
wc_att = rsrc.FnGetAtt('data')
self.assertEqual(u'{"1": null, "2": null}', wc_att)
self.assertEqual(json.loads(u'{"1": null, "2": null}'),
json.loads(wc_att))
self.m.VerifyAll()
def test_data_partial_complete(self):
@ -261,7 +264,8 @@ class HeatWaitConditionTest(common.HeatTestCase):
expected = 'status:SUCCESS reason:Signal 2 received'
self.assertEqual(expected, ret)
wc_att = rsrc.FnGetAtt('data')
self.assertEqual(u'{"1": null, "2": null}', wc_att)
self.assertEqual(json.loads(u'{"1": null, "2": null}'),
json.loads(wc_att))
self.m.VerifyAll()
def _create_heat_handle(self):

View File

@ -26,6 +26,7 @@ heat.tests.ceilometer.test_gnocchi_alarm
heat.tests.cinder.test_cinder_volume_type
heat.tests.cinder.test_volume
heat.tests.cinder.test_volume_type_encryption
heat.tests.clients
heat.tests.clients.test_barbican_client
heat.tests.clients.test_cinder_client
heat.tests.clients.test_glance_client
@ -83,6 +84,7 @@ heat.tests.nova.test_nova_floatingip
heat.tests.nova.test_nova_keypair
heat.tests.nova.test_nova_servergroup
heat.tests.nova.test_server
heat.tests.openstack
heat.tests.test_attributes
heat.tests.test_auth_password
heat.tests.test_auth_url