lbaas. Adding column level constraints to table definition

Bug #1188959 reported by Avishay Balderman
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Fix Released
Low
Avishay Balderman

Bug Description

In https://github.com/openstack/quantum/blob/master/quantum/db/loadbalancer/loadbalancer_db.py the lbaas model is defined.
There are fields the needs extra constraint definition.
Examples:
- All fields in PoolStatistics can not be negative.
- Weight field in Member can not be negative.
- Delay field in HealthMonitor can not be negative.

Those constraints can be added using:
http://docs.sqlalchemy.org/en/rel_0_8/core/schema.html?highlight=checkconstraint#sqlalchemy.schema.CheckConstraint
See here for example:
http://stackoverflow.com/questions/14225998/flask-sqlalchemy-column-constraint-for-positive-integer

Tags: lbaas
Revision history for this message
Eugene Nikanorov (enikanorov) wrote :

I think those parameters should be validated in the extension in the first place

Revision history for this message
Avishay Balderman (avishayb) wrote :

I agree, and I think they are:
weight - https://github.com/openstack/quantum/blob/master/quantum/extensions/loadbalancer.py#L189
delay - https://github.com/openstack/quantum/blob/master/quantum/extensions/loadbalancer.py#L213
stats field are not input fields, so we are OK here.

So since we do the validation in 2 layers (extension + db) - I think the constraints should be added to the db layer.

Revision history for this message
Avishay Balderman (avishayb) wrote :

Note: Not sure that MySQL supports 'CheckConstraint'

Revision history for this message
Avishay Balderman (avishayb) wrote :

code below can work for the pool stats fields

@validates('bytes_in','bytes_out','active_connections','total_connections')
def validate_non_negative_int(self, key, value):
    if value < 0:
        raise ValueError
    return value

Revision history for this message
Eugene Nikanorov (enikanorov) wrote :

Why do we need to validate stats if they're going from the driver anyway? It's not a user input.

Revision history for this message
Avishay Balderman (avishayb) wrote :

because driver can insert negative values by mistake.

Revision history for this message
Mark McClain (markmcclain) wrote :

I think it is a good idea to guard against a misconfigured driver in this case since that is only way this value is populated.

Changed in quantum:
importance: Undecided → Low
Changed in quantum:
assignee: nobody → Avishay Balderman (avishayb)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to quantum (master)

Fix proposed to branch: master
Review: https://review.openstack.org/32545

Changed in quantum:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to quantum (master)

Reviewed: https://review.openstack.org/32545
Committed: http://github.com/openstack/quantum/commit/135d20218ac8f67153c106d373d3a1c1a00f55d6
Submitter: Jenkins
Branch: master

commit 135d20218ac8f67153c106d373d3a1c1a00f55d6
Author: Avishay Balderman <email address hidden>
Date: Tue Jun 11 01:52:20 2013 -0700

    Protect PoolStats table from negative values.

    Fixes: bug #1188959

    Change-Id: I67038734dae5dc29e5c0666fdc98827dfd50b678

Changed in quantum:
status: In Progress → Fix Committed
Changed in quantum:
milestone: none → havana-2
Thierry Carrez (ttx)
Changed in neutron:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in neutron:
milestone: havana-2 → 2013.2
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.