From: Cedric Brandily Date: Wed, 29 Jul 2015 11:19:45 +0000 (+0000) Subject: Python 3: hmac requires bytes key/msg X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=60a9f4a6f8a1f31093a2a888466f91ff202b971f;p=openstack-build%2Fneutron-build.git Python 3: hmac requires bytes key/msg This change encodes hmac key/msg inputs because py3K requires it. Change-Id: I54a6789aee2fb707c0d753f569d0b2d5fd460682 Blueprint: neutron-python3 --- diff --git a/neutron/agent/metadata/agent.py b/neutron/agent/metadata/agent.py index 60a571f08..c458c6d04 100644 --- a/neutron/agent/metadata/agent.py +++ b/neutron/agent/metadata/agent.py @@ -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 db15ec3da..8d0bc2659 100644 --- 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 \