Test Failed
Pull Request — master (#104)
by Vinicius
03:26
created

test_flow_builder_failover   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 946
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 682
dl 0
loc 946
rs 9.9179
c 0
b 0
f 0
wmc 9

3 Functions

Rating   Name   Duplication   Size   Complexity  
B test_handle_failover_old_path_diff_svlan() 0 402 3
B test_handle_failover_link_down() 0 286 3
B test_handle_failover_old_path_same_svlan() 0 244 3
1
import json
2
3
from unittest.mock import AsyncMock, MagicMock
4
from napps.kytos.telemetry_int.managers.int import INTManager
5
from napps.kytos.telemetry_int.proxy_port import ProxyPort
6
from kytos.lib.helpers import get_controller_mock, get_switch_mock, get_interface_mock
7
from kytos.core.common import EntityStatus
8
9
10
async def test_handle_failover_link_down() -> None:
11
    """Test handle failover_link_down.
12
13
               +----+                                              +----+
14
              5|    |6                                            5|    |6
15
           +---+----v---+            +------------+           +----+----v---+
16
        1  |            |            |            |           |             |1
17
    -------+            |3         2 |            |3        2 |             +-------
18
     vlan  |     s1     +------------+    s2      +-----------+    s3       | vlan
19
     100   |            |            |            |           |             | 100
20
           |            |            |            |           |             |
21
           +------------+            +------------+           +-------------+
22
                |4                                                   3|
23
                |_____________________________________________________|
24
    """
25
26
    controller = get_controller_mock()
27
    int_manager = INTManager(controller)
28
    get_proxy_port_or_raise = MagicMock()
29
    int_manager.get_proxy_port_or_raise = get_proxy_port_or_raise
30
31
    dpid_a = "00:00:00:00:00:00:00:01"
32
    mock_switch_a = get_switch_mock(dpid_a, 0x04)
33
    mock_interface_a1 = get_interface_mock("s1-eth1", 1, mock_switch_a)
34
    mock_interface_a1.id = f"{dpid_a}:{mock_interface_a1.port_number}"
35
    mock_interface_a5 = get_interface_mock("s1-eth5", 5, mock_switch_a)
36
    mock_interface_a1.metadata = {"proxy_port": mock_interface_a5.port_number}
37
    mock_interface_a5.status = EntityStatus.UP
38
    mock_interface_a6 = get_interface_mock("s1-eth6", 6, mock_switch_a)
39
    mock_interface_a6.status = EntityStatus.UP
40
    mock_interface_a5.metadata = {
41
        "looped": {
42
            "port_numbers": [
43
                mock_interface_a5.port_number,
44
                mock_interface_a6.port_number,
45
            ]
46
        }
47
    }
48
49
    dpid_z = "00:00:00:00:00:00:00:03"
50
    mock_switch_z = get_switch_mock(dpid_z, 0x04)
51
    mock_interface_z1 = get_interface_mock("s1-eth1", 1, mock_switch_z)
52
    mock_interface_z1.status = EntityStatus.UP
53
    mock_interface_z1.id = f"{dpid_z}:{mock_interface_z1.port_number}"
54
    mock_interface_z5 = get_interface_mock("s1-eth5", 5, mock_switch_z)
55
    mock_interface_z1.metadata = {"proxy_port": mock_interface_z5.port_number}
56
    mock_interface_z5.status = EntityStatus.UP
57
    mock_interface_z6 = get_interface_mock("s1-eth6", 6, mock_switch_z)
58
    mock_interface_z6.status = EntityStatus.UP
59
    mock_interface_z5.metadata = {
60
        "looped": {
61
            "port_numbers": [
62
                mock_interface_z5.port_number,
63
                mock_interface_z6.port_number,
64
            ]
65
        }
66
    }
67
68
    mock_switch_a.get_interface_by_port_no = lambda port_no: {
69
        mock_interface_a5.port_number: mock_interface_a5,
70
        mock_interface_a6.port_number: mock_interface_a6,
71
    }[port_no]
72
73
    mock_switch_z.get_interface_by_port_no = lambda port_no: {
74
        mock_interface_z5.port_number: mock_interface_z5,
75
        mock_interface_z6.port_number: mock_interface_z6,
76
    }[port_no]
77
78
    pp_a = ProxyPort(controller, source=mock_interface_a5)
79
    assert pp_a.source == mock_interface_a5
80
    assert pp_a.destination == mock_interface_a6
81
    pp_z = ProxyPort(controller, source=mock_interface_z5)
82
    assert pp_z.source == mock_interface_z5
83
    assert pp_z.destination == mock_interface_z6
84
85
    evcs_data = {
86
        "ceaf53b16c3a40": {
87
            "flows": {
88
                "00:00:00:00:00:00:00:01": [
89
                    {
90
                        "match": {"in_port": 1, "dl_vlan": 100},
91
                        "cookie": 12307967605643950656,
92
                        "actions": [
93
                            {"action_type": "push_vlan", "tag_type": "s"},
94
                            {"action_type": "set_vlan", "vlan_id": 1},
95
                            {"action_type": "output", "port": 3},
96
                        ],
97
                        "owner": "mef_eline",
98
                        "table_group": "evpl",
99
                        "table_id": 0,
100
                        "priority": 20000,
101
                    }
102
                ],
103
                "00:00:00:00:00:00:00:03": [
104
                    {
105
                        "match": {"in_port": 1, "dl_vlan": 100},
106
                        "cookie": 12307967605643950656,
107
                        "actions": [
108
                            {"action_type": "push_vlan", "tag_type": "s"},
109
                            {"action_type": "set_vlan", "vlan_id": 1},
110
                            {"action_type": "output", "port": 2},
111
                        ],
112
                        "owner": "mef_eline",
113
                        "table_group": "evpl",
114
                        "table_id": 0,
115
                        "priority": 20000,
116
                    }
117
                ],
118
            },
119
            "evc_id": "ceaf53b16c3a40",
120
            "id": "ceaf53b16c3a40",
121
            "name": "inter_evpl",
122
            "metadata": {
123
                "telemetry_request": {},
124
                "telemetry": {
125
                    "enabled": True,
126
                    "status": "UP",
127
                    "status_reason": [],
128
                    "status_updated_at": "2024-06-11T16:56:29",
129
                },
130
            },
131
            "active": True,
132
            "enabled": True,
133
            "uni_a": {
134
                "interface_id": "00:00:00:00:00:00:00:01:1",
135
                "tag": {"tag_type": "vlan", "value": 100},
136
            },
137
            "uni_z": {
138
                "interface_id": "00:00:00:00:00:00:00:03:1",
139
                "tag": {"tag_type": "vlan", "value": 100},
140
            },
141
        }
142
    }
143
144
    int_manager._send_flows = AsyncMock()
145
    int_manager._install_int_flows = AsyncMock()
146
    int_manager._remove_int_flows = AsyncMock()
147
    int_manager.remove_int_flows = AsyncMock()
148
    await int_manager.handle_failover_flows(evcs_data, "failover_link_down")
149
    assert int_manager._install_int_flows.call_count == 1
150
    assert int_manager._remove_int_flows.call_count == 0
151
    assert int_manager.remove_int_flows.call_count == 0
152
153
    expected_built_flows = {
154
        "12307967605643950656": [
155
            {
156
                "flow": {
157
                    "match": {
158
                        "in_port": 1,
159
                        "dl_vlan": 100,
160
                        "dl_type": 2048,
161
                        "nw_proto": 6,
162
                    },
163
                    "cookie": 12163852417568094784,
164
                    "owner": "telemetry_int",
165
                    "table_group": "evpl",
166
                    "table_id": 0,
167
                    "priority": 20100,
168
                    "instructions": [
169
                        {
170
                            "instruction_type": "apply_actions",
171
                            "actions": [{"action_type": "push_int"}],
172
                        },
173
                        {"instruction_type": "goto_table", "table_id": 2},
174
                    ],
175
                },
176
                "switch": "00:00:00:00:00:00:00:01",
177
            },
178
            {
179
                "flow": {
180
                    "match": {
181
                        "in_port": 1,
182
                        "dl_vlan": 100,
183
                        "dl_type": 2048,
184
                        "nw_proto": 17,
185
                    },
186
                    "cookie": 12163852417568094784,
187
                    "owner": "telemetry_int",
188
                    "table_group": "evpl",
189
                    "table_id": 0,
190
                    "priority": 20100,
191
                    "instructions": [
192
                        {
193
                            "instruction_type": "apply_actions",
194
                            "actions": [{"action_type": "push_int"}],
195
                        },
196
                        {"instruction_type": "goto_table", "table_id": 2},
197
                    ],
198
                },
199
                "switch": "00:00:00:00:00:00:00:01",
200
            },
201
            {
202
                "flow": {
203
                    "match": {"in_port": 1, "dl_vlan": 100},
204
                    "cookie": 12163852417568094784,
205
                    "owner": "telemetry_int",
206
                    "table_group": "evpl",
207
                    "table_id": 2,
208
                    "priority": 20000,
209
                    "instructions": [
210
                        {
211
                            "instruction_type": "apply_actions",
212
                            "actions": [
213
                                {"action_type": "add_int_metadata"},
214
                                {"action_type": "push_vlan", "tag_type": "s"},
215
                                {"action_type": "set_vlan", "vlan_id": 1},
216
                                {"action_type": "output", "port": 3},
217
                            ],
218
                        }
219
                    ],
220
                },
221
                "switch": "00:00:00:00:00:00:00:01",
222
            },
223
            {
224
                "flow": {
225
                    "match": {
226
                        "in_port": 1,
227
                        "dl_vlan": 100,
228
                        "dl_type": 2048,
229
                        "nw_proto": 6,
230
                    },
231
                    "cookie": 12163852417568094784,
232
                    "owner": "telemetry_int",
233
                    "table_group": "evpl",
234
                    "table_id": 0,
235
                    "priority": 20100,
236
                    "instructions": [
237
                        {
238
                            "instruction_type": "apply_actions",
239
                            "actions": [{"action_type": "push_int"}],
240
                        },
241
                        {"instruction_type": "goto_table", "table_id": 2},
242
                    ],
243
                },
244
                "switch": "00:00:00:00:00:00:00:03",
245
            },
246
            {
247
                "flow": {
248
                    "match": {
249
                        "in_port": 1,
250
                        "dl_vlan": 100,
251
                        "dl_type": 2048,
252
                        "nw_proto": 17,
253
                    },
254
                    "cookie": 12163852417568094784,
255
                    "owner": "telemetry_int",
256
                    "table_group": "evpl",
257
                    "table_id": 0,
258
                    "priority": 20100,
259
                    "instructions": [
260
                        {
261
                            "instruction_type": "apply_actions",
262
                            "actions": [{"action_type": "push_int"}],
263
                        },
264
                        {"instruction_type": "goto_table", "table_id": 2},
265
                    ],
266
                },
267
                "switch": "00:00:00:00:00:00:00:03",
268
            },
269
            {
270
                "flow": {
271
                    "match": {"in_port": 1, "dl_vlan": 100},
272
                    "cookie": 12163852417568094784,
273
                    "owner": "telemetry_int",
274
                    "table_group": "evpl",
275
                    "table_id": 2,
276
                    "priority": 20000,
277
                    "instructions": [
278
                        {
279
                            "instruction_type": "apply_actions",
280
                            "actions": [
281
                                {"action_type": "add_int_metadata"},
282
                                {"action_type": "push_vlan", "tag_type": "s"},
283
                                {"action_type": "set_vlan", "vlan_id": 1},
284
                                {"action_type": "output", "port": 2},
285
                            ],
286
                        }
287
                    ],
288
                },
289
                "switch": "00:00:00:00:00:00:00:03",
290
            },
291
        ]
292
    }
293
294
    serd = json.dumps(expected_built_flows)
295
    assert json.dumps(int_manager._install_int_flows.call_args[0][0]) == serd
296
297
298
async def test_handle_failover_old_path_same_svlan() -> None:
299
    """Test handle failover_old_path_same_svlan.
300
301
               +----+                                              +----+
302
              5|    |6                                            5|    |6
303
           +---+----v---+            +------------+           +----+----v---+
304
        1  |            |            |            |           |             |1
305
    -------+            |3         2 |            |3        2 |             +-------
306
     vlan  |     s1     +------------+    s2      +-----------+    s3       | vlan
307
     100   |            |            |            |           |             | 100
308
           |            |            |            |           |             |
309
           +------------+            +------------+           +-------------+
310
                |4                                                   3|
311
                |_____________________________________________________|
312
    """
313
314
    controller = get_controller_mock()
315
    int_manager = INTManager(controller)
316
    get_proxy_port_or_raise = MagicMock()
317
    int_manager.get_proxy_port_or_raise = get_proxy_port_or_raise
318
319
    dpid_a = "00:00:00:00:00:00:00:01"
320
    mock_switch_a = get_switch_mock(dpid_a, 0x04)
321
    mock_interface_a1 = get_interface_mock("s1-eth1", 1, mock_switch_a)
322
    mock_interface_a1.id = f"{dpid_a}:{mock_interface_a1.port_number}"
323
    mock_interface_a5 = get_interface_mock("s1-eth5", 5, mock_switch_a)
324
    mock_interface_a1.metadata = {"proxy_port": mock_interface_a5.port_number}
325
    mock_interface_a5.status = EntityStatus.UP
326
    mock_interface_a6 = get_interface_mock("s1-eth6", 6, mock_switch_a)
327
    mock_interface_a6.status = EntityStatus.UP
328
    mock_interface_a5.metadata = {
329
        "looped": {
330
            "port_numbers": [
331
                mock_interface_a5.port_number,
332
                mock_interface_a6.port_number,
333
            ]
334
        }
335
    }
336
337
    dpid_z = "00:00:00:00:00:00:00:03"
338
    mock_switch_z = get_switch_mock(dpid_z, 0x04)
339
    mock_interface_z1 = get_interface_mock("s1-eth1", 1, mock_switch_z)
340
    mock_interface_z1.status = EntityStatus.UP
341
    mock_interface_z1.id = f"{dpid_z}:{mock_interface_z1.port_number}"
342
    mock_interface_z5 = get_interface_mock("s1-eth5", 5, mock_switch_z)
343
    mock_interface_z1.metadata = {"proxy_port": mock_interface_z5.port_number}
344
    mock_interface_z5.status = EntityStatus.UP
345
    mock_interface_z6 = get_interface_mock("s1-eth6", 6, mock_switch_z)
346
    mock_interface_z6.status = EntityStatus.UP
347
    mock_interface_z5.metadata = {
348
        "looped": {
349
            "port_numbers": [
350
                mock_interface_z5.port_number,
351
                mock_interface_z6.port_number,
352
            ]
353
        }
354
    }
355
356
    mock_switch_a.get_interface_by_port_no = lambda port_no: {
357
        mock_interface_a5.port_number: mock_interface_a5,
358
        mock_interface_a6.port_number: mock_interface_a6,
359
    }[port_no]
360
361
    mock_switch_z.get_interface_by_port_no = lambda port_no: {
362
        mock_interface_z5.port_number: mock_interface_z5,
363
        mock_interface_z6.port_number: mock_interface_z6,
364
    }[port_no]
365
366
    pp_a = ProxyPort(controller, source=mock_interface_a5)
367
    assert pp_a.source == mock_interface_a5
368
    assert pp_a.destination == mock_interface_a6
369
    pp_z = ProxyPort(controller, source=mock_interface_z5)
370
    assert pp_z.source == mock_interface_z5
371
    assert pp_z.destination == mock_interface_z6
372
373
    evcs_data = {
374
        "ceaf53b16c3a40": {
375
            "removed_flows": {
376
                "00:00:00:00:00:00:00:01": [
377
                    {
378
                        "cookie": 12307967605643950656,
379
                        "match": {"in_port": 4, "dl_vlan": 1},
380
                        "cookie_mask": 18446744073709551615,
381
                    }
382
                ],
383
                "00:00:00:00:00:00:00:03": [
384
                    {
385
                        "cookie": 12307967605643950656,
386
                        "match": {"in_port": 3, "dl_vlan": 1},
387
                        "cookie_mask": 18446744073709551615,
388
                    }
389
                ],
390
            },
391
            "current_path": [
392
                {
393
                    "id": "78282c4d5b579265f04ebadc4405ca1b49628eb1d684bb45e5d0607fa8b713d0",
394
                    "endpoint_a": {
395
                        "id": "00: 00:00:00:00:00:00:01:3",
396
                        "name": "s1-eth3",
397
                        "port_number": 3,
398
                        "mac": "b2:ac:2b:ac:87:bb",
399
                        "switch": "00:00:00:00:00:00:00:01",
400
                        "type": "interface",
401
                        "nni": True,
402
                        "uni": False,
403
                        "speed": 1250000000.0,
404
                        "metadata": {},
405
                        "lldp": True,
406
                        "active": True,
407
                        "enabled": True,
408
                        "status": "UP",
409
                        "status_reason": [],
410
                        "link": "78282c4d5b579265f04ebadc4405ca1b49628eb1d684bb45e5d0607fa8b713d0",
411
                    },
412
                    "endpoint_b": {
413
                        "id": "00:00:00:00:00:00:00:02:2",
414
                        "name": "s2-eth2",
415
                        "port_number": 2,
416
                        "mac": "62:50:49:d7:79:8a",
417
                        "switch": "00:00:00:00:00:00:00:02",
418
                        "type": "interface",
419
                        "nni": True,
420
                        "uni": False,
421
                        "speed": 1250000000.0,
422
                        "metadata": {},
423
                        "lldp": True,
424
                        "active": True,
425
                        "enabled": True,
426
                        "status": "UP",
427
                        "status_reason": [],
428
                        "link": "78282c4d5b579265f04ebadc4405ca1b4 9628eb1d684bb45e5d0607fa8b713d0",
429
                    },
430
                    "metadata": {"s_vlan": {"tag_type": "vlan", "value": 1}},
431
                    "active": True,
432
                    "enabled": True,
433
                    "status": "UP",
434
                    "status_reason": [],
435
                },
436
                {
437
                    "id": "4d42dc0852278accac7d9df15418f6d921db160b13d674029a87cef1b5f67f30",
438
                    "endpoint_a": {
439
                        "id": "00:00:00:00:00:00:00:02:3",
440
                        "name": "s2-eth3",
441
                        "port_number": 3,
442
                        "mac": "76:82:ef:6e:d2:9d",
443
                        "switch": "00:00:00:00:00:00:00:02",
444
                        "type": "interface",
445
                        "nni": True,
446
                        "uni": False,
447
                        "speed": 1250000000.0,
448
                        "metadata": {},
449
                        "lldp": True,
450
                        "active": True,
451
                        "enabled": True,
452
                        "status": "UP",
453
                        "status_reason ": [],
454
                        "link": "4d42dc0852278accac7d9df15418f6d921db160b13d674029a87cef1b5f67f30",
455
                    },
456
                    "endpoint_b": {
457
                        "id": "00:00:00:00:00:00:00:03:2",
458
                        "name": "s3-eth2",
459
                        "port_number": 2,
460
                        "mac": "6a:c1:51:b1:a9:8a",
461
                        "switch": "00:00:00:00:00:00:00:03",
462
                        "type": "interface",
463
                        "nni": True,
464
                        "uni": False,
465
                        "speed": 1250000000.0,
466
                        "metadata": {},
467
                        "lldp": True,
468
                        "active": True,
469
                        "enabled": True,
470
                        "status": "UP",
471
                        "status_reason": [],
472
                        "link": "4d42dc0852278accac7d9df15418f6d921db160b13d674029a87cef1b5f67f30",
473
                    },
474
                    "metadata": {"s_vlan": {"tag_type": "vlan", "value": 1}},
475
                    "active": True,
476
                    "enabled": True,
477
                    "status": "UP",
478
                    "status_reason": [],
479
                },
480
            ],
481
            "evc_id": "ceaf53b16c3a40",
482
            "id": "ceaf53b16c3a40",
483
            "name": "inter_evpl",
484
            "metadata": {
485
                "telemetry_request": {},
486
                "telemetry": {
487
                    "enabled": True,
488
                    "status": "UP",
489
                    "status_reason": [],
490
                    "status_updated_at": "2024-06-11T16:56:29",
491
                },
492
            },
493
            "active": True,
494
            "enabled": True,
495
            "uni_a": {
496
                "interface_id": "00:00:00:00:00:00:00:01:1",
497
                "tag": {"tag_type": "vlan", "value": 100},
498
            },
499
            "uni_z": {
500
                "interface_id": "00:00:00:00:00:00:00:03:1",
501
                "tag": {"tag_type": "vlan", "value": 100},
502
            },
503
        }
504
    }
505
506
    get_proxy_port_or_raise.side_effect = [pp_a, pp_z]
507
    int_manager._send_flows = AsyncMock()
508
    int_manager._install_int_flows = AsyncMock()
509
    int_manager._remove_int_flows = AsyncMock()
510
    int_manager.remove_int_flows = AsyncMock()
511
    await int_manager.handle_failover_flows(evcs_data, "failover_old_path")
512
    assert int_manager._install_int_flows.call_count == 0
513
    assert int_manager._remove_int_flows.call_count == 1
514
    assert int_manager.remove_int_flows.call_count == 0
515
516
    expected_built_flows = {
517
        "12307967605643950656": [
518
            {
519
                "flow": {
520
                    "cookie": 12163852417568094784,
521
                    "match": {"in_port": 4, "dl_vlan": 1},
522
                    "cookie_mask": 18446744073709551615,
523
                    "priority": 21000,
524
                    "table_group": "evpl",
525
                },
526
                "switch": "00:00:00:00:00:00:00:01",
527
            },
528
            {
529
                "flow": {
530
                    "cookie": 12163852417568094784,
531
                    "match": {"in_port": 3, "dl_vlan": 1},
532
                    "cookie_mask": 18446744073709551615,
533
                    "priority": 21000,
534
                    "table_group": "evpl",
535
                },
536
                "switch": "00:00:00:00:00:00:00:03",
537
            },
538
        ]
539
    }
540
    serd = json.dumps(expected_built_flows)
541
    assert json.dumps(int_manager._remove_int_flows.call_args[0][0]) == serd
542
543
544
async def test_handle_failover_old_path_diff_svlan() -> None:
545
    """Test handle failover_old_path_diff_svlan.
546
547
               +----+                                              +----+
548
              5|    |6                                            5|    |6
549
           +---+----v---+            +------------+           +----+----v---+
550
        1  |            |            |            |           |             |1
551
    -------+            |3         2 |            |3        2 |             +-------
552
     vlan  |     s1     +------------+    s2      +-----------+    s3       | vlan
553
     100   |            |            |            |           |             | 100
554
           |            |            |            |           |             |
555
           +------------+            +------------+           +-------------+
556
                |4                                                   3|
557
                |_____________________________________________________|
558
    """
559
560
    controller = get_controller_mock()
561
    int_manager = INTManager(controller)
562
    get_proxy_port_or_raise = MagicMock()
563
    int_manager.get_proxy_port_or_raise = get_proxy_port_or_raise
564
565
    dpid_a = "00:00:00:00:00:00:00:01"
566
    mock_switch_a = get_switch_mock(dpid_a, 0x04)
567
    mock_interface_a1 = get_interface_mock("s1-eth1", 1, mock_switch_a)
568
    mock_interface_a1.id = f"{dpid_a}:{mock_interface_a1.port_number}"
569
    mock_interface_a4 = get_interface_mock("s1-eth4", 4, mock_switch_a)
570
    mock_interface_a4.id = f"{dpid_a}:{mock_interface_a4.port_number}"
571
    mock_interface_a5 = get_interface_mock("s1-eth5", 5, mock_switch_a)
572
    mock_interface_a1.metadata = {"proxy_port": mock_interface_a5.port_number}
573
    mock_interface_a4.status = EntityStatus.UP
574
    mock_interface_a5.status = EntityStatus.UP
575
    mock_interface_a6 = get_interface_mock("s1-eth6", 6, mock_switch_a)
576
    mock_interface_a6.status = EntityStatus.UP
577
    mock_interface_a5.metadata = {
578
        "looped": {
579
            "port_numbers": [
580
                mock_interface_a5.port_number,
581
                mock_interface_a6.port_number,
582
            ]
583
        }
584
    }
585
586
    dpid_z = "00:00:00:00:00:00:00:03"
587
    mock_switch_z = get_switch_mock(dpid_z, 0x04)
588
    mock_interface_z1 = get_interface_mock("s1-eth1", 1, mock_switch_z)
589
    mock_interface_z1.status = EntityStatus.UP
590
    mock_interface_z1.id = f"{dpid_z}:{mock_interface_z1.port_number}"
591
    mock_interface_z3 = get_interface_mock("s1-eth3", 3, mock_switch_z)
592
    mock_interface_z3.status = EntityStatus.UP
593
    mock_interface_z3.id = f"{dpid_z}:{mock_interface_z3.port_number}"
594
    mock_interface_z5 = get_interface_mock("s1-eth5", 5, mock_switch_z)
595
    mock_interface_z1.metadata = {"proxy_port": mock_interface_z5.port_number}
596
    mock_interface_z5.status = EntityStatus.UP
597
    mock_interface_z6 = get_interface_mock("s1-eth6", 6, mock_switch_z)
598
    mock_interface_z6.status = EntityStatus.UP
599
    mock_interface_z5.metadata = {
600
        "looped": {
601
            "port_numbers": [
602
                mock_interface_z5.port_number,
603
                mock_interface_z6.port_number,
604
            ]
605
        }
606
    }
607
608
    mock_switch_a.get_interface_by_port_no = lambda port_no: {
609
        mock_interface_a5.port_number: mock_interface_a5,
610
        mock_interface_a6.port_number: mock_interface_a6,
611
    }[port_no]
612
613
    mock_switch_z.get_interface_by_port_no = lambda port_no: {
614
        mock_interface_z5.port_number: mock_interface_z5,
615
        mock_interface_z6.port_number: mock_interface_z6,
616
    }[port_no]
617
618
    pp_a = ProxyPort(controller, source=mock_interface_a5)
619
    assert pp_a.source == mock_interface_a5
620
    assert pp_a.destination == mock_interface_a6
621
    pp_z = ProxyPort(controller, source=mock_interface_z5)
622
    assert pp_z.source == mock_interface_z5
623
    assert pp_z.destination == mock_interface_z6
624
625
    evcs_data = {
626
        "ceaf53b16c3a40": {
627
            "removed_flows": {
628
                "00:00:00:00:00:00:00:01": [
629
                    {
630
                        "cookie": 12307967605643950656,
631
                        "match": {"in_port": 4, "dl_vlan": 2},
632
                        "cookie_mask": 18446744073709551615,
633
                    }
634
                ],
635
                "00:00:00:00:00:00:00:03": [
636
                    {
637
                        "cookie": 12307967605643950656,
638
                        "match": {"in_port": 3, "dl_vlan": 2},
639
                        "cookie_mask": 18446744073709551615,
640
                    }
641
                ],
642
            },
643
            "current_path": [
644
                {
645
                    "id": "78282c4d5b579265f04ebadc4405ca1b49628eb1d684bb45e5d0607fa8b713d0",
646
                    "endpoint_a": {
647
                        "id": "00:00:00:00:00:00:00:01:3",
648
                        "name": "s1-eth3",
649
                        "port_number": 3,
650
                        "mac": "b2:ac:2b:ac:87:bb",
651
                        "switch": "00:00:00:00:00:00:00:01",
652
                        "type": "interface",
653
                        "nni": True,
654
                        "uni": False,
655
                        "speed": 1250000000.0,
656
                        "metadata": {},
657
                        "lldp": True,
658
                        "active": True,
659
                        "enabled": True,
660
                        "status": "UP",
661
                        "status_reason": [],
662
                        "link": "78282c4d5b579265f04ebadc4405ca1b49628eb1d684bb45e5d0607fa8b713d0",
663
                    },
664
                    "endpoint_b": {
665
                        "id": "00:00:00:00:00:00:00:02:2",
666
                        "name": "s2-eth2",
667
                        "port_number": 2,
668
                        "mac": "62:50:49:d7:79:8a",
669
                        "switch": "00:00:00:00:00:00:00:02",
670
                        "type": "interface",
671
                        "nni": True,
672
                        "uni": False,
673
                        "speed": 1250000000.0,
674
                        "metadata": {},
675
                        "lldp": True,
676
                        "active": True,
677
                        "enabled": True,
678
                        "status": "UP",
679
                        "status_reason": [],
680
                        "link": "78282c4d5b579265f04ebadc4405ca1b4 9628eb1d684bb45e5d0607fa8b713d0",
681
                    },
682
                    "metadata": {"s_vlan": {"tag_type": "vlan", "value": 1}},
683
                    "active": True,
684
                    "enabled": True,
685
                    "status": "UP",
686
                    "status_reason": [],
687
                },
688
                {
689
                    "id": "4d42dc0852278accac7d9df15418f6d921db160b13d674029a87cef1b5f67f30",
690
                    "endpoint_a": {
691
                        "id": "00:00:00:00:00:00:00:02:3",
692
                        "name": "s2-eth3",
693
                        "port_number": 3,
694
                        "mac": "76:82:ef:6e:d2:9d",
695
                        "switch": "00:00:00:00:00:00:00:02",
696
                        "type": "interface",
697
                        "nni": True,
698
                        "uni": False,
699
                        "speed": 1250000000.0,
700
                        "metadata": {},
701
                        "lldp": True,
702
                        "active": True,
703
                        "enabled": True,
704
                        "status": "UP",
705
                        "status_reason ": [],
706
                        "link": "4d42dc0852278accac7d9df15418f6d921db160b13d674029a87cef1b5f67f30",
707
                    },
708
                    "endpoint_b": {
709
                        "id": "00:00:00:00:00:00:00:03:2",
710
                        "name": "s3-eth2",
711
                        "port_number": 2,
712
                        "mac": "6a:c1: 51:b1:a9:8a",
713
                        "switch": "00:00:00:00:00:00:00:03",
714
                        "type": "interface",
715
                        "nni": True,
716
                        "uni": False,
717
                        "speed": 1250000000.0,
718
                        "metadata": {},
719
                        "lldp": True,
720
                        "active": True,
721
                        "enabled": True,
722
                        "status": "UP",
723
                        "status_reason": [],
724
                        "link": "4d42dc0852278accac7d9df15418f6d921db160b13d674029a87cef1b5f67f30",
725
                    },
726
                    "metadata": {"s_vlan": {"tag_type": "vlan", "value": 1}},
727
                    "active": True,
728
                    "enabled": True,
729
                    "status": "UP",
730
                    "status_reason": [],
731
                },
732
            ],
733
            "evc_id": "ceaf53b16c3a40",
734
            "id": "ceaf53b16c3a40",
735
            "name": "inter_evpl",
736
            "metadata": {
737
                "telemetry_request": {},
738
                "telemetry": {
739
                    "enabled": True,
740
                    "status": "UP",
741
                    "status_reason": [],
742
                    "status_updated_at": "2024-06-11T16:56:29",
743
                },
744
            },
745
            "active": True,
746
            "enabled": True,
747
            "uni_a": {
748
                "interface_id": "00:00:00:00:00:00:00:01:1",
749
                "tag": {"tag_type": "vlan", "value": 100},
750
            },
751
            "uni_z": {
752
                "interface_id": "00:00:00:00:00:00:00:03:1",
753
                "tag": {"tag_type": "vlan", "value": 100},
754
            },
755
        }
756
    }
757
758
    get_proxy_port_or_raise.side_effect = [pp_a, pp_z]
759
    int_manager._send_flows = AsyncMock()
760
    int_manager._install_int_flows = AsyncMock()
761
    int_manager._remove_int_flows = AsyncMock()
762
    int_manager.remove_int_flows = AsyncMock()
763
    await int_manager.handle_failover_flows(evcs_data, "failover_deployed")
764
    assert int_manager._install_int_flows.call_count == 0
765
    assert int_manager._remove_int_flows.call_count == 1
766
    assert int_manager.remove_int_flows.call_count == 0
767
768
    expected_built_flows = {
769
        "12307967605643950656": [
770
            {
771
                "flow": {
772
                    "cookie": 12163852417568094784,
773
                    "match": {
774
                        "in_port": 4,
775
                        "dl_vlan": 2,
776
                        "dl_type": 2048,
777
                        "nw_proto": 6,
778
                    },
779
                    "cookie_mask": 18446744073709551615,
780
                    "priority": 21100,
781
                    "table_group": "evpl",
782
                    "owner": "telemetry_int",
783
                    "instructions": [
784
                        {
785
                            "instruction_type": "apply_actions",
786
                            "actions": [
787
                                {"action_type": "add_int_metadata"},
788
                                {"action_type": "output", "port": 5},
789
                            ],
790
                        }
791
                    ],
792
                },
793
                "switch": "00:00:00:00:00:00:00:01",
794
            },
795
            {
796
                "flow": {
797
                    "cookie": 12163852417568094784,
798
                    "match": {
799
                        "in_port": 4,
800
                        "dl_vlan": 2,
801
                        "dl_type": 2048,
802
                        "nw_proto": 17,
803
                    },
804
                    "cookie_mask": 18446744073709551615,
805
                    "priority": 21100,
806
                    "table_group": "evpl",
807
                    "owner": "telemetry_int",
808
                    "instructions": [
809
                        {
810
                            "instruction_type": "apply_actions",
811
                            "actions": [
812
                                {"action_type": "add_int_metadata"},
813
                                {"action_type": "output", "port": 5},
814
                            ],
815
                        }
816
                    ],
817
                },
818
                "switch": "00:00:00:00:00:00:00:01",
819
            },
820
            {
821
                "flow": {
822
                    "cookie": 12163852417568094784,
823
                    "match": {"in_port": 6, "dl_vlan": 2},
824
                    "cookie_mask": 18446744073709551615,
825
                    "priority": 21000,
826
                    "table_group": "evpl",
827
                    "owner": "telemetry_int",
828
                    "instructions": [
829
                        {
830
                            "instruction_type": "apply_actions",
831
                            "actions": [{"action_type": "send_report"}],
832
                        },
833
                        {"instruction_type": "goto_table", "table_id": 2},
834
                    ],
835
                },
836
                "switch": "00:00:00:00:00:00:00:01",
837
            },
838
            {
839
                "flow": {
840
                    "cookie": 12163852417568094784,
841
                    "match": {"in_port": 6, "dl_vlan": 2},
842
                    "cookie_mask": 18446744073709551615,
843
                    "priority": 21000,
844
                    "table_group": "evpl",
845
                    "owner": "telemetry_int",
846
                    "instructions": [
847
                        {
848
                            "instruction_type": "apply_actions",
849
                            "actions": [{"action_type": "pop_int"}],
850
                        }
851
                    ],
852
                    "table_id": 2,
853
                },
854
                "switch": "00:00:00:00:00:00:00:01",
855
            },
856
            {
857
                "flow": {
858
                    "cookie": 12163852417568094784,
859
                    "match": {
860
                        "in_port": 3,
861
                        "dl_vlan": 2,
862
                        "dl_type": 2048,
863
                        "nw_proto": 6,
864
                    },
865
                    "cookie_mask": 18446744073709551615,
866
                    "priority": 21100,
867
                    "table_group": "evpl",
868
                    "owner": "telemetry_int",
869
                    "instructions": [
870
                        {
871
                            "instruction_type": "apply_actions",
872
                            "actions": [
873
                                {"action_type": "add_int_metadata"},
874
                                {"action_type": "output", "port": 5},
875
                            ],
876
                        }
877
                    ],
878
                },
879
                "switch": "00:00:00:00:00:00:00:03",
880
            },
881
            {
882
                "flow": {
883
                    "cookie": 12163852417568094784,
884
                    "match": {
885
                        "in_port": 3,
886
                        "dl_vlan": 2,
887
                        "dl_type": 2048,
888
                        "nw_proto": 17,
889
                    },
890
                    "cookie_mask": 18446744073709551615,
891
                    "priority": 21100,
892
                    "table_group": "evpl",
893
                    "owner": "telemetry_int",
894
                    "instructions": [
895
                        {
896
                            "instruction_type": "apply_actions",
897
                            "actions": [
898
                                {"action_type": "add_int_metadata"},
899
                                {"action_type": "output", "port": 5},
900
                            ],
901
                        }
902
                    ],
903
                },
904
                "switch": "00:00:00:00:00:00:00:03",
905
            },
906
            {
907
                "flow": {
908
                    "cookie": 12163852417568094784,
909
                    "match": {"in_port": 6, "dl_vlan": 2},
910
                    "cookie_mask": 18446744073709551615,
911
                    "priority": 21000,
912
                    "table_group": "evpl",
913
                    "owner": "telemetry_int",
914
                    "instructions": [
915
                        {
916
                            "instruction_type": "apply_actions",
917
                            "actions": [{"action_type": "send_report"}],
918
                        },
919
                        {"instruction_type": "goto_table", "table_id": 2},
920
                    ],
921
                },
922
                "switch": "00:00:00:00:00:00:00:03",
923
            },
924
            {
925
                "flow": {
926
                    "cookie": 12163852417568094784,
927
                    "match": {"in_port": 6, "dl_vlan": 2},
928
                    "cookie_mask": 18446744073709551615,
929
                    "priority": 21000,
930
                    "table_group": "evpl",
931
                    "owner": "telemetry_int",
932
                    "instructions": [
933
                        {
934
                            "instruction_type": "apply_actions",
935
                            "actions": [{"action_type": "pop_int"}],
936
                        }
937
                    ],
938
                    "table_id": 2,
939
                },
940
                "switch": "00:00:00:00:00:00:00:03",
941
            },
942
        ]
943
    }
944
    serd = json.dumps(expected_built_flows)
945
    assert json.dumps(int_manager._remove_int_flows.call_args[0][0]) == serd
946