summaryrefslogtreecommitdiff
path: root/ceilometerclient/tests/test_utils.py
diff options
context:
space:
mode:
authorUros Jovanovic <uros.jovanovic@gmail.com>2014-03-05 18:49:14 +0000
committerUros Jovanovic <uros.jovanovic@gmail.com>2014-03-26 08:24:56 +0000
commit7146571b702579fa1367598ab278ca2f8ec1e156 (patch)
tree051046a88aca58b13ef56a7747a2d4e689e369e9 /ceilometerclient/tests/test_utils.py
parent3e8045c9caad407b38758da7f611982809e3a0f5 (diff)
downloadpython-ceilometerclient-7146571b702579fa1367598ab278ca2f8ec1e156.tar.gz
Adds alarm time constraint support to ceilometer CLI
Time constraints can be specified for create and update families of commands with the following format: --time-constraint name=constraint1;start='0 11 * * *';duration=300 This switch can be specified multiple times in the case of multiple time constraints. With update commands, time constraints are updated by name, e.g. --time-constraint name=constraint1;duration=500 updates the constraint 'constraint1' with a new duration 500. Time constraints can be removed with update commands using the switch --remove-time-constraint=constraint1,constraint2 . Example of display outputs: > ceilometer alarm-list +--------------------------------------+-------+-------------------+---------+------------+----------------------------+--------------------------------------------------------------+ | Alarm ID | Name | State | Enabled | Continuous | Alarm condition | Time constraints | +--------------------------------------+-------+-------------------+---------+------------+----------------------------+--------------------------------------------------------------+ | 2ead776d-2fc7-47a2-b0bb-0f88dcefa457 | test2 | insufficient data | True | False | cpu == 50.0 during 1 x 60s | cons1 at 0 11 * * * for 300s, cons2 at 0 23 * * * for 600s | +--------------------------------------+-------+-------------------+---------+------------+----------------------------+--------------------------------------------------------------+ > ceilometer alarm-show -a +---------------------------+-----------------------------------------------------------------------+ | Property | Value | +---------------------------+-----------------------------------------------------------------------+ | alarm_actions | [] | | alarm_id | 2ead776d-2fc7-47a2-b0bb-0f88dcefa457 | | comparison_operator | eq | | description | Alarm when cpu is eq a avg of 50.0 over 60 seconds | | enabled | True | | evaluation_periods | 1 | | exclude_outliers | False | | insufficient_data_actions | [] | | meter_name | cpu | | name | test2 | | ok_actions | [] | | period | 60 | | project_id | 962f75ad22c24cbf99d40d7b82718505 | | query | | | repeat_actions | False | | state | insufficient data | | statistic | avg | | threshold | 50.0 | | time_constraints | [{name: cons1, | | | description: Time constraint at 0 11 * * * lasting for 300 seconds, | | | start: 0 11 * * *, | | | duration: 300}, | | | {name: cons2, | | | description: Time constraint at 0 23 * * * lasting for 600 seconds, | | | start: 0 23 * * *, | | | duration: 600}] | | type | threshold | | user_id | 76f335df8e2f4c7e9e8185e26ea85759 | +---------------------------+-----------------------------------------------------------------------+ > ceilometer alarm-history -a 2ead776d-2fc7-47a2-b0bb-0f88dcefa457 +----------+----------------------------+--------------------------------------------------------------------------------+ | Type | Timestamp | Detail | +----------+----------------------------+--------------------------------------------------------------------------------+ | creation | 2014-03-06T07:41:35.362050 | name: test2 | | | | description: Alarm when cpu is eq a avg of 50.0 over 60 seconds | | | | type: threshold | | | | rule: cpu == 50.0 during 1 x 60s | | | | time_constraints: cons1 at 0 11 * * * for 300s, cons2 at 0 23 * * * for 600s | +----------+----------------------------+--------------------------------------------------------------------------------+ Change-Id: I3953276537b4526e46e5e6d229d6fa154f8ab0fc Closes-Bug: #1288246
Diffstat (limited to 'ceilometerclient/tests/test_utils.py')
-rw-r--r--ceilometerclient/tests/test_utils.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/ceilometerclient/tests/test_utils.py b/ceilometerclient/tests/test_utils.py
index 1f3074b..9082328 100644
--- a/ceilometerclient/tests/test_utils.py
+++ b/ceilometerclient/tests/test_utils.py
@@ -14,6 +14,7 @@
# under the License.
+import itertools
import mock
import six
import sys
@@ -117,6 +118,33 @@ class UtilsTest(test_utils.BaseTestCase):
'other': 'value'
})
+ def test_args_array_to_list_of_dicts(self):
+ starts = ['0 11 * * *', '"0 11 * * *"', '\'0 11 * * *\'']
+ timezones = [None, 'US/Eastern', '"US/Eastern"', '\'US/Eastern\'']
+ descs = [None, 'de sc', '"de sc"', '\'de sc\'']
+ for start, tz, desc in itertools.product(starts, timezones, descs):
+ my_args = {
+ 'time_constraints': ['name=const1;start=%s;duration=1'
+ % start],
+ 'other': 'value'
+ }
+ expected = {
+ 'time_constraints': [dict(name='const1',
+ start='0 11 * * *',
+ duration='1')],
+ 'other': 'value'
+ }
+ if tz:
+ my_args['time_constraints'][0] += ';timezone=%s' % tz
+ expected['time_constraints'][0]['timezone'] = 'US/Eastern'
+ if desc:
+ my_args['time_constraints'][0] += ';description=%s' % desc
+ expected['time_constraints'][0]['description'] = 'de sc'
+
+ cleaned = utils.args_array_to_list_of_dicts(my_args,
+ 'time_constraints')
+ self.assertEqual(expected, cleaned)
+
def test_key_with_slash_to_nested_dict(self):
my_args = {
'combination_rule/alarm_ids': ['id1', 'id2'],