neutron/neutron/agent
Ihar Hrachyshka 118a76fd65 metadata: don't crash proxy on non-unicode user data
We attempt to log every successful metadata response with LOG.debug. But
as per oslo.log docs [1], we should make sure that what we pass into the
library is unicode.

Http.request returns a tuple of Response object and a string, which is
bytes in Python 2.x [2].

That's why we need to convert the response content to unicode before
passing it into oslo.log.

To achieve it, we utilize encodeutils.safe_decode with 'replace' errors
handling strategy, so that we don't get exceptions on input that does
not conform unicode.

For the unit test case, we pass a string that is not expected to convert
to unicode with errors='strict' strategy or similar, and check that we
still don't crash.

While at it, we remove a check for the number of log calls being
triggered, because it's something that we should avoid validating in
test cases, and it cannot trigger a real bug. The mock that was used to
count the number would also hide the bug that we try to reproduce.

Note that the bug does not require debug to be set because the crash
occurs before oslo.log machinery decides it should not log the message.

[1]: http://docs.openstack.org/developer/oslo.log/usage.html#no-more-implicit-conversion-to-unicode-str
[2]: http://bitworking.org/projects/httplib2/doc/html/libhttplib2.html#httplib2.Http.request

Conflicts:
	neutron/agent/metadata/namespace_proxy.py
	neutron/tests/unit/agent/metadata/test_namespace_proxy.py

Closes-Bug: #1501772
Change-Id: I6a32c40ff117fae43913386134c8981539697ce8
(cherry picked from commit 80e3d9be49)
2015-10-09 17:46:19 +02:00
..
common Correct neutron-ns-metadata-proxy command when watch_log is False 2015-09-01 18:10:49 +00:00
dhcp fix DHCP port changed when dhcp-agent restart 2015-06-29 15:01:08 +00:00
l3 Stop sending gratuitous arp when ip version is 6 2015-09-30 06:17:08 +00:00
linux Merge "Process user iptables rules before INVALID" into stable/kilo 2015-10-06 23:57:25 +00:00
metadata metadata: don't crash proxy on non-unicode user data 2015-10-09 17:46:19 +02:00
ovsdb Check idl.run() return value before blocking 2015-09-30 13:53:08 +00:00
windows OVS agent support on Hyper-V 2015-03-25 13:48:33 -07:00
__init__.py Empty files should not contain copyright or license 2014-10-20 00:50:32 +00:00
dhcp_agent.py Allow metadata proxy running with nobody user/group 2015-04-06 18:31:37 +02:00
firewall.py Add missing methods to NoopFirewallDriver 2014-09-28 22:16:57 +04:00
l2population_rpc.py Migrate to oslo.log 2015-03-12 11:22:56 +01:00
l3_agent.py Allow metadata proxy running with nobody user/group 2015-04-06 18:31:37 +02:00
metadata_agent.py Allow metadata proxy running with nobody user/group 2015-04-06 18:31:37 +02:00
rpc.py Migrate to oslo.log 2015-03-12 11:22:56 +01:00
securitygroups_rpc.py Migrate to oslo.log 2015-03-12 11:22:56 +01:00