diff --git a/ceilometer/publisher/utils.py b/ceilometer/publisher/utils.py index 51d755b4e..6f89eae8f 100644 --- a/ceilometer/publisher/utils.py +++ b/ceilometer/publisher/utils.py @@ -45,7 +45,9 @@ def compute_signature(message, secret): if not secret: return '' - digest_maker = hmac.new(secret, '', hashlib.sha256) + if isinstance(secret, six.text_type): + secret = secret.encode('utf-8') + digest_maker = hmac.new(secret, b'', hashlib.sha256) for name, value in utils.recursive_keypairs(message): if name == 'message_signature': # Skip any existing signature value, which would not have diff --git a/ceilometer/storage/impl_sqlalchemy.py b/ceilometer/storage/impl_sqlalchemy.py index 77078691d..845d1e915 100644 --- a/ceilometer/storage/impl_sqlalchemy.py +++ b/ceilometer/storage/impl_sqlalchemy.py @@ -270,8 +270,10 @@ class Connection(base.Connection): # TODO(gordc): implement lru_cache to improve performance try: res = models.Resource.__table__ - m_hash = hashlib.md5(jsonutils.dumps(rmeta, - sort_keys=True)).hexdigest() + m_hash = jsonutils.dumps(rmeta, sort_keys=True) + if six.PY3: + m_hash = m_hash.encode('utf-8') + m_hash = hashlib.md5(m_hash).hexdigest() trans = conn.begin_nested() if conn.dialect.name == 'sqlite': trans = conn.begin() diff --git a/ceilometer/tests/test_notification.py b/ceilometer/tests/test_notification.py index 950870401..057ed6b00 100644 --- a/ceilometer/tests/test_notification.py +++ b/ceilometer/tests/test_notification.py @@ -21,6 +21,7 @@ from oslo_context import context import oslo_messaging import oslo_messaging.conffixture from oslo_utils import timeutils +import six from stevedore import extension import yaml @@ -182,6 +183,8 @@ class BaseRealNotification(tests_base.BaseTestCase): 'transformers': [], 'publishers': ['test://'], }]) + if six.PY3: + pipeline = pipeline.encode('utf-8') self.expected_samples = 2 pipeline_cfg_file = fileutils.write_to_tempfile(content=pipeline, prefix="pipeline", @@ -202,6 +205,8 @@ class BaseRealNotification(tests_base.BaseTestCase): 'publishers': ['test://'] }] }) + if six.PY3: + ev_pipeline = ev_pipeline.encode('utf-8') self.expected_events = 1 ev_pipeline_cfg_file = fileutils.write_to_tempfile( content=ev_pipeline, prefix="event_pipeline", suffix="yaml")