diff options
| author | Luong Anh Tuan <tuanla@vn.fujitsu.com> | 2016-11-15 14:36:46 +0700 |
|---|---|---|
| committer | Tuan Luong-Anh <tuanla@vn.fujitsu.com> | 2016-11-16 08:19:51 +0000 |
| commit | ab41106cf66f779f4b29a113ab1757bc7de66f0c (patch) | |
| tree | 62d53ddfb7ffaec1c25e193555bd3585d8de6b7d /ironic_python_agent | |
| parent | f330dac837f0deef069681ef8fe2145c01eb8181 (diff) | |
| download | ironic-python-agent-ab41106cf66f779f4b29a113ab1757bc7de66f0c.tar.gz | |
Python 3 Compatible JSON
In order to be really python3 compatible, the json lib was replaced
with oslo.serialization(1.10 or newer) module jsontuils since it's
the recommended migration to python3 guide.
https://wiki.openstack.org/wiki/Python3#Serialization:_base64.2C_JSON.2C_etc.
Change-Id: I2d8b62e642aba4ccd1b70be7e9b3784a95a6743d
Closes-Bug: #1629068
Diffstat (limited to 'ironic_python_agent')
| -rw-r--r-- | ironic_python_agent/inspector.py | 4 | ||||
| -rw-r--r-- | ironic_python_agent/ironic_api_client.py | 6 | ||||
| -rw-r--r-- | ironic_python_agent/tests/unit/test_agent.py | 5 | ||||
| -rw-r--r-- | ironic_python_agent/tests/unit/test_ironic_api_client.py | 5 |
4 files changed, 10 insertions, 10 deletions
diff --git a/ironic_python_agent/inspector.py b/ironic_python_agent/inspector.py index bcd54489..97d82774 100644 --- a/ironic_python_agent/inspector.py +++ b/ironic_python_agent/inspector.py @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json import os import time @@ -21,6 +20,7 @@ import netaddr from oslo_concurrency import processutils from oslo_config import cfg from oslo_log import log as logging +from oslo_serialization import jsonutils from oslo_utils import excutils from oslo_utils import units import requests @@ -363,7 +363,7 @@ def collect_extra_hardware(data, failures): return try: - data['data'] = json.loads(out) + data['data'] = jsonutils.loads(out) except ValueError as exc: msg = 'JSON returned from hardware-detect cannot be decoded: %s' failures.add(msg, exc) diff --git a/ironic_python_agent/ironic_api_client.py b/ironic_python_agent/ironic_api_client.py index 6d48e551..1fd8caf1 100644 --- a/ironic_python_agent/ironic_api_client.py +++ b/ironic_python_agent/ironic_api_client.py @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json from oslo_log import log +from oslo_serialization import jsonutils from oslo_service import loopingcall import requests @@ -72,7 +72,7 @@ class APIClient(object): raise errors.HeartbeatError(str(e)) if response.status_code == requests.codes.CONFLICT: - data = json.loads(response.content) + data = jsonutils.loads(response.content) raise errors.HeartbeatConflictError(data.get('faultstring')) elif response.status_code != requests.codes.ACCEPTED: msg = 'Invalid status code: {}'.format(response.status_code) @@ -118,7 +118,7 @@ class APIClient(object): return False try: - content = json.loads(response.content) + content = jsonutils.loads(response.content) except Exception as e: LOG.warning('Error decoding response: %s', e) return False diff --git a/ironic_python_agent/tests/unit/test_agent.py b/ironic_python_agent/tests/unit/test_agent.py index 7c35ec68..a0a0690d 100644 --- a/ironic_python_agent/tests/unit/test_agent.py +++ b/ironic_python_agent/tests/unit/test_agent.py @@ -12,13 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json import socket import time import mock from oslo_concurrency import processutils from oslo_config import cfg +from oslo_serialization import jsonutils from oslotest import base as test_base import pkg_resources from stevedore import extension @@ -158,7 +158,8 @@ class TestBaseAgent(test_base.BaseTestCase): # object. a_encoded = self.encoder.encode(a) b_encoded = self.encoder.encode(b) - self.assertEqual(json.loads(a_encoded), json.loads(b_encoded)) + self.assertEqual(jsonutils.loads(a_encoded), + jsonutils.loads(b_encoded)) def test_get_status(self): started_at = time.time() diff --git a/ironic_python_agent/tests/unit/test_ironic_api_client.py b/ironic_python_agent/tests/unit/test_ironic_api_client.py index 3c345a93..3fe1807c 100644 --- a/ironic_python_agent/tests/unit/test_ironic_api_client.py +++ b/ironic_python_agent/tests/unit/test_ironic_api_client.py @@ -12,9 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json - import mock +from oslo_serialization import jsonutils from oslo_service import loopingcall from oslotest import base as test_base @@ -28,7 +27,7 @@ API_URL = 'http://agent-api.ironic.example.org/' class FakeResponse(object): def __init__(self, content=None, status_code=200, headers=None): content = content or {} - self.content = json.dumps(content) + self.content = jsonutils.dumps(content) self.status_code = status_code self.headers = headers or {} |
