From b60d221fe1b18b155066c93f62df7bef7013168a Mon Sep 17 00:00:00 2001 From: Jehoszafat Zimnowoda Date: Sun, 4 Jun 2017 20:33:17 +0200 Subject: [PATCH] Use simplejson to load json file The simplejson extends json library. It provides sufficient information about JSON syntax errors, which often occurs during instackenv.json file creation. Change-Id: Ied1c080678af728820e02b7b99c51762b49b1449 Closes-Bug: #1693442 Depends on external: https://review.rdoproject.org/r/#/c/7872/ --- requirements.txt | 1 + tripleoclient/utils.py | 4 ++-- tripleoclient/v1/baremetal.py | 6 +++--- tripleoclient/v1/overcloud_parameters.py | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/requirements.txt b/requirements.txt index bbaff35ed..3e82167bb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,6 +11,7 @@ python-heatclient>=1.6.1 # Apache-2.0 python-ironicclient>=1.14.0 # Apache-2.0 python-mistralclient>=3.1.0 # Apache-2.0 python-openstackclient!=3.10.0,>=3.3.0 # Apache-2.0 +simplejson>=2.2.0 # MIT six>=1.9.0 # MIT osc-lib>=1.7.0 # Apache-2.0 websocket-client>=0.32.0 # LGPLv2+ diff --git a/tripleoclient/utils.py b/tripleoclient/utils.py index 083424f14..c73dae870 100644 --- a/tripleoclient/utils.py +++ b/tripleoclient/utils.py @@ -17,10 +17,10 @@ from __future__ import print_function import csv import datetime import hashlib -import json import logging import os import os.path +import simplejson import six import socket import subprocess @@ -647,7 +647,7 @@ def _csv_to_nodes_dict(nodes_csv): def parse_env_file(env_file, file_type=None): if file_type == 'json' or env_file.name.endswith('.json'): - nodes_config = json.load(env_file) + nodes_config = simplejson.load(env_file) elif file_type == 'csv' or env_file.name.endswith('.csv'): nodes_config = _csv_to_nodes_dict(env_file) elif env_file.name.endswith('.yaml'): diff --git a/tripleoclient/v1/baremetal.py b/tripleoclient/v1/baremetal.py index 4a6ecda58..d4a50ea62 100644 --- a/tripleoclient/v1/baremetal.py +++ b/tripleoclient/v1/baremetal.py @@ -16,8 +16,8 @@ from __future__ import print_function import argparse -import json import logging +import simplejson import time import uuid @@ -50,7 +50,7 @@ class ValidateInstackEnv(command.Command): self.error_count = 0 with open(parsed_args.instackenv, 'r') as net_file: - env_data = json.load(net_file) + env_data = simplejson.load(net_file) maclist = [] baremetal_ips = [] @@ -356,7 +356,7 @@ class ConfigureReadyState(command.Command): self.bm_client = self.app.client_manager.baremetal with open(parsed_args.file, 'r') as fp: - self.ready_state_config = json.load(fp) + self.ready_state_config = simplejson.load(fp) drac_nodes = [] for node in self.bm_client.node.list(detail=True): diff --git a/tripleoclient/v1/overcloud_parameters.py b/tripleoclient/v1/overcloud_parameters.py index 957d20a57..b58f27792 100644 --- a/tripleoclient/v1/overcloud_parameters.py +++ b/tripleoclient/v1/overcloud_parameters.py @@ -11,9 +11,9 @@ # under the License. import argparse -import json import logging import os +import simplejson import yaml from osc_lib.command import command @@ -44,7 +44,7 @@ class SetParameters(command.Command): self.log.debug("take_action(%s)" % parsed_args) if parsed_args.file_in.name.endswith('.json'): - params = json.load(parsed_args.file_in) + params = simplejson.load(parsed_args.file_in) elif parsed_args.file_in.name.endswith('.yaml'): params = yaml.safe_load(parsed_args.file_in) else: