diff options
| author | ZhiQiang Fan <zhiqiang.fan@huawei.com> | 2015-04-01 22:22:07 +0800 |
|---|---|---|
| committer | ZhiQiang Fan <zhiqiang.fan@huawei.com> | 2015-04-02 18:43:25 +0800 |
| commit | 16880fcaebb9a950c7ad7ca17ff87b000645f2ac (patch) | |
| tree | b5d4cae1e62a8be5b12c30fb7b8c785c2be94b4d /ceilometerclient/tests | |
| parent | c40d67cf97d9e4bfdde4e6d3ee28a31d61c8cafe (diff) | |
| download | python-ceilometerclient-16880fcaebb9a950c7ad7ca17ff87b000645f2ac.tar.gz | |
print user friendly error message for alarm update time constraints
Currently, if we update an alarm with wrong time constraint which
doesn't get name defined, then the shell only prints a very simple
string 'name'.
This is because our code assume name field has always been specified,
however it is not true, then KeyError exception will be raised but not
handled well, finally user only gets an implicit message.
This patch uses dict.get() for name field, and sends request (may be broken)
to ceilometer api, then extracts error message from response.
Change-Id: I086c4ec790acc22767ba7f5e43dbcf73f3af5dff
Closes-Bug: #1439207
Diffstat (limited to 'ceilometerclient/tests')
| -rw-r--r-- | ceilometerclient/tests/unit/v2/test_alarms.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/ceilometerclient/tests/unit/v2/test_alarms.py b/ceilometerclient/tests/unit/v2/test_alarms.py index 4239d2f..9d3b75e 100644 --- a/ceilometerclient/tests/unit/v2/test_alarms.py +++ b/ceilometerclient/tests/unit/v2/test_alarms.py @@ -529,6 +529,23 @@ class AlarmTimeConstraintTest(testtools.TestCase): ] self.http_client.assert_called(*expect) + def test_update_time_constraint_no_name(self): + updated_constraint = { + 'start': '0 23 * * *', + 'duration': 500 + } + kwargs = dict(time_constraints=[updated_constraint]) + self.mgr.update(alarm_id='alarm-id', **kwargs) + body = copy.deepcopy(AN_ALARM) + body[u'time_constraints'].append({ + 'start': '0 23 * * *', + 'duration': 500, + }) + expect = [ + 'PUT', '/v2/alarms/alarm-id', body + ] + self.http_client.assert_called(*expect) + def test_remove(self): kwargs = dict(remove_time_constraints=['cons2']) self.mgr.update(alarm_id='alarm-id', **kwargs) |
