Merge "print user friendly error message for alarm update time constraints"
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -135,14 +135,15 @@ class AlarmManager(base.Manager):
|
||||
updated_tcs = [dict(tc) for tc in existing_tcs]
|
||||
for tc in new_tcs:
|
||||
for i, old_tc in enumerate(updated_tcs):
|
||||
if old_tc['name'] == tc['name']: # if names match, merge
|
||||
# if names match, merge
|
||||
if old_tc['name'] == tc.get('name'):
|
||||
utils.merge_nested_dict(updated_tcs[i], tc)
|
||||
break
|
||||
else:
|
||||
updated_tcs.append(tc)
|
||||
tcs_to_remove = kwargs.get('remove_time_constraints', [])
|
||||
for tc in updated_tcs:
|
||||
if tc['name'] in tcs_to_remove:
|
||||
if tc.get('name') in tcs_to_remove:
|
||||
updated_tcs.remove(tc)
|
||||
return updated_tcs
|
||||
|
||||
|
||||
Reference in New Issue
Block a user