Allow lower case for queries with state and severity
Add tests to validate. Change some tempest tests to validate. Change-Id: I92bcf8fc8f1605dcf3a291b3fd224d930f96b1f0
This commit is contained in:
parent
d9794a53f3
commit
65aefd7772
|
@ -1,4 +1,4 @@
|
||||||
# (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
|
# (C) Copyright 2015-2017 Hewlett Packard Enterprise Development LP
|
||||||
# Copyright 2015 Cray Inc. All Rights Reserved.
|
# Copyright 2015 Cray Inc. All Rights Reserved.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
@ -18,6 +18,7 @@ import unittest
|
||||||
import falcon
|
import falcon
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
|
import monasca_api.v2.common.exceptions as common_exceptions
|
||||||
import monasca_api.v2.common.schemas.alarm_definition_request_body_schema as schemas_alarm_defs
|
import monasca_api.v2.common.schemas.alarm_definition_request_body_schema as schemas_alarm_defs
|
||||||
import monasca_api.v2.common.schemas.exceptions as schemas_exceptions
|
import monasca_api.v2.common.schemas.exceptions as schemas_exceptions
|
||||||
import monasca_api.v2.common.schemas.notifications_request_body_schema as schemas_notifications
|
import monasca_api.v2.common.schemas.notifications_request_body_schema as schemas_notifications
|
||||||
|
@ -137,6 +138,51 @@ class TestValueMetaValidation(unittest.TestCase):
|
||||||
value_meta)
|
value_meta)
|
||||||
|
|
||||||
|
|
||||||
|
class TestStateValidation(unittest.TestCase):
|
||||||
|
|
||||||
|
VALID_STATES = "OK", "ALARM", "UNDETERMINED"
|
||||||
|
|
||||||
|
def test_valid_states(self):
|
||||||
|
for state in self.VALID_STATES:
|
||||||
|
validation.validate_alarm_state(state)
|
||||||
|
|
||||||
|
def test_valid_states_lower_case(self):
|
||||||
|
for state in self.VALID_STATES:
|
||||||
|
validation.validate_alarm_state(state.lower())
|
||||||
|
|
||||||
|
def test_invalid_state(self):
|
||||||
|
self.assertRaises(common_exceptions.HTTPUnprocessableEntityError,
|
||||||
|
validation.validate_alarm_state, 'BOGUS')
|
||||||
|
|
||||||
|
|
||||||
|
class TestSeverityValidation(unittest.TestCase):
|
||||||
|
|
||||||
|
VALID_SEVERITIES = "LOW", "MEDIUM", "HIGH", "CRITICAL"
|
||||||
|
|
||||||
|
def test_valid_severities(self):
|
||||||
|
for state in self.VALID_SEVERITIES:
|
||||||
|
validation.validate_severity_query(state)
|
||||||
|
|
||||||
|
def test_valid_severities_lower_case(self):
|
||||||
|
for state in self.VALID_SEVERITIES:
|
||||||
|
validation.validate_severity_query(state.lower())
|
||||||
|
|
||||||
|
def test_valid_multi_severities(self):
|
||||||
|
validation.validate_severity_query('|'.join(self.VALID_SEVERITIES))
|
||||||
|
|
||||||
|
def test_valid_multi_severities_lower_case(self):
|
||||||
|
validation.validate_severity_query('|'.join(self.VALID_SEVERITIES)
|
||||||
|
.lower())
|
||||||
|
|
||||||
|
def test_invalid_state(self):
|
||||||
|
self.assertRaises(common_exceptions.HTTPUnprocessableEntityError,
|
||||||
|
validation.validate_severity_query,
|
||||||
|
'BOGUS')
|
||||||
|
self.assertRaises(common_exceptions.HTTPUnprocessableEntityError,
|
||||||
|
validation.validate_severity_query,
|
||||||
|
'|'.join([self.VALID_SEVERITIES[0], 'BOGUS']))
|
||||||
|
|
||||||
|
|
||||||
class TestRoleValidation(unittest.TestCase):
|
class TestRoleValidation(unittest.TestCase):
|
||||||
|
|
||||||
def test_role_valid(self):
|
def test_role_valid(self):
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# (C) Copyright 2015,2016 Hewlett Packard Enterprise Development Company LP
|
# (C) Copyright 2015-2017 Hewlett Packard Enterprise Development LP
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
# not use this file except in compliance with the License. You may obtain
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
@ -56,14 +56,14 @@ def dimension_value(value):
|
||||||
|
|
||||||
|
|
||||||
def validate_alarm_state(state):
|
def validate_alarm_state(state):
|
||||||
if state not in VALID_ALARM_STATES:
|
if state.upper() not in VALID_ALARM_STATES:
|
||||||
raise HTTPUnprocessableEntityError("Invalid State",
|
raise HTTPUnprocessableEntityError("Invalid State",
|
||||||
"State {} must be one of {}".format(state.encode('utf8'),
|
"State {} must be one of {}".format(state.encode('utf8'),
|
||||||
VALID_ALARM_STATES))
|
VALID_ALARM_STATES))
|
||||||
|
|
||||||
|
|
||||||
def validate_alarm_definition_severity(severity):
|
def validate_alarm_definition_severity(severity):
|
||||||
if severity not in VALID_ALARM_DEFINITION_SEVERITIES:
|
if severity.upper() not in VALID_ALARM_DEFINITION_SEVERITIES:
|
||||||
raise HTTPUnprocessableEntityError("Invalid Severity",
|
raise HTTPUnprocessableEntityError("Invalid Severity",
|
||||||
"Severity {} must be one of {}".format(severity.encode('utf8'),
|
"Severity {} must be one of {}".format(severity.encode('utf8'),
|
||||||
VALID_ALARM_DEFINITION_SEVERITIES))
|
VALID_ALARM_DEFINITION_SEVERITIES))
|
||||||
|
@ -115,12 +115,6 @@ def validate_value_meta(value_meta):
|
||||||
assert len(value_meta[name]) >= 1, "ValueMeta value cannot be empty"
|
assert len(value_meta[name]) >= 1, "ValueMeta value cannot be empty"
|
||||||
|
|
||||||
|
|
||||||
def validate_state_query(state_str):
|
|
||||||
if state_str not in VALID_ALARM_STATES:
|
|
||||||
raise HTTPUnprocessableEntityError("Unprocessable Entity",
|
|
||||||
"state {} must be one of 'ALARM','OK','UNDETERMINED'".format(state_str))
|
|
||||||
|
|
||||||
|
|
||||||
def validate_email_address(email):
|
def validate_email_address(email):
|
||||||
if re.match(EMAIL_PATTERN, email) is None:
|
if re.match(EMAIL_PATTERN, email) is None:
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# (C) Copyright 2014,2015-2017 Hewlett Packard Enterprise Development LP
|
# (C) Copyright 2014-2017 Hewlett Packard Enterprise Development LP
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
# not use this file except in compliance with the License. You may obtain
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
@ -89,6 +89,7 @@ class AlarmDefinitions(alarm_definitions_api_v2.AlarmDefinitionsV2API,
|
||||||
severity = helpers.get_query_param(req, "severity", default_val=None)
|
severity = helpers.get_query_param(req, "severity", default_val=None)
|
||||||
if severity is not None:
|
if severity is not None:
|
||||||
validation.validate_severity_query(severity)
|
validation.validate_severity_query(severity)
|
||||||
|
severity = severity.upper()
|
||||||
sort_by = helpers.get_query_param(req, 'sort_by', default_val=None)
|
sort_by = helpers.get_query_param(req, 'sort_by', default_val=None)
|
||||||
if sort_by is not None:
|
if sort_by is not None:
|
||||||
if isinstance(sort_by, basestring):
|
if isinstance(sort_by, basestring):
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Copyright 2014-2016 Hewlett Packard Enterprise Development Company LP
|
# Copyright 2014-2017 Hewlett Packard Enterprise Development LP
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
# not use this file except in compliance with the License. You may obtain
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
@ -115,9 +115,11 @@ class Alarms(alarms_api_v2.AlarmsV2API,
|
||||||
query_parms = falcon.uri.parse_query_string(req.query_string)
|
query_parms = falcon.uri.parse_query_string(req.query_string)
|
||||||
if 'state' in query_parms:
|
if 'state' in query_parms:
|
||||||
validation.validate_alarm_state(query_parms['state'])
|
validation.validate_alarm_state(query_parms['state'])
|
||||||
|
query_parms['state'] = query_parms['state'].upper()
|
||||||
|
|
||||||
if 'severity' in query_parms:
|
if 'severity' in query_parms:
|
||||||
validation.validate_severity_query(query_parms['severity'])
|
validation.validate_severity_query(query_parms['severity'])
|
||||||
|
query_parms['severity'] = query_parms['severity'].upper()
|
||||||
|
|
||||||
if 'sort_by' in query_parms:
|
if 'sort_by' in query_parms:
|
||||||
if isinstance(query_parms['sort_by'], basestring):
|
if isinstance(query_parms['sort_by'], basestring):
|
||||||
|
@ -128,12 +130,6 @@ class Alarms(alarms_api_v2.AlarmsV2API,
|
||||||
'state_updated_timestamp', 'updated_timestamp', 'created_timestamp'}
|
'state_updated_timestamp', 'updated_timestamp', 'created_timestamp'}
|
||||||
validation.validate_sort_by(query_parms['sort_by'], allowed_sort_by)
|
validation.validate_sort_by(query_parms['sort_by'], allowed_sort_by)
|
||||||
|
|
||||||
if 'state' in query_parms:
|
|
||||||
validation.validate_alarm_state(query_parms['state'])
|
|
||||||
|
|
||||||
if 'severity' in query_parms:
|
|
||||||
validation.validate_severity_query(query_parms['severity'])
|
|
||||||
|
|
||||||
# ensure metric_dimensions is a list
|
# ensure metric_dimensions is a list
|
||||||
if 'metric_dimensions' in query_parms and isinstance(query_parms['metric_dimensions'], str):
|
if 'metric_dimensions' in query_parms and isinstance(query_parms['metric_dimensions'], str):
|
||||||
query_parms['metric_dimensions'] = query_parms['metric_dimensions'].split(',')
|
query_parms['metric_dimensions'] = query_parms['metric_dimensions'].split(',')
|
||||||
|
@ -395,9 +391,11 @@ class AlarmsCount(alarms_api_v2.AlarmsCountV2API, alarming.Alarming):
|
||||||
|
|
||||||
if 'state' in query_parms:
|
if 'state' in query_parms:
|
||||||
validation.validate_alarm_state(query_parms['state'])
|
validation.validate_alarm_state(query_parms['state'])
|
||||||
|
query_parms['state'] = query_parms['state'].upper()
|
||||||
|
|
||||||
if 'severity' in query_parms:
|
if 'severity' in query_parms:
|
||||||
validation.validate_severity_query(query_parms['severity'])
|
validation.validate_severity_query(query_parms['severity'])
|
||||||
|
query_parms['severity'] = query_parms['severity'].upper()
|
||||||
|
|
||||||
if 'group_by' in query_parms:
|
if 'group_by' in query_parms:
|
||||||
if not isinstance(query_parms['group_by'], list):
|
if not isinstance(query_parms['group_by'], list):
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# (C) Copyright 2015,2016 Hewlett Packard Enterprise Development Company LP
|
# (C) Copyright 2015-2017 Hewlett Packard Enterprise Development LP
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
# not use this file except in compliance with the License. You may obtain
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
@ -426,7 +426,7 @@ class TestAlarmDefinitions(base.BaseMonascaTest):
|
||||||
name=name,
|
name=name,
|
||||||
description="description",
|
description="description",
|
||||||
expression=expression,
|
expression=expression,
|
||||||
severity="LOW")
|
severity="low")
|
||||||
resp, res_body_create_alarm_def = self.monasca_client.\
|
resp, res_body_create_alarm_def = self.monasca_client.\
|
||||||
create_alarm_definitions(alarm_definition)
|
create_alarm_definitions(alarm_definition)
|
||||||
self.assertEqual(201, resp.status)
|
self.assertEqual(201, resp.status)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# (C) Copyright 2015-2016 Hewlett Packard Enterprise Development Company LP
|
# (C) Copyright 2015-2017 Hewlett Packard Enterprise Development LP
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
# not use this file except in compliance with the License. You may obtain
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
@ -252,7 +252,7 @@ class TestAlarms(base.BaseMonascaTest):
|
||||||
resp, response_body1 = self.monasca_client.list_alarms(query_parms)
|
resp, response_body1 = self.monasca_client.list_alarms(query_parms)
|
||||||
len1 = len(response_body1['elements'])
|
len1 = len(response_body1['elements'])
|
||||||
self.assertEqual(200, resp.status)
|
self.assertEqual(200, resp.status)
|
||||||
query_parms = '?state=OK'
|
query_parms = '?state=ok'
|
||||||
resp, response_body2 = self.monasca_client.list_alarms(query_parms)
|
resp, response_body2 = self.monasca_client.list_alarms(query_parms)
|
||||||
len2 = len(response_body2['elements'])
|
len2 = len(response_body2['elements'])
|
||||||
self.assertEqual(200, resp.status)
|
self.assertEqual(200, resp.status)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# (C) Copyright 2016 Hewlett Packard Enterprise Development Company LP
|
# (C) Copyright 2016-2017 Hewlett Packard Enterprise Development LP
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
# not use this file except in compliance with the License. You may obtain
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
@ -194,7 +194,7 @@ class TestAlarmsCount(base.BaseMonascaTest):
|
||||||
resp, response_body = self.monasca_client.list_alarms("?state=ALARM")
|
resp, response_body = self.monasca_client.list_alarms("?state=ALARM")
|
||||||
self.assertEqual(200, resp.status)
|
self.assertEqual(200, resp.status)
|
||||||
alarm_state_count = len(response_body['elements'])
|
alarm_state_count = len(response_body['elements'])
|
||||||
resp, response_body = self.monasca_client.list_alarms("?state=UNDETERMINED")
|
resp, response_body = self.monasca_client.list_alarms("?state=undetermined")
|
||||||
self.assertEqual(200, resp.status)
|
self.assertEqual(200, resp.status)
|
||||||
undet_state_count = len(response_body['elements'])
|
undet_state_count = len(response_body['elements'])
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ class TestAlarmsCount(base.BaseMonascaTest):
|
||||||
# test with filter parameters
|
# test with filter parameters
|
||||||
@test.attr(type='gate')
|
@test.attr(type='gate')
|
||||||
def test_filter_params(self):
|
def test_filter_params(self):
|
||||||
resp, response_body = self.monasca_client.list_alarms("?severity=LOW")
|
resp, response_body = self.monasca_client.list_alarms("?severity=low")
|
||||||
self.assertEqual(200, resp.status)
|
self.assertEqual(200, resp.status)
|
||||||
expected_count = len(response_body['elements'])
|
expected_count = len(response_body['elements'])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue