]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Python 3: hmac requires bytes key/msg
authorCedric Brandily <zzelle@gmail.com>
Wed, 29 Jul 2015 11:19:45 +0000 (11:19 +0000)
committerCedric Brandily <zzelle@gmail.com>
Thu, 13 Aug 2015 10:30:42 +0000 (12:30 +0200)
This change encodes hmac key/msg inputs because py3K requires it.

Change-Id: I54a6789aee2fb707c0d753f569d0b2d5fd460682
Blueprint: neutron-python3

neutron/agent/metadata/agent.py
tox.ini

index 60a571f087c7b9efa1e55989c5a7ea4622019a3b..c458c6d04e63db4e2c72b525969d0cb34cca8b91 100644 (file)
@@ -269,9 +269,12 @@ class MetadataProxyHandler(object):
             raise Exception(_('Unexpected response code: %s') % resp.status)
 
     def _sign_instance_id(self, instance_id):
-        return hmac.new(self.conf.metadata_proxy_shared_secret,
-                        instance_id,
-                        hashlib.sha256).hexdigest()
+        secret = self.conf.metadata_proxy_shared_secret
+        if isinstance(secret, six.text_type):
+            secret = secret.encode('utf-8')
+        if isinstance(instance_id, six.text_type):
+            instance_id = instance_id.encode('utf-8')
+        return hmac.new(secret, instance_id, hashlib.sha256).hexdigest()
 
 
 class UnixDomainMetadataProxy(object):
diff --git a/tox.ini b/tox.ini
index db15ec3dafdd1247247a456895e13880cd0ab774..8d0bc2659c4ece037938f07c18809dc1b10ba1ed 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -176,6 +176,7 @@ commands = python -m testtools.run \
     neutron.tests.unit.api.rpc.handlers.test_dvr_rpc \
     neutron.tests.unit.api.rpc.agentnotifiers.test_dhcp_rpc_agent_api \
     neutron.tests.unit.api.v2.test_attributes \
+    neutron.tests.unit.agent.metadata.test_agent \
     neutron.tests.unit.agent.metadata.test_driver \
     neutron.tests.unit.agent.metadata.test_namespace_proxy \
     neutron.tests.unit.agent.test_rpc \