Update json module to jsonutils

oslo project provide jsonutils, and mistralclient use it in many place[1],
this PS to update the remained json module to oslo jsonutils for
consistency.

[1]: https://github.com/openstack/python-mistralclient/search?utf8=%E2%9C%93&q=jsonutils&type=

Change-Id: Ibbb3f2b5636147a0faf7a23e6bb177978282cbd3
This commit is contained in:
cao.yuan
2019-02-25 00:41:26 +08:00
parent 9824e87cad
commit d81f8997eb
20 changed files with 94 additions and 78 deletions

View File

@@ -13,9 +13,10 @@
# limitations under the License. # limitations under the License.
import copy import copy
import json
import six import six
from oslo_serialization import jsonutils
from keystoneauth1 import exceptions from keystoneauth1 import exceptions
urlparse = six.moves.urllib.parse urlparse = six.moves.urllib.parse
@@ -126,7 +127,7 @@ class ResourceManager(object):
def _create(self, url, data, response_key=None, dump_json=True): def _create(self, url, data, response_key=None, dump_json=True):
if dump_json: if dump_json:
data = json.dumps(data) data = jsonutils.dumps(data)
try: try:
resp = self.http_client.post(url, data) resp = self.http_client.post(url, data)
@@ -140,7 +141,7 @@ class ResourceManager(object):
def _update(self, url, data, response_key=None, dump_json=True): def _update(self, url, data, response_key=None, dump_json=True):
if dump_json: if dump_json:
data = json.dumps(data) data = jsonutils.dumps(data)
try: try:
resp = self.http_client.put(url, data) resp = self.http_client.put(url, data)
@@ -208,7 +209,7 @@ def get_json(response):
if callable(json_field_or_function): if callable(json_field_or_function):
return response.json() return response.json()
else: else:
return json.loads(response.content) return jsonutils.loads(response.content)
class APIException(Exception): class APIException(Exception):

View File

@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import json from oslo_serialization import jsonutils
from mistralclient.api import base from mistralclient.api import base
@@ -30,10 +30,10 @@ class ActionExecutionManager(base.ResourceManager):
data = {'name': name} data = {'name': name}
if input: if input:
data['input'] = json.dumps(input) data['input'] = jsonutils.dumps(input)
if params: if params:
data['params'] = json.dumps(params) data['params'] = jsonutils.dumps(params)
return self._create( return self._create(
'/action_executions', '/action_executions',

View File

@@ -12,8 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import json from oslo_serialization import jsonutils
from oslo_utils import uuidutils from oslo_utils import uuidutils
from mistralclient.api import base from mistralclient.api import base
@@ -47,10 +46,10 @@ class CronTriggerManager(base.ResourceManager):
data.update({'workflow_name': workflow_identifier}) data.update({'workflow_name': workflow_identifier})
if workflow_input: if workflow_input:
data.update({'workflow_input': json.dumps(workflow_input)}) data.update({'workflow_input': jsonutils.dumps(workflow_input)})
if workflow_params: if workflow_params:
data.update({'workflow_params': json.dumps(workflow_params)}) data.update({'workflow_params': jsonutils.dumps(workflow_params)})
return self._create('/cron_triggers', data) return self._create('/cron_triggers', data)

View File

@@ -12,9 +12,10 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import json
import six import six
from oslo_serialization import jsonutils
from mistralclient.api import base from mistralclient.api import base
from mistralclient import utils from mistralclient import utils
@@ -26,7 +27,7 @@ class Environment(base.Resource):
"""Override loading of the "variables" attribute from text to dict.""" """Override loading of the "variables" attribute from text to dict."""
for k, v in self._data.items(): for k, v in self._data.items():
if k == 'variables' and isinstance(v, six.string_types): if k == 'variables' and isinstance(v, six.string_types):
v = json.loads(v) v = jsonutils.loads(v)
try: try:
setattr(self, k, v) setattr(self, k, v)
@@ -50,7 +51,7 @@ class EnvironmentManager(base.ResourceManager):
# Convert dict to text for the variables attribute. # Convert dict to text for the variables attribute.
if isinstance(kwargs['variables'], dict): if isinstance(kwargs['variables'], dict):
kwargs['variables'] = json.dumps(kwargs['variables']) kwargs['variables'] = jsonutils.dumps(kwargs['variables'])
return self._create('/environments', kwargs) return self._create('/environments', kwargs)
@@ -66,7 +67,7 @@ class EnvironmentManager(base.ResourceManager):
# Convert dict to text for the variables attribute. # Convert dict to text for the variables attribute.
if kwargs.get('variables') and isinstance(kwargs['variables'], dict): if kwargs.get('variables') and isinstance(kwargs['variables'], dict):
kwargs['variables'] = json.dumps(kwargs['variables']) kwargs['variables'] = jsonutils.dumps(kwargs['variables'])
return self._update('/environments', kwargs) return self._update('/environments', kwargs)

View File

@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import json from oslo_serialization import jsonutils
from mistralclient.api import base from mistralclient.api import base
@@ -40,10 +40,10 @@ class EventTriggerManager(base.ResourceManager):
} }
if workflow_input: if workflow_input:
data.update({'workflow_input': json.dumps(workflow_input)}) data.update({'workflow_input': jsonutils.dumps(workflow_input)})
if workflow_params: if workflow_params:
data.update({'workflow_params': json.dumps(workflow_params)}) data.update({'workflow_params': jsonutils.dumps(workflow_params)})
return self._create('/event_triggers', data) return self._create('/event_triggers', data)

