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/
This commit is contained in:
Jehoszafat Zimnowoda 2017-06-04 20:33:17 +02:00 committed by Jehoszafat Zimnowoda
parent 9c9521f31b
commit b60d221fe1
4 changed files with 8 additions and 7 deletions

View File

@ -11,6 +11,7 @@ python-heatclient>=1.6.1 # Apache-2.0
python-ironicclient>=1.14.0 # Apache-2.0 python-ironicclient>=1.14.0 # Apache-2.0
python-mistralclient>=3.1.0 # Apache-2.0 python-mistralclient>=3.1.0 # Apache-2.0
python-openstackclient!=3.10.0,>=3.3.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 six>=1.9.0 # MIT
osc-lib>=1.7.0 # Apache-2.0 osc-lib>=1.7.0 # Apache-2.0
websocket-client>=0.32.0 # LGPLv2+ websocket-client>=0.32.0 # LGPLv2+

View File

@ -17,10 +17,10 @@ from __future__ import print_function
import csv import csv
import datetime import datetime
import hashlib import hashlib
import json
import logging import logging
import os import os
import os.path import os.path
import simplejson
import six import six
import socket import socket
import subprocess import subprocess
@ -647,7 +647,7 @@ def _csv_to_nodes_dict(nodes_csv):
def parse_env_file(env_file, file_type=None): def parse_env_file(env_file, file_type=None):
if file_type == 'json' or env_file.name.endswith('.json'): 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'): elif file_type == 'csv' or env_file.name.endswith('.csv'):
nodes_config = _csv_to_nodes_dict(env_file) nodes_config = _csv_to_nodes_dict(env_file)
elif env_file.name.endswith('.yaml'): elif env_file.name.endswith('.yaml'):

View File

@ -16,8 +16,8 @@
from __future__ import print_function from __future__ import print_function
import argparse import argparse
import json
import logging import logging
import simplejson
import time import time
import uuid import uuid
@ -50,7 +50,7 @@ class ValidateInstackEnv(command.Command):
self.error_count = 0 self.error_count = 0
with open(parsed_args.instackenv, 'r') as net_file: with open(parsed_args.instackenv, 'r') as net_file:
env_data = json.load(net_file) env_data = simplejson.load(net_file)
maclist = [] maclist = []
baremetal_ips = [] baremetal_ips = []
@ -356,7 +356,7 @@ class ConfigureReadyState(command.Command):
self.bm_client = self.app.client_manager.baremetal self.bm_client = self.app.client_manager.baremetal
with open(parsed_args.file, 'r') as fp: with open(parsed_args.file, 'r') as fp:
self.ready_state_config = json.load(fp) self.ready_state_config = simplejson.load(fp)
drac_nodes = [] drac_nodes = []
for node in self.bm_client.node.list(detail=True): for node in self.bm_client.node.list(detail=True):

View File

@ -11,9 +11,9 @@
# under the License. # under the License.
import argparse import argparse
import json
import logging import logging
import os import os
import simplejson
import yaml import yaml
from osc_lib.command import command from osc_lib.command import command
@ -44,7 +44,7 @@ class SetParameters(command.Command):
self.log.debug("take_action(%s)" % parsed_args) self.log.debug("take_action(%s)" % parsed_args)
if parsed_args.file_in.name.endswith('.json'): 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'): elif parsed_args.file_in.name.endswith('.yaml'):
params = yaml.safe_load(parsed_args.file_in) params = yaml.safe_load(parsed_args.file_in)
else: else: