Clean up versioned object backlevelling code
The backlevelling code for the VIF objects have a number of sharp edges. This commit changes the layout of the obj_make_compatible methods to conform to a fixed pattern. Given the following version history: # Version 1.0: Initial Release based on ParentClass 1.0 # Version 1.1: Added member_one_one # Version 1.2: ParentClass version increased to 1.1 from 1.0 # Version 1.3: Added member_one_three # Version 1.4: ParentClass version increased to 1.2 from 1.1 # Version 1.5: Added member_one_five Use the following pattern for obj_make_compatible(): 0. use versionutils to calculate target_version 1. Remove added members from the primitive in reverse order: - if target_version < (1, 5) and 'member_one_five' in primitive: del primitive['member_one_five'] - if target_version < (1, 3) and 'member_one_three' in primitive: del primitive['member_one_three'] - if target_version < (1, 1) and 'member_one_one' in primitive: del primitive['member_one_one'] 2. Call the parent method explicitly when the parent class caused a version bump in this object, in the following if/elif tree: - if target_version < (1, 2): super(MyClass, self).obj_make_compatible(primitive, '1.0') - elif target_version < (1, 4): super(MyClass, self).obj_make_compatible(primitive, '1.1') 3. Finally, if target_version is recent enough, call the parent method with the current version of the parent class: - else: super(MyClass, self).obj_make_compatible(primitive, '1.2') This pattern has been documented in: https://review.openstack.org/632321/ Change-Id: Ib7b0cca596c0cad8095ef18243b94ada2587d1cd Signed-off-by: Jan Gutter <jan.gutter@netronome.com> blueprint: generic-os-vif-offloads
This commit is contained in:
parent
3869596374
commit
c90081bb94
@ -101,11 +101,10 @@ class HostVIFInfo(osv_base.VersionedObject, base.ComparableVersionedObject,
|
||||
}
|
||||
|
||||
def obj_make_compatible(self, primitive, target_version):
|
||||
super(HostVIFInfo, self).obj_make_compatible(primitive,
|
||||
target_version)
|
||||
target_version = versionutils.convert_version_to_tuple(target_version)
|
||||
if target_version < (1, 1) and 'supported_port_profiles' in primitive:
|
||||
del primitive['supported_port_profiles']
|
||||
super(HostVIFInfo, self).obj_make_compatible(primitive, '1.0')
|
||||
|
||||
def get_common_version(self):
|
||||
return _get_common_version(self.vif_object_name,
|
||||
|
@ -48,5 +48,6 @@ class Network(osv_base.VersionedObject):
|
||||
|
||||
def obj_make_compatible(self, primitive, target_version):
|
||||
target_version = versionutils.convert_version_to_tuple(target_version)
|
||||
if target_version < (1, 1):
|
||||
primitive.pop('mtu', None)
|
||||
if target_version < (1, 1) and 'mtu' in primitive:
|
||||
del primitive['mtu']
|
||||
super(Network, self).obj_make_compatible(primitive, '1.0')
|
||||
|
@ -122,7 +122,8 @@ class VIFDirect(VIFBase):
|
||||
@base.VersionedObjectRegistry.register
|
||||
class VIFVHostUser(VIFBase):
|
||||
# For libvirt drivers, this maps to type='vhostuser'
|
||||
|
||||
# Version 1.0: Initial release
|
||||
# Version 1.1: Added 'vif_name'
|
||||
VERSION = '1.1'
|
||||
|
||||
fields = {
|
||||
@ -137,11 +138,10 @@ class VIFVHostUser(VIFBase):
|
||||
}
|
||||
|
||||
def obj_make_compatible(self, primitive, target_version):
|
||||
super(VIFVHostUser, self).obj_make_compatible(primitive,
|
||||
target_version)
|
||||
target_version = versionutils.convert_version_to_tuple(target_version)
|
||||
if target_version < (1, 1) and 'vif_name' in primitive:
|
||||
del primitive['vif_name']
|
||||
super(VIFVHostUser, self).obj_make_compatible(primitive, '1.0')
|
||||
|
||||
|
||||
@base.VersionedObjectRegistry.register
|
||||
@ -225,7 +225,7 @@ class VIFPortProfileOpenVSwitch(VIFPortProfileBase):
|
||||
# Port profile info for OpenVSwitch networks
|
||||
# Version 1.0: Initial release
|
||||
# Version 1.1: Added 'datapath_type'
|
||||
# Version 1.2: VIFPortProfileBase updated to 1.1
|
||||
# Version 1.2: VIFPortProfileBase updated to 1.1 from 1.0
|
||||
# Version 1.3: Added 'create_port'
|
||||
VERSION = '1.3'
|
||||
|
||||
@ -241,25 +241,26 @@ class VIFPortProfileOpenVSwitch(VIFPortProfileBase):
|
||||
}
|
||||
|
||||
def obj_make_compatible(self, primitive, target_version):
|
||||
super(VIFPortProfileOpenVSwitch, self).obj_make_compatible(
|
||||
primitive, target_version)
|
||||
target_version = versionutils.convert_version_to_tuple(target_version)
|
||||
if target_version < (1, 3) and 'create_port' in primitive:
|
||||
del primitive['create_port']
|
||||
if target_version < (1, 1) and 'datapath_type' in primitive:
|
||||
del primitive['datapath_type']
|
||||
if target_version < (1, 2):
|
||||
super(VIFPortProfileOpenVSwitch, self).obj_make_compatible(
|
||||
primitive, "1.0")
|
||||
if target_version < (1, 3) and 'create_port' in primitive:
|
||||
del primitive['create_port']
|
||||
primitive, '1.0')
|
||||
else:
|
||||
super(VIFPortProfileOpenVSwitch, self).obj_make_compatible(
|
||||
primitive, '1.1')
|
||||
|
||||
|
||||
@base.VersionedObjectRegistry.register
|
||||
class VIFPortProfileFPOpenVSwitch(VIFPortProfileOpenVSwitch):
|
||||
# Port profile info for OpenVSwitch networks using fastpath
|
||||
# Version 1.0: Initial release
|
||||
# Version 1.1: VIFPortProfileOpenVSwitch updated to 1.1
|
||||
# Version 1.2: VIFPortProfileOpenVSwitch updated to 1.2
|
||||
# Version 1.3: VIFPortProfileOpenVSwitch updated to 1.3
|
||||
# Version 1.1: VIFPortProfileOpenVSwitch updated to 1.1 from 1.0
|
||||
# Version 1.2: VIFPortProfileOpenVSwitch updated to 1.2 from 1.1
|
||||
# Version 1.3: VIFPortProfileOpenVSwitch updated to 1.3 from 1.2
|
||||
VERSION = '1.3'
|
||||
|
||||
fields = {
|
||||
@ -274,13 +275,16 @@ class VIFPortProfileFPOpenVSwitch(VIFPortProfileOpenVSwitch):
|
||||
target_version = versionutils.convert_version_to_tuple(target_version)
|
||||
if target_version < (1, 1):
|
||||
super(VIFPortProfileFPOpenVSwitch, self).obj_make_compatible(
|
||||
primitive, "1.0")
|
||||
if target_version < (1, 2):
|
||||
primitive, '1.0')
|
||||
elif target_version < (1, 2):
|
||||
super(VIFPortProfileFPOpenVSwitch, self).obj_make_compatible(
|
||||
primitive, "1.1")
|
||||
if target_version < (1, 3):
|
||||
primitive, '1.1')
|
||||
elif target_version < (1, 3):
|
||||
super(VIFPortProfileFPOpenVSwitch, self).obj_make_compatible(
|
||||
primitive, "1.2")
|
||||
primitive, '1.2')
|
||||
else:
|
||||
super(VIFPortProfileFPOpenVSwitch, self).obj_make_compatible(
|
||||
primitive, '1.3')
|
||||
|
||||
|
||||
@removals.removed_class("VIFPortProfileOVSRepresentor",
|
||||
@ -292,9 +296,9 @@ class VIFPortProfileOVSRepresentor(VIFPortProfileOpenVSwitch):
|
||||
# 'datapath_offload' field in port profiles should be used instead.
|
||||
#
|
||||
# Version 1.0: Initial release
|
||||
# Version 1.1: VIFPortProfileOpenVSwitch updated to 1.1
|
||||
# Version 1.2: VIFPortProfileOpenVSwitch updated to 1.2
|
||||
# Version 1.3: VIFPortProfileOpenVSwitch updated to 1.3
|
||||
# Version 1.1: VIFPortProfileOpenVSwitch updated to 1.1 from 1.0
|
||||
# Version 1.2: VIFPortProfileOpenVSwitch updated to 1.2 from 1.1
|
||||
# Version 1.3: VIFPortProfileOpenVSwitch updated to 1.3 from 1.2
|
||||
VERSION = '1.3'
|
||||
|
||||
fields = {
|
||||
@ -309,13 +313,16 @@ class VIFPortProfileOVSRepresentor(VIFPortProfileOpenVSwitch):
|
||||
target_version = versionutils.convert_version_to_tuple(target_version)
|
||||
if target_version < (1, 1):
|
||||
super(VIFPortProfileOVSRepresentor, self).obj_make_compatible(
|
||||
primitive, "1.0")
|
||||
if target_version < (1, 2):
|
||||
primitive, '1.0')
|
||||
elif target_version < (1, 2):
|
||||
super(VIFPortProfileOVSRepresentor, self).obj_make_compatible(
|
||||
primitive, "1.1")
|
||||
if target_version < (1, 3):
|
||||
primitive, '1.1')
|
||||
elif target_version < (1, 3):
|
||||
super(VIFPortProfileOVSRepresentor, self).obj_make_compatible(
|
||||
primitive, "1.2")
|
||||
primitive, '1.2')
|
||||
else:
|
||||
super(VIFPortProfileOVSRepresentor, self).obj_make_compatible(
|
||||
primitive, '1.3')
|
||||
|
||||
|
||||
@base.VersionedObjectRegistry.register
|
||||
@ -323,7 +330,7 @@ class VIFPortProfileFPBridge(VIFPortProfileBase):
|
||||
# Port profile info for LinuxBridge networks using fastpath
|
||||
#
|
||||
# Version 1.0: Initial release
|
||||
# Version 1.1: VIFPortProfileBase updated to 1.1
|
||||
# Version 1.1: VIFPortProfileBase updated to 1.1 from 1.0
|
||||
VERSION = '1.1'
|
||||
|
||||
fields = {
|
||||
@ -335,7 +342,10 @@ class VIFPortProfileFPBridge(VIFPortProfileBase):
|
||||
target_version = versionutils.convert_version_to_tuple(target_version)
|
||||
if target_version < (1, 1):
|
||||
super(VIFPortProfileFPBridge, self).obj_make_compatible(
|
||||
primitive, "1.0")
|
||||
primitive, '1.0')
|
||||
else:
|
||||
super(VIFPortProfileFPBridge, self).obj_make_compatible(
|
||||
primitive, '1.1')
|
||||
|
||||
|
||||
@base.VersionedObjectRegistry.register
|
||||
@ -343,7 +353,7 @@ class VIFPortProfileFPTap(VIFPortProfileBase):
|
||||
# Port profile info for Calico networks using fastpath
|
||||
#
|
||||
# Version 1.0: Initial release
|
||||
# Version 1.1: VIFPortProfileBase updated to 1.1
|
||||
# Version 1.1: VIFPortProfileBase updated to 1.1 from 1.0
|
||||
VERSION = '1.1'
|
||||
|
||||
fields = {
|
||||
@ -355,7 +365,10 @@ class VIFPortProfileFPTap(VIFPortProfileBase):
|
||||
target_version = versionutils.convert_version_to_tuple(target_version)
|
||||
if target_version < (1, 1):
|
||||
super(VIFPortProfileFPTap, self).obj_make_compatible(
|
||||
primitive, "1.0")
|
||||
primitive, '1.0')
|
||||
else:
|
||||
super(VIFPortProfileFPTap, self).obj_make_compatible(
|
||||
primitive, '1.1')
|
||||
|
||||
|
||||
@base.VersionedObjectRegistry.register
|
||||
@ -363,7 +376,7 @@ class VIFPortProfile8021Qbg(VIFPortProfileBase):
|
||||
# Port profile info for VEPA 802.1qbg networks
|
||||
#
|
||||
# Version 1.0: Initial release
|
||||
# Version 1.1: VIFPortProfileBase updated to 1.1
|
||||
# Version 1.1: VIFPortProfileBase updated to 1.1 from 1.0
|
||||
VERSION = '1.1'
|
||||
|
||||
fields = {
|
||||
@ -377,7 +390,10 @@ class VIFPortProfile8021Qbg(VIFPortProfileBase):
|
||||
target_version = versionutils.convert_version_to_tuple(target_version)
|
||||
if target_version < (1, 1):
|
||||
super(VIFPortProfile8021Qbg, self).obj_make_compatible(
|
||||
primitive, "1.0")
|
||||
primitive, '1.0')
|
||||
else:
|
||||
super(VIFPortProfile8021Qbg, self).obj_make_compatible(
|
||||
primitive, '1.1')
|
||||
|
||||
|
||||
@base.VersionedObjectRegistry.register
|
||||
@ -385,7 +401,7 @@ class VIFPortProfile8021Qbh(VIFPortProfileBase):
|
||||
# Port profile info for VEPA 802.1qbh networks
|
||||
#
|
||||
# Version 1.0: Initial release
|
||||
# Version 1.1: VIFPortProfileBase updated to 1.1
|
||||
# Version 1.1: VIFPortProfileBase updated to 1.1 from 1.0
|
||||
VERSION = '1.1'
|
||||
|
||||
fields = {
|
||||
@ -396,7 +412,10 @@ class VIFPortProfile8021Qbh(VIFPortProfileBase):
|
||||
target_version = versionutils.convert_version_to_tuple(target_version)
|
||||
if target_version < (1, 1):
|
||||
super(VIFPortProfile8021Qbh, self).obj_make_compatible(
|
||||
primitive, "1.0")
|
||||
primitive, '1.0')
|
||||
else:
|
||||
super(VIFPortProfile8021Qbh, self).obj_make_compatible(
|
||||
primitive, '1.1')
|
||||
|
||||
|
||||
@base.VersionedObjectRegistry.register
|
||||
@ -404,7 +423,7 @@ class VIFPortProfileK8sDPDK(VIFPortProfileBase):
|
||||
# Port profile info for Kuryr-Kubernetes DPDK ports
|
||||
#
|
||||
# Version 1.0: Initial release
|
||||
# Version 1.1: VIFPortProfileBase updated to 1.1
|
||||
# Version 1.1: VIFPortProfileBase updated to 1.1 from 1.0
|
||||
VERSION = '1.1'
|
||||
|
||||
fields = {
|
||||
@ -423,4 +442,7 @@ class VIFPortProfileK8sDPDK(VIFPortProfileBase):
|
||||
target_version = versionutils.convert_version_to_tuple(target_version)
|
||||
if target_version < (1, 1):
|
||||
super(VIFPortProfileK8sDPDK, self).obj_make_compatible(
|
||||
primitive, "1.0")
|
||||
primitive, '1.0')
|
||||
else:
|
||||
super(VIFPortProfileK8sDPDK, self).obj_make_compatible(
|
||||
primitive, '1.1')
|
||||
|
Loading…
Reference in New Issue
Block a user