View File

@@ -13,9 +13,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import json
import six import six
from oslo_serialization import jsonutils
from oslo_utils import uuidutils from oslo_utils import uuidutils
from mistralclient.api import base from mistralclient.api import base
@@ -53,10 +53,10 @@ class ExecutionManager(base.ResourceManager):
if isinstance(workflow_input, six.string_types): if isinstance(workflow_input, six.string_types):
data.update({'input': workflow_input}) data.update({'input': workflow_input})
else: else:
data.update({'input': json.dumps(workflow_input)}) data.update({'input': jsonutils.dumps(workflow_input)})
if params: if params:
data.update({'params': json.dumps(params)}) data.update({'params': jsonutils.dumps(params)})
return self._create('/executions', data) return self._create('/executions', data)

View File

@@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import json from oslo_serialization import jsonutils
from mistralclient.api import base from mistralclient.api import base
@@ -60,6 +60,6 @@ class TaskManager(base.ResourceManager):
} }
if env: if env:
body['env'] = json.dumps(env) body['env'] = jsonutils.dumps(env)
return self._update(url, body) return self._update(url, body)

View File

@@ -14,9 +14,10 @@
# under the License. # under the License.
# #
import json
import logging import logging
from oslo_serialization import jsonutils
from osc_lib.command import command from osc_lib.command import command
from mistralclient.commands.v2 import base from mistralclient.commands.v2 import base
@@ -259,8 +260,8 @@ class GetOutput(command.Command):
output = mistral_client.action_executions.get(parsed_args.id).output output = mistral_client.action_executions.get(parsed_args.id).output
try: try:
output = json.loads(output) output = jsonutils.loads(output)
output = json.dumps(output, indent=4) + "\n" output = jsonutils.dumps(output, indent=4) + "\n"
except Exception: except Exception:
LOG.debug("Task result is not JSON.") LOG.debug("Task result is not JSON.")
@@ -284,8 +285,8 @@ class GetInput(command.Command):
result = mistral_client.action_executions.get(parsed_args.id).input result = mistral_client.action_executions.get(parsed_args.id).input
try: try:
result = json.loads(result) result = jsonutils.loads(result)
result = json.dumps(result, indent=4) + "\n" result = jsonutils.dumps(result, indent=4) + "\n"
except Exception: except Exception:
LOG.debug("Task result is not JSON.") LOG.debug("Task result is not JSON.")

View File

