| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
from oslo_versionedobjects import base as ovo_base |
| 14 |
from oslo_versionedobjects import fixture |
| 15 |
|
| 16 |
import os_vif |
| 17 |
from os_vif import objects |
| 18 |
from os_vif.tests.unit import base |
| 19 |
|
| 20 |
|
| 21 |
object_data = { |
| 22 |
'HostInfo': '1.0-4dba5ce236ea2dc559de8764995dd247', |
| 23 |
'HostPluginInfo': '1.0-5204e579864981c9891ecb5d1c9329f2', |
| 24 |
'HostPortProfileInfo': '1.0-e0bc9228c1456b220830d67b05bc4bf2', |
| 25 |
'HostVIFInfo': '1.1-00fdbeba3f9bb3bd2a723c17023ba182', |
| 26 |
'FixedIP': '1.0-d1a0ec7e7b6ce021a784c54d44cce009', |
| 27 |
'FixedIPList': '1.0-15ecf022a68ddbb8c2a6739cfc9f8f5e', |
| 28 |
'InstanceInfo': '1.0-84104d3435046b1a282ac8265ec2a976', |
| 29 |
'Network': '1.1-27a8a3e236d1d239121668a590130154', |
| 30 |
'Route': '1.0-5ca049cb82c4d4ec5edb1b839c1429c7', |
| 31 |
'RouteList': '1.0-15ecf022a68ddbb8c2a6739cfc9f8f5e', |
| 32 |
'Subnet': '1.0-6a8c192ef7492120d1a5e0fd08e44272', |
| 33 |
'SubnetList': '1.0-15ecf022a68ddbb8c2a6739cfc9f8f5e', |
| 34 |
'VIFBase': '1.0-4a5a8881dc999752cb050dd443458b6a', |
| 35 |
'VIFBridge': '1.0-e78d355f3505361fafbf0797ffad484a', |
| 36 |
'VIFDirect': '1.0-05c939280f4025fd1f7efb921a835c57', |
| 37 |
'VIFGeneric': '1.0-c72e637ed620f0135ea50a9409a3f389', |
| 38 |
'VIFHostDevice': '1.0-bb090f1869c3b4df36efda216ab97a61', |
| 39 |
'VIFOpenVSwitch': '1.0-e78d355f3505361fafbf0797ffad484a', |
| 40 |
'VIFPortProfile8021Qbg': '1.1-b3011621809dca9216b50579ce9d6b19', |
| 41 |
'VIFPortProfile8021Qbh': '1.1-226b61b2e76ba452f7b31530cff80ac9', |
| 42 |
'VIFPortProfileBase': '1.1-4982d1621df12ebd1f3b07948f3d0e5f', |
| 43 |
'VIFPortProfileOpenVSwitch': '1.4-54fb321f2b70c37d392fadc226c889e7', |
| 44 |
'VIFPortProfileFPOpenVSwitch': '1.4-20904c1dcdac0641cabf7b02525973bd', |
| 45 |
'VIFPortProfileFPBridge': '1.1-49f1952bf50bab7a95112c908534751f', |
| 46 |
'VIFPortProfileFPTap': '1.1-fd178229477604dfb65de5ce929488e5', |
| 47 |
'VIFVHostUser': '1.1-1f95b43be1f884f090ca1f4d79adfd35', |
| 48 |
'VIFPortProfileOVSRepresentor': '1.4-82b7292ee4cd6f808b724d2f5648932b', |
| 49 |
'VIFNestedDPDK': '1.0-fdbaf6b20afd116529929b21aa7158dc', |
| 50 |
'VIFPortProfileK8sDPDK': '1.1-e2a2abd112b14e0239e76b99d9b252ae', |
| 51 |
'DatapathOffloadBase': '1.0-77509ea1ea0dd750d5864b9bd87d3f9d', |
| 52 |
'DatapathOffloadRepresentor': '1.0-802a5dff22f73046df3742c815c51421', |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
class TestObjectVersions(base.TestCase): |
| 57 |
def setUp(self): |
| 58 |
super(TestObjectVersions, self).setUp() |
| 59 |
|
| 60 |
os_vif.objects.register_all() |
| 61 |
|
| 62 |
def test_versions(self): |
| 63 |
checker = fixture.ObjectVersionChecker( |
| 64 |
ovo_base.VersionedObjectRegistry.obj_classes()) |
| 65 |
|
| 66 |
expected, actual = checker.test_hashes(object_data) |
| 67 |
self.assertEqual(expected, actual, |
| 68 |
'Some objects have changed; please make sure the ' |
| 69 |
'versions have been bumped, and then update their ' |
| 70 |
'hashes here.') |
| 71 |
|
| 72 |
def test_vif_vhost_user_obj_make_compatible(self): |
| 73 |
vif = objects.vif.VIFVHostUser( |
| 74 |
path="/some/socket.path", |
| 75 |
mode=objects.fields.VIFVHostUserMode.CLIENT, |
| 76 |
vif_name="vhu123") |
| 77 |
primitive = vif.obj_to_primitive()['versioned_object.data'] |
| 78 |
self.assertIn('vif_name', primitive) |
| 79 |
vif.obj_make_compatible(primitive, '1.0') |
| 80 |
self.assertNotIn('vif_name', primitive) |
| 81 |
|
| 82 |
def test_vif_port_profile_ovs_obj_make_compatible_1_4(self): |
| 83 |
"""Test obj_make_compatible removes create_tap and multiqueue for |
| 84 |
versions < 1.4. |
| 85 |
""" |
| 86 |
profile = objects.vif.VIFPortProfileOpenVSwitch( |
| 87 |
interface_id='e65867e0-9340-4a7f-a256-09af6eb7a3aa', |
| 88 |
create_tap=True, |
| 89 |
multiqueue=True) |
| 90 |
primitive = profile.obj_to_primitive()['versioned_object.data'] |
| 91 |
self.assertIn('create_tap', primitive) |
| 92 |
self.assertIn('multiqueue', primitive) |
| 93 |
|
| 94 |
|
| 95 |
profile.obj_make_compatible(primitive, '1.3') |
| 96 |
self.assertNotIn('create_tap', primitive) |
| 97 |
self.assertNotIn('multiqueue', primitive) |
| 98 |
|
| 99 |
def test_vif_port_profile_ovs_obj_make_compatible_1_3(self): |
| 100 |
"""Test obj_make_compatible removes create_port for versions < 1.3.""" |
| 101 |
profile = objects.vif.VIFPortProfileOpenVSwitch( |
| 102 |
interface_id='e65867e0-9340-4a7f-a256-09af6eb7a3aa', |
| 103 |
create_port=True) |
| 104 |
primitive = profile.obj_to_primitive()['versioned_object.data'] |
| 105 |
self.assertIn('create_port', primitive) |
| 106 |
|
| 107 |
|
| 108 |
profile.obj_make_compatible(primitive, '1.2') |
| 109 |
self.assertNotIn('create_port', primitive) |
| 110 |
|
| 111 |
def test_vif_port_profile_ovs_create_tap_multiqueue_fields(self): |
| 112 |
"""Test that create_tap and multiqueue fields can be set.""" |
| 113 |
profile = objects.vif.VIFPortProfileOpenVSwitch( |
| 114 |
interface_id='e65867e0-9340-4a7f-a256-09af6eb7a3aa', |
| 115 |
create_tap=True, |
| 116 |
multiqueue=True) |
| 117 |
self.assertTrue(profile.create_tap) |
| 118 |
self.assertTrue(profile.multiqueue) |
| 119 |
|
| 120 |
|
| 121 |
profile_default = objects.vif.VIFPortProfileOpenVSwitch( |
| 122 |
interface_id='e65867e0-9340-4a7f-a256-09af6eb7a3aa', |
| 123 |
create_tap=False, |
| 124 |
multiqueue=False) |
| 125 |
self.assertFalse(profile_default.create_tap) |
| 126 |
self.assertFalse(profile_default.multiqueue) |
| 127 |
|
| 128 |
def test_vif_port_profile_ovs_in_operator(self): |
| 129 |
"""Test that 'in' operator works for checking field existence.""" |
| 130 |
profile = objects.vif.VIFPortProfileOpenVSwitch( |
| 131 |
interface_id='e65867e0-9340-4a7f-a256-09af6eb7a3aa', |
| 132 |
create_tap=True, |
| 133 |
multiqueue=True) |
| 134 |
self.assertIn('create_tap', profile) |
| 135 |
self.assertIn('multiqueue', profile) |
| 136 |
self.assertIn('interface_id', profile) |
| 137 |
self.assertNotIn('nonexistent_field', profile) |