Browse Source

Fix aodhclient for pyparse 3.0.6

Replaces removed pyparsing.operatorPrecedence().

Also removes broken ceilometer threshold tests as they
don't seem to be supported by aodh anymore.

Change-Id: Ifa82042fc15e6c167ed2e3a1923baa6ee61c6237
changes/93/819393/2 2.4.0
rabi 6 months ago committed by Rabi Mishra
parent
commit
3a36ed1774
  1. 175
      aodhclient/tests/functional/test_alarm.py
  2. 2
      aodhclient/utils.py

175
aodhclient/tests/functional/test_alarm.py

@ -184,162 +184,6 @@ class AodhClientTest(base.ClientTestBase):
self.assertNotIn(ALARM_ID,
[r['alarm_id'] for r in self.parser.listing(result)])
def test_threshold_scenario(self):
PROJECT_ID = uuidutils.generate_uuid()
# CREATE
result = self.aodh(u'alarm',
params=(u"create --type threshold --name "
"test_threshold_scenario "
"-m meter_name --threshold 5 "
"--project-id %s" % PROJECT_ID))
alarm = self.details_multiple(result)[0]
ALARM_ID = alarm['alarm_id']
self.assertEqual('test_threshold_scenario', alarm['name'])
self.assertEqual('meter_name', alarm['meter_name'])
self.assertEqual('5.0', alarm['threshold'])
# CREATE WITH --TIME-CONSTRAINT
result = self.aodh(
u'alarm',
params=(u"create --type threshold --name alarm_tc "
"-m meter_name --threshold 5 "
"--time-constraint "
"name=cons1;start='0 11 * * *';duration=300 "
"--time-constraint "
"name=cons2;start='0 23 * * *';duration=600 "
"--project-id %s" % PROJECT_ID))
alarm = self.details_multiple(result)[0]
self.assertEqual('alarm_tc', alarm['name'])
self.assertEqual('meter_name', alarm['meter_name'])
self.assertEqual('5.0', alarm['threshold'])
self.assertIsNotNone(alarm['time_constraints'])
# CREATE FAIL MISSING PARAM
self.assertRaises(exceptions.CommandFailed,
self.aodh, u'alarm',
params=(u"create --type threshold --name "
"test_threshold_scenario "
"--project-id %s" % PROJECT_ID))
# UPDATE
result = self.aodh(
'alarm', params=("update %s --severity critical --threshold 10"
% ALARM_ID))
alarm_updated = self.details_multiple(result)[0]
self.assertEqual(ALARM_ID, alarm_updated["alarm_id"])
self.assertEqual('critical', alarm_updated['severity'])
self.assertEqual('10.0', alarm_updated["threshold"])
# GET
result = self.aodh(
'alarm', params="show %s" % ALARM_ID)
alarm_show = self.details_multiple(result)[0]
self.assertEqual(ALARM_ID, alarm_show["alarm_id"])
self.assertEqual(PROJECT_ID, alarm_show["project_id"])
self.assertEqual('test_threshold_scenario', alarm_show['name'])
self.assertEqual('meter_name', alarm_show['meter_name'])
self.assertEqual('10.0', alarm_show['threshold'])
# GET BY NAME
result = self.aodh(
'alarm', params="show --name test_threshold_scenario")
alarm_show = self.details_multiple(result)[0]
self.assertEqual(ALARM_ID, alarm_show["alarm_id"])
self.assertEqual(PROJECT_ID, alarm_show["project_id"])
self.assertEqual('test_threshold_scenario', alarm_show['name'])
self.assertEqual('meter_name', alarm_show['meter_name'])
self.assertEqual('10.0', alarm_show['threshold'])
# GET BY NAME AND ID ERROR
self.assertRaises(exceptions.CommandFailed,
self.aodh, u'alarm',
params=(u"show %s --name test_threshold_scenario" %
ALARM_ID))
# LIST
result = self.aodh('alarm', params="list --filter all_projects=true")
self.assertIn(ALARM_ID,
[r['alarm_id'] for r in self.parser.listing(result)])
output_colums = ['alarm_id', 'type', 'name', 'state', 'severity',
'enabled']
for alarm_list in self.parser.listing(result):
self.assertEqual(sorted(output_colums), sorted(alarm_list.keys()))
if alarm_list["alarm_id"] == ALARM_ID:
self.assertEqual('test_threshold_scenario', alarm_list['name'])
# LIST WITH PAGINATION
# list with limit
result = self.aodh('alarm',
params="list --filter all_projects=true --limit 1 ")
alarm_list = self.parser.listing(result)
self.assertEqual(1, len(alarm_list))
# list with sort with key=name dir=asc
result = self.aodh(
'alarm',
params="list --filter all_projects=true --sort name:asc")
names = [r['name'] for r in self.parser.listing(result)]
sorted_name = sorted(names)
self.assertEqual(sorted_name, names)
# list with sort with key=name dir=asc and key=alarm_id dir=asc
result = self.aodh(u'alarm',
params=(u"create --type threshold --name "
"test_threshold_scenario "
"-m meter_name --threshold 5 "
"--project-id %s" % PROJECT_ID))
created_alarm_id = self.details_multiple(result)[0]['alarm_id']
result = self.aodh(
'alarm',
params="list --filter all_projects=true --sort name:asc --sort "
"alarm_id:asc")
alarm_list = self.parser.listing(result)
ids_with_same_name = []
names = []
for alarm in alarm_list:
names.append(['alarm_name'])
if alarm['name'] == 'test_threshold_scenario':
ids_with_same_name.append(alarm['alarm_id'])
sorted_ids = sorted(ids_with_same_name)
sorted_names = sorted(names)
self.assertEqual(sorted_names, names)
self.assertEqual(sorted_ids, ids_with_same_name)
# list with sort with key=name dir=desc and with the marker equal to
# the alarm_id of the test_threshold_scenario we created for this test.
result = self.aodh(
'alarm',
params="list --filter all_projects=true --sort name:desc "
"--marker %s" % created_alarm_id)
self.assertIn('alarm_tc',
[r['name'] for r in self.parser.listing(result)])
self.aodh('alarm', params="delete %s" % created_alarm_id)
# LIST WITH QUERY
result = self.aodh('alarm',
params=("list --query project_id=%s" % PROJECT_ID))
alarm_list = self.parser.listing(result)[0]
self.assertEqual(ALARM_ID, alarm_list["alarm_id"])
self.assertEqual('test_threshold_scenario', alarm_list['name'])
# DELETE
result = self.aodh('alarm', params="delete %s" % ALARM_ID)
self.assertEqual("", result)
# GET FAIL
result = self.aodh('alarm', params="show %s" % ALARM_ID,
fail_ok=True, merge_stderr=True)
expected = "Alarm %s not found (HTTP 404)" % ALARM_ID
self.assertFirstLineStartsWith(result.splitlines(), expected)
# DELETE FAIL
result = self.aodh('alarm', params="delete %s" % ALARM_ID,
fail_ok=True, merge_stderr=True)
self.assertFirstLineStartsWith(result.splitlines(), expected)
# LIST DOES NOT HAVE ALARM
result = self.aodh('alarm', params="list")
self.assertNotIn(ALARM_ID,
[r['alarm_id'] for r in self.parser.listing(result)])
def test_composite_scenario(self):
project_id = uuidutils.generate_uuid()
@ -454,25 +298,6 @@ class AodhClientTest(base.ClientTestBase):
test(params)
self.aodh('alarm', params='delete %s' % alarm['alarm_id'])
def test_threshold_alarm_create_show_query(self):
params = ('create --type threshold --name alarm-multiple-query '
'-m cpu_util --threshold 90 --query "project_id=123;'
'resource_id=456"')
expected_lines = {
'query': 'project_id = 123 AND',
'': 'resource_id = 456'
}
self._test_alarm_create_show_query(params, expected_lines)
params = ('create --type threshold --name alarm-single-query '
'-m cpu_util --threshold 90 --query project_id=123')
expected_lines = {'query': 'project_id = 123'}
self._test_alarm_create_show_query(params, expected_lines)
params = ('create --type threshold --name alarm-no-query '
'-m cpu_util --threshold 90')
self._test_alarm_create_show_query(params, {'query': ''})
def test_event_alarm_create_show_query(self):
params = ('create --type event --name alarm-multiple-query '
'--query "traits.project_id=789;traits.resource_id=012"')

2
aodhclient/utils.py

@ -40,7 +40,7 @@ comparison_term << (null | boolean | uuid | identifier | number |
quoted_string)
condition = pp.Group(comparison_term + operator + comparison_term)
expr = pp.operatorPrecedence(condition, [
expr = pp.infixNotation(condition, [
("not", 1, pp.opAssoc.RIGHT, ),
("and", 2, pp.opAssoc.LEFT, ),
("or", 2, pp.opAssoc.LEFT, ),

Loading…
Cancel
Save