Debian Codegraph @

os_vif/tests/unit/test_host_info.py

raw symbols SCIP
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 from vif_plug_linux_bridge import constants as lb_constants
14 from vif_plug_ovs import constants as ovs_constants
15
16 from os_vif import exception
17 from os_vif import objects
18 from os_vif.tests.unit import base
19
20
21 class TestHostInfo(base.TestCase):
22
23 def setUp(self):
24 super(TestHostInfo, self).setUp()
25
26 objects.register_all()
27
28 self.host_info = objects.host_info.HostInfo(
29 plugin_info=[
30 objects.host_info.HostPluginInfo(
31 plugin_name=lb_constants.PLUGIN_NAME,
32 vif_info=[
33 objects.host_info.HostVIFInfo(
34 vif_object_name="VIFBridge",
35 min_version="1.0",
36 max_version="3.0"
37 ),
38 ]),
39 objects.host_info.HostPluginInfo(
40 plugin_name=ovs_constants.PLUGIN_NAME,
41 vif_info=[
42 objects.host_info.HostVIFInfo(
43 vif_object_name="VIFBridge",
44 min_version="2.0",
45 max_version="7.0"
46 ),
47 objects.host_info.HostVIFInfo(
48 vif_object_name="VIFOpenVSwitch",
49 min_version="1.0",
50 max_version="2.0"
51 ),
52 objects.host_info.HostVIFInfo(
53 vif_object_name="VIFVHostUser",
54 min_version="1.0",
55 max_version="2.0"
56 ),
57 ])
58 ])
59 # https://bugs.launchpad.net/oslo.versionedobjects/+bug/1563787
60 self.host_info.obj_reset_changes(recursive=True)
61
62 def test_serialization(self):
63 json = self.host_info.obj_to_primitive()
64 self.assertEqual("os_vif", json["versioned_object.namespace"])
65
66 host_info = objects.host_info.HostInfo.obj_from_primitive(json)
67 # Copied from test_vif.py:
68 #
69 # The __eq__ function works by using obj_to_primitive()
70 # and this includes a list of changed fields. Very
71 # occassionally the ordering of the list of changes
72 # varies, causing bogus equality failures. This is
73 # arguably a bug in oslo.versionedobjects since the
74 # set of changes fields should not affect equality
75 # comparisons. Remove this hack once this is fixed:
76 #
77 # https://bugs.launchpad.net/oslo.versionedobjects/+bug/1563787
78 host_info.obj_reset_changes(recursive=True)
79
80 self.assertEqual(self.host_info, host_info)
81
82 def test_plugin_existance(self):
83 self.assertTrue(self.host_info.has_plugin(ovs_constants.PLUGIN_NAME))
84 self.assertFalse(self.host_info.has_plugin("fishfood"))
85
86 def test_plugin_fetch(self):
87 plugin = self.host_info.get_plugin(ovs_constants.PLUGIN_NAME)
88 self.assertEqual(ovs_constants.PLUGIN_NAME, plugin.plugin_name)
89
90 self.assertRaises(exception.NoMatchingPlugin,
91 self.host_info.get_plugin,
92 "fishfood")
93
94 def test_vif_existance(self):
95 plugin = self.host_info.get_plugin(ovs_constants.PLUGIN_NAME)
96 self.assertTrue(plugin.has_vif("VIFOpenVSwitch"))
97 self.assertFalse(plugin.has_vif("VIFFishFood"))
98
99 def test_vif_fetch(self):
100 plugin = self.host_info.get_plugin(ovs_constants.PLUGIN_NAME)
101
102 vif = plugin.get_vif("VIFOpenVSwitch")
103 self.assertEqual("VIFOpenVSwitch", vif.vif_object_name)
104
105 self.assertRaises(exception.NoMatchingVIFClass,
106 plugin.get_vif,
107 "VIFFishFood")
108
109 def test_common_version_no_obj(self):
110 info = objects.host_info.HostVIFInfo(
111 vif_object_name="VIFFishFood",
112 min_version="1.0",
113 max_version="1.8")
114
115 self.assertRaises(exception.NoMatchingVIFClass,
116 info.get_common_version)
117
118 def test_common_version_no_version(self):
119 info = objects.host_info.HostVIFInfo(
120 vif_object_name="VIFOpenVSwitch",
121 min_version="1729.0",
122 max_version="8753.0")
123
124 self.assertRaises(exception.NoSupportedVIFVersion,
125 info.get_common_version)
126
127 def test_common_version_ok(self):
128 info = objects.host_info.HostVIFInfo(
129 vif_object_name="VIFOpenVSwitch",
130 min_version="1.0",
131 max_version="10.0")
132
133 ver = info.get_common_version()
134 self.assertEqual(objects.vif.VIFOpenVSwitch.VERSION,
135 ver)
136
137 def test_filtering(self):
138 host_info = objects.host_info.HostInfo(
139 plugin_info=[
140 objects.host_info.HostPluginInfo(
141 plugin_name=lb_constants.PLUGIN_NAME,
142 vif_info=[
143 objects.host_info.HostVIFInfo(
144 vif_object_name="VIFBridge",
145 min_version="1.0",
146 max_version="3.0"
147 ),
148 ]),
149 objects.host_info.HostPluginInfo(
150 plugin_name=ovs_constants.PLUGIN_NAME,
151 vif_info=[
152 objects.host_info.HostVIFInfo(
153 vif_object_name="VIFBridge",
154 min_version="2.0",
155 max_version="7.0"
156 ),
157 objects.host_info.HostVIFInfo(
158 vif_object_name="VIFOpenVSwitch",
159 min_version="1.0",
160 max_version="2.0"
161 ),
162 objects.host_info.HostVIFInfo(
163 vif_object_name="VIFVHostUser",
164 min_version="1.0",
165 max_version="2.0"
166 ),
167 ])
168 ])
169
170 host_info.filter_vif_types(["VIFBridge", "VIFOpenVSwitch"])
171
172 self.assertEqual(len(host_info.plugin_info), 2)
173
174 plugin = host_info.plugin_info[0]
175 self.assertEqual(len(plugin.vif_info), 1)
176 self.assertEqual(plugin.vif_info[0].vif_object_name,
177 "VIFBridge")
178
179 plugin = host_info.plugin_info[1]
180 self.assertEqual(len(plugin.vif_info), 2)
181 self.assertEqual(plugin.vif_info[0].vif_object_name,
182 "VIFBridge")
183 self.assertEqual(plugin.vif_info[1].vif_object_name,
184 "VIFOpenVSwitch")
185
186 host_info.filter_vif_types(["VIFOpenVSwitch"])
187
188 self.assertEqual(len(host_info.plugin_info), 1)
189
190 plugin = host_info.plugin_info[0]
191 self.assertEqual(len(plugin.vif_info), 1)
192 self.assertEqual(plugin.vif_info[0].vif_object_name,
193 "VIFOpenVSwitch")