Browse Source

Merge "Add Octavia OVN Driver's UT"

changes/98/660798/6
Zuul 1 month ago
parent
commit
0bb4256d79

+ 0
- 0
networking_ovn/tests/unit/octavia/__init__.py View File


+ 686
- 0
networking_ovn/tests/unit/octavia/test_ovn_driver.py View File

@@ -0,0 +1,686 @@
1
+#
2
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
3
+#    not use this file except in compliance with the License. You may obtain
4
+#    a copy of the License at
5
+#
6
+#         http://www.apache.org/licenses/LICENSE-2.0
7
+#
8
+#    Unless required by applicable law or agreed to in writing, software
9
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11
+#    License for the specific language governing permissions and limitations
12
+#    under the License.
13
+#
14
+import collections
15
+
16
+import mock
17
+from neutron.tests import base
18
+from octavia_lib.api.drivers import data_models
19
+from octavia_lib.api.drivers import exceptions
20
+from octavia_lib.common import constants
21
+from oslo_utils import uuidutils
22
+
23
+from networking_ovn.octavia import ovn_driver
24
+
25
+
26
+class MockedLB(data_models.LoadBalancer):
27
+    def __init__(self, *args, **kwargs):
28
+        self.external_ids = kwargs.pop('ext_ids')
29
+        self.uuid = kwargs.pop('uuid')
30
+        super(MockedLB, self).__init__(*args, **kwargs)
31
+
32
+    def __hash__(self):
33
+        # Required for Python3, not for Python2
34
+        return self.__sizeof__()
35
+
36
+
37
+class TestOvnOctaviaBase(base.BaseTestCase):
38
+
39
+    def setUp(self):
40
+        super(TestOvnOctaviaBase, self).setUp()
41
+        self.listener_id = uuidutils.generate_uuid()
42
+        self.loadbalancer_id = uuidutils.generate_uuid()
43
+        self.member_id = uuidutils.generate_uuid()
44
+        self.member_subnet_id = uuidutils.generate_uuid()
45
+        self.pool_id = uuidutils.generate_uuid()
46
+        self.port1_id = uuidutils.generate_uuid()
47
+        self.port2_id = uuidutils.generate_uuid()
48
+        self.project_id = uuidutils.generate_uuid()
49
+        self.vip_network_id = uuidutils.generate_uuid()
50
+        self.vip_port_id = uuidutils.generate_uuid()
51
+        self.vip_subnet_id = uuidutils.generate_uuid()
52
+        mock.patch("networking_ovn.common.utils.get_ovsdb_connection").start()
53
+        self.member_address = "192.168.2.149"
54
+        self.vip_address = '192.148.210.109'
55
+        self.member_port = "1010"
56
+        self.member_pool_id = self.pool_id
57
+        self.member_subnet_id = uuidutils.generate_uuid()
58
+        mock.patch(
59
+            'ovsdbapp.backend.ovs_idl.idlutils.get_schema_helper').start()
60
+
61
+
62
+class TestOvnProviderDriver(TestOvnOctaviaBase):
63
+
64
+    def setUp(self):
65
+        super(TestOvnProviderDriver, self).setUp()
66
+        self.driver = ovn_driver.OvnProviderDriver()
67
+        add_req_thread = mock.patch.object(ovn_driver.OvnProviderHelper,
68
+                                           'add_request')
69
+        self.ovn_lb = mock.MagicMock()
70
+        self.mock_add_request = add_req_thread.start()
71
+        self.project_id = uuidutils.generate_uuid()
72
+
73
+        self.fail_member = data_models.Member(
74
+            address='198.51.100.4',
75
+            admin_state_up=True,
76
+            member_id=self.member_id,
77
+            monitor_address="100.200.200.100",
78
+            monitor_port=66,
79
+            name='Amazin',
80
+            pool_id=self.pool_id,
81
+            protocol_port=99,
82
+            subnet_id=self.member_subnet_id,
83
+            weight=55)
84
+        self.ref_member = data_models.Member(
85
+            address='198.52.100.4',
86
+            admin_state_up=True,
87
+            member_id=self.member_id,
88
+            monitor_address=data_models.Unset,
89
+            monitor_port=data_models.Unset,
90
+            name='Amazing',
91
+            pool_id=self.pool_id,
92
+            protocol_port=99,
93
+            subnet_id=self.member_subnet_id,
94
+            weight=55)
95
+        self.update_member = data_models.Member(
96
+            address='198.53.100.4',
97
+            admin_state_up=False,
98
+            member_id=self.member_id,
99
+            monitor_address=data_models.Unset,
100
+            monitor_port=data_models.Unset,
101
+            name='Amazin',
102
+            pool_id=self.pool_id,
103
+            protocol_port=99,
104
+            subnet_id=self.member_subnet_id,
105
+            weight=55)
106
+        self.ref_update_pool = data_models.Pool(
107
+            admin_state_up=False,
108
+            description='pool',
109
+            name='Peter',
110
+            lb_algorithm=constants.LB_ALGORITHM_ROUND_ROBIN,
111
+            loadbalancer_id=self.loadbalancer_id,
112
+            listener_id=self.listener_id,
113
+            members=[self.ref_member],
114
+            pool_id=self.pool_id,
115
+            protocol='TCP',
116
+            session_persistence={'type': 'fix'})
117
+        self.ref_pool = data_models.Pool(
118
+            admin_state_up=True,
119
+            description='pool',
120
+            name='Peter',
121
+            lb_algorithm=constants.LB_ALGORITHM_ROUND_ROBIN,
122
+            loadbalancer_id=self.loadbalancer_id,
123
+            listener_id=self.listener_id,
124
+            members=[self.ref_member],
125
+            pool_id=self.pool_id,
126
+            protocol='TCP',
127
+            session_persistence={'type': 'fix'})
128
+        self.ref_http_pool = data_models.Pool(
129
+            admin_state_up=True,
130
+            description='pool',
131
+            lb_algorithm=constants.LB_ALGORITHM_ROUND_ROBIN,
132
+            loadbalancer_id=self.loadbalancer_id,
133
+            listener_id=self.listener_id,
134
+            members=[self.ref_member],
135
+            name='Groot',
136
+            pool_id=self.pool_id,
137
+            protocol='HTTP',
138
+            session_persistence={'type': 'fix'})
139
+        self.ref_lc_pool = data_models.Pool(
140
+            admin_state_up=True,
141
+            description='pool',
142
+            lb_algorithm=constants.LB_ALGORITHM_LEAST_CONNECTIONS,
143
+            loadbalancer_id=self.loadbalancer_id,
144
+            listener_id=self.listener_id,
145
+            members=[self.ref_member],
146
+            name='Groot',
147
+            pool_id=self.pool_id,
148
+            protocol='HTTP',
149
+            session_persistence={'type': 'fix'})
150
+        self.ref_listener = data_models.Listener(
151
+            admin_state_up=False,
152
+            connection_limit=5,
153
+            default_pool=self.ref_pool,
154
+            default_pool_id=self.pool_id,
155
+            listener_id=self.listener_id,
156
+            loadbalancer_id=self.loadbalancer_id,
157
+            name='listener',
158
+            protocol='TCP',
159
+            protocol_port=42)
160
+        self.ref_listener_udp = data_models.Listener(
161
+            admin_state_up=False,
162
+            connection_limit=5,
163
+            default_pool=self.ref_pool,
164
+            default_pool_id=self.pool_id,
165
+            listener_id=self.listener_id,
166
+            loadbalancer_id=self.loadbalancer_id,
167
+            name='listener',
168
+            protocol='UDP',
169
+            protocol_port=42)
170
+        self.fail_listener = data_models.Listener(
171
+            admin_state_up=False,
172
+            connection_limit=5,
173
+            default_pool=self.ref_pool,
174
+            default_pool_id=self.pool_id,
175
+            listener_id=self.listener_id,
176
+            loadbalancer_id=self.loadbalancer_id,
177
+            name='listener',
178
+            protocol='http',
179
+            protocol_port=42)
180
+        self.ref_lb0 = data_models.LoadBalancer(
181
+            admin_state_up=False,
182
+            listeners=[self.ref_listener],
183
+            loadbalancer_id=self.loadbalancer_id,
184
+            name='favorite_lb0',
185
+            project_id=self.project_id,
186
+            vip_address=self.vip_address,
187
+            vip_network_id=self.vip_network_id)
188
+        self.ref_lb1 = data_models.LoadBalancer(
189
+            admin_state_up=True,
190
+            listeners=[self.ref_listener],
191
+            loadbalancer_id=self.loadbalancer_id,
192
+            name='favorite_lb1',
193
+            project_id=self.project_id,
194
+            vip_address=self.vip_address,
195
+            vip_network_id=self.vip_network_id)
196
+        mock.patch.object(ovn_driver.OvnProviderHelper, '_find_ovn_lb',
197
+                          return_value=self.ovn_lb).start()
198
+        mock.patch.object(
199
+            ovn_driver.OvnProviderHelper, 'get_member_info',
200
+            return_value=[
201
+                (self.ref_member.member_id, "198.52.100.4:99"),
202
+                (self.fail_member.member_id, "198.51.100.4:99")]).start()
203
+        mock.patch.object(ovn_driver.OvnProviderHelper,
204
+                          '_find_ovn_lb_with_pool_key',
205
+                          return_value=self.ovn_lb).start()
206
+        self.vip_dict = {'vip_network_id': uuidutils.generate_uuid(),
207
+                         'vip_subnet_id': uuidutils.generate_uuid()}
208
+        self.vip_output = {'vip_network_id': self.vip_dict['vip_network_id'],
209
+                           'vip_subnet_id': self.vip_dict['vip_subnet_id']}
210
+
211
+    def test_member_create(self):
212
+        info = {'id': self.ref_member.member_id,
213
+                'address': self.ref_member.address,
214
+                'protocol_port': self.ref_member.protocol_port,
215
+                'pool_id': self.ref_member.pool_id,
216
+                'subnet_id': self.ref_member.subnet_id,
217
+                'admin_state_up': self.ref_member.admin_state_up}
218
+        expected_dict = {'type': ovn_driver.REQ_TYPE_MEMBER_CREATE,
219
+                         'info': info}
220
+        self.driver.member_create(self.ref_member)
221
+        self.mock_add_request.assert_called_once_with(expected_dict)
222
+
223
+    def test_member_create_failure(self):
224
+        self.assertRaises(exceptions.UnsupportedOptionError,
225
+                          self.driver.member_create, self.fail_member)
226
+
227
+    def test_member_update(self):
228
+        info = {'id': self.update_member.member_id,
229
+                'address': self.ref_member.address,
230
+                'protocol_port': self.ref_member.protocol_port,
231
+                'pool_id': self.ref_member.pool_id,
232
+                'admin_state_up': self.update_member.admin_state_up,
233
+                'subnet_id': self.ref_member.subnet_id}
234
+        expected_dict = {'type': ovn_driver.REQ_TYPE_MEMBER_UPDATE,
235
+                         'info': info}
236
+        self.driver.member_update(self.ref_member, self.update_member)
237
+        self.mock_add_request.assert_called_once_with(expected_dict)
238
+
239
+    def test_member_update_batch(self):
240
+        self.driver.member_batch_update([self.ref_member, self.update_member])
241
+        self.assertEqual(self.mock_add_request.call_count, 3)
242
+
243
+    def test_member_update_failure(self):
244
+        self.assertRaises(exceptions.UnsupportedOptionError,
245
+                          self.driver.member_update, self.ref_member,
246
+                          self.fail_member)
247
+
248
+    def test_member_delete(self):
249
+        info = {'id': self.ref_member.member_id,
250
+                'address': self.ref_member.address,
251
+                'protocol_port': self.ref_member.protocol_port,
252
+                'pool_id': self.ref_member.pool_id,
253
+                'subnet_id': self.ref_member.subnet_id}
254
+        expected_dict = {'type': ovn_driver.REQ_TYPE_MEMBER_DELETE,
255
+                         'info': info}
256
+        self.driver.member_delete(self.ref_member)
257
+        self.mock_add_request.assert_called_once_with(expected_dict)
258
+
259
+    def test_listener_create(self):
260
+        info = {'id': self.ref_listener.listener_id,
261
+                'protocol': self.ref_listener.protocol,
262
+                'protocol_port': self.ref_listener.protocol_port,
263
+                'default_pool_id': self.ref_listener.default_pool_id,
264
+                'admin_state_up': self.ref_listener.admin_state_up,
265
+                'loadbalancer_id': self.ref_listener.loadbalancer_id}
266
+        expected_dict = {'type': ovn_driver.REQ_TYPE_LISTENER_CREATE,
267
+                         'info': info}
268
+        self.driver.listener_create(self.ref_listener)
269
+        self.mock_add_request.assert_called_once_with(expected_dict)
270
+
271
+    def test_listener_update(self):
272
+        info = {'id': self.ref_listener.listener_id,
273
+                'protocol_port': self.ref_listener.protocol_port,
274
+                'admin_state_up': self.ref_listener.admin_state_up,
275
+                'loadbalancer_id': self.ref_listener.loadbalancer_id}
276
+        if self.ref_listener.default_pool_id:
277
+            info['default_pool_id'] = self.ref_listener.default_pool_id
278
+        expected_dict = {'type': ovn_driver.REQ_TYPE_LISTENER_UPDATE,
279
+                         'info': info}
280
+        self.driver.listener_update(self.ref_listener, self.ref_listener)
281
+        self.mock_add_request.assert_called_once_with(expected_dict)
282
+
283
+    @mock.patch.object(ovn_driver.OvnProviderHelper, '_is_listener_in_lb',
284
+                       return_value=True)
285
+    def test_listener_failure(self, mock_listener):
286
+        self.assertRaises(exceptions.UnsupportedOptionError,
287
+                          self.driver.listener_create, self.fail_listener)
288
+        self.assertRaises(exceptions.UnsupportedOptionError,
289
+                          self.driver.listener_update, self.ref_listener,
290
+                          self.fail_listener)
291
+        self.ovn_lb.protocol = ['TCP']
292
+        self.assertRaises(exceptions.UnsupportedOptionError,
293
+                          self.driver.listener_create,
294
+                          self.ref_listener_udp)
295
+
296
+    def test_listener_delete(self):
297
+        info = {'id': self.ref_listener.listener_id,
298
+                'protocol_port': self.ref_listener.protocol_port,
299
+                'loadbalancer_id': self.ref_listener.loadbalancer_id}
300
+        expected_dict = {'type': ovn_driver.REQ_TYPE_LISTENER_DELETE,
301
+                         'info': info}
302
+        self.driver.listener_delete(self.ref_listener)
303
+        self.mock_add_request.assert_called_once_with(expected_dict)
304
+
305
+    def test_loadbalancer_create(self):
306
+        info = {'id': self.ref_lb0.loadbalancer_id,
307
+                'vip_address': self.ref_lb0.vip_address,
308
+                'vip_network_id': self.ref_lb0.vip_network_id,
309
+                'admin_state_up': self.ref_lb0.admin_state_up}
310
+        expected_dict = {'type': ovn_driver.REQ_TYPE_LB_CREATE,
311
+                         'info': info}
312
+        self.driver.loadbalancer_create(self.ref_lb0)
313
+        self.mock_add_request.assert_called_once_with(expected_dict)
314
+
315
+    def test_loadbalancer_update(self):
316
+        info = {'id': self.ref_lb1.loadbalancer_id,
317
+                'admin_state_up': self.ref_lb1.admin_state_up}
318
+        expected_dict = {'type': ovn_driver.REQ_TYPE_LB_UPDATE,
319
+                         'info': info}
320
+        self.driver.loadbalancer_update(self.ref_lb0, self.ref_lb1)
321
+        self.mock_add_request.assert_called_once_with(expected_dict)
322
+
323
+    def test_loadbalancer_delete(self):
324
+        info = {'id': self.ref_lb0.loadbalancer_id,
325
+                'cascade': False}
326
+        expected_dict = {'type': ovn_driver.REQ_TYPE_LB_DELETE,
327
+                         'info': info}
328
+        self.driver.loadbalancer_delete(self.ref_lb1)
329
+        self.mock_add_request.assert_called_once_with(expected_dict)
330
+
331
+    def test_loadbalancer_failover(self):
332
+        info = {'id': self.ref_lb0.loadbalancer_id}
333
+        expected_dict = {'type': ovn_driver.REQ_TYPE_LB_FAILOVER,
334
+                         'info': info}
335
+        self.driver.loadbalancer_failover(info['id'])
336
+        self.mock_add_request.assert_called_once_with(expected_dict)
337
+
338
+    def test_pool_create_http(self):
339
+        self.assertRaises(exceptions.UnsupportedOptionError,
340
+                          self.driver.pool_create, self.ref_http_pool)
341
+
342
+    def test_pool_create_leastcount_algo(self):
343
+        self.assertRaises(exceptions.UnsupportedOptionError,
344
+                          self.driver.pool_create, self.ref_lc_pool)
345
+
346
+    def test_pool_create_tcp(self):
347
+        info = {'id': self.ref_pool.pool_id,
348
+                'loadbalancer_id': self.ref_pool.loadbalancer_id,
349
+                'listener_id': self.ref_pool.listener_id,
350
+                'admin_state_up': self.ref_pool.admin_state_up}
351
+        expected_dict = {'type': ovn_driver.REQ_TYPE_POOL_CREATE,
352
+                         'info': info}
353
+        self.driver.pool_create(self.ref_pool)
354
+        self.mock_add_request.assert_called_once_with(expected_dict)
355
+
356
+    def test_pool_delete(self):
357
+        # Pretent we don't have members
358
+        self.ref_pool.members = []
359
+        info = {'id': self.ref_pool.pool_id,
360
+                'loadbalancer_id': self.ref_pool.loadbalancer_id}
361
+        expected = {'type': ovn_driver.REQ_TYPE_POOL_DELETE,
362
+                    'info': info}
363
+        self.driver.pool_delete(self.ref_pool)
364
+        self.mock_add_request.assert_called_once_with(expected)
365
+
366
+    def test_pool_delete_with_members(self):
367
+        info = {'id': self.ref_pool.pool_id,
368
+                'loadbalancer_id': self.ref_pool.loadbalancer_id}
369
+        expected = {'type': ovn_driver.REQ_TYPE_POOL_DELETE,
370
+                    'info': info}
371
+        info_member = {'id': self.ref_member.member_id,
372
+                       'pool_id': self.ref_member.pool_id,
373
+                       'subnet_id': self.ref_member.subnet_id,
374
+                       'protocol_port': self.ref_member.protocol_port,
375
+                       'address': self.ref_member.address}
376
+        expected_members = {
377
+            'type': ovn_driver.REQ_TYPE_MEMBER_DELETE,
378
+            'info': info_member}
379
+        calls = [mock.call(expected_members),
380
+                 mock.call(expected)]
381
+        self.driver.pool_delete(self.ref_pool)
382
+        self.mock_add_request.assert_has_calls(calls)
383
+
384
+    def test_pool_update(self):
385
+        info = {'id': self.ref_update_pool.pool_id,
386
+                'loadbalancer_id': self.ref_update_pool.loadbalancer_id,
387
+                'admin_state_up': self.ref_update_pool.admin_state_up}
388
+        expected_dict = {'type': ovn_driver.REQ_TYPE_POOL_UPDATE,
389
+                         'info': info}
390
+        self.driver.pool_update(self.ref_pool, self.ref_update_pool)
391
+        self.mock_add_request.assert_called_once_with(expected_dict)
392
+
393
+    def test_create_vip_port(self):
394
+        with mock.patch.object(ovn_driver, 'get_network_driver'):
395
+            port_dict = self.driver.create_vip_port(self.loadbalancer_id,
396
+                                                    self.project_id,
397
+                                                    self.vip_dict)
398
+            for key, value in self.vip_output.items():
399
+                self.assertEqual(value, port_dict[key])
400
+            self.vip_dict['vip_address'] = '10.1.10.1'
401
+            port_dict = self.driver.create_vip_port(self.loadbalancer_id,
402
+                                                    self.project_id,
403
+                                                    self.vip_dict)
404
+            # The network_driver function is mocked, therefore the
405
+            # created port vip_address is also mocked. Check if it exists
406
+            # and move on.
407
+            self.assertIsNotNone(port_dict.pop('vip_address', None))
408
+            for key, value in self.vip_output.items():
409
+                self.assertEqual(value, port_dict[key])
410
+
411
+
412
+class TestOvnProviderHelper(TestOvnOctaviaBase):
413
+
414
+    def setUp(self):
415
+        super(TestOvnProviderHelper, self).setUp()
416
+        self.helper = ovn_driver.OvnProviderHelper()
417
+        mock.patch.object(self.helper, '_update_status_to_octavia').start()
418
+        self.listener = {'id': self.listener_id,
419
+                         'loadbalancer_id': self.loadbalancer_id,
420
+                         'protocol': "TCP",
421
+                         'protocol_port': 80,
422
+                         'default_pool_id': self.pool_id,
423
+                         'admin_state_up': False}
424
+        self.lb = {'id': self.loadbalancer_id,
425
+                   'vip_address': self.vip_address,
426
+                   'cascade': False,
427
+                   'vip_network_id': self.vip_network_id,
428
+                   'admin_state_up': False}
429
+        self.ports = {'ports': [{
430
+            'fixed_ips': [{'ip_address': self.vip_address}],
431
+            'id': self.port1_id}]}
432
+        self.pool = {'id': self.pool_id,
433
+                     'loadbalancer_id': self.loadbalancer_id,
434
+                     'listener_id': self.listener_id,
435
+                     'admin_state_up': False}
436
+        self.member = {'id': self.member_id,
437
+                       'address': self.member_address,
438
+                       'protocol_port': self.member_port,
439
+                       'subnet_id': self.member_subnet_id,
440
+                       'pool_id': self.member_pool_id,
441
+                       'admin_state_up': True}
442
+        mock.patch.object(self.helper, 'ovn_nbdb_api').start()
443
+        add_req_thread = mock.patch.object(ovn_driver.OvnProviderHelper,
444
+                                           'add_request')
445
+        self.mock_add_request = add_req_thread.start()
446
+        self.logical_sw = self.helper.ovn_nbdb_api.ls_get.return_value
447
+        self.logical_sw.execute.return_value.ports = []
448
+        self.ovn_lb = mock.MagicMock()
449
+        self.ovn_lb.uuid = uuidutils.generate_uuid()
450
+        self.ovn_lb.external_ids.get.return_value = {}
451
+        self.helper.ovn_nbdb_api.db_find.return_value.\
452
+            execute.return_value = [self.ovn_lb]
453
+        self.helper.ovn_nbdb_api.db_list_rows.return_value.\
454
+            execute.return_value = [self.ovn_lb]
455
+        ref_lb1 = MockedLB(
456
+            uuid=uuidutils.generate_uuid(),
457
+            admin_state_up=True,
458
+            listeners=[],
459
+            loadbalancer_id=self.loadbalancer_id,
460
+            name='favorite_lb1',
461
+            project_id=self.project_id,
462
+            vip_address=self.vip_address,
463
+            vip_network_id=self.vip_network_id,
464
+            ext_ids={ovn_driver.LB_EXT_IDS_LR_REF_KEY: '1'})
465
+        ref_lb2 = MockedLB(
466
+            uuid=uuidutils.generate_uuid(),
467
+            admin_state_up=True,
468
+            listeners=[],
469
+            loadbalancer_id=self.loadbalancer_id,
470
+            name='favorite_lb2',
471
+            project_id=self.project_id,
472
+            vip_address=self.vip_address,
473
+            vip_network_id=self.vip_network_id,
474
+            ext_ids={ovn_driver.LB_EXT_IDS_LR_REF_KEY: '1'})
475
+        loadbalancer = collections.namedtuple("LoadBalancer",
476
+                                              "load_balancer name uuid")
477
+        mock.patch.object(self.helper,
478
+                          '_find_ovn_lb_with_pool_key',
479
+                          return_value=self.ovn_lb).start()
480
+        mock.patch.object(self.helper,
481
+                          '_get_pool_listeners',
482
+                          return_value=[]).start()
483
+        mock.patch.object(self.helper,
484
+                          '_update_lb_to_ls_association',
485
+                          return_value=[]).start()
486
+        mock.patch.object(self.helper,
487
+                          '_update_lb_to_lr_association',
488
+                          return_value=[]).start()
489
+        self.router = loadbalancer(load_balancer=[ref_lb1], name='router_lb',
490
+                                   uuid=uuidutils.generate_uuid())
491
+        self.network = loadbalancer(load_balancer=[ref_lb2], name='network_lb',
492
+                                    uuid=uuidutils.generate_uuid())
493
+
494
+    @mock.patch('networking_ovn.octavia.ovn_driver.get_network_driver')
495
+    def test_lb_create(self, net_dr):
496
+        net_dr.return_value.neutron_client.list_ports.return_value = (
497
+            self.ports)
498
+        status = self.helper.lb_create(self.lb)
499
+        self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
500
+                         constants.ACTIVE)
501
+        self.assertEqual(status['loadbalancers'][0]['operating_status'],
502
+                         constants.OFFLINE)
503
+        self.lb['admin_state_up'] = True
504
+        status = self.helper.lb_create(self.lb)
505
+        self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
506
+                         constants.ACTIVE)
507
+        self.assertEqual(status['loadbalancers'][0]['operating_status'],
508
+                         constants.ONLINE)
509
+
510
+    @mock.patch('networking_ovn.octavia.ovn_driver.OvnProviderHelper.'
511
+                '_find_ovn_lb')
512
+    @mock.patch('networking_ovn.octavia.ovn_driver.get_network_driver')
513
+    def test_lb_delete(self, net_dr, lb):
514
+        net_dr.return_value.neutron_client.delete_port.return_value = None
515
+        lb.return_value.external_ids.get.return_value = {}
516
+        status = self.helper.lb_delete(self.lb)
517
+        self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
518
+                         constants.DELETED)
519
+        self.assertEqual(status['loadbalancers'][0]['operating_status'],
520
+                         constants.OFFLINE)
521
+
522
+    @mock.patch('networking_ovn.octavia.ovn_driver.OvnProviderHelper.'
523
+                '_find_ovn_lb')
524
+    @mock.patch('networking_ovn.octavia.ovn_driver.get_network_driver')
525
+    def test_lb_cascade_delete(self, net_dr, lb):
526
+        net_dr.return_value.neutron_client.delete_port.return_value = None
527
+        lb.return_value.external_ids.get.return_value = {}
528
+        self.lb['cascade'] = True
529
+        status = self.helper.lb_delete(self.lb)
530
+        self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
531
+                         constants.DELETED)
532
+        self.assertEqual(status['loadbalancers'][0]['operating_status'],
533
+                         constants.OFFLINE)
534
+
535
+    def test_lb_update(self):
536
+        status = self.helper.lb_update(self.lb)
537
+        self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
538
+                         constants.ACTIVE)
539
+        self.assertEqual(status['loadbalancers'][0]['operating_status'],
540
+                         constants.OFFLINE)
541
+        self.lb['admin_state_up'] = True
542
+        status = self.helper.lb_update(self.lb)
543
+        self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
544
+                         constants.ACTIVE)
545
+        self.assertEqual(status['loadbalancers'][0]['operating_status'],
546
+                         constants.ONLINE)
547
+
548
+    def test_listener_update(self):
549
+        status = self.helper.listener_update(self.listener)
550
+        self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
551
+                         constants.ACTIVE)
552
+        self.assertEqual(status['listeners'][0]['provisioning_status'],
553
+                         constants.ACTIVE)
554
+        self.assertEqual(status['pools'], [])
555
+        self.listener['admin_state_up'] = True
556
+        status = self.helper.listener_update(self.listener)
557
+        self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
558
+                         constants.ACTIVE)
559
+        self.assertEqual(status['listeners'][0]['provisioning_status'],
560
+                         constants.ACTIVE)
561
+        self.assertEqual(status['pools'], [])
562
+
563
+    def test_listener_create(self):
564
+        status = self.helper.listener_create(self.listener)
565
+        self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
566
+                         constants.ACTIVE)
567
+        self.assertEqual(status['listeners'][0]['provisioning_status'],
568
+                         constants.ACTIVE)
569
+        self.assertEqual(status['listeners'][0]['operating_status'],
570
+                         constants.OFFLINE)
571
+        self.listener['admin_state_up'] = True
572
+        status = self.helper.listener_create(self.listener)
573
+        self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
574
+                         constants.ACTIVE)
575
+        self.assertEqual(status['listeners'][0]['provisioning_status'],
576
+                         constants.ACTIVE)
577
+        self.assertEqual(status['listeners'][0]['operating_status'],
578
+                         constants.ONLINE)
579
+        mock.patch.object(self.helper, "_is_listener_in_lb",
580
+                          return_value=True).start()
581
+        status = self.helper.listener_create(self.listener)
582
+
583
+    def test_listener_delete(self):
584
+        status = self.helper.listener_delete(self.listener)
585
+        self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
586
+                         constants.ACTIVE)
587
+        self.assertEqual(status['listeners'][0]['provisioning_status'],
588
+                         constants.DELETED)
589
+        self.assertEqual(status['listeners'][0]['operating_status'],
590
+                         constants.OFFLINE)
591
+
592
+    def test_pool_create(self):
593
+        status = self.helper.pool_create(self.pool)
594
+        self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
595
+                         constants.ACTIVE)
596
+        self.assertEqual(status['listeners'][0]['provisioning_status'],
597
+                         constants.ACTIVE)
598
+        self.assertEqual(status['pools'][0]['provisioning_status'],
599
+                         constants.ACTIVE)
600
+        self.assertEqual(status['pools'][0]['operating_status'],
601
+                         constants.OFFLINE)
602
+        self.pool['admin_state_up'] = True
603
+        # Pool Operating status shouldnt change if member isnt present.
604
+        status = self.helper.pool_create(self.pool)
605
+        self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
606
+                         constants.ACTIVE)
607
+        self.assertEqual(status['pools'][0]['provisioning_status'],
608
+                         constants.ACTIVE)
609
+        self.assertEqual(status['pools'][0]['operating_status'],
610
+                         constants.OFFLINE)
611
+
612
+    def test_pool_update(self):
613
+        status = self.helper.pool_update(self.pool)
614
+        self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
615
+                         constants.ACTIVE)
616
+        self.assertEqual(status['pools'][0]['provisioning_status'],
617
+                         constants.ACTIVE)
618
+        self.assertEqual(status['pools'][0]['operating_status'],
619
+                         constants.OFFLINE)
620
+        self.pool['admin_state_up'] = True
621
+        status = self.helper.pool_update(self.pool)
622
+        self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
623
+                         constants.ACTIVE)
624
+        self.assertEqual(status['pools'][0]['provisioning_status'],
625
+                         constants.ACTIVE)
626
+        self.assertEqual(status['pools'][0]['operating_status'],
627
+                         constants.ONLINE)
628
+
629
+    def test_pool_delete(self):
630
+        status = self.helper.pool_delete(self.pool)
631
+        self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
632
+                         constants.ACTIVE)
633
+        self.assertEqual(status['pools'][0]['provisioning_status'],
634
+                         constants.DELETED)
635
+
636
+    def test_member_create(self):
637
+        status = self.helper.member_create(self.member)
638
+        self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
639
+                         constants.ACTIVE)
640
+        self.assertEqual(status['pools'][0]['provisioning_status'],
641
+                         constants.ACTIVE)
642
+        self.assertEqual(status['members'][0]['provisioning_status'],
643
+                         constants.ACTIVE)
644
+        self.member['admin_state_up'] = False
645
+        status = self.helper.member_create(self.member)
646
+        self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
647
+                         constants.ACTIVE)
648
+        self.assertEqual(status['pools'][0]['provisioning_status'],
649
+                         constants.ACTIVE)
650
+        self.assertEqual(status['members'][0]['provisioning_status'],
651
+                         constants.ACTIVE)
652
+
653
+    def test_member_update(self):
654
+        status = self.helper.member_update(self.member)
655
+        self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
656
+                         constants.ACTIVE)
657
+        self.assertEqual(status['pools'][0]['provisioning_status'],
658
+                         constants.ACTIVE)
659
+        self.assertEqual(status['members'][0]['provisioning_status'],
660
+                         constants.ACTIVE)
661
+        self.assertEqual(status['members'][0]['operating_status'],
662
+                         constants.ONLINE)
663
+        self.member['admin_state_up'] = False
664
+        status = self.helper.member_update(self.member)
665
+        self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
666
+                         constants.ACTIVE)
667
+        self.assertEqual(status['pools'][0]['provisioning_status'],
668
+                         constants.ACTIVE)
669
+        self.assertEqual(status['members'][0]['provisioning_status'],
670
+                         constants.ACTIVE)
671
+        self.assertEqual(status['members'][0]['operating_status'],
672
+                         constants.OFFLINE)
673
+
674
+    @mock.patch('networking_ovn.octavia.ovn_driver.OvnProviderHelper.'
675
+                '_refresh_lb_vips')
676
+    def test_member_delete(self, mock_vip_command):
677
+        self.ovn_lb.external_ids = {
678
+            'pool_' + self.pool_id: 'member_' + self.member_id + '_' +
679
+            self.member_address + ':' + self.member_port}
680
+        status = self.helper.member_delete(self.member)
681
+        self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
682
+                         constants.ACTIVE)
683
+        self.assertEqual(status['pools'][0]['provisioning_status'],
684
+                         constants.ACTIVE)
685
+        self.assertEqual(status['members'][0]['provisioning_status'],
686
+                         constants.DELETED)

Loading…
Cancel
Save