Add "qos_policy_id" field to "FloatingIP" OVO
This new synthetic field is linked to a "QosPolicyFloatingIPBinding" register. This binding register will bind a QoS policy and a floating IP. Now is possible to provide this field in the create/update input parameters. If provided, the "FloatingIP" OVO will create/delete the "QosPolicyFloatingIPBinding" register. The OVO takes this parameter from the DB object. When the DB object is retrieved, the QoS policy binding register is retrieved too due to a backref link in the "QosFIPPolicyBinding" DB model to the "FloatingIP" DB model. Change-Id: Ideb042a71336b110bbe0f9e81ed8e0c21434fc42 Closes-Bug: #1877404 Related-Bug: #1877408
This commit is contained in:
parent
2ac52607c2
commit
8cfe41fa6b
neutron
objects
tests/unit
@ -19,6 +19,7 @@ from neutron_lib.api.validators import availability_zone as az_validator
|
||||
from neutron_lib import constants as n_const
|
||||
from neutron_lib.objects import common_types
|
||||
from neutron_lib.utils import net as net_utils
|
||||
from oslo_utils import versionutils
|
||||
from oslo_versionedobjects import fields as obj_fields
|
||||
import six
|
||||
from sqlalchemy import func
|
||||
@ -29,6 +30,7 @@ from neutron.db.models import l3_attrs
|
||||
from neutron.db.models import l3agent as rb_model
|
||||
from neutron.db import models_v2
|
||||
from neutron.objects import base
|
||||
from neutron.objects.qos import binding as qos_binding
|
||||
|
||||
|
||||
@base.NeutronObjectRegistry.register
|
||||
@ -233,7 +235,8 @@ class Router(base.NeutronDbObject):
|
||||
@base.NeutronObjectRegistry.register
|
||||
class FloatingIP(base.NeutronDbObject):
|
||||
# Version 1.0: Initial version
|
||||
VERSION = '1.0'
|
||||
# Version 1.1: Added qos_policy_id field
|
||||
VERSION = '1.1'
|
||||
|
||||
db_model = l3.FloatingIP
|
||||
|
||||
@ -245,6 +248,7 @@ class FloatingIP(base.NeutronDbObject):
|
||||
'floating_port_id': common_types.UUIDField(),
|
||||
'fixed_port_id': common_types.UUIDField(nullable=True),
|
||||
'fixed_ip_address': obj_fields.IPAddressField(nullable=True),
|
||||
'qos_policy_id': common_types.UUIDField(nullable=True, default=None),
|
||||
'router_id': common_types.UUIDField(nullable=True),
|
||||
'last_known_router_id': common_types.UUIDField(nullable=True),
|
||||
'status': common_types.FloatingIPStatusEnumField(nullable=True),
|
||||
@ -252,7 +256,9 @@ class FloatingIP(base.NeutronDbObject):
|
||||
}
|
||||
fields_no_update = ['project_id', 'floating_ip_address',
|
||||
'floating_network_id', 'floating_port_id']
|
||||
synthetic_fields = ['dns']
|
||||
synthetic_fields = ['dns',
|
||||
'qos_policy_id',
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def modify_fields_from_db(cls, db_obj):
|
||||
@ -277,6 +283,46 @@ class FloatingIP(base.NeutronDbObject):
|
||||
result['floating_ip_address'])
|
||||
return result
|
||||
|
||||
def _attach_qos_policy(self, qos_policy_id):
|
||||
qos_binding.QosPolicyFloatingIPBinding.delete_objects(
|
||||
self.obj_context, fip_id=self.id)
|
||||
if qos_policy_id:
|
||||
fip_binding_obj = qos_binding.QosPolicyFloatingIPBinding(
|
||||
self.obj_context, policy_id=qos_policy_id, fip_id=self.id)
|
||||
fip_binding_obj.create()
|
||||
|
||||
self.qos_policy_id = qos_policy_id
|
||||
self.obj_reset_changes(['qos_policy_id'])
|
||||
|
||||
def create(self):
|
||||
fields = self.obj_get_changes()
|
||||
with self.db_context_writer(self.obj_context):
|
||||
qos_policy_id = self.qos_policy_id
|
||||
super(FloatingIP, self).create()
|
||||
if 'qos_policy_id' in fields:
|
||||
self._attach_qos_policy(qos_policy_id)
|
||||
|
||||
def update(self):
|
||||
fields = self.obj_get_changes()
|
||||
with self.db_context_writer(self.obj_context):
|
||||
super(FloatingIP, self).update()
|
||||
if 'qos_policy_id' in fields:
|
||||
self._attach_qos_policy(fields['qos_policy_id'])
|
||||
|
||||
def from_db_object(self, db_obj):
|
||||
super(FloatingIP, self).from_db_object(db_obj)
|
||||
fields_to_change = []
|
||||
if db_obj.get('qos_policy_binding'):
|
||||
self.qos_policy_id = db_obj.qos_policy_binding.policy_id
|
||||
fields_to_change.append('qos_policy_id')
|
||||
|
||||
self.obj_reset_changes(fields_to_change)
|
||||
|
||||
def obj_make_compatible(self, primitive, target_version):
|
||||
_target_version = versionutils.convert_version_to_tuple(target_version)
|
||||
if _target_version < (1, 1):
|
||||
primitive.pop('qos_policy_id', None)
|
||||
|
||||
@classmethod
|
||||
def get_scoped_floating_ips(cls, context, router_ids):
|
||||
query = context.session.query(l3.FloatingIP,
|
||||
|
@ -42,7 +42,7 @@ object_data = {
|
||||
'FlatAllocation': '1.0-bf666f24f4642b047eeca62311fbcb41',
|
||||
'Flavor': '1.0-82194de5c9aafce08e8527bb7977f5c6',
|
||||
'FlavorServiceProfileBinding': '1.0-a2c8731e16cefdac4571f80abf1f8930',
|
||||
'FloatingIP': '1.0-0205cc99ec79e8089d641ed1b565ddae',
|
||||
'FloatingIP': '1.1-595514f8e992849cfc67981d1fd6614e',
|
||||
'FloatingIPDNS': '1.0-ee3db848500fa1825235f701828c06d5',
|
||||
'GeneveAllocation': '1.0-d5f76e8eac60a778914d61dd8e23e90f',
|
||||
'GeneveEndpoint': '1.0-040f026996b5952e2ae4ccd40ac61ca6',
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from neutron.objects.qos import binding as qos_binding
|
||||
from neutron.objects import router
|
||||
from neutron.tests.unit.objects import test_base as obj_test_base
|
||||
from neutron.tests.unit import testlib_api
|
||||
@ -169,6 +170,42 @@ class FloatingIPDbObjectTestCase(obj_test_base.BaseDbObjectTestCase,
|
||||
'fixed_port_id': lambda: self._create_test_port_id(),
|
||||
'router_id': lambda: self._create_test_router_id()})
|
||||
|
||||
def test_qos_policy(self):
|
||||
_qos_policy_1 = self._create_test_qos_policy()
|
||||
_qos_policy_2 = self._create_test_qos_policy()
|
||||
|
||||
self.obj_fields[0]['qos_policy_id'] = _qos_policy_1.id
|
||||
obj = self._test_class(
|
||||
self.context, **obj_test_base.remove_timestamps_from_fields(
|
||||
self.obj_fields[0], self._test_class.fields))
|
||||
obj.create()
|
||||
self.assertEqual(_qos_policy_1.id, obj.qos_policy_id)
|
||||
|
||||
obj.qos_policy_id = _qos_policy_2.id
|
||||
obj.update()
|
||||
self.assertEqual(_qos_policy_2.id, obj.qos_policy_id)
|
||||
|
||||
obj.qos_policy_id = None
|
||||
obj.update()
|
||||
self.assertIsNone(obj.qos_policy_id)
|
||||
|
||||
obj.qos_policy_id = _qos_policy_1.id
|
||||
obj.update()
|
||||
fip_id = obj.id
|
||||
qos_fip_binding = qos_binding.QosPolicyFloatingIPBinding.get_objects(
|
||||
self.context, fip_id=fip_id)
|
||||
self.assertEqual(1, len(qos_fip_binding))
|
||||
self.assertEqual(_qos_policy_1.id, qos_fip_binding[0].policy_id)
|
||||
obj.delete()
|
||||
qos_fip_binding = qos_binding.QosPolicyFloatingIPBinding.get_objects(
|
||||
self.context, fip_id=fip_id)
|
||||
self.assertEqual([], qos_fip_binding)
|
||||
|
||||
def test_v1_1_to_v1_0_drops_qos_policy_id(self):
|
||||
obj = self._make_object(self.obj_fields[0])
|
||||
obj_v1_0 = obj.obj_to_primitive(target_version='1.0')
|
||||
self.assertNotIn('qos_policy_id', obj_v1_0['versioned_object.data'])
|
||||
|
||||
|
||||
class DvrFipGatewayPortAgentBindingTestCase(
|
||||
obj_test_base.BaseObjectIfaceTestCase):
|
||||
|
@ -77,6 +77,7 @@ class TestPortForwardingPlugin(testlib_api.SqlTestCase):
|
||||
mock.patch(
|
||||
'neutron.objects.base.NeutronDbObject.modify_fields_from_db'
|
||||
).start()
|
||||
mock.patch.object(router.FloatingIP, 'from_db_object').start()
|
||||
|
||||
cfg.CONF.set_override("core_plugin", DB_PLUGIN_KLASS)
|
||||
cfg.CONF.set_override("service_plugins", ["router", "port_forwarding"])
|
||||
|
Loading…
x
Reference in New Issue
Block a user