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
This commit is contained in:
Luong Anh Tuan 2016-11-15 14:36:46 +07:00 committed by Tuan Luong-Anh
parent f330dac837
commit ab41106cf6
5 changed files with 11 additions and 10 deletions

View File

@ -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)

View File

@ -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

View File

@ -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()

View File

@ -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 {}

View File

@ -9,6 +9,7 @@ netifaces>=0.10.4 # MIT
oslo.config!=3.18.0,>=3.14.0 # Apache-2.0
oslo.concurrency>=3.8.0 # Apache-2.0
oslo.log>=3.11.0 # Apache-2.0
oslo.serialization>=1.10.0 # Apache-2.0
oslo.service>=1.10.0 # Apache-2.0
oslo.utils>=3.18.0 # Apache-2.0
pecan!=1.0.2,!=1.0.3,!=1.0.4,!=1.2,>=1.0.0 # BSD