Merge "Revert "Replace jsonutils by ujson""
This commit is contained in:
commit
b10d196fa5
@ -12,7 +12,7 @@
|
||||
# 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 threading
|
||||
|
||||
import cachetools
|
||||
@ -21,7 +21,6 @@ from gnocchiclient import exceptions
|
||||
from keystoneauth1 import exceptions as ka_exceptions
|
||||
from oslo_config import cfg
|
||||
import pecan
|
||||
import ujson
|
||||
import wsme
|
||||
from wsme import types as wtypes
|
||||
|
||||
@ -155,7 +154,7 @@ class AggregationMetricByResourcesLookupRule(AlarmGnocchiThresholdRule):
|
||||
|
||||
# check the query string is a valid json
|
||||
try:
|
||||
query = ujson.loads(rule.query)
|
||||
query = json.loads(rule.query)
|
||||
except ValueError:
|
||||
raise wsme.exc.InvalidInput('rule/query', rule.query)
|
||||
|
||||
@ -178,7 +177,7 @@ class AggregationMetricByResourcesLookupRule(AlarmGnocchiThresholdRule):
|
||||
]}
|
||||
|
||||
query = {"and": [perms_filter, query]}
|
||||
rule.query = ujson.dumps(query)
|
||||
rule.query = json.dumps(query)
|
||||
|
||||
gnocchi_client = client.Client(
|
||||
'1', keystone_client.get_session(conf),
|
||||
|
@ -12,7 +12,7 @@
|
||||
# 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 operator
|
||||
|
||||
from oslo_config import cfg
|
||||
@ -20,7 +20,6 @@ from oslo_log import log
|
||||
from oslo_utils import fnmatch
|
||||
from oslo_utils import timeutils
|
||||
import six
|
||||
import ujson
|
||||
|
||||
from aodh import evaluator
|
||||
from aodh.i18n import _
|
||||
@ -253,8 +252,8 @@ class EventAlarmEvaluator(evaluator.Evaluator):
|
||||
'query <query=%(alarm_query)s>.') %
|
||||
{'id': event.id,
|
||||
'event_type': event.get_value('event_type'),
|
||||
'alarm_query': ujson.dumps(alarm.obj.rule['query'],
|
||||
sort_keys=True)})
|
||||
'alarm_query': json.dumps(alarm.obj.rule['query'],
|
||||
sort_keys=True)})
|
||||
reason_data = {'type': 'event', 'event': event.obj}
|
||||
always_record = alarm.obj.repeat_actions
|
||||
self._refresh(alarm.obj, state, reason, reason_data, always_record)
|
||||
|
@ -12,6 +12,7 @@
|
||||
# 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
|
||||
|
||||
from gnocchiclient import client
|
||||
from gnocchiclient import exceptions
|
||||
@ -19,7 +20,6 @@ from oslo_log import log
|
||||
|
||||
from aodh.evaluator import threshold
|
||||
from aodh import keystone_client
|
||||
import ujson
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
@ -140,7 +140,7 @@ class GnocchiAggregationResourcesThresholdEvaluator(GnocchiBase):
|
||||
return self._gnocchi_client.metric.aggregation(
|
||||
metrics=rule['metric'],
|
||||
granularity=rule['granularity'],
|
||||
query=ujson.loads(rule['query']),
|
||||
query=json.loads(rule['query']),
|
||||
resource_type=rule["resource_type"],
|
||||
start=start, stop=end,
|
||||
aggregation=rule['aggregation_method'],
|
||||
|
@ -13,13 +13,13 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""Rest alarm notifier."""
|
||||
import json
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
from oslo_utils import uuidutils
|
||||
import requests
|
||||
import six.moves.urllib.parse as urlparse
|
||||
import ujson
|
||||
|
||||
from aodh import notifier
|
||||
|
||||
@ -77,7 +77,7 @@ class RestAlarmNotifier(notifier.AlarmNotifier):
|
||||
'current': current, 'reason': reason,
|
||||
'reason_data': reason_data}
|
||||
headers['content-type'] = 'application/json'
|
||||
kwargs = {'data': ujson.dumps(body),
|
||||
kwargs = {'data': json.dumps(body),
|
||||
'headers': headers}
|
||||
|
||||
if action.scheme == 'https':
|
||||
|
@ -15,13 +15,13 @@
|
||||
"""Tests alarm operation."""
|
||||
|
||||
import datetime
|
||||
import json as jsonlib
|
||||
import os
|
||||
|
||||
import mock
|
||||
from oslo_utils import uuidutils
|
||||
import six
|
||||
from six import moves
|
||||
import ujson
|
||||
import webtest
|
||||
|
||||
from aodh.api import app
|
||||
@ -197,8 +197,7 @@ class TestAlarms(TestAlarmsBase):
|
||||
'value': isotime}],
|
||||
expect_errors=True)
|
||||
self.assertEqual(resp.status_code, 400)
|
||||
self.assertEqual(ujson.loads(resp.body)['error_message']
|
||||
['faultstring'],
|
||||
self.assertEqual(resp.json['error_message']['faultstring'],
|
||||
'Unknown argument: "timestamp": '
|
||||
'not valid for this resource')
|
||||
|
||||
@ -273,8 +272,7 @@ class TestAlarms(TestAlarmsBase):
|
||||
self.assertEqual(404, resp.status_code)
|
||||
self.assertEqual('Alarm alarm-id-3 not found in project %s' %
|
||||
self.auth_headers["X-Project-Id"],
|
||||
ujson.loads(resp.body)['error_message']
|
||||
['faultstring'])
|
||||
resp.json['error_message']['faultstring'])
|
||||
|
||||
def test_get_alarm(self):
|
||||
alarms = self.get_json('/alarms',
|
||||
@ -1091,8 +1089,7 @@ class TestAlarms(TestAlarmsBase):
|
||||
aspect = 'user' if 'user' in identifiers else 'project'
|
||||
params = dict(aspect=aspect, id=identifiers[aspect])
|
||||
self.assertEqual("Not Authorized to access %(aspect)s %(id)s" % params,
|
||||
ujson.loads(resp.body)['error_message']
|
||||
['faultstring'])
|
||||
resp.json['error_message']['faultstring'])
|
||||
|
||||
def test_post_alarm_as_nonadmin_on_behalf_of_another_user(self):
|
||||
identifiers = dict(user='auseridthatisnotmine')
|
||||
@ -1829,14 +1826,14 @@ class TestAlarmsHistory(TestAlarmsBase):
|
||||
for k, v in six.iteritems(expected):
|
||||
current = actual.get(k)
|
||||
if k == 'detail' and isinstance(v, dict):
|
||||
current = ujson.loads(current)
|
||||
current = jsonlib.loads(current)
|
||||
self.assertEqual(v, current, 'mismatched field: %s' % k)
|
||||
self.assertIsNotNone(actual['event_id'])
|
||||
|
||||
def _assert_in_json(self, expected, actual):
|
||||
actual = ujson.dumps(ujson.loads(actual), sort_keys=True)
|
||||
actual = jsonlib.dumps(jsonlib.loads(actual), sort_keys=True)
|
||||
for k, v in six.iteritems(expected):
|
||||
fragment = ujson.dumps({k: v}, sort_keys=True)[1:-1]
|
||||
fragment = jsonlib.dumps({k: v}, sort_keys=True)[1:-1]
|
||||
self.assertIn(fragment, actual,
|
||||
'%s not in %s' % (fragment, actual))
|
||||
|
||||
@ -1862,7 +1859,7 @@ class TestAlarmsHistory(TestAlarmsBase):
|
||||
new_alarm = self._get_alarm('a')
|
||||
history = self._get_alarm_history('a')
|
||||
self.assertEqual(1, len(history))
|
||||
self.assertEqual('{"severity": "low"}',
|
||||
self.assertEqual(jsonlib.dumps({'severity': 'low'}),
|
||||
history[0]['detail'])
|
||||
self.assertEqual('low', new_alarm['severity'])
|
||||
|
||||
@ -1879,7 +1876,7 @@ class TestAlarmsHistory(TestAlarmsBase):
|
||||
new_alarm = self._get_alarm('a')
|
||||
history = self._get_alarm_history('a')
|
||||
self.assertEqual(1, len(history))
|
||||
self.assertEqual("min", ujson.loads(history[0]['detail'])
|
||||
self.assertEqual("min", jsonlib.loads(history[0]['detail'])
|
||||
['rule']["statistic"])
|
||||
self.assertEqual('min', new_alarm['threshold_rule']['statistic'])
|
||||
|
||||
@ -1893,14 +1890,14 @@ class TestAlarmsHistory(TestAlarmsBase):
|
||||
new_alarm = self._get_alarm('a')
|
||||
history = self._get_alarm_history('a')
|
||||
self.assertEqual(1, len(history))
|
||||
self.assertEqual('{"severity": "low"}',
|
||||
self.assertEqual(jsonlib.dumps({'severity': 'low'}),
|
||||
history[0]['detail'])
|
||||
self.assertEqual('low', new_alarm['severity'])
|
||||
|
||||
self._update_alarm('a', dict(severity='low'))
|
||||
updated_history = self._get_alarm_history('a')
|
||||
self.assertEqual(1, len(updated_history))
|
||||
self.assertEqual('{"severity": "low"}',
|
||||
self.assertEqual(jsonlib.dumps({'severity': 'low'}),
|
||||
updated_history[0]['detail'])
|
||||
self.assertEqual(history, updated_history)
|
||||
|
||||
@ -2146,7 +2143,7 @@ class TestAlarmsHistory(TestAlarmsBase):
|
||||
query = dict(field='severity', op='eq', value='low')
|
||||
history = self._get_alarm_history('a', query=query)
|
||||
self.assertEqual(1, len(history))
|
||||
self.assertEqual('{"severity": "low"}',
|
||||
self.assertEqual(jsonlib.dumps({'severity': 'low'}),
|
||||
history[0]['detail'])
|
||||
|
||||
def test_get_nonexistent_alarm_history(self):
|
||||
@ -2343,8 +2340,7 @@ class TestAlarmsRuleThreshold(TestAlarmsBase):
|
||||
resp = self.post_json('/alarms', params=json, expect_errors=True,
|
||||
status=400, headers=self.auth_headers)
|
||||
expected_error_message = 'The data type blob is not supported.'
|
||||
resp_string = ujson.loads(resp.body)
|
||||
fault_string = resp_string['error_message']['faultstring']
|
||||
fault_string = resp.json['error_message']['faultstring']
|
||||
self.assertTrue(fault_string.startswith(expected_error_message))
|
||||
alarms = list(self.alarm_conn.get_alarms())
|
||||
self.assertEqual(0, len(alarms))
|
||||
@ -2731,7 +2727,7 @@ class TestAlarmsRuleGnocchi(TestAlarmsBase):
|
||||
self.assertEqual(1, len(alarms))
|
||||
|
||||
json['gnocchi_aggregation_by_resources_threshold_rule']['query'] = (
|
||||
ujson.dumps(expected_query))
|
||||
jsonlib.dumps(expected_query))
|
||||
self._verify_alarm(json, alarms[0])
|
||||
|
||||
|
||||
@ -3044,8 +3040,7 @@ class TestPaginationQuery(TestAlarmsBase):
|
||||
"('alarm_id', 'enabled', 'name', 'type', 'severity',"
|
||||
" 'timestamp', 'user_id', 'project_id', 'state', "
|
||||
"'repeat_actions', 'state_timestamp')",
|
||||
ujson.loads(resp.body)['error_message']
|
||||
['faultstring'])
|
||||
resp.json['error_message']['faultstring'])
|
||||
|
||||
def test_pagination_query_only_sort_key_specified(self):
|
||||
data = self.get_json('/alarms?sort=name',
|
||||
|
@ -15,12 +15,12 @@
|
||||
|
||||
import copy
|
||||
import datetime
|
||||
import json
|
||||
import six
|
||||
|
||||
import mock
|
||||
from oslo_utils import timeutils
|
||||
from oslo_utils import uuidutils
|
||||
import ujson
|
||||
|
||||
from aodh import evaluator
|
||||
from aodh.evaluator import event as event_evaluator
|
||||
@ -128,8 +128,7 @@ class TestEventAlarmEvaluate(base.TestEvaluatorBase):
|
||||
'query <query=%(query)s>.') % {
|
||||
'e': event['message_id'],
|
||||
'type': event['event_type'],
|
||||
'query': ujson.dumps(alarm.rule['query'],
|
||||
sort_keys=True)}
|
||||
'query': json.dumps(alarm.rule['query'], sort_keys=True)}
|
||||
data = {'type': 'event', 'event': event}
|
||||
expected = dict(alarm_id=alarm.alarm_id,
|
||||
state=evaluator.ALARM,
|
||||
|
@ -13,6 +13,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import fixtures
|
||||
import json
|
||||
import time
|
||||
|
||||
import mock
|
||||
@ -20,14 +21,13 @@ from oslo_config import fixture as fixture_config
|
||||
import oslo_messaging
|
||||
import requests
|
||||
import six.moves.urllib.parse as urlparse
|
||||
import ujson
|
||||
|
||||
from aodh import notifier
|
||||
from aodh import service
|
||||
from aodh.tests import base as tests_base
|
||||
|
||||
|
||||
DATA_JSON = ujson.loads(
|
||||
DATA_JSON = json.loads(
|
||||
'{"current": "ALARM", "alarm_id": "foobar", "alarm_name": "testalarm",'
|
||||
' "severity": "critical", "reason": "what ?",'
|
||||
' "reason_data": {"test": "test"}, "previous": "OK"}'
|
||||
@ -175,7 +175,7 @@ class TestAlarmNotifier(tests_base.BaseTestCase):
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
kwargs['headers'])
|
||||
self.assertEqual(DATA_JSON, ujson.loads(kwargs['data']))
|
||||
self.assertEqual(DATA_JSON, json.loads(kwargs['data']))
|
||||
self.assertEqual(2, len(m_log.info.call_args_list))
|
||||
expected = mock.call('Notifying alarm <%(id)s> gets response: '
|
||||
'%(status_code)s %(reason)s.',
|
||||
@ -204,7 +204,7 @@ class TestAlarmNotifier(tests_base.BaseTestCase):
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
kwargs['headers'])
|
||||
self.assertEqual(DATA_JSON, ujson.loads(kwargs['data']))
|
||||
self.assertEqual(DATA_JSON, json.loads(kwargs['data']))
|
||||
|
||||
def test_notify_alarm_rest_action_with_ssl_client_cert_and_key(self):
|
||||
action = 'https://host/action'
|
||||
@ -229,7 +229,7 @@ class TestAlarmNotifier(tests_base.BaseTestCase):
|
||||
kwargs['headers']['x-openstack-request-id'],
|
||||
'content-type': 'application/json'},
|
||||
kwargs['headers'])
|
||||
self.assertEqual(DATA_JSON, ujson.loads(kwargs['data']))
|
||||
self.assertEqual(DATA_JSON, json.loads(kwargs['data']))
|
||||
|
||||
def test_notify_alarm_rest_action_with_ssl_verify_disable_by_cfg(self):
|
||||
action = 'https://host/action'
|
||||
@ -252,7 +252,7 @@ class TestAlarmNotifier(tests_base.BaseTestCase):
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
kwargs['headers'])
|
||||
self.assertEqual(DATA_JSON, ujson.loads(kwargs['data']))
|
||||
self.assertEqual(DATA_JSON, json.loads(kwargs['data']))
|
||||
|
||||
def test_notify_alarm_rest_action_with_ssl_server_verify_enable(self):
|
||||
action = 'https://host/action'
|
||||
@ -270,7 +270,7 @@ class TestAlarmNotifier(tests_base.BaseTestCase):
|
||||
headers=mock.ANY,
|
||||
verify=ca_bundle)
|
||||
args, kwargs = poster.call_args
|
||||
self.assertEqual(DATA_JSON, ujson.loads(kwargs['data']))
|
||||
self.assertEqual(DATA_JSON, json.loads(kwargs['data']))
|
||||
|
||||
def test_notify_alarm_rest_action_with_ssl_verify_disable(self):
|
||||
action = 'https://host/action?aodh-alarm-ssl-verify=0'
|
||||
@ -291,7 +291,7 @@ class TestAlarmNotifier(tests_base.BaseTestCase):
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
kwargs['headers'])
|
||||
self.assertEqual(DATA_JSON, ujson.loads(kwargs['data']))
|
||||
self.assertEqual(DATA_JSON, json.loads(kwargs['data']))
|
||||
|
||||
def test_notify_alarm_rest_action_with_ssl_verify_enable_by_user(self):
|
||||
action = 'https://host/action?aodh-alarm-ssl-verify=1'
|
||||
@ -314,7 +314,7 @@ class TestAlarmNotifier(tests_base.BaseTestCase):
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
kwargs['headers'])
|
||||
self.assertEqual(DATA_JSON, ujson.loads(kwargs['data']))
|
||||
self.assertEqual(DATA_JSON, json.loads(kwargs['data']))
|
||||
|
||||
@staticmethod
|
||||
def _fake_urlsplit(*args, **kwargs):
|
||||
@ -375,7 +375,7 @@ class TestAlarmNotifier(tests_base.BaseTestCase):
|
||||
},
|
||||
kwargs['headers'])
|
||||
|
||||
self.assertEqual(DATA_JSON, ujson.loads(kwargs['data']))
|
||||
self.assertEqual(DATA_JSON, json.loads(kwargs['data']))
|
||||
|
||||
def test_zaqar_notifier_action(self):
|
||||
with mock.patch.object(notifier.zaqar.ZaqarAlarmNotifier,
|
||||
|
@ -34,4 +34,3 @@ cachetools>=1.1.6
|
||||
cotyledon
|
||||
keystoneauth1>=2.1
|
||||
debtcollector>=1.2.0 # Apache-2.0
|
||||
ujson
|
||||
|
Loading…
x
Reference in New Issue
Block a user