Fixes RM2442 VIF ordering

Ports should now be ordered by created_at.
This commit is contained in:
John Perkins
2013-11-19 16:10:32 -06:00
parent efb9cadcd3
commit 707f13c159
2 changed files with 60 additions and 3 deletions

View File

@@ -21,7 +21,7 @@ from neutron.openstack.common import timeutils
from neutron.openstack.common import uuidutils
from sqlalchemy import event
from sqlalchemy import func as sql_func
from sqlalchemy import and_, orm, or_
from sqlalchemy import and_, asc, orm, or_
from quark.db import models
from quark import network_strategy
@@ -159,8 +159,8 @@ def scoped(f):
def port_find(context, **filters):
query = context.session.query(models.Port).\
options(orm.joinedload(models.Port.ip_addresses))
model_filters = _model_query(context, models.Port, filters)
model_filters = _model_query(context, models.Port, filters)
if filters.get("ip_address_id"):
model_filters.append(models.Port.ip_addresses.any(
models.IPAddress.id.in_(filters["ip_address_id"])))
@@ -168,7 +168,7 @@ def port_find(context, **filters):
if filters.get("device_id"):
model_filters.append(models.Port.device_id.in_(filters["device_id"]))
return query.filter(*model_filters)
return query.filter(*model_filters).order_by(asc(models.Port.created_at))
def port_count_all(context, **filters):

View File

@@ -0,0 +1,57 @@
# Copyright 2013 Openstack Foundation
# All Rights Reserved.
#
# 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.
from neutron import context
from neutron.db import api as neutron_db_api
from neutron.openstack.common.db.sqlalchemy import session as neutron_session
from oslo.config import cfg
import unittest2
from quark.db import api as db_api
from quark.db import models
class QuarkNetworkFunctionalTest(unittest2.TestCase):
def setUp(self):
self.context = context.Context('fake', 'fake', is_admin=False)
super(QuarkNetworkFunctionalTest, self).setUp()
cfg.CONF.set_override('connection', 'sqlite://', 'database')
neutron_db_api.configure_db()
models.BASEV2.metadata.create_all(neutron_session._ENGINE)
def tearDown(self):
neutron_db_api.clear_db()
class QuarkFindPortsSorted(QuarkNetworkFunctionalTest):
def test_ports_sorted_by_created_at(self):
# create a network
network = dict(name="public", tenant_id="fake", network_plugin="BASE")
net_mod = db_api.network_create(self.context, **network)
# create ports
port1 = dict(network_id=net_mod["id"], backend_key="1", device_id="1")
port2 = dict(network_id=net_mod["id"], backend_key="1", device_id="1")
port3 = dict(network_id=net_mod["id"], backend_key="1", device_id="1")
port_mod1 = db_api.port_create(self.context, **port1)
port_mod2 = db_api.port_create(self.context, **port2)
port_mod3 = db_api.port_create(self.context, **port3)
res = db_api.port_find(self.context, scope=db_api.ALL)
self.assertTrue(res[0]["created_at"] < res[1]["created_at"] <
res[2]['created_at'])
db_api.network_delete(self.context, net_mod)
db_api.port_delete(self.context, port_mod1)
db_api.port_delete(self.context, port_mod2)
db_api.port_delete(self.context, port_mod3)