summaryrefslogtreecommitdiff
path: root/ceilometerclient/tests/v2/test_shell.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/v2/test_shell.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/v2/test_shell.py')
-rw-r--r--ceilometerclient/tests/v2/test_shell.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/ceilometerclient/tests/v2/test_shell.py b/ceilometerclient/tests/v2/test_shell.py
index 4d45a0b..37dc09e 100644
--- a/ceilometerclient/tests/v2/test_shell.py
+++ b/ceilometerclient/tests/v2/test_shell.py
@@ -158,6 +158,16 @@ class ShellAlarmCommandTest(utils.BaseTestCase):
"value": "INSTANCE_ID",
"op": "eq"}],
"comparison_operator": "gt"},
+ "time_constraints": [{"name": "cons1",
+ "description": "desc1",
+ "start": "0 11 * * *",
+ "duration": 300,
+ "timezone": ""},
+ {"name": "cons2",
+ "description": "desc2",
+ "start": "0 23 * * *",
+ "duration": 600,
+ "timezone": ""}],
"alarm_id": ALARM_ID,
"state": "insufficient data",
"insufficient_data_actions": [],
@@ -276,6 +286,36 @@ class ShellAlarmCommandTest(utils.BaseTestCase):
sys.stdout.close()
sys.stdout = orig
+ def test_alarm_create_time_constraints(self):
+ shell = base_shell.CeilometerShell()
+ argv = ['alarm-threshold-create',
+ '--name', 'cpu_high',
+ '--meter-name', 'cpu_util',
+ '--threshold', '70.0',
+ '--time-constraint',
+ 'name=cons1;start="0 11 * * *";duration=300',
+ '--time-constraint',
+ 'name=cons2;start="0 23 * * *";duration=600',
+ ]
+ _, args = shell.parse_args(argv)
+
+ orig = sys.stdout
+ sys.stdout = six.StringIO()
+ alarm = alarms.Alarm(mock.Mock(), self.ALARM)
+ self.cc.alarms.create.return_value = alarm
+
+ try:
+ ceilometer_shell.do_alarm_threshold_create(self.cc, args)
+ _, kwargs = self.cc.alarms.create.call_args
+ time_constraints = [dict(name='cons1', start='0 11 * * *',
+ duration='300'),
+ dict(name='cons2', start='0 23 * * *',
+ duration='600')]
+ self.assertEqual(time_constraints, kwargs['time_constraints'])
+ finally:
+ sys.stdout.close()
+ sys.stdout = orig
+
class ShellSampleListCommandTest(utils.BaseTestCase):