@@ -13,7 +13,8 @@
# limitations under the License. # limitations under the License.
import argparse import argparse
import json
from oslo_serialization import jsonutils
from osc_lib.command import command from osc_lib.command import command
@@ -48,7 +49,7 @@ class EnvironmentFormatter(base.MistralFormatter):
else: else:
data += (None,) data += (None,)
if not lister: if not lister:
data += (json.dumps(environment.variables, indent=4),) data += (jsonutils.dumps(environment.variables, indent=4),)
data += ( data += (
environment.scope, environment.scope,
environment.created_at,) environment.created_at,)
@@ -113,7 +114,7 @@ class Get(command.ShowOne):
data = (environment.name, data = (environment.name,
environment.description, environment.description,
environment.scope, environment.scope,
json.dumps(environment.variables)) jsonutils.dumps(environment.variables))
return columns, data return columns, data

View File

@@ -17,10 +17,11 @@
# under the License. # under the License.
# #
import json
import logging import logging
import os.path import os.path
from oslo_serialization import jsonutils
from osc_lib.command import command from osc_lib.command import command
from mistralclient.commands.v2 import base from mistralclient.commands.v2 import base
@@ -296,8 +297,8 @@ class GetInput(command.Command):
ex_input = mistral_client.executions.get(parsed_args.id).input ex_input = mistral_client.executions.get(parsed_args.id).input
try: try:
ex_input = json.loads(ex_input) ex_input = jsonutils.loads(ex_input)
ex_input = json.dumps(ex_input, indent=4) + "\n" ex_input = jsonutils.dumps(ex_input, indent=4) + "\n"
except Exception: except Exception:
LOG.debug("Execution input is not JSON.") LOG.debug("Execution input is not JSON.")
@@ -320,8 +321,8 @@ class GetOutput(command.Command):
output = mistral_client.executions.get(parsed_args.id).output output = mistral_client.executions.get(parsed_args.id).output
try: try:
output = json.loads(output) output = jsonutils.loads(output)
output = json.dumps(output, indent=4) + "\n" output = jsonutils.dumps(output, indent=4) + "\n"
except Exception: except Exception:
LOG.debug("Execution output is not JSON.") LOG.debug("Execution output is not JSON.")

View File

@@ -15,10 +15,11 @@
# under the License. # under the License.
# #
import json
import logging import logging
import os.path import os.path
from oslo_serialization import jsonutils
from osc_lib.command import command from osc_lib.command import command
from mistralclient.commands.v2 import base from mistralclient.commands.v2 import base
@@ -126,8 +127,8 @@ class GetResult(command.Command):
result = mistral_client.tasks.get(parsed_args.id).result result = mistral_client.tasks.get(parsed_args.id).result
try: try:
result = json.loads(result) result = jsonutils.loads(result)
result = json.dumps(result, indent=4) + "\n" result = jsonutils.dumps(result, indent=4) + "\n"
except Exception: except Exception:
LOG.debug("Task result is not JSON.") LOG.debug("Task result is not JSON.")
@@ -150,8 +151,8 @@ class GetPublished(command.Command):
result = mistral_client.tasks.get(parsed_args.id).published result = mistral_client.tasks.get(parsed_args.id).published
try: try:
result = json.loads(result) result = jsonutils.loads(result)
result = json.dumps(result, indent=4) + "\n" result = jsonutils.dumps(result, indent=4) + "\n"
except Exception: except Exception:
LOG.debug("Task result is not JSON.") LOG.debug("Task result is not JSON.")

View File

