Fixes querying alarm history with severity field

Querying alarm-history with the severity field
fails with a 500 error as the storage model has
no severity field.

This fix adds the severity field to AlarmHistory
table and model and allows search on severity field.

Change-Id: I4a374d324c7e1bde566e26daf7092fd325f33625
Closes-Bug: 1473046
This commit is contained in:
Rohit Jaiswal 2015-07-09 20:04:45 +00:00
parent 204b5af04e
commit c0ea892e87
4 changed files with 52 additions and 2 deletions

View File

@ -525,6 +525,7 @@ class AlarmController(rest.RestController):
user_id = pecan.request.headers.get('X-User-Id')
project_id = pecan.request.headers.get('X-Project-Id')
on_behalf_of = on_behalf_of or project_id
severity = scrubbed_data.get('severity')
payload = dict(event_id=str(uuid.uuid4()),
alarm_id=self._id,
type=type,
@ -532,7 +533,8 @@ class AlarmController(rest.RestController):
user_id=user_id,
project_id=project_id,
on_behalf_of=on_behalf_of,
timestamp=now)
timestamp=now,
severity=severity)
try:
self.conn.record_alarm_change(payload)
@ -702,6 +704,7 @@ class AlarmsController(rest.RestController):
detail = json.dumps(scrubbed_data)
user_id = pecan.request.headers.get('X-User-Id')
project_id = pecan.request.headers.get('X-Project-Id')
severity = scrubbed_data.get('severity')
payload = dict(event_id=str(uuid.uuid4()),
alarm_id=alarm_id,
type=type,
@ -709,7 +712,8 @@ class AlarmsController(rest.RestController):
user_id=user_id,
project_id=project_id,
on_behalf_of=project_id,
timestamp=now)
timestamp=now,
severity=severity)
try:
conn.record_alarm_change(payload)

View File

@ -0,0 +1,36 @@
# Copyright 2015 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
"""add severity to alarm history
Revision ID: bb07adac380
Revises: 12fe8fac9fe4
Create Date: 2015-08-06 15:15:43.717068
"""
# revision identifiers, used by Alembic.
revision = 'bb07adac380'
down_revision = '12fe8fac9fe4'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('alarm_history',
sa.Column('severity', sa.String(length=50), nullable=True))

View File

@ -143,3 +143,4 @@ class AlarmChange(Base):
type = Column(String(20))
detail = Column(Text)
timestamp = Column(PreciseTimestamp, default=lambda: timeutils.utcnow())
severity = Column(String(50))

View File

@ -1992,6 +1992,15 @@ class TestAlarmsHistory(TestAlarmsBase):
self.assertEqual(msg,
resp.json['error_message']['faultstring'])
def test_get_alarm_history_constrained_by_severity(self):
alarm = self._get_alarm('a')
self._update_alarm(alarm, dict(severity='low'))
query = dict(field='severity', op='eq', value='low')
history = self._get_alarm_history('a', query=query)
self.assertEqual(1, len(history))
self.assertEqual(jsonutils.dumps({'severity': 'low'}),
history[0]['detail'])
def test_get_nonexistent_alarm_history(self):
# the existence of alarm history is independent of the
# continued existence of the alarm itself