From 378083e91e33ae62ee53f0d249f1981d4403e2eb Mon Sep 17 00:00:00 2001 From: "cao.yuan" Date: Sun, 24 Feb 2019 22:45:07 +0800 Subject: [PATCH] Update json module to jsonutils oslo project provide jsonutils, and the others use it in many place, this PS to update the json module to oslo jsonutils for consistency. Change-Id: Ie8bdc41e420fbbbafaca7d7eaeaa702d93c6a18d --- vitrage_tempest_plugin/tests/api/rca/base.py | 5 ++--- .../tests/api/resources/test_resources.py | 5 ++--- vitrage_tempest_plugin/tests/common/aodh_utils.py | 7 +++++-- .../tests/notifiers/test_mistral_notifier.py | 6 +++--- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/vitrage_tempest_plugin/tests/api/rca/base.py b/vitrage_tempest_plugin/tests/api/rca/base.py index bf25dd2..d38d788 100644 --- a/vitrage_tempest_plugin/tests/api/rca/base.py +++ b/vitrage_tempest_plugin/tests/api/rca/base.py @@ -12,9 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import json - from oslo_log import log as logging +from oslo_serialization import jsonutils from testtools import matchers from vitrage_tempest_plugin.tests.base import BaseVitrageTempest @@ -70,7 +69,7 @@ class BaseRcaTest(BaseVitrageTempest): LOG.debug("The rca taken from cli is : %s", cli_rca) LOG.debug("The rca taken by api is : %s", api_rca) - parsed_rca = json.loads(cli_rca) + parsed_rca = jsonutils.loads(cli_rca) sorted_cli_graph = self._clean_timestamps(sorted(parsed_rca.items())) sorted_api_graph = self._clean_timestamps(sorted(api_rca.items())) self.assert_list_equal(sorted_cli_graph, sorted_api_graph) diff --git a/vitrage_tempest_plugin/tests/api/resources/test_resources.py b/vitrage_tempest_plugin/tests/api/resources/test_resources.py index b3c7500..da029db 100644 --- a/vitrage_tempest_plugin/tests/api/resources/test_resources.py +++ b/vitrage_tempest_plugin/tests/api/resources/test_resources.py @@ -12,9 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import json - from oslo_log import log as logging +from oslo_serialization import jsonutils from testtools import matchers from vitrage_tempest_plugin.tests.base import BaseVitrageTempest @@ -172,7 +171,7 @@ class TestResource(BaseVitrageTempest): 'The resources taken from rest api is empty') sorted_cli_resources = sorted( - json.loads(cli_resources), + jsonutils.loads(cli_resources), key=lambda resource: resource["ID"]) sorted_api_resources = sorted( api_resources, diff --git a/vitrage_tempest_plugin/tests/common/aodh_utils.py b/vitrage_tempest_plugin/tests/common/aodh_utils.py index 6d62e90..a835577 100644 --- a/vitrage_tempest_plugin/tests/common/aodh_utils.py +++ b/vitrage_tempest_plugin/tests/common/aodh_utils.py @@ -11,9 +11,12 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import json + import random import time + +from oslo_serialization import jsonutils + from vitrage_tempest_plugin.tests.common.constants import AodhProperties as \ AodhProps from vitrage_tempest_plugin.tests.common.tempest_clients import TempestClients @@ -125,7 +128,7 @@ def _aodh_request(type, resource_id=None, name=None, rule=None): # alarms, update accordingly query[0].update(dict(field='resource_id')) rule[AodhProps.RESOURCES_THRESHOLD_RULE].update(dict( - query=json.dumps(query))) + query=jsonutils.dump_as_bytes(query))) request.update(rule) return request diff --git a/vitrage_tempest_plugin/tests/notifiers/test_mistral_notifier.py b/vitrage_tempest_plugin/tests/notifiers/test_mistral_notifier.py index ad88984..f44a3ac 100644 --- a/vitrage_tempest_plugin/tests/notifiers/test_mistral_notifier.py +++ b/vitrage_tempest_plugin/tests/notifiers/test_mistral_notifier.py @@ -12,10 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. -import json import time from oslo_log import log as logging +from oslo_serialization import jsonutils from testtools.matchers import HasLength from vitrage_tempest_plugin.tests.api.event.base import BaseTestEvents @@ -140,7 +140,7 @@ class TestMistralNotifier(BaseTestEvents): # are at the end. Check the last `num_instances` executions. execution = \ self.mistral_client.executions.get(executions[-i].id) - execution_input = json.loads(execution.input) + execution_input = jsonutils.loads(execution.input) executed_on_instances.add(execution_input['farewell']) msg = "There are %d instances in the graph but only %d distinct " \ @@ -160,7 +160,7 @@ class TestMistralNotifier(BaseTestEvents): 'The last execution had no input') self.assertIn('farewell', execution_input_str, 'No \'farewell\' key in the last execution input') - execution_input = json.loads(execution_input_str) + execution_input = jsonutils.loads(execution_input_str) farewell_value = execution_input['farewell'] self.assertIsNotNone(farewell_value, '\'farewell\' input parameter is ' 'None in last workflow execution')