Avoid unnecessary GET of existing alarm for update
The existing alarm representation is retrieved prior to update, which is uneccessary as the API merges the new and existing state in any case. This change saves the threshold eval logic one unnecessary API call per state transition. Change-Id: If21c53d6f43164315e1e70e62b0c70520fb5a45c
This commit is contained in:
@@ -64,11 +64,8 @@ class AlarmManager(base.Manager):
|
|||||||
return self._create(self._path(), new)
|
return self._create(self._path(), new)
|
||||||
|
|
||||||
def update(self, alarm_id, **kwargs):
|
def update(self, alarm_id, **kwargs):
|
||||||
existing = self.get(alarm_id)
|
updated = dict((key, value) for (key, value) in kwargs.items()
|
||||||
updated = existing.to_dict()
|
if key in UPDATABLE_ATTRIBUTES)
|
||||||
for (key, value) in kwargs.items():
|
|
||||||
if key in updated and key in UPDATABLE_ATTRIBUTES:
|
|
||||||
updated[key] = value
|
|
||||||
return self._update(self._path(alarm_id), updated)
|
return self._update(self._path(alarm_id), updated)
|
||||||
|
|
||||||
def delete(self, alarm_id):
|
def delete(self, alarm_id):
|
||||||
|
|||||||
@@ -146,8 +146,7 @@ class AlarmManagerTest(unittest.TestCase):
|
|||||||
def test_update(self):
|
def test_update(self):
|
||||||
alarm = self.mgr.update(alarm_id='alarm-id', **DELTA_ALARM)
|
alarm = self.mgr.update(alarm_id='alarm-id', **DELTA_ALARM)
|
||||||
expect = [
|
expect = [
|
||||||
('GET', '/v2/alarms/alarm-id', {}, None),
|
('PUT', '/v2/alarms/alarm-id', {}, DELTA_ALARM),
|
||||||
('PUT', '/v2/alarms/alarm-id', {}, UPDATED_ALARM),
|
|
||||||
]
|
]
|
||||||
self.assertEqual(self.api.calls, expect)
|
self.assertEqual(self.api.calls, expect)
|
||||||
self.assertTrue(alarm)
|
self.assertTrue(alarm)
|
||||||
|
|||||||
Reference in New Issue
Block a user