Merge "Add py3.5 support for alarms endpoint/unit test"
This commit is contained in:
commit
5bd1b5e212
@ -879,16 +879,17 @@ class MetricsRepository(metrics_repository.AbstractMetricsRepository):
|
||||
if 'values' in result.raw['series'][0]:
|
||||
|
||||
for point in result.raw['series'][0]['values']:
|
||||
alarm_point = {u'timestamp': point[0],
|
||||
u'alarm_id': point[1],
|
||||
u'metrics': rest_utils.from_json(point[2]),
|
||||
u'new_state': point[3],
|
||||
u'old_state': point[4],
|
||||
u'reason': point[5],
|
||||
u'reason_data': point[6],
|
||||
u'sub_alarms': rest_utils.from_json(point[7]),
|
||||
point_list = list(point)
|
||||
alarm_point = {u'timestamp': point_list[0],
|
||||
u'alarm_id': point_list[1],
|
||||
u'metrics': rest_utils.from_json(point_list[2]),
|
||||
u'new_state': point_list[3],
|
||||
u'old_state': point_list[4],
|
||||
u'reason': point_list[5],
|
||||
u'reason_data': point_list[6],
|
||||
u'sub_alarms': rest_utils.from_json(point_list[7]),
|
||||
u'id': str(self._get_millis_from_timestamp(
|
||||
timeutils.parse_isotime(point[0])))}
|
||||
timeutils.parse_isotime(point_list[0])))}
|
||||
|
||||
# java api formats these during json serialization
|
||||
if alarm_point[u'sub_alarms']:
|
||||
|
@ -79,27 +79,27 @@ class SubAlarmDefinition(object):
|
||||
|
||||
"""Build the entire expressions as a string with spaces."""
|
||||
|
||||
result = "{}({}".format(self.function.lower().encode('utf8'),
|
||||
self.metric_name.encode('utf8'))
|
||||
result = u"{}({}".format(self.function.lower(),
|
||||
self.metric_name)
|
||||
|
||||
if self.dimensions_str:
|
||||
result += "{{{}}}".format(self.dimensions_str.encode('utf8'))
|
||||
result += u"{{{}}}".format(self.dimensions_str)
|
||||
|
||||
if self.deterministic:
|
||||
result += ', deterministic'
|
||||
result += u", deterministic"
|
||||
|
||||
if self.period:
|
||||
result += ", {}".format(str(self.period).encode('utf8'))
|
||||
result += u", {}".format(str(self.period))
|
||||
|
||||
result += ")"
|
||||
result += u")"
|
||||
|
||||
result += " {} {}".format(self.operator.encode('utf8'),
|
||||
str(self.threshold).encode('utf8'))
|
||||
result += u" {} {}".format(self.operator,
|
||||
str(self.threshold))
|
||||
|
||||
if self.periods:
|
||||
result += " times {}".format(str(self.periods).encode('utf8'))
|
||||
result += u" times {}".format(str(self.periods))
|
||||
|
||||
return result.decode('utf8')
|
||||
return result
|
||||
|
||||
def __hash__(self):
|
||||
|
||||
|
@ -26,6 +26,7 @@ import testtools.matchers as matchers
|
||||
from mock import Mock
|
||||
|
||||
import oslo_config.fixture
|
||||
from oslo_serialization import jsonutils
|
||||
import six
|
||||
|
||||
from monasca_api.common.repositories.model import sub_alarm_definition
|
||||
@ -125,7 +126,7 @@ class RESTResponseEquals(object):
|
||||
if len(actual) != 1:
|
||||
return matchers.Mismatch("Response contains <> 1 item: %r" % actual)
|
||||
|
||||
response_data = json.loads(actual[0])
|
||||
response_data = jsonutils.loads(actual[0])
|
||||
|
||||
if u"links" in response_data:
|
||||
del response_data[u"links"]
|
||||
@ -256,24 +257,24 @@ class TestAlarmDefinition(AlarmTestBase):
|
||||
return_value.create_alarm_definition.return_value = u"00000001-0001-0001-0001-000000000001"
|
||||
|
||||
valid_expressions = [
|
||||
"max(-_.千幸福的笑脸{घोड़ा=馬, "
|
||||
"dn2=dv2,千幸福的笑脸घ=千幸福的笑脸घ}) gte 100 "
|
||||
"times 3 && "
|
||||
"(min(ເຮືອນ{dn3=dv3,家=дом}) < 10 or sum(biz{dn5=dv5}) >99 and "
|
||||
"count(fizzle) lt 0or count(baz) > 1)".decode('utf8'),
|
||||
u"max(-_.千幸福的笑脸{घोड़ा=馬, "
|
||||
u"dn2=dv2,千幸福的笑脸घ=千幸福的笑脸घ}) gte 100 "
|
||||
u"times 3 && "
|
||||
u"(min(ເຮືອນ{dn3=dv3,家=дом}) < 10 or sum(biz{dn5=dv5}) >99 and "
|
||||
u"count(fizzle) lt 0or count(baz) > 1)",
|
||||
|
||||
"max(foo{hostname=mini-mon,千=千}, 120) > 100 and (max(bar)>100 "
|
||||
" or max(biz)>100)".decode('utf8'),
|
||||
u"max(foo{hostname=mini-mon,千=千}, 120) > 100 and (max(bar)>100 "
|
||||
u" or max(biz)>100)",
|
||||
|
||||
"max(foo)>=100",
|
||||
u"max(foo)>=100",
|
||||
|
||||
"test_metric{this=that, that = this} < 1",
|
||||
u"test_metric{this=that, that = this} < 1",
|
||||
|
||||
"max ( 3test_metric5 { this = that }) lt 5 times 3",
|
||||
u"max ( 3test_metric5 { this = that }) lt 5 times 3",
|
||||
|
||||
"3test_metric5 lt 3",
|
||||
u"3test_metric5 lt 3",
|
||||
|
||||
"ntp.offset > 1 or ntp.offset < -5",
|
||||
u"ntp.offset > 1 or ntp.offset < -5",
|
||||
]
|
||||
|
||||
alarm_def = {
|
||||
@ -412,7 +413,7 @@ class TestAlarmDefinition(AlarmTestBase):
|
||||
body=json.dumps(alarm_def))
|
||||
|
||||
self.assertEqual(self.srmock.status, falcon.HTTP_200)
|
||||
result_def = json.loads(result[0])
|
||||
result_def = jsonutils.loads(result[0])
|
||||
self.assertEqual(result_def, expected_def)
|
||||
|
||||
def test_alarm_definition_patch_no_id(self):
|
||||
@ -533,7 +534,7 @@ class TestAlarmDefinition(AlarmTestBase):
|
||||
body=json.dumps(alarm_def))
|
||||
|
||||
self.assertEqual(self.srmock.status, falcon.HTTP_200)
|
||||
result_def = json.loads(result[0])
|
||||
result_def = jsonutils.loads(result[0])
|
||||
self.assertEqual(result_def, expected_def)
|
||||
# If the alarm-definition-updated event does not have all of the
|
||||
# fields set, the Threshold Engine will get confused. For example,
|
||||
@ -645,7 +646,7 @@ class TestAlarmDefinition(AlarmTestBase):
|
||||
body=json.dumps(alarm_def))
|
||||
|
||||
self.assertEqual(self.srmock.status, falcon.HTTP_200)
|
||||
result_def = json.loads(result[0])
|
||||
result_def = jsonutils.loads(result[0])
|
||||
self.assertEqual(result_def, expected_def)
|
||||
|
||||
for key, value in alarm_def.items():
|
||||
|
@ -12,6 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from builtins import str as text
|
||||
import re
|
||||
|
||||
import falcon
|
||||
@ -655,8 +656,7 @@ def get_query_alarm_definition_description(alarm_definition,
|
||||
|
||||
def get_query_alarm_definition_severity(alarm_definition, return_none=False):
|
||||
if 'severity' in alarm_definition:
|
||||
severity = alarm_definition['severity']
|
||||
severity = severity.decode('utf8').upper()
|
||||
severity = text(alarm_definition['severity']).upper()
|
||||
if severity not in ['LOW', 'MEDIUM', 'HIGH', 'CRITICAL']:
|
||||
raise HTTPUnprocessableEntityError('Unprocessable Entity', 'Invalid severity')
|
||||
return severity
|
||||
@ -736,7 +736,7 @@ def get_comma_separated_str_as_list(comma_separated_str):
|
||||
if not comma_separated_str:
|
||||
return []
|
||||
else:
|
||||
return comma_separated_str.decode('utf8').split(',')
|
||||
return text(comma_separated_str).split(',')
|
||||
|
||||
|
||||
def is_definition_deterministic(expression):
|
||||
|
@ -14,6 +14,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from builtins import str as text
|
||||
import datetime
|
||||
|
||||
import falcon
|
||||
@ -366,7 +367,7 @@ def paginate(resource, uri, limit):
|
||||
else:
|
||||
|
||||
resource = {u'links': ([{u'rel': u'self',
|
||||
u'href': self_link.decode('utf8')}]),
|
||||
u'href': text(self_link)}]),
|
||||
u'elements': resource}
|
||||
|
||||
return resource
|
||||
|
Loading…
Reference in New Issue
Block a user