From 98cdd8207e19e7540d0b1e23f56e4641a2c434c1 Mon Sep 17 00:00:00 2001 From: jacky06 Date: Thu, 28 Feb 2019 00:34:20 +0800 Subject: [PATCH] Update json module to jsonutils oslo project provide jsonutils, and karbor use it in many place[1], this PS to update the remained json module to oslo jsonutils for consistency. [1]: https://github.com/openstack/karbor/search?q=jsonutils&unscoped_q=jsonutils Change-Id: I8a191a0a668a05eb1a63bb6cf45eb2624a7f848a --- karbor_dashboard/checkpoints/forms.py | 7 ++++--- karbor_dashboard/checkpoints/utils.py | 4 ++-- karbor_dashboard/protectionplans/forms.py | 11 ++++++----- karbor_dashboard/protectionplans/views.py | 7 +++---- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/karbor_dashboard/checkpoints/forms.py b/karbor_dashboard/checkpoints/forms.py index 5ab0b07..a1be4b5 100644 --- a/karbor_dashboard/checkpoints/forms.py +++ b/karbor_dashboard/checkpoints/forms.py @@ -20,7 +20,8 @@ from horizon import exceptions from horizon import forms as horizon_forms from horizon import messages -import json +from oslo_serialization import jsonutils + from karbor_dashboard.api import karbor as karborclient EMPTY_VALUES = (None, '', u'', [], (), {}) @@ -85,7 +86,7 @@ class RestoreCheckpointForm(horizon_forms.SelfHandlingForm): provider_id = str(kwargs["initial"]["provider_id"]) provider = karborclient.provider_get(request, provider_id) - self.fields['provider'].initial = json.dumps(provider._info) + self.fields['provider'].initial = jsonutils.dumps(provider._info) @sensitive_variables('restore_target_password') def handle(self, request, data): @@ -114,7 +115,7 @@ class RestoreCheckpointForm(horizon_forms.SelfHandlingForm): return False try: - data_parameters = json.loads(data["parameters"]) + data_parameters = jsonutils.loads(data["parameters"]) restore_auth = { "type": "password", "username": target_username, diff --git a/karbor_dashboard/checkpoints/utils.py b/karbor_dashboard/checkpoints/utils.py index 49527bf..3e8cb11 100644 --- a/karbor_dashboard/checkpoints/utils.py +++ b/karbor_dashboard/checkpoints/utils.py @@ -15,7 +15,7 @@ import collections from collections import namedtuple from django.utils.translation import ugettext_lazy as _ -import json +from oslo_serialization import jsonutils FILTER_LIST = ['provider_filter', 'plan_filter', 'date_filter'] @@ -46,7 +46,7 @@ PackedGraph = namedtuple('PackedGraph', ['nodes', 'adjacency']) def deserialize_resource_graph(serialized_resource_graph): - deserialized_graph = json.loads(serialized_resource_graph) + deserialized_graph = jsonutils.loads(serialized_resource_graph) packed_resource_graph = PackedGraph(nodes=deserialized_graph[0], adjacency=deserialized_graph[1]) for sid, node in packed_resource_graph.nodes.items(): diff --git a/karbor_dashboard/protectionplans/forms.py b/karbor_dashboard/protectionplans/forms.py index b472020..0301ed7 100644 --- a/karbor_dashboard/protectionplans/forms.py +++ b/karbor_dashboard/protectionplans/forms.py @@ -19,7 +19,8 @@ from horizon import exceptions from horizon import forms as horizon_forms from horizon import messages -import json +from oslo_serialization import jsonutils + from karbor_dashboard.api import karbor as karborclient STATUS_CHOICE = [("suspended", "suspended"), @@ -50,7 +51,7 @@ class CreateProtectionPlanForm(horizon_forms.SelfHandlingForm): providers = karborclient.provider_list(request) self.fields['providers'].initial = \ - json.dumps([f._info for f in providers]) + jsonutils.dumps([f._info for f in providers]) if providers: result = [(e.id, e.name) for e in providers] @@ -59,9 +60,9 @@ class CreateProtectionPlanForm(horizon_forms.SelfHandlingForm): def handle(self, request, data): try: - resources = json.loads(data["resources"]) + resources = jsonutils.loads(data["resources"]) types = {resource["type"] for resource in resources} - parameters = json.loads(data["parameters"]) + parameters = jsonutils.loads(data["parameters"]) parameters = {k: v for k, v in parameters.items() if k.split("#")[0] in types} new_plan = karborclient.plan_create( @@ -112,7 +113,7 @@ class UpdateProtectionPlanForm(horizon_forms.SelfHandlingForm): if name: data_.update({"name": name}) - resources = json.loads(data["resources"]) + resources = jsonutils.loads(data["resources"]) if resources: resources_ = [] for resource in resources: diff --git a/karbor_dashboard/protectionplans/views.py b/karbor_dashboard/protectionplans/views.py index 6b898cb..04f7eb7 100644 --- a/karbor_dashboard/protectionplans/views.py +++ b/karbor_dashboard/protectionplans/views.py @@ -12,8 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -import json - from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse_lazy from django.utils.translation import ugettext_lazy as _ @@ -28,6 +26,7 @@ from karbor_dashboard.api import karbor as karborclient from karbor_dashboard.protectionplans import forms from karbor_dashboard.protectionplans import tables from karborclient.v1 import protectables +from oslo_serialization import jsonutils from oslo_utils import uuidutils @@ -212,8 +211,8 @@ class UpdateView(horizon_forms.ModalFormView): provider = self.get_provider_object(plan.provider_id) initial.update({'plan_id': self.kwargs['plan_id'], 'name': getattr(plan, 'name', ''), - 'plan': json.dumps(plan._info), - 'provider': json.dumps(provider._info)}) + 'plan': jsonutils.dumps(plan._info), + 'provider': jsonutils.dumps(provider._info)}) return initial