Use jsonutils from oslo.serialization
Sahara should use jsonutils from oslo_serialization because it support all functions from json. Also added hacking check for that. Change-Id: I8c286ad947b92d6552b17cfa7ef80ba1beb5b51b Closes-bug: 1442120
This commit is contained in:
parent
603b30f90a
commit
efc639caff
@ -44,3 +44,9 @@ Logs
|
|||||||
- [S373] LOG.debug never used for translations
|
- [S373] LOG.debug never used for translations
|
||||||
|
|
||||||
- [S374] You used a deprecated log level
|
- [S374] You used a deprecated log level
|
||||||
|
|
||||||
|
Importing json
|
||||||
|
--------------
|
||||||
|
|
||||||
|
- [S375] It's more preferable to use ``jsonutils`` from ``oslo_serialization``
|
||||||
|
instead of ``json`` for operating with ``json`` objects.
|
||||||
|
@ -13,12 +13,12 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import json
|
|
||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import jsonschema
|
import jsonschema
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
from oslo_serialization import jsonutils as json
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from sahara import conductor
|
from sahara import conductor
|
||||||
|
@ -23,13 +23,13 @@
|
|||||||
# We also change some importings to use Sahara inherited classes.
|
# We also change some importings to use Sahara inherited classes.
|
||||||
|
|
||||||
import cookielib
|
import cookielib
|
||||||
import json
|
|
||||||
import posixpath
|
import posixpath
|
||||||
import types
|
import types
|
||||||
import urllib
|
import urllib
|
||||||
import urllib2
|
import urllib2
|
||||||
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
from oslo_serialization import jsonutils as json
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from sahara.i18n import _LW
|
from sahara.i18n import _LW
|
||||||
|
@ -22,12 +22,12 @@
|
|||||||
# To satisfy the pep8 and python3 tests, we did some changes to the codes.
|
# To satisfy the pep8 and python3 tests, we did some changes to the codes.
|
||||||
# We also change some importings to use Sahara inherited classes.
|
# We also change some importings to use Sahara inherited classes.
|
||||||
|
|
||||||
import json
|
|
||||||
import posixpath
|
import posixpath
|
||||||
import socket
|
import socket
|
||||||
import urllib2
|
import urllib2
|
||||||
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
from oslo_serialization import jsonutils as json
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from sahara import context
|
from sahara import context
|
||||||
|
@ -22,8 +22,7 @@
|
|||||||
# To satisfy the pep8 and python3 tests, we did some changes to the codes.
|
# To satisfy the pep8 and python3 tests, we did some changes to the codes.
|
||||||
# We also change some importings to use Sahara inherited classes.
|
# We also change some importings to use Sahara inherited classes.
|
||||||
|
|
||||||
import json
|
from oslo_serialization import jsonutils as json
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from sahara.plugins.cdh.client import role_config_groups
|
from sahara.plugins.cdh.client import role_config_groups
|
||||||
|
@ -24,9 +24,9 @@
|
|||||||
|
|
||||||
import copy
|
import copy
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from oslo_serialization import jsonutils as json
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from sahara import context
|
from sahara import context
|
||||||
|
@ -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 as json
|
||||||
|
|
||||||
from sahara.plugins import provisioning as p
|
from sahara.plugins import provisioning as p
|
||||||
from sahara.utils import files as f
|
from sahara.utils import files as f
|
||||||
|
@ -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 as json
|
||||||
|
|
||||||
from sahara.plugins.cdh.client import api_client
|
from sahara.plugins.cdh.client import api_client
|
||||||
|
|
||||||
|
@ -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 as json
|
||||||
|
|
||||||
from sahara.plugins import provisioning as p
|
from sahara.plugins import provisioning as p
|
||||||
from sahara.utils import files as f
|
from sahara.utils import files as f
|
||||||
|
@ -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 as json
|
||||||
|
|
||||||
from sahara.plugins.cdh.client import api_client
|
from sahara.plugins.cdh.client import api_client
|
||||||
|
|
||||||
|
@ -13,10 +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
|
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
from oslo_serialization import jsonutils as json
|
||||||
import pkg_resources as pkg
|
import pkg_resources as pkg
|
||||||
|
|
||||||
from sahara import context
|
from sahara import context
|
||||||
|
@ -13,10 +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
|
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
from oslo_serialization import jsonutils as json
|
||||||
import pkg_resources as pkg
|
import pkg_resources as pkg
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
@ -13,10 +13,10 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
|
||||||
import json
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
from oslo_serialization import jsonutils as json
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
|
|
||||||
from sahara import context
|
from sahara import context
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
|
||||||
import json
|
from oslo_serialization import jsonutils as json
|
||||||
|
|
||||||
from sahara import context
|
from sahara import context
|
||||||
import sahara.exceptions as e
|
import sahara.exceptions as e
|
||||||
|
@ -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 re
|
import re
|
||||||
|
|
||||||
|
from oslo_serialization import jsonutils as json
|
||||||
from six.moves.urllib import parse as urlparse
|
from six.moves.urllib import parse as urlparse
|
||||||
|
|
||||||
import sahara.exceptions as ex
|
import sahara.exceptions as ex
|
||||||
|
@ -13,10 +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
|
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
from oslo_serialization import jsonutils as json
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from sahara import conductor as c
|
from sahara import conductor as c
|
||||||
|
@ -12,13 +12,13 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import json
|
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
|
from oslo_serialization import jsonutils as json
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from sahara.tests.integration.tests import base as b
|
from sahara.tests.integration.tests import base as b
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import functools
|
import functools
|
||||||
import glob
|
import glob
|
||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@ -24,6 +23,7 @@ import time
|
|||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
|
from oslo_serialization import jsonutils as json
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
import prettytable
|
import prettytable
|
||||||
import six
|
import six
|
||||||
|
@ -13,12 +13,12 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import json
|
|
||||||
import tempfile
|
import tempfile
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import jsonschema
|
import jsonschema
|
||||||
import mock
|
import mock
|
||||||
|
from oslo_serialization import jsonutils as json
|
||||||
from oslo_utils import uuidutils
|
from oslo_utils import uuidutils
|
||||||
|
|
||||||
from sahara import context
|
from sahara import context
|
||||||
|
@ -14,10 +14,10 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import itertools
|
import itertools
|
||||||
import json
|
|
||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
from oslo_serialization import jsonutils as json
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
from sahara.service.validations.edp import data_source
|
from sahara.service.validations.edp import data_source
|
||||||
|
@ -49,3 +49,18 @@ class HackingTestCase(testtools.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(0, len(list(checks.dict_constructor_with_list_copy(
|
self.assertEqual(0, len(list(checks.dict_constructor_with_list_copy(
|
||||||
" self._render_dict(xml, data_el, data.__dict__)"))))
|
" self._render_dict(xml, data_el, data.__dict__)"))))
|
||||||
|
|
||||||
|
def test_use_jsonutils(self):
|
||||||
|
self.assertEqual(0, len(list(checks.use_jsonutils(
|
||||||
|
"import json # noqa", "path"))))
|
||||||
|
self.assertEqual(0, len(list(checks.use_jsonutils(
|
||||||
|
"from oslo_serialization import jsonutils as json", "path"))))
|
||||||
|
self.assertEqual(0, len(list(checks.use_jsonutils(
|
||||||
|
"import jsonschema", "path"))))
|
||||||
|
self.assertEqual(0, len(list(checks.use_jsonutils(
|
||||||
|
"import json", "sahara/openstack/common/utils.py"))))
|
||||||
|
|
||||||
|
self.assertEqual(1, len(list(checks.use_jsonutils(
|
||||||
|
"import json", "path"))))
|
||||||
|
self.assertEqual(1, len(list(checks.use_jsonutils(
|
||||||
|
"import json as jsonutils", "path"))))
|
||||||
|
@ -13,6 +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 pep8
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import tokenize
|
import tokenize
|
||||||
@ -97,6 +98,25 @@ def dict_constructor_with_list_copy(logical_line):
|
|||||||
'constructor with a sequence of key-value pairs.')
|
'constructor with a sequence of key-value pairs.')
|
||||||
|
|
||||||
|
|
||||||
|
def use_jsonutils(logical_line, filename):
|
||||||
|
"""Check to prevent importing json in sahara code.
|
||||||
|
|
||||||
|
S375
|
||||||
|
"""
|
||||||
|
if pep8.noqa(logical_line):
|
||||||
|
return
|
||||||
|
ignore_dirs = ["sahara/openstack/common"]
|
||||||
|
for dir in ignore_dirs:
|
||||||
|
if dir in filename:
|
||||||
|
return
|
||||||
|
invalid_line = re.compile(r"(import\s+json)")
|
||||||
|
valid_line = re.compile(r"(import\s+jsonschema)")
|
||||||
|
if (re.match(invalid_line, logical_line) and
|
||||||
|
not re.match(valid_line, logical_line)):
|
||||||
|
yield(0, "S375: Use jsonutils from oslo_serialization instead"
|
||||||
|
" of json")
|
||||||
|
|
||||||
|
|
||||||
def factory(register):
|
def factory(register):
|
||||||
register(import_db_only_in_conductor)
|
register(import_db_only_in_conductor)
|
||||||
register(hacking_no_author_attr)
|
register(hacking_no_author_attr)
|
||||||
@ -109,3 +129,4 @@ def factory(register):
|
|||||||
register(logging_checks.validate_log_translations)
|
register(logging_checks.validate_log_translations)
|
||||||
register(logging_checks.no_translate_debug_logs)
|
register(logging_checks.no_translate_debug_logs)
|
||||||
register(logging_checks.accepted_log_levels)
|
register(logging_checks.accepted_log_levels)
|
||||||
|
register(use_jsonutils)
|
||||||
|
@ -13,9 +13,8 @@
|
|||||||
# 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_config import cfg
|
from oslo_config import cfg
|
||||||
|
from oslo_serialization import jsonutils as json
|
||||||
from six.moves.urllib import parse as urlparse
|
from six.moves.urllib import parse as urlparse
|
||||||
|
|
||||||
from sahara import context
|
from sahara import context
|
||||||
|
Loading…
Reference in New Issue
Block a user