@@ -13,11 +13,11 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import json
import os import os
import tempfile import tempfile
import mock import mock
from oslo_serialization import jsonutils
from oslo_utils import uuidutils from oslo_utils import uuidutils
from oslotest import base from oslotest import base
import osprofiler.profiler import osprofiler.profiler
@@ -40,7 +40,7 @@ class BaseClientTests(base.BaseTestCase):
keystone_client_instance.auth_token = uuidutils.generate_uuid() keystone_client_instance.auth_token = uuidutils.generate_uuid()
keystone_client_instance.project_id = uuidutils.generate_uuid() keystone_client_instance.project_id = uuidutils.generate_uuid()
keystone_client_instance.user_id = uuidutils.generate_uuid() keystone_client_instance.user_id = uuidutils.generate_uuid()
keystone_client_instance.auth_ref = str(json.dumps({})) keystone_client_instance.auth_ref = str(jsonutils.dumps({}))
return keystone_client_instance return keystone_client_instance
@mock.patch('keystoneauth1.session.Session') @mock.patch('keystoneauth1.session.Session')

View File

@@ -12,17 +12,17 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import json
import os.path import os.path
import tempfile import tempfile
import yaml import yaml
from mistralclient import utils from mistralclient import utils
from oslo_serialization import jsonutils
from oslotest import base from oslotest import base
ENV_DICT = {'k1': 'abc', 'k2': 123, 'k3': True} ENV_DICT = {'k1': 'abc', 'k2': 123, 'k3': True}
ENV_STR = json.dumps(ENV_DICT) ENV_STR = jsonutils.dumps(ENV_DICT)
ENV_YAML = yaml.safe_dump(ENV_DICT, default_flow_style=False) ENV_YAML = yaml.safe_dump(ENV_DICT, default_flow_style=False)

View File

@@ -15,13 +15,14 @@
# #
import copy import copy
import json
import sys import sys
import six import six
import mock import mock
from oslo_serialization import jsonutils
from mistralclient.api.v2 import action_executions as action_ex from mistralclient.api.v2 import action_executions as action_ex
from mistralclient.commands.v2 import action_executions as action_ex_cmd from mistralclient.commands.v2 import action_executions as action_ex_cmd
from mistralclient.tests.unit import base from mistralclient.tests.unit import base
@@ -44,10 +45,11 @@ ACTION_EX_RESULT = {"test": "is", "passed": "successfully"}
ACTION_EX_INPUT = {"param1": "val1", "param2": 2} ACTION_EX_INPUT = {"param1": "val1", "param2": 2}
ACTION_EX_WITH_OUTPUT_DICT = ACTION_EX_DICT.copy() ACTION_EX_WITH_OUTPUT_DICT = ACTION_EX_DICT.copy()
ACTION_EX_WITH_OUTPUT_DICT.update({'output': json.dumps(ACTION_EX_RESULT)}) ACTION_EX_WITH_OUTPUT_DICT.update(
{'output': jsonutils.dumps(ACTION_EX_RESULT)})
ACTION_EX_WITH_INPUT_DICT = ACTION_EX_DICT.copy() ACTION_EX_WITH_INPUT_DICT = ACTION_EX_DICT.copy()
ACTION_EX_WITH_INPUT_DICT.update({'input': json.dumps(ACTION_EX_INPUT)}) ACTION_EX_WITH_INPUT_DICT.update({'input': jsonutils.dumps(ACTION_EX_INPUT)})
ACTION_EX = action_ex.ActionExecution(mock, ACTION_EX_DICT) ACTION_EX = action_ex.ActionExecution(mock, ACTION_EX_DICT)
ACTION_EX_WITH_OUTPUT = action_ex.ActionExecution( ACTION_EX_WITH_OUTPUT = action_ex.ActionExecution(
@@ -72,7 +74,7 @@ class TestCLIActionExecutions(base.BaseCommandTest):
self.assertDictEqual( self.assertDictEqual(
ACTION_EX_RESULT, ACTION_EX_RESULT,
json.loads(self.app.stdout.write.call_args[0][0]) jsonutils.loads(self.app.stdout.write.call_args[0][0])
) )
def test_create_save_result(self): def test_create_save_result(self):
@@ -105,7 +107,7 @@ class TestCLIActionExecutions(base.BaseCommandTest):
self.assertDictEqual( self.assertDictEqual(
ACTION_EX_RESULT, ACTION_EX_RESULT,
json.loads(self.app.stdout.write.call_args[0][0]) jsonutils.loads(self.app.stdout.write.call_args[0][0])
) )
def test_create_run_sync_and_save_result(self): def test_create_run_sync_and_save_result(self):
@@ -121,7 +123,7 @@ class TestCLIActionExecutions(base.BaseCommandTest):
self.assertDictEqual( self.assertDictEqual(
ACTION_EX_RESULT, ACTION_EX_RESULT,
json.loads(self.app.stdout.write.call_args[0][0]) jsonutils.loads(self.app.stdout.write.call_args[0][0])
) )
def test_update(self): def test_update(self):
@@ -202,7 +204,7 @@ class TestCLIActionExecutions(base.BaseCommandTest):
self.assertDictEqual( self.assertDictEqual(
ACTION_EX_RESULT, ACTION_EX_RESULT,
json.loads(self.app.stdout.write.call_args[0][0]) jsonutils.loads(self.app.stdout.write.call_args[0][0])
) )
def test_get_input(self): def test_get_input(self):
@@ -212,7 +214,7 @@ class TestCLIActionExecutions(base.BaseCommandTest):
self.assertDictEqual( self.assertDictEqual(
ACTION_EX_INPUT, ACTION_EX_INPUT,
json.loads(self.app.stdout.write.call_args[0][0]) jsonutils.loads(self.app.stdout.write.call_args[0][0])
) )
def test_delete(self): def test_delete(self):

View File

@@ -14,10 +14,11 @@
import copy import copy
import datetime import datetime
import json
import os import os
import tempfile import tempfile
from oslo_serialization import jsonutils
import mock import mock
import yaml import yaml
@@ -43,7 +44,7 @@ ENVIRONMENT_DICT = {
ENVIRONMENT = environments.Environment(mock, ENVIRONMENT_DICT) ENVIRONMENT = environments.Environment(mock, ENVIRONMENT_DICT)
EXPECTED_RESULT = (ENVIRONMENT_DICT['name'], EXPECTED_RESULT = (ENVIRONMENT_DICT['name'],
ENVIRONMENT_DICT['description'], ENVIRONMENT_DICT['description'],
json.dumps(ENVIRONMENT_DICT['variables'], indent=4), jsonutils.dumps(ENVIRONMENT_DICT['variables'], indent=4),
ENVIRONMENT_DICT['scope'], ENVIRONMENT_DICT['scope'],
ENVIRONMENT_DICT['created_at'], ENVIRONMENT_DICT['created_at'],
ENVIRONMENT_DICT['updated_at']) ENVIRONMENT_DICT['updated_at'])
@@ -51,7 +52,7 @@ EXPECTED_RESULT = (ENVIRONMENT_DICT['name'],
EXPECTED_EXPORT_RESULT = (ENVIRONMENT_DICT['name'], EXPECTED_EXPORT_RESULT = (ENVIRONMENT_DICT['name'],
ENVIRONMENT_DICT['description'], ENVIRONMENT_DICT['description'],
ENVIRONMENT_DICT['scope'], ENVIRONMENT_DICT['scope'],
json.dumps(ENVIRONMENT_DICT['variables'])) jsonutils.dumps(ENVIRONMENT_DICT['variables']))
class TestCLIEnvironmentsV2(base.BaseCommandTest): class TestCLIEnvironmentsV2(base.BaseCommandTest):
@@ -67,7 +68,7 @@ class TestCLIEnvironmentsV2(base.BaseCommandTest):
self.assertEqual(EXPECTED_RESULT, result[1]) self.assertEqual(EXPECTED_RESULT, result[1])
def test_create_from_json(self): def test_create_from_json(self):
self._test_create(json.dumps(ENVIRONMENT_DICT, indent=4)) self._test_create(jsonutils.dumps(ENVIRONMENT_DICT, indent=4))
def test_create_from_yaml(self): def test_create_from_yaml(self):
yml = yaml.dump(ENVIRONMENT_DICT, default_flow_style=False) yml = yaml.dump(ENVIRONMENT_DICT, default_flow_style=False)
@@ -87,7 +88,7 @@ class TestCLIEnvironmentsV2(base.BaseCommandTest):
env = copy.deepcopy(ENVIRONMENT_DICT) env = copy.deepcopy(ENVIRONMENT_DICT)
del env['created_at'] del env['created_at']
del env['updated_at'] del env['updated_at']
self._test_update(json.dumps(env, indent=4)) self._test_update(jsonutils.dumps(env, indent=4))
def test_update_from_yaml(self): def test_update_from_yaml(self):
env = copy.deepcopy(ENVIRONMENT_DICT) env = copy.deepcopy(ENVIRONMENT_DICT)

View File

@@ -15,7 +15,7 @@
# under the License. # under the License.
# #
import json from oslo_serialization import jsonutils
import mock import mock
@@ -39,9 +39,9 @@ TASK_RESULT = {"test": "is", "passed": "successfully"}
TASK_PUBLISHED = {"bar1": "val1", "var2": 2} TASK_PUBLISHED = {"bar1": "val1", "var2": 2}
TASK_WITH_RESULT_DICT = TASK_DICT.copy() TASK_WITH_RESULT_DICT = TASK_DICT.copy()
TASK_WITH_RESULT_DICT.update({'result': json.dumps(TASK_RESULT)}) TASK_WITH_RESULT_DICT.update({'result': jsonutils.dumps(TASK_RESULT)})
TASK_WITH_PUBLISHED_DICT = TASK_DICT.copy() TASK_WITH_PUBLISHED_DICT = TASK_DICT.copy()
TASK_WITH_PUBLISHED_DICT.update({'published': json.dumps(TASK_PUBLISHED)}) TASK_WITH_PUBLISHED_DICT.update({'published': jsonutils.dumps(TASK_PUBLISHED)})
TASK = tasks.Task(mock, TASK_DICT) TASK = tasks.Task(mock, TASK_DICT)
TASK_WITH_RESULT = tasks.Task(mock, TASK_WITH_RESULT_DICT) TASK_WITH_RESULT = tasks.Task(mock, TASK_WITH_RESULT_DICT)
@@ -85,7 +85,7 @@ class TestCLITasksV2(base.BaseCommandTest):
self.assertDictEqual( self.assertDictEqual(
TASK_RESULT, TASK_RESULT,
json.loads(self.app.stdout.write.call_args[0][0]) jsonutils.loads(self.app.stdout.write.call_args[0][0])
) )
def test_get_published(self): def test_get_published(self):
@@ -95,7 +95,7 @@ class TestCLITasksV2(base.BaseCommandTest):
self.assertDictEqual( self.assertDictEqual(
TASK_PUBLISHED, TASK_PUBLISHED,
json.loads(self.app.stdout.write.call_args[0][0]) jsonutils.loads(self.app.stdout.write.call_args[0][0])
) )
def test_rerun(self): def test_rerun(self):

View File

@@ -11,11 +11,13 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import collections import collections
import copy import copy
import json
import os.path import os.path
from oslo_serialization import jsonutils
import pkg_resources as pkg import pkg_resources as pkg
from six.moves.urllib import parse from six.moves.urllib import parse
from six.moves.urllib import request from six.moves.urllib import request
@@ -52,7 +54,8 @@ class TestEnvironmentsV2(base.BaseClientV2Test):
self.assertIsNotNone(env) self.assertIsNotNone(env)
expected_data = copy.deepcopy(data) expected_data = copy.deepcopy(data)
expected_data['variables'] = json.dumps(expected_data['variables']) expected_data['variables'] = jsonutils.dumps(
expected_data['variables'])
self.assertEqual(expected_data, self.requests_mock.last_request.json()) self.assertEqual(expected_data, self.requests_mock.last_request.json())
@@ -81,7 +84,8 @@ class TestEnvironmentsV2(base.BaseClientV2Test):
self.assertIsNotNone(env) self.assertIsNotNone(env)
expected_data = copy.deepcopy(data) expected_data = copy.deepcopy(data)
expected_data['variables'] = json.dumps(expected_data['variables']) expected_data['variables'] = jsonutils.dumps(
expected_data['variables'])
self.assertEqual(expected_data, self.requests_mock.last_request.json()) self.assertEqual(expected_data, self.requests_mock.last_request.json())
@@ -104,7 +108,8 @@ class TestEnvironmentsV2(base.BaseClientV2Test):
self.assertIsNotNone(env) self.assertIsNotNone(env)
expected_data = copy.deepcopy(data) expected_data = copy.deepcopy(data)
expected_data['variables'] = json.dumps(expected_data['variables']) expected_data['variables'] = jsonutils.dumps(
expected_data['variables'])
self.assertEqual(expected_data, self.requests_mock.last_request.json()) self.assertEqual(expected_data, self.requests_mock.last_request.json())
@@ -127,7 +132,8 @@ class TestEnvironmentsV2(base.BaseClientV2Test):
self.assertIsNotNone(env) self.assertIsNotNone(env)
expected_data = copy.deepcopy(data) expected_data = copy.deepcopy(data)
expected_data['variables'] = json.dumps(expected_data['variables']) expected_data['variables'] = jsonutils.dumps(
expected_data['variables'])
self.assertEqual(expected_data, self.requests_mock.last_request.json()) self.assertEqual(expected_data, self.requests_mock.last_request.json())

View File

@@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import json from oslo_serialization import jsonutils
from mistralclient.api import base as api_base from mistralclient.api import base as api_base
from mistralclient.api.v2 import executions from mistralclient.api.v2 import executions
@@ -67,7 +67,7 @@ class TestExecutionsV2(base.BaseClientV2Test):
body = { body = {
'workflow_name': EXEC['workflow_name'], 'workflow_name': EXEC['workflow_name'],
'description': '', 'description': '',
'input': json.dumps(EXEC['input']) 'input': jsonutils.dumps(EXEC['input'])
} }
ex = self.executions.create( ex = self.executions.create(
@@ -93,7 +93,7 @@ class TestExecutionsV2(base.BaseClientV2Test):
body = { body = {
'workflow_id': EXEC['workflow_id'], 'workflow_id': EXEC['workflow_id'],
'description': '', 'description': '',
'input': json.dumps(EXEC['input']) 'input': jsonutils.dumps(EXEC['input'])
} }
ex = self.executions.create( ex = self.executions.create(

View File

@@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import json from oslo_serialization import jsonutils
from mistralclient.api.v2 import tasks from mistralclient.api.v2 import tasks
from mistralclient.tests.unit.v2 import base from mistralclient.tests.unit.v2 import base
@@ -133,6 +133,6 @@ class TestTasksV2(base.BaseClientV2Test):
'reset': True, 'reset': True,
'state': 'RUNNING', 'state': 'RUNNING',
'id': TASK['id'], 'id': TASK['id'],
'env': json.dumps({'k1': 'foobar'}) 'env': jsonutils.dumps({'k1': 'foobar'})
} }
self.assertDictEqual(body, self.requests_mock.last_request.json()) self.assertDictEqual(body, self.requests_mock.last_request.json())

View File

@@ -13,10 +13,11 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import json
import os import os
import yaml import yaml
from oslo_serialization import jsonutils
from six.moves.urllib import parse from six.moves.urllib import parse
from six.moves.urllib import request from six.moves.urllib import request
@@ -46,7 +47,7 @@ def load_content(content):
try: try:
data = yaml.safe_load(content) data = yaml.safe_load(content)
except Exception: except Exception:
data = json.loads(content) data = jsonutils.loads(content)
return data return data
@@ -83,7 +84,8 @@ def get_contents_if_file(contents_or_file_name):
def load_json(input_string): def load_json(input_string):
try: try:
with open(input_string) as fh: # binary mode is needed due to bug/1515231
return json.load(fh) with open(input_string, 'r+b') as fh:
return jsonutils.load(fh)
except IOError: except IOError:
return json.loads(input_string) return jsonutils.loads(input_string)