Add VIFMigrateData.get_dest_vif
This adds a simple helper function to VIFMigrateData to get a destination VIF object based on the set source_vif but updated with destination port binding details. This will be used by the libvirt driver in later patches in the series. Part of blueprint neutron-new-port-binding-api Change-Id: I4c5b1fee4a4f6b6ab7b0b1bb2c1049e23a981b48
This commit is contained in:
parent
0a71a542e0
commit
8d3a049507
|
@ -12,10 +12,13 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import copy
|
||||||
|
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import versionutils
|
from oslo_utils import versionutils
|
||||||
|
|
||||||
|
from nova import exception
|
||||||
from nova import objects
|
from nova import objects
|
||||||
from nova.objects import base as obj_base
|
from nova.objects import base as obj_base
|
||||||
from nova.objects import fields
|
from nova.objects import fields
|
||||||
|
@ -71,6 +74,25 @@ class VIFMigrateData(obj_base.NovaObject):
|
||||||
def profile(self, profile_dict):
|
def profile(self, profile_dict):
|
||||||
self.profile_json = jsonutils.dumps(profile_dict)
|
self.profile_json = jsonutils.dumps(profile_dict)
|
||||||
|
|
||||||
|
def get_dest_vif(self):
|
||||||
|
"""Get a destination VIF representation of this object.
|
||||||
|
|
||||||
|
This method takes the source_vif and updates it to include the
|
||||||
|
destination host port binding information using the other fields
|
||||||
|
on this object.
|
||||||
|
|
||||||
|
:return: nova.network.model.VIF object
|
||||||
|
"""
|
||||||
|
if 'source_vif' not in self:
|
||||||
|
raise exception.ObjectActionError(
|
||||||
|
action='get_dest_vif', reason='source_vif is not set')
|
||||||
|
vif = copy.deepcopy(self.source_vif)
|
||||||
|
vif['type'] = self.vif_type
|
||||||
|
vif['vnic_type'] = self.vnic_type
|
||||||
|
vif['profile'] = self.profile
|
||||||
|
vif['details'] = self.vif_details
|
||||||
|
return vif
|
||||||
|
|
||||||
|
|
||||||
@obj_base.NovaObjectRegistry.register_if(False)
|
@obj_base.NovaObjectRegistry.register_if(False)
|
||||||
class LiveMigrateData(obj_base.NovaObject):
|
class LiveMigrateData(obj_base.NovaObject):
|
||||||
|
|
|
@ -15,9 +15,11 @@
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from oslo_versionedobjects import base as ovo_base
|
from oslo_versionedobjects import base as ovo_base
|
||||||
|
|
||||||
|
from nova import exception
|
||||||
from nova.network import model as network_model
|
from nova.network import model as network_model
|
||||||
from nova import objects
|
from nova import objects
|
||||||
from nova.objects import migrate_data
|
from nova.objects import migrate_data
|
||||||
|
from nova import test
|
||||||
from nova.tests.unit.objects import test_objects
|
from nova.tests.unit.objects import test_objects
|
||||||
from nova.tests import uuidsentinel as uuids
|
from nova.tests import uuidsentinel as uuids
|
||||||
|
|
||||||
|
@ -550,3 +552,31 @@ class TestPowerVMLiveMigrateData(test_objects._LocalTest,
|
||||||
class TestRemotePowerVMLiveMigrateData(test_objects._RemoteTest,
|
class TestRemotePowerVMLiveMigrateData(test_objects._RemoteTest,
|
||||||
_TestPowerVMLiveMigrateData):
|
_TestPowerVMLiveMigrateData):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class TestVIFMigrateData(test.NoDBTestCase):
|
||||||
|
|
||||||
|
def test_get_dest_vif_source_vif_not_set(self):
|
||||||
|
migrate_vif = objects.VIFMigrateData(
|
||||||
|
port_id=uuids.port_id, vnic_type=network_model.VNIC_TYPE_NORMAL,
|
||||||
|
vif_type=network_model.VIF_TYPE_OVS, vif_details={},
|
||||||
|
profile={}, host='fake-dest-host')
|
||||||
|
self.assertRaises(
|
||||||
|
exception.ObjectActionError, migrate_vif.get_dest_vif)
|
||||||
|
|
||||||
|
def test_get_dest_vif(self):
|
||||||
|
source_vif = network_model.VIF(
|
||||||
|
id=uuids.port_id, type=network_model.VIF_TYPE_OVS, details={},
|
||||||
|
vnic_type=network_model.VNIC_TYPE_DIRECT, profile={'foo': 'bar'},
|
||||||
|
ovs_interfaceid=uuids.ovs_interfaceid)
|
||||||
|
migrate_vif = objects.VIFMigrateData(
|
||||||
|
port_id=uuids.port_id, vnic_type=network_model.VNIC_TYPE_NORMAL,
|
||||||
|
vif_type=network_model.VIF_TYPE_BRIDGE, vif_details={'bar': 'baz'},
|
||||||
|
profile={}, host='fake-dest-host', source_vif=source_vif)
|
||||||
|
dest_vif = migrate_vif.get_dest_vif()
|
||||||
|
self.assertEqual(migrate_vif.port_id, dest_vif['id'])
|
||||||
|
self.assertEqual(migrate_vif.vnic_type, dest_vif['vnic_type'])
|
||||||
|
self.assertEqual(migrate_vif.vif_type, dest_vif['type'])
|
||||||
|
self.assertEqual(migrate_vif.vif_details, dest_vif['details'])
|
||||||
|
self.assertEqual(migrate_vif.profile, dest_vif['profile'])
|
||||||
|
self.assertEqual(uuids.ovs_interfaceid, dest_vif['ovs_interfaceid'])
|
||||||
|
|
Loading…
Reference in New Issue