Passed
Pull Request — master (#491)
by Aldo
04:27
created

TestEVC.test_prepare_flow_mod()   A

Complexity

Conditions 1

Size

Total Lines 36
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 29
nop 1
dl 0
loc 36
ccs 13
cts 13
cp 1
crap 1
rs 9.184
c 0
b 0
f 0
1
"""Method to thest EVCDeploy class."""
2 1
import sys
3 1
from unittest.mock import MagicMock, Mock, call, patch
4 1
import operator
5 1
import pytest
6 1
from kytos.lib.helpers import get_controller_mock
7
8 1
from kytos.core.common import EntityStatus
9 1
from kytos.core.exceptions import KytosNoTagAvailableError
10 1
from kytos.core.interface import Interface
11 1
from kytos.core.switch import Switch
12 1
from httpx import TimeoutException
13
# pylint: disable=wrong-import-position
14 1
sys.path.insert(0, "/var/lib/kytos/napps/..")
15
# pylint: enable=wrong-import-position
16
17 1
from napps.kytos.mef_eline.exceptions import (FlowModException,   # NOQA
18
                                              EVCPathNotInstalled,
19
                                              EVCPathNotDeleted)
20 1
from napps.kytos.mef_eline.models import EVC, EVCDeploy, Path  # NOQA
21 1
from napps.kytos.mef_eline.settings import (ANY_SB_PRIORITY,  # NOQA
22
                                            EPL_SB_PRIORITY, EVPL_SB_PRIORITY,
23
                                            MANAGER_URL,
24
                                            SDN_TRACE_CP_URL,
25
                                            UNTAGGED_SB_PRIORITY)
26 1
from napps.kytos.mef_eline.tests.helpers import (get_link_mocked,  # NOQA
27
                                                 get_uni_mocked)
28
29
30
# pylint: disable=too-many-public-methods, too-many-lines
31 1
class TestEVC():
32
    """Tests to verify EVC class."""
33
34 1
    def setup_method(self):
35
        """Setup method"""
36 1
        attributes = {
37
            "controller": get_controller_mock(),
38
            "name": "circuit_for_tests",
39
            "uni_a": get_uni_mocked(is_valid=True),
40
            "uni_z": get_uni_mocked(is_valid=True),
41
        }
42 1
        self.evc_deploy = EVCDeploy(**attributes)
43
44 1
    def test_primary_links_zipped_empty(self):
45
        """Test primary links zipped method."""
46 1
        assert not self.evc_deploy.links_zipped(None)
47
48 1
    @staticmethod
49 1
    @patch("napps.kytos.mef_eline.models.evc.log")
50 1
    def test_should_deploy_case1(log_mock):
51
        """Test should deploy method without primary links."""
52 1
        log_mock.debug.return_value = True
53 1
        attributes = {
54
            "controller": get_controller_mock(),
55
            "name": "custom_name",
56
            "uni_a": get_uni_mocked(is_valid=True),
57
            "uni_z": get_uni_mocked(is_valid=True),
58
        }
59
60 1
        evc = EVC(**attributes)
61 1
        evc.should_deploy()
62 1
        log_mock.debug.assert_called_with("Path is empty.")
63
64 1 View Code Duplication
    @patch("napps.kytos.mef_eline.models.evc.log")
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
65 1
    def test_should_deploy_case2(self, log_mock):
66
        """Test should deploy method with disable circuit."""
67 1
        log_mock.debug.return_value = True
68 1
        attributes = {
69
            "controller": get_controller_mock(),
70
            "name": "custom_name",
71
            "uni_a": get_uni_mocked(is_valid=True),
72
            "uni_z": get_uni_mocked(is_valid=True),
73
            "primary_links": [get_link_mocked(), get_link_mocked()],
74
        }
75 1
        evc = EVC(**attributes)
76
77 1
        assert evc.should_deploy(attributes["primary_links"]) is False
78 1
        log_mock.debug.assert_called_with(f"{evc} is disabled.")
79
80 1 View Code Duplication
    @patch("napps.kytos.mef_eline.models.evc.log")
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
81 1
    def test_should_deploy_case3(self, log_mock):
82
        """Test should deploy method with enabled and not active circuit."""
83 1
        log_mock.debug.return_value = True
84 1
        attributes = {
85
            "controller": get_controller_mock(),
86
            "name": "custom_name",
87
            "uni_a": get_uni_mocked(is_valid=True),
88
            "uni_z": get_uni_mocked(is_valid=True),
89
            "primary_links": [get_link_mocked(), get_link_mocked()],
90
            "enabled": True,
91
        }
92 1
        evc = EVC(**attributes)
93 1
        assert evc.should_deploy(attributes["primary_links"]) is True
94 1
        log_mock.debug.assert_called_with(f"{evc} will be deployed.")
95
96 1
    @patch("napps.kytos.mef_eline.models.evc.log")
97 1
    def test_should_deploy_case4(self, log_mock):
98
        """Test should deploy method with enabled and active circuit."""
99 1
        log_mock.debug.return_value = True
100 1
        attributes = {
101
            "controller": get_controller_mock(),
102
            "name": "custom_name",
103
            "uni_a": get_uni_mocked(is_valid=True),
104
            "uni_z": get_uni_mocked(is_valid=True),
105
            "primary_links": [get_link_mocked(), get_link_mocked()],
106
            "enabled": True,
107
            "active": True,
108
        }
109 1
        evc = EVC(**attributes)
110 1
        assert evc.should_deploy(attributes["primary_links"]) is False
111
112 1
    @patch("napps.kytos.mef_eline.models.evc.httpx")
113 1
    def test_send_flow_mods_case1(self, httpx_mock):
114
        """Test if you are sending flow_mods."""
115 1
        flow_mods = {"id": 20}
116 1
        switch = Mock(spec=Switch, id=1)
117
118 1
        response = MagicMock()
119 1
        response.status_code = 201
120 1
        response.is_server_error = False
121 1
        httpx_mock.post.return_value = response
122
123
        # pylint: disable=protected-access
124 1
        EVC._send_flow_mods(switch.id, flow_mods)
125
126 1
        expected_endpoint = f"{MANAGER_URL}/flows/{switch.id}"
127 1
        expected_data = {"flows": flow_mods, "force": False}
128 1
        assert httpx_mock.post.call_count == 1
129 1
        httpx_mock.post.assert_called_once_with(
130
            expected_endpoint, json=expected_data, timeout=10
131
        )
132
133 1
    @patch("napps.kytos.mef_eline.models.evc.httpx")
134 1
    def test_send_flow_mods_case2(self, httpx_mock):
135
        """Test if you are sending flow_mods."""
136 1
        flow_mods = {"id": 20}
137 1
        switch = Mock(spec=Switch, id=1)
138 1
        response = MagicMock()
139 1
        response.status_code = 201
140 1
        response.is_server_error = False
141 1
        httpx_mock.post.return_value = response
142
143
        # pylint: disable=protected-access
144 1
        EVC._send_flow_mods(switch.id, flow_mods, command='delete', force=True)
145
146 1
        expected_endpoint = f"{MANAGER_URL}/delete/{switch.id}"
147 1
        expected_data = {"flows": flow_mods, "force": True}
148 1
        assert httpx_mock.post.call_count == 1
149 1
        httpx_mock.post.assert_called_once_with(
150
            expected_endpoint, json=expected_data, timeout=10
151
        )
152
153 1
    @patch("time.sleep")
154 1
    @patch("napps.kytos.mef_eline.models.evc.httpx")
155 1
    def test_send_flow_mods_error(self, httpx_mock, _):
156
        """Test flow_manager call fails."""
157 1
        flow_mods = {"id": 20}
158 1
        switch = Mock(spec=Switch, id=1)
159 1
        response = MagicMock()
160 1
        response.status_code = 415
161 1
        httpx_mock.post.return_value = response
162
163
        # pylint: disable=protected-access
164 1
        with pytest.raises(FlowModException):
165 1
            EVC._send_flow_mods(
166
                switch.id,
167
                flow_mods,
168
                command='delete',
169
                force=True
170
            )
171 1
        assert httpx_mock.post.call_count == 3
172
173 1
    def test_prepare_flow_mod(self):
174
        """Test prepare flow_mod method."""
175 1
        interface_a = Interface("eth0", 1, Mock(spec=Switch))
176 1
        interface_z = Interface("eth1", 3, Mock(spec=Switch))
177 1
        attributes = {
178
            "table_group": {"epl": 0, "evpl": 0},
179
            "controller": get_controller_mock(),
180
            "name": "custom_name",
181
            "uni_a": get_uni_mocked(is_valid=True),
182
            "uni_z": get_uni_mocked(is_valid=True),
183
            "primary_links": [get_link_mocked(), get_link_mocked()],
184
            "enabled": True,
185
            "active": True,
186
        }
187 1
        evc = EVC(**attributes)
188
189
        # pylint: disable=protected-access
190 1
        flow_mod = evc._prepare_flow_mod(interface_a, interface_z)
191 1
        expected_flow_mod = {
192
            "match": {"in_port": interface_a.port_number},
193
            "cookie": evc.get_cookie(),
194
            "owner": "mef_eline",
195
            "actions": [
196
                {"action_type": "output", "port": interface_z.port_number}
197
            ],
198
            "priority": EVPL_SB_PRIORITY,
199
            "table_group": "evpl",
200
            "table_id": 0,
201
        }
202 1
        assert expected_flow_mod == flow_mod
203
204 1
        evc.sb_priority = 1234
205 1
        flow_mod = evc._prepare_flow_mod(interface_a, interface_z, 3)
206 1
        assert flow_mod["priority"] == 1234
207 1
        assert flow_mod["actions"][1]["action_type"] == "set_queue"
208 1
        assert flow_mod["actions"][1]["queue_id"] == 3
209
210 1
    def test_prepare_pop_flow(self):
211
        """Test prepare pop flow  method."""
212 1
        attributes = {
213
            "table_group": {"epl": 0, "evpl": 0},
214
            "controller": get_controller_mock(),
215
            "name": "custom_name",
216
            "uni_a": get_uni_mocked(interface_port=1, is_valid=True),
217
            "uni_z": get_uni_mocked(interface_port=2, is_valid=True),
218
        }
219 1
        evc = EVC(**attributes)
220 1
        interface_a = evc.uni_a.interface
221 1
        interface_z = evc.uni_z.interface
222 1
        in_vlan = 10
223
224
        # pylint: disable=protected-access
225 1
        flow_mod = evc._prepare_pop_flow(
226
            interface_a, interface_z, in_vlan
227
        )
228
229 1
        expected_flow_mod = {
230
            "match": {"in_port": interface_a.port_number,
231
                      "dl_vlan": in_vlan},
232
            "cookie": evc.get_cookie(),
233
            "owner": "mef_eline",
234
            "actions": [
235
                {"action_type": "pop_vlan"},
236
                {"action_type": "output", "port": interface_z.port_number},
237
            ],
238
            "priority": EVPL_SB_PRIORITY,
239
            "table_group": "evpl",
240
            "table_id": 0,
241
        }
242 1
        assert expected_flow_mod == flow_mod
243
244
    # pylint: disable=too-many-branches
245 1
    @pytest.mark.parametrize(
246
        "in_vlan_a,in_vlan_z",
247
        [
248
            (100, 50),
249
            (100, 100),
250
            (100, "4096/4096"),
251
            (100, 0),
252
            (100, None),
253
            ("4096/4096", 50),
254
            ("4096/4096", "4096/4096"),
255
            ("4096/4096", 0),
256
            ("4096/4096", None),
257
            (0, 50),
258
            (0, "4096/4096"),
259
            (0, 0),
260
            (0, None),
261
            (None, 50),
262
            (None, "4096/4096"),
263
            (None, 0),
264
            (None, None),
265
        ]
266
    )
267 1
    def test_prepare_push_flow(self, in_vlan_a, in_vlan_z):
268
        """Test prepare push flow method."""
269 1
        attributes = {
270
            "table_group": {"evpl": 3, "epl": 4},
271
            "controller": get_controller_mock(),
272
            "name": "custom_name",
273
            "uni_a": get_uni_mocked(interface_port=1, is_valid=True),
274
            "uni_z": get_uni_mocked(interface_port=2, is_valid=True),
275
        }
276 1
        evc = EVC(**attributes)
277 1
        interface_a = evc.uni_a.interface
278 1
        interface_z = evc.uni_z.interface
279 1
        out_vlan_a = 20
280
281
        # pylint: disable=protected-access
282 1
        flow_mod = evc._prepare_push_flow(interface_a, interface_z,
283
                                          in_vlan_a, out_vlan_a,
284
                                          in_vlan_z)
285 1
        expected_flow_mod = {
286
            'match': {'in_port': interface_a.port_number},
287
            'cookie': evc.get_cookie(),
288
            'owner': 'mef_eline',
289
            'table_id': 3,
290
            'table_group': 'evpl',
291
            'actions': [
292
                {'action_type': 'push_vlan', 'tag_type': 's'},
293
                {'action_type': 'set_vlan', 'vlan_id': out_vlan_a},
294
                {
295
                    'action_type': 'output',
296
                    'port': interface_z.port_number
297
                }
298
            ],
299
            "priority": EVPL_SB_PRIORITY,
300
        }
301 1
        expected_flow_mod["priority"] = evc.get_priority(in_vlan_a)
302 1
        if in_vlan_a is not None:
303 1
            expected_flow_mod['match']['dl_vlan'] = in_vlan_a
304 1
        if in_vlan_z not in evc.special_cases and in_vlan_a != in_vlan_z:
305 1
            new_action = {"action_type": "set_vlan",
306
                          "vlan_id": in_vlan_z}
307 1
            expected_flow_mod["actions"].insert(0, new_action)
308 1
        if in_vlan_a not in evc.special_cases:
309 1
            if in_vlan_z == 0:
310 1
                new_action = {"action_type": "pop_vlan"}
311 1
                expected_flow_mod["actions"].insert(0, new_action)
312 1
        elif in_vlan_a == "4096/4096":
313 1
            if in_vlan_z == 0:
314 1
                new_action = {"action_type": "pop_vlan"}
315 1
                expected_flow_mod["actions"].insert(0, new_action)
316 1
        elif not in_vlan_a:
317 1
            if in_vlan_a is None:
318 1
                expected_flow_mod["table_group"] = "epl"
319 1
                expected_flow_mod["table_id"] = 4
320 1
            if in_vlan_z not in evc.special_cases:
321 1
                new_action = {"action_type": "push_vlan",
322
                              "tag_type": "c"}
323 1
                expected_flow_mod["actions"].insert(0, new_action)
324 1
        assert expected_flow_mod == flow_mod
325
326 1
    @staticmethod
327 1
    @patch("napps.kytos.mef_eline.models.evc.EVC._send_flow_mods")
328 1
    def test_install_uni_flows(send_flow_mods_mock):
329
        """Test install uni flows method.
330
331
        This test will verify the flows send to the send_flow_mods method.
332
        """
333 1
        evc = TestEVC.create_evc_inter_switch()
334
335
        # pylint: disable=protected-access
336 1
        evc._install_uni_flows()
337 1
        send_flow_mods_mock.assert_not_called()
338
339
        # pylint: disable=protected-access
340 1
        uni_flows = evc._install_uni_flows(evc.primary_links)
341 1
        assert uni_flows
342 1
        assert list(uni_flows.keys()) == [evc.uni_a.interface.switch.id,
343
                                          evc.uni_z.interface.switch.id]
344
345 1
        expected_flow_mod_a = [
346
            {
347
                "match": {
348
                    "in_port": evc.uni_a.interface.port_number,
349
                    "dl_vlan": evc.uni_a.user_tag.value,
350
                },
351
                "cookie": evc.get_cookie(),
352
                "owner": "mef_eline",
353
                "table_group": "evpl",
354
                "table_id": 0,
355
                "actions": [
356
                    {
357
                        "action_type": "set_vlan",
358
                        "vlan_id": evc.uni_z.user_tag.value
359
                    },
360
                    {"action_type": "push_vlan", "tag_type": "s"},
361
                    {
362
                        "action_type": "set_vlan",
363
                        "vlan_id": evc.primary_links[0]
364
                        .get_metadata("s_vlan")
365
                        .value,
366
                    },
367
                    {
368
                        "action_type": "output",
369
                        "port": evc.primary_links[0].endpoint_a.port_number,
370
                    },
371
                ],
372
                "priority": EVPL_SB_PRIORITY,
373
            },
374
            {
375
                "match": {
376
                    "in_port": evc.primary_links[0].endpoint_a.port_number,
377
                    "dl_vlan": evc.primary_links[0]
378
                    .get_metadata("s_vlan")
379
                    .value,
380
                },
381
                "cookie": evc.get_cookie(),
382
                "owner": "mef_eline",
383
                "table_group": "evpl",
384
                "table_id": 0,
385
                "actions": [
386
                    {"action_type": "pop_vlan"},
387
                    {
388
                        "action_type": "output",
389
                        "port": evc.uni_a.interface.port_number,
390
                    },
391
                ],
392
                "priority": EVPL_SB_PRIORITY,
393
            },
394
        ]
395
396 1
        send_flow_mods_mock.assert_any_call(
397
            evc.uni_a.interface.switch.id, expected_flow_mod_a
398
        )
399
400 1
        expected_flow_mod_z = [
401
            {
402
                "match": {
403
                    "in_port": evc.uni_z.interface.port_number,
404
                    "dl_vlan": evc.uni_z.user_tag.value,
405
                },
406
                "cookie": evc.get_cookie(),
407
                "owner": "mef_eline",
408
                "table_group": "evpl",
409
                "table_id": 0,
410
                "actions": [
411
                    {
412
                        "action_type": "set_vlan",
413
                        "vlan_id": evc.uni_a.user_tag.value
414
                    },
415
                    {"action_type": "push_vlan", "tag_type": "s"},
416
                    {
417
                        "action_type": "set_vlan",
418
                        "vlan_id": evc.primary_links[-1]
419
                        .get_metadata("s_vlan")
420
                        .value,
421
                    },
422
                    {
423
                        "action_type": "output",
424
                        "port": evc.primary_links[-1].endpoint_b.port_number,
425
                    },
426
                ],
427
                "priority": EVPL_SB_PRIORITY,
428
            },
429
            {
430
                "match": {
431
                    "in_port": evc.primary_links[-1].endpoint_b.port_number,
432
                    "dl_vlan": evc.primary_links[-1]
433
                    .get_metadata("s_vlan")
434
                    .value,
435
                },
436
                "cookie": evc.get_cookie(),
437
                "owner": "mef_eline",
438
                "table_group": "evpl",
439
                "table_id": 0,
440
                "actions": [
441
                    {"action_type": "pop_vlan"},
442
                    {
443
                        "action_type": "output",
444
                        "port": evc.uni_z.interface.port_number,
445
                    },
446
                ],
447
                "priority": EVPL_SB_PRIORITY,
448
            },
449
        ]
450
451 1
        send_flow_mods_mock.assert_any_call(
452
            evc.uni_z.interface.switch.id, expected_flow_mod_z
453
        )
454
455 1
    @staticmethod
456 1
    def create_evc_inter_switch(tag_value_a=82, tag_value_z=83):
457
        """Create inter-switch EVC with two links in the path"""
458 1
        uni_a = get_uni_mocked(
459
            interface_port=2,
460
            tag_value=tag_value_a,
461
            switch_id=1,
462
            switch_dpid=1,
463
            is_valid=True,
464
        )
465 1
        uni_z = get_uni_mocked(
466
            interface_port=3,
467
            tag_value=tag_value_z,
468
            switch_id=3,
469
            switch_dpid=3,
470
            is_valid=True,
471
        )
472
473 1
        attributes = {
474
            "controller": get_controller_mock(),
475
            "name": "custom_name",
476
            "id": "1",
477
            "uni_a": uni_a,
478
            "uni_z": uni_z,
479
            "primary_links": [
480
                get_link_mocked(
481
                    switch_a=Switch(1),
482
                    switch_b=Switch(2),
483
                    endpoint_a_port=9,
484
                    endpoint_b_port=10,
485
                    metadata={"s_vlan": 5},
486
                ),
487
                get_link_mocked(
488
                    switch_a=Switch(2),
489
                    switch_b=Switch(3),
490
                    endpoint_a_port=11,
491
                    endpoint_b_port=12,
492
                    metadata={"s_vlan": 6},
493
                ),
494
            ],
495
            "table_group": {"epl": 0, "evpl": 0}
496
        }
497 1
        return EVC(**attributes)
498
499 1
    @staticmethod
500 1
    @patch("napps.kytos.mef_eline.models.evc.EVC._send_flow_mods")
501 1
    def test_install_nni_flows(send_flow_mods_mock):
502
        """Test install nni flows method.
503
504
        This test will verify the flows send to the send_flow_mods method.
505
        """
506 1
        evc = TestEVC.create_evc_inter_switch()
507
508
        # pylint: disable=protected-access
509 1
        nni_flows = evc._install_nni_flows(evc.primary_links)
510 1
        assert nni_flows
511 1
        dpid = evc.primary_links[0].endpoint_b.switch.id
512 1
        assert list(nni_flows.keys()) == [dpid]
513
514 1
        in_vlan = evc.primary_links[0].get_metadata("s_vlan").value
515 1
        out_vlan = evc.primary_links[-1].get_metadata("s_vlan").value
516
517 1
        in_port = evc.primary_links[0].endpoint_b.port_number
518 1
        out_port = evc.primary_links[-1].endpoint_a.port_number
519
520 1
        expected_flow_mods = [
521
            {
522
                "match": {"in_port": in_port, "dl_vlan": in_vlan},
523
                "cookie": evc.get_cookie(),
524
                "owner": "mef_eline",
525
                "table_group": "evpl",
526
                "table_id": 0,
527
                "actions": [
528
                    {"action_type": "set_vlan", "vlan_id": out_vlan},
529
                    {"action_type": "output", "port": out_port},
530
                ],
531
                "priority": EVPL_SB_PRIORITY
532
            },
533
            {
534
                "match": {"in_port": out_port, "dl_vlan": out_vlan},
535
                "cookie": evc.get_cookie(),
536
                "owner": "mef_eline",
537
                "table_group": "evpl",
538
                "table_id": 0,
539
                "actions": [
540
                    {"action_type": "set_vlan", "vlan_id": in_vlan},
541
                    {"action_type": "output", "port": in_port},
542
                ],
543
                "priority": EVPL_SB_PRIORITY,
544
            },
545
        ]
546
547 1
        dpid = evc.primary_links[0].endpoint_b.switch.id
548 1
        send_flow_mods_mock.assert_called_once_with(dpid, expected_flow_mods)
549
550 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy._send_flow_mods")
551 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy._prepare_nni_flows")
552 1
    def test_install_nni_flows_error(self, prepare_nni_mock, send_flow_mock):
553
        """Test _install_nni_flows with error"""
554 1
        prepare_nni_mock.return_value = {'1': 1}
555 1
        send_flow_mock.side_effect = FlowModException('err')
556 1
        with pytest.raises(EVCPathNotInstalled):
557 1
            self.evc_deploy._install_nni_flows()
558
559 1
    @patch("httpx.post")
560 1
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
561 1
    @patch("napps.kytos.mef_eline.models.evc.log")
562 1
    @patch("napps.kytos.mef_eline.models.path.Path.choose_vlans")
563 1
    @patch("napps.kytos.mef_eline.models.evc.EVC._install_nni_flows")
564 1
    @patch("napps.kytos.mef_eline.models.evc.EVC._install_uni_flows")
565 1
    @patch("napps.kytos.mef_eline.models.evc.EVC._install_direct_uni_flows")
566 1
    @patch("napps.kytos.mef_eline.models.evc.EVC.activate")
567 1
    @patch("napps.kytos.mef_eline.models.evc.EVC.should_deploy")
568 1
    def test_deploy_successfully(self, *args):
569
        """Test if all methods to deploy are called."""
570
        # pylint: disable=too-many-locals
571 1
        (
572
            should_deploy_mock,
573
            activate_mock,
574
            install_direct_uni_flows_mock,
575
            install_uni_flows_mock,
576
            install_nni_flows,
577
            chose_vlans_mock,
578
            log_mock,
579
            _,
580
            httpx_mock,
581
        ) = args
582
583 1
        response = MagicMock()
584 1
        response.status_code = 201
585 1
        httpx_mock.return_value = response
586
587 1
        should_deploy_mock.return_value = True
588 1
        evc = self.create_evc_inter_switch()
589 1
        deployed = evc.deploy_to_path(evc.primary_links)
590
591 1
        assert should_deploy_mock.call_count == 1
592 1
        assert activate_mock.call_count == 1
593 1
        assert install_uni_flows_mock.call_count == 1
594 1
        assert install_nni_flows.call_count == 1
595 1
        assert chose_vlans_mock.call_count == 1
596 1
        log_mock.info.assert_called_with(f"{evc} was deployed.")
597 1
        assert deployed is True
598 1
        assert not evc.error_status
599
600
        # intra switch EVC
601 1
        evc = self.create_evc_intra_switch()
602 1
        assert evc.deploy_to_path(evc.primary_links) is True
603 1
        assert install_direct_uni_flows_mock.call_count == 1
604 1
        assert activate_mock.call_count == 2
605 1
        assert log_mock.info.call_count == 2
606 1
        assert not evc.error_status
607 1
        log_mock.info.assert_called_with(f"{evc} was deployed.")
608
609 1
    @patch("httpx.post")
610 1
    @patch("napps.kytos.mef_eline.models.evc.log")
611 1
    @patch("napps.kytos.mef_eline.models.evc.EVC.discover_new_paths")
612 1
    @patch("napps.kytos.mef_eline.models.path.Path.choose_vlans")
613 1
    @patch("napps.kytos.mef_eline.models.evc.EVC._install_nni_flows")
614 1
    @patch("napps.kytos.mef_eline.models.evc.EVC._install_uni_flows")
615 1
    @patch("napps.kytos.mef_eline.models.evc.EVC.activate")
616 1
    @patch("napps.kytos.mef_eline.models.evc.EVC.should_deploy")
617 1
    @patch("napps.kytos.mef_eline.models.EVC.sync")
618 1
    def test_deploy_fail(self, *args):
619
        """Test if all methods is ignored when the should_deploy is false."""
620
        # pylint: disable=too-many-locals
621 1
        (
622
            sync_mock,
623
            should_deploy_mock,
624
            activate_mock,
625
            install_uni_flows_mock,
626
            install_nni_flows,
627
            choose_vlans_mock,
628
            discover_new_paths_mock,
629
            log_mock,
630
            httpx_mock,
631
        ) = args
632
633 1
        response = MagicMock()
634 1
        response.status_code = 201
635 1
        httpx_mock.return_value = response
636
637 1
        evc = self.create_evc_inter_switch()
638 1
        should_deploy_mock.return_value = False
639 1
        discover_new_paths_mock.return_value = []
640 1
        deployed = evc.deploy_to_path()
641
642 1
        assert discover_new_paths_mock.call_count == 1
643 1
        assert should_deploy_mock.call_count == 1
644 1
        assert activate_mock.call_count == 0
645 1
        assert install_uni_flows_mock.call_count == 0
646 1
        assert install_nni_flows.call_count == 0
647 1
        assert choose_vlans_mock.call_count == 0
648 1
        assert log_mock.info.call_count == 0
649 1
        assert sync_mock.call_count == 0
650 1
        assert deployed is False
651
652
        # NoTagAvailable on static path
653 1
        should_deploy_mock.return_value = True
654 1
        choose_vlans_mock.side_effect = KytosNoTagAvailableError(MagicMock())
655 1
        assert evc.deploy_to_path(evc.primary_links) is False
656
657
        # NoTagAvailable on dynamic path
658 1
        should_deploy_mock.return_value = False
659 1
        discover_new_paths_mock.return_value = [Path(['a', 'b'])]
660 1
        choose_vlans_mock.side_effect = KytosNoTagAvailableError(MagicMock())
661 1
        assert evc.deploy_to_path(evc.primary_links) is False
662 1
        assert not evc.error_status
663
664 1
    @patch("napps.kytos.mef_eline.models.evc.log")
665 1
    @patch(
666
        "napps.kytos.mef_eline.models.evc.EVC.discover_new_paths",
667
        return_value=[],
668
    )
669 1
    @patch("napps.kytos.mef_eline.models.path.Path.choose_vlans")
670 1
    @patch("napps.kytos.mef_eline.models.evc.EVC._install_nni_flows")
671 1
    @patch("napps.kytos.mef_eline.models.evc.EVC.should_deploy")
672 1
    @patch("napps.kytos.mef_eline.models.evc.EVC.remove_current_flows")
673 1
    @patch("napps.kytos.mef_eline.models.evc.EVC.sync")
674 1
    def test_deploy_error(self, *args):
675
        """Test if all methods is ignored when the should_deploy is false."""
676
        # pylint: disable=too-many-locals
677 1
        (
678
            sync_mock,
679
            remove_current_flows,
680
            should_deploy_mock,
681
            install_nni_flows,
682
            choose_vlans_mock,
683
            discover_new_paths,
684
            log_mock,
685
        ) = args
686
687 1
        install_nni_flows.side_effect = EVCPathNotInstalled
688 1
        should_deploy_mock.return_value = True
689 1
        uni_a = get_uni_mocked(
690
            interface_port=2,
691
            tag_value=82,
692
            switch_id="switch_uni_a",
693
            is_valid=True,
694
        )
695 1
        uni_z = get_uni_mocked(
696
            interface_port=3,
697
            tag_value=83,
698
            switch_id="switch_uni_z",
699
            is_valid=True,
700
        )
701
702 1
        primary_links = [
703
            get_link_mocked(
704
                endpoint_a_port=9, endpoint_b_port=10, metadata={"s_vlan": 5}
705
            ),
706
            get_link_mocked(
707
                endpoint_a_port=11, endpoint_b_port=12, metadata={"s_vlan": 6}
708
            ),
709
        ]
710
711 1
        attributes = {
712
            "controller": get_controller_mock(),
713
            "name": "custom_name",
714
            "uni_a": uni_a,
715
            "uni_z": uni_z,
716
            "primary_links": primary_links,
717
            "queue_id": 5,
718
        }
719
        # Setup path to deploy
720 1
        path = Path()
721 1
        path.append(primary_links[0])
722 1
        path.append(primary_links[1])
723
724 1
        evc = EVC(**attributes)
725
726 1
        deployed = evc.deploy_to_path(path)
727
728 1
        assert discover_new_paths.call_count == 0
729 1
        assert should_deploy_mock.call_count == 1
730 1
        assert install_nni_flows.call_count == 1
731 1
        assert choose_vlans_mock.call_count == 1
732 1
        assert log_mock.error.call_count == 1
733 1
        assert sync_mock.call_count == 1
734 1
        assert remove_current_flows.call_count == 1
735 1
        assert evc.error_status['current_path']
736 1
        assert deployed is False
737
738 1
    @patch("napps.kytos.mef_eline.models.evc.emit_event")
739 1
    @patch("napps.kytos.mef_eline.models.evc.EVC.get_failover_path_candidates")
740 1
    @patch("napps.kytos.mef_eline.models.evc.EVC._install_nni_flows")
741 1
    @patch("napps.kytos.mef_eline.models.evc.EVC._install_uni_flows")
742 1
    @patch("napps.kytos.mef_eline.models.evc.EVC.remove_path_flows")
743 1
    @patch("napps.kytos.mef_eline.models.EVC.sync")
744 1
    def test_setup_failover_path(self, *args):
745
        """Test setup_failover_path method."""
746 1
        (
747
            sync_mock,
748
            remove_path_flows_mock,
749
            install_uni_flows_mock,
750
            install_nni_flows_mock,
751
            get_failover_path_candidates_mock,
752
            emit_event_mock,
753
        ) = args
754
755
        # case1: early return intra switch
756 1
        evc1 = self.create_evc_intra_switch()
757
758 1
        assert evc1.setup_failover_path() is False
759 1
        assert sync_mock.call_count == 0
760
761
        # case2: early return not eligible for path failover
762 1
        evc2 = self.create_evc_inter_switch()
763 1
        evc2.is_eligible_for_failover_path = MagicMock(return_value=False)
764
765 1
        assert evc2.setup_failover_path() is False
766 1
        assert sync_mock.call_count == 0
767
768
        # case3: error deleting previous failover_path
769 1
        evc2.is_eligible_for_failover_path = MagicMock(return_value=True)
770 1
        remove_path_flows_mock.side_effect = EVCPathNotDeleted('err')
771 1
        assert evc2.setup_failover_path() is False
772 1
        assert evc2.error_status['failover_path']
773 1
        assert emit_event_mock.call_count == 1
774 1
        assert sync_mock.call_count == 1
775
776
        # case3: success failover_path setup
777 1
        remove_path_flows_mock.side_effect = None
778 1
        evc2.failover_path = ["link1", "link2"]
779 1
        path_mock = MagicMock()
780 1
        path_mock.__iter__.return_value = ["link3"]
781 1
        get_failover_path_candidates_mock.return_value = [None, path_mock]
782 1
        mock_choose = path_mock.choose_vlans
783
784 1
        assert evc2.setup_failover_path() is True
785 1
        remove_path_flows_mock.assert_called_with(["link1", "link2"])
786 1
        mock_choose.assert_called()
787 1
        install_nni_flows_mock.assert_called_with(path_mock)
788 1
        install_uni_flows_mock.assert_called_with(path_mock, skip_in=True)
789 1
        assert evc2.failover_path == path_mock
790 1
        assert sync_mock.call_count == 2
791 1
        assert emit_event_mock.call_count == 2
792 1
        assert emit_event_mock.call_args[0][1] == "failover_deployed"
793 1
        assert not evc2.error_status
794
795
        # case 4: failed to setup failover_path - No Tag available
796 1
        evc2.failover_path = []
797 1
        mock_choose.side_effect = KytosNoTagAvailableError(MagicMock())
798 1
        sync_mock.call_count = 0
799
800 1
        assert evc2.setup_failover_path() is False
801 1
        assert len(list(evc2.failover_path)) == 0
802 1
        assert sync_mock.call_count == 1
803 1
        assert not evc2.error_status
804
805
        # case 5: failed to setup failover_path - FlowMod exception
806 1
        evc2.failover_path = []
807 1
        mock_choose.side_effect = None
808 1
        install_nni_flows_mock.side_effect = EVCPathNotInstalled("error")
809 1
        sync_mock.call_count = 0
810
811 1
        assert evc2.setup_failover_path() is False
812 1
        assert len(list(evc2.failover_path)) == 1
813 1
        assert sync_mock.call_count == 1
814 1
        remove_path_flows_mock.assert_called_with([])
815 1
        assert evc2.error_status['failover_path']
816
817 1
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy_to_path")
818 1
    @patch("napps.kytos.mef_eline.models.evc.EVC.discover_new_paths")
819 1
    def test_deploy_to_backup_path1(
820
        self, discover_new_paths_mocked, deploy_to_path_mocked
821
    ):
822
        """Test deployment when dynamic_backup_path is False in same switch"""
823 1
        uni_a = get_uni_mocked(interface_port=2, tag_value=82, is_valid=True)
824 1
        uni_z = get_uni_mocked(interface_port=3, tag_value=83, is_valid=True)
825
826 1
        switch = Mock(spec=Switch)
827 1
        uni_a.interface.switch = switch
828 1
        uni_z.interface.switch = switch
829
830 1
        attributes = {
831
            "controller": get_controller_mock(),
832
            "name": "custom_name",
833
            "uni_a": uni_a,
834
            "uni_z": uni_z,
835
            "enabled": True,
836
            "dynamic_backup_path": False,
837
        }
838
839 1
        evc = EVC(**attributes)
840 1
        discover_new_paths_mocked.return_value = []
841 1
        deploy_to_path_mocked.return_value = True
842
843 1
        deployed = evc.deploy_to_backup_path()
844
845 1
        deploy_to_path_mocked.assert_called_once_with()
846 1
        assert deployed is True
847
848 1
    @patch("httpx.post")
849 1
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
850 1
    @patch("napps.kytos.mef_eline.models.evc.log")
851 1
    @patch("napps.kytos.mef_eline.models.path.Path.choose_vlans")
852 1
    @patch("napps.kytos.mef_eline.models.evc.EVC._install_nni_flows")
853 1
    @patch("napps.kytos.mef_eline.models.evc.EVC._install_uni_flows")
854 1
    @patch("napps.kytos.mef_eline.models.evc.EVC.activate")
855 1
    @patch("napps.kytos.mef_eline.models.evc.EVC.should_deploy")
856 1
    @patch("napps.kytos.mef_eline.models.evc.EVC.discover_new_paths")
857 1
    def test_deploy_without_path_case1(self, *args):
858
        """Test if not path is found a dynamic path is used."""
859
        # pylint: disable=too-many-locals
860 1
        (
861
            discover_new_paths_mocked,
862
            should_deploy_mock,
863
            activate_mock,
864
            install_uni_flows_mock,
865
            install_nni_flows,
866
            chose_vlans_mock,
867
            log_mock,
868
            _,
869
            httpx_mock,
870
        ) = args
871
872 1
        response = MagicMock()
873 1
        response.status_code = 201
874 1
        httpx_mock.return_value = response
875
876 1
        should_deploy_mock.return_value = False
877 1
        uni_a = get_uni_mocked(
878
            interface_port=2,
879
            tag_value=82,
880
            switch_id="switch_uni_a",
881
            is_valid=True,
882
        )
883 1
        uni_z = get_uni_mocked(
884
            interface_port=3,
885
            tag_value=83,
886
            switch_id="switch_uni_z",
887
            is_valid=True,
888
        )
889
890 1
        attributes = {
891
            "controller": get_controller_mock(),
892
            "name": "custom_name",
893
            "uni_a": uni_a,
894
            "uni_z": uni_z,
895
            "enabled": True,
896
            "dynamic_backup_path": False,
897
        }
898
899 1
        dynamic_backup_path = Path(
900
            [
901
                get_link_mocked(
902
                    endpoint_a_port=9,
903
                    endpoint_b_port=10,
904
                    metadata={"s_vlan": 5},
905
                ),
906
                get_link_mocked(
907
                    endpoint_a_port=11,
908
                    endpoint_b_port=12,
909
                    metadata={"s_vlan": 6},
910
                ),
911
            ]
912
        )
913
914 1
        evc = EVC(**attributes)
915 1
        discover_new_paths_mocked.return_value = [dynamic_backup_path]
916
917 1
        deployed = evc.deploy_to_path()
918
919 1
        assert should_deploy_mock.call_count == 1
920 1
        assert discover_new_paths_mocked.call_count == 1
921 1
        assert activate_mock.call_count == 1
922 1
        assert install_uni_flows_mock.call_count == 1
923 1
        assert install_nni_flows.call_count == 1
924 1
        assert chose_vlans_mock.call_count == 1
925 1
        log_mock.info.assert_called_with(f"{evc} was deployed.")
926 1
        assert deployed is True
927
928 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.deploy_to_primary_path")
929 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.deploy_to_backup_path")
930 1
    @patch("napps.kytos.mef_eline.models.evc.emit_event")
931 1
    def test_deploy(self, *args):
932
        """Test method deploy"""
933 1
        (emit_event_mock, deploy_primary_mock, deploy_backup_mock) = args
934
935
        # case 1: deploy to primary
936 1
        self.evc_deploy.archived = False
937 1
        deploy_primary_mock.return_value = True
938 1
        assert self.evc_deploy.deploy()
939 1
        assert emit_event_mock.call_count == 1
940
941
        # case 2: deploy to backup
942 1
        deploy_primary_mock.return_value = False
943 1
        deploy_backup_mock.return_value = True
944 1
        assert self.evc_deploy.deploy()
945 1
        assert emit_event_mock.call_count == 2
946
947
        # case 3: fail to deploy to primary and backup
948 1
        deploy_backup_mock.return_value = False
949 1
        assert self.evc_deploy.deploy() is False
950 1
        assert emit_event_mock.call_count == 2
951
952
        # case 4: archived
953 1
        self.evc_deploy.archived = True
954 1
        assert self.evc_deploy.deploy() is False
955 1
        assert emit_event_mock.call_count == 2
956
957 1
    @patch("napps.kytos.mef_eline.models.evc.EVCBase.sync")
958 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.clean_errors")
959 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.remove_current_flows")
960 1
    def test_deploy_to_path_error(
961
        self, remove_current_mock, clean_mock, sync_mock
962
    ):
963
        """Test deploy_to_path"""
964 1
        remove_current_mock.side_effect = EVCPathNotDeleted('err')
965 1
        result = self.evc_deploy.deploy_to_path()
966 1
        assert result is False
967 1
        assert sync_mock.call_count == 1
968 1
        assert clean_mock.call_count == 1
969
970 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.remove_current_flows")
971 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.sync")
972 1
    @patch("napps.kytos.mef_eline.models.evc.emit_event")
973 1
    def test_remove(self, *args):
974
        """Test method remove"""
975 1
        (emit_event_mock, sync_mock, remove_flows_mock) = args
976 1
        self.evc_deploy.remove()
977 1
        remove_flows_mock.assert_called()
978 1
        sync_mock.assert_called()
979 1
        emit_event_mock.assert_called()
980 1
        assert self.evc_deploy.is_enabled() is False
981
982 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.deactivate_set_error")
983 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.remove_failover_flows")
984 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.remove_current_flows")
985 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.sync")
986 1
    def test_remove_error(self, *args):
987
        """Test remove with error"""
988 1
        (sync_mock, remove_current_mock,
989
         remove_failover_mock, de_err_mock) = args
990 1
        remove_failover_mock.side_effect = EVCPathNotDeleted('err')
991 1
        with pytest.raises(EVCPathNotDeleted):
992 1
            self.evc_deploy.remove()
993 1
        assert remove_current_mock.call_count == 1
994 1
        assert de_err_mock.call_args[0][0] == 'failover_path'
995 1
        assert sync_mock.call_count == 1
996
997 1
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
998 1
    @patch("napps.kytos.mef_eline.models.evc.EVC._send_flow_mods")
999 1
    @patch("napps.kytos.mef_eline.models.evc.log.error")
1000 1
    def test_remove_current_flows(self, *args):
1001
        """Test remove current flows."""
1002
        # pylint: disable=too-many-locals
1003 1
        (log_error_mock, send_flow_mods_mocked, _) = args
1004 1
        uni_a = get_uni_mocked(
1005
            interface_port=2,
1006
            tag_value=82,
1007
            switch_id="switch_uni_a",
1008
            is_valid=True,
1009
        )
1010 1
        uni_z = get_uni_mocked(
1011
            interface_port=3,
1012
            tag_value=83,
1013
            switch_id="switch_uni_z",
1014
            is_valid=True,
1015
        )
1016
1017 1
        switch_a = Switch("00:00:00:00:00:01")
1018 1
        switch_b = Switch("00:00:00:00:00:02")
1019 1
        switch_c = Switch("00:00:00:00:00:03")
1020
1021 1
        attributes = {
1022
            "controller": get_controller_mock(),
1023
            "name": "custom_name",
1024
            "uni_a": uni_a,
1025
            "uni_z": uni_z,
1026
            "active": True,
1027
            "enabled": True,
1028
            "primary_links": [
1029
                get_link_mocked(
1030
                    switch_a=switch_a,
1031
                    switch_b=switch_b,
1032
                    endpoint_a_port=9,
1033
                    endpoint_b_port=10,
1034
                    metadata={"s_vlan": 5},
1035
                ),
1036
                get_link_mocked(
1037
                    switch_a=switch_b,
1038
                    switch_b=switch_c,
1039
                    endpoint_a_port=11,
1040
                    endpoint_b_port=12,
1041
                    metadata={"s_vlan": 6},
1042
                ),
1043
            ],
1044
        }
1045
1046 1
        evc = EVC(**attributes)
1047
1048 1
        evc.current_path = evc.primary_links
1049 1
        send_flow_mods_mocked.side_effect = FlowModException('err')
1050 1
        send_flow_mods_mocked.return_value = True
1051 1
        with pytest.raises(EVCPathNotDeleted):
1052 1
            evc.remove_current_flows()
1053 1
        send_flow_mods_mocked.side_effect = None
1054 1
        evc.remove_current_flows()
1055
1056 1
        assert send_flow_mods_mocked.call_count == 6
1057 1
        assert evc.is_active() is False
1058 1
        flows = [
1059
            {"cookie": evc.get_cookie(), "cookie_mask": 18446744073709551615}
1060
        ]
1061 1
        switch_1 = evc.primary_links[0].endpoint_a.switch
1062 1
        switch_2 = evc.primary_links[0].endpoint_b.switch
1063 1
        send_flow_mods_mocked.assert_any_call(switch_1.id, flows, 'delete',
1064
                                              force=True)
1065 1
        send_flow_mods_mocked.assert_any_call(switch_2.id, flows, 'delete',
1066
                                              force=True)
1067
1068 1
        send_flow_mods_mocked.side_effect = FlowModException("error")
1069 1
        evc.remove_current_flows()
1070 1
        log_error_mock.assert_called()
1071
1072 1
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
1073 1
    @patch("napps.kytos.mef_eline.models.evc.EVC._send_flow_mods")
1074 1
    @patch("napps.kytos.mef_eline.models.evc.log.error")
1075 1
    def test_remove_failover_flows_exclude_uni_switches(self, *args):
1076
        """Test remove failover flows excluding UNI switches."""
1077
        # pylint: disable=too-many-locals
1078 1
        (log_error_mock, send_flow_mods_mocked, mock_upsert) = args
1079 1
        uni_a = get_uni_mocked(
1080
            interface_port=2,
1081
            tag_value=82,
1082
            switch_id="00:00:00:00:00:00:00:01",
1083
            is_valid=True,
1084
        )
1085 1
        uni_z = get_uni_mocked(
1086
            interface_port=3,
1087
            tag_value=83,
1088
            switch_id="00:00:00:00:00:00:00:03",
1089
            is_valid=True,
1090
        )
1091
1092 1
        switch_a = Switch("00:00:00:00:00:00:00:01")
1093 1
        switch_b = Switch("00:00:00:00:00:00:00:02")
1094 1
        switch_c = Switch("00:00:00:00:00:00:00:03")
1095
1096 1
        attributes = {
1097
            "controller": get_controller_mock(),
1098
            "name": "custom_name",
1099
            "uni_a": uni_a,
1100
            "uni_z": uni_z,
1101
            "active": True,
1102
            "enabled": True,
1103
            "failover_path": [
1104
                get_link_mocked(
1105
                    switch_a=switch_a,
1106
                    switch_b=switch_b,
1107
                    endpoint_a_port=9,
1108
                    endpoint_b_port=10,
1109
                    metadata={"s_vlan": 5},
1110
                ),
1111
                get_link_mocked(
1112
                    switch_a=switch_b,
1113
                    switch_b=switch_c,
1114
                    endpoint_a_port=11,
1115
                    endpoint_b_port=12,
1116
                    metadata={"s_vlan": 6},
1117
                ),
1118
            ],
1119
        }
1120
1121 1
        evc = EVC(**attributes)
1122
1123 1
        send_flow_mods_mocked.side_effect = [
1124
            FlowModException('err'), None
1125
        ]
1126 1
        with pytest.raises(EVCPathNotDeleted):
1127 1
            evc.remove_failover_flows(exclude_uni_switches=True, sync=True)
1128
1129 1
        evc.remove_failover_flows(exclude_uni_switches=True, sync=True)
1130
1131 1
        assert send_flow_mods_mocked.call_count == 2
1132 1
        flows = [
1133
            {"cookie": evc.get_cookie(),
1134
             "cookie_mask": int(0xffffffffffffffff)}
1135
        ]
1136 1
        send_flow_mods_mocked.assert_any_call(switch_b.id, flows, 'delete',
1137
                                              force=True)
1138 1
        assert mock_upsert.call_count == 1
1139
1140 1
        send_flow_mods_mocked.side_effect = FlowModException("error")
1141 1
        evc.remove_current_flows()
1142 1
        log_error_mock.assert_called()
1143
1144 1
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
1145 1
    @patch("napps.kytos.mef_eline.models.evc.EVC._send_flow_mods")
1146 1
    def test_remove_failover_flows_include_all(self, *args):
1147
        """Test remove failover flows including UNI switches."""
1148
        # pylint: disable=too-many-locals
1149 1
        (send_flow_mods_mocked, mock_upsert) = args
1150 1
        uni_a = get_uni_mocked(
1151
            interface_port=2,
1152
            tag_value=82,
1153
            switch_id="00:00:00:00:00:00:00:01",
1154
            is_valid=True,
1155
        )
1156 1
        uni_z = get_uni_mocked(
1157
            interface_port=3,
1158
            tag_value=83,
1159
            switch_id="00:00:00:00:00:00:00:03",
1160
            is_valid=True,
1161
        )
1162
1163 1
        switch_a = Switch("00:00:00:00:00:00:00:01")
1164 1
        switch_b = Switch("00:00:00:00:00:00:00:02")
1165 1
        switch_c = Switch("00:00:00:00:00:00:00:03")
1166
1167 1
        attributes = {
1168
            "controller": get_controller_mock(),
1169
            "name": "custom_name",
1170
            "uni_a": uni_a,
1171
            "uni_z": uni_z,
1172
            "active": True,
1173
            "enabled": True,
1174
            "failover_path": [
1175
                get_link_mocked(
1176
                    switch_a=switch_a,
1177
                    switch_b=switch_b,
1178
                    endpoint_a_port=9,
1179
                    endpoint_b_port=10,
1180
                    metadata={"s_vlan": 5},
1181
                ),
1182
                get_link_mocked(
1183
                    switch_a=switch_b,
1184
                    switch_b=switch_c,
1185
                    endpoint_a_port=11,
1186
                    endpoint_b_port=12,
1187
                    metadata={"s_vlan": 6},
1188
                ),
1189
            ],
1190
        }
1191
1192 1
        evc = EVC(**attributes)
1193 1
        evc.remove_failover_flows(exclude_uni_switches=False, sync=True)
1194
1195 1
        assert send_flow_mods_mocked.call_count == 3
1196 1
        flows = [
1197
            {"cookie": evc.get_cookie(),
1198
             "cookie_mask": int(0xffffffffffffffff)}
1199
        ]
1200 1
        send_flow_mods_mocked.assert_any_call(switch_a.id, flows, 'delete',
1201
                                              force=True)
1202 1
        send_flow_mods_mocked.assert_any_call(switch_b.id, flows, 'delete',
1203
                                              force=True)
1204 1
        send_flow_mods_mocked.assert_any_call(switch_c.id, flows, 'delete',
1205
                                              force=True)
1206 1
        assert mock_upsert.call_count == 1
1207
1208 1
    @staticmethod
1209 1
    def create_evc_intra_switch():
1210
        """Create intra-switch EVC."""
1211 1
        switch = Mock(spec=Switch)
1212 1
        switch.dpid = 2
1213 1
        switch.id = switch.dpid
1214 1
        interface_a = Interface("eth0", 1, switch)
1215 1
        interface_z = Interface("eth1", 3, switch)
1216 1
        uni_a = get_uni_mocked(
1217
            tag_value=82,
1218
            is_valid=True,
1219
        )
1220 1
        uni_z = get_uni_mocked(
1221
            tag_value=84,
1222
            is_valid=True,
1223
        )
1224 1
        uni_a.interface = interface_a
1225 1
        uni_z.interface = interface_z
1226 1
        attributes = {
1227
            "table_group": {"epl": 0, "evpl": 0},
1228
            "controller": get_controller_mock(),
1229
            "name": "custom_name",
1230
            "id": "1",
1231
            "uni_a": uni_a,
1232
            "uni_z": uni_z,
1233
            "enabled": True,
1234
        }
1235 1
        return EVC(**attributes)
1236
1237
    # pylint: disable=too-many-branches
1238 1
    @pytest.mark.parametrize(
1239
        "uni_a,uni_z",
1240
        [
1241
            (100, 50),
1242
            (100, "4096/4096"),
1243
            (100, 0),
1244
            (100, None),
1245
            ("4096/4096", 50),
1246
            ("4096/4096", "4096/4096"),
1247
            ("4096/4096", 0),
1248
            ("4096/4096", None),
1249
            (0, 50),
1250
            (0, "4096/4096"),
1251
            (0, 0),
1252
            (0, None),
1253
            (None, 50),
1254
            (None, "4096/4096"),
1255
            (None, 0),
1256
            (None, None),
1257
        ]
1258
    )
1259 1
    @patch("napps.kytos.mef_eline.models.evc.EVC._send_flow_mods")
1260 1
    def test_deploy_direct_uni_flows(self, send_flow_mods_mock, uni_a, uni_z):
1261
        """Test _install_direct_uni_flows"""
1262 1
        evc = TestEVC.create_evc_intra_switch()
1263 1
        expected_dpid = evc.uni_a.interface.switch.id
1264
1265 1
        expected_flows = [
1266
            {
1267
                "match": {"in_port": 1},
1268
                "cookie": evc.get_cookie(),
1269
                "owner": "mef_eline",
1270
                "table_id": 0,
1271
                "table_group": "epl",
1272
                "actions": [
1273
                    {"action_type": "output", "port": 3},
1274
                ],
1275
                "priority": EPL_SB_PRIORITY
1276
            },
1277
            {
1278
                "match": {"in_port": 3},
1279
                "cookie": evc.get_cookie(),
1280
                "owner": "mef_eline",
1281
                "table_id": 0,
1282
                "table_group": "epl",
1283
                "actions": [
1284
                    {"action_type": "output", "port": 1},
1285
                ],
1286
                "priority": EPL_SB_PRIORITY
1287
            }
1288
        ]
1289 1
        evc.uni_a = get_uni_mocked(tag_value=uni_a, is_valid=True)
1290 1
        evc.uni_a.interface.port_number = 1
1291 1
        evc.uni_z = get_uni_mocked(tag_value=uni_z, is_valid=True)
1292 1
        evc.uni_z.interface.port_number = 3
1293 1
        expected_dpid = evc.uni_a.interface.switch.id
1294 1
        evc._install_direct_uni_flows()
1295 1
        if uni_a is not None:
1296 1
            expected_flows[0]["match"]["dl_vlan"] = uni_a
1297 1
            expected_flows[0]["table_group"] = "evpl"
1298 1
        if uni_z is not None:
1299 1
            expected_flows[1]["match"]["dl_vlan"] = uni_z
1300 1
            expected_flows[1]["table_group"] = "evpl"
1301 1
        expected_flows[0]["priority"] = EVC.get_priority(uni_a)
1302 1
        expected_flows[1]["priority"] = EVC.get_priority(uni_z)
1303 1
        if uni_z not in evc.special_cases:
1304 1
            expected_flows[0]["actions"].insert(
1305
                0, {"action_type": "set_vlan", "vlan_id": uni_z}
1306
            )
1307 1
        if uni_a not in evc.special_cases:
1308 1
            expected_flows[1]["actions"].insert(
1309
                    0, {"action_type": "set_vlan",
1310
                        "vlan_id": uni_a}
1311
                )
1312 1
            if not uni_z:
1313 1
                expected_flows[1]["actions"].insert(
1314
                    0, {"action_type": "push_vlan",
1315
                        "tag_type": "c"}
1316
                )
1317 1
            if uni_z == 0:
1318 1
                new_action = {"action_type": "pop_vlan"}
1319 1
                expected_flows[0]["actions"].insert(0, new_action)
1320 1
        elif uni_a == "4096/4096":
1321 1
            if uni_z == 0:
1322 1
                new_action = {"action_type": "pop_vlan"}
1323 1
                expected_flows[0]["actions"].insert(0, new_action)
1324 1
        elif uni_a == 0:
1325 1
            if uni_z not in evc.special_cases:
1326 1
                expected_flows[0]["actions"].insert(
1327
                    0, {"action_type": "push_vlan",
1328
                        "tag_type": "c"}
1329
                )
1330 1
            if uni_z:
1331 1
                new_action = {"action_type": "pop_vlan"}
1332 1
                expected_flows[1]["actions"].insert(0, new_action)
1333 1
        elif uni_a is None:
1334 1
            if uni_z not in evc.special_cases:
1335 1
                expected_flows[0]["actions"].insert(
1336
                    0, {"action_type": "push_vlan",
1337
                        "tag_type": "c"}
1338
                )
1339 1
        send_flow_mods_mock.assert_called_with(
1340
            expected_dpid, expected_flows
1341
        )
1342
1343 1
    def test_is_affected_by_link(self):
1344
        """Test is_affected_by_link method"""
1345 1
        self.evc_deploy.current_path = Path(['a', 'b', 'c'])
1346 1
        assert self.evc_deploy.is_affected_by_link('b') is True
1347
1348 1
    def test_is_backup_path_affected_by_link(self):
1349
        """Test is_backup_path_affected_by_link method"""
1350 1
        self.evc_deploy.backup_path = Path(['a', 'b', 'c'])
1351 1
        assert self.evc_deploy.is_backup_path_affected_by_link('d') is False
1352
1353 1
    def test_is_primary_path_affected_by_link(self):
1354
        """Test is_primary_path_affected_by_link method"""
1355 1
        self.evc_deploy.primary_path = Path(['a', 'b', 'c'])
1356 1
        assert self.evc_deploy.is_primary_path_affected_by_link('c') is True
1357
1358 1
    def test_is_using_primary_path(self):
1359
        """Test is_using_primary_path method"""
1360 1
        self.evc_deploy.primary_path = Path(['a', 'b', 'c'])
1361 1
        self.evc_deploy.current_path = Path(['e', 'f', 'g'])
1362 1
        assert self.evc_deploy.is_using_primary_path() is False
1363
1364 1
    def test_is_using_backup_path(self):
1365
        """Test is_using_backup_path method"""
1366 1
        self.evc_deploy.backup_path = Path(['a', 'b', 'c'])
1367 1
        self.evc_deploy.current_path = Path(['e', 'f', 'g'])
1368 1
        assert self.evc_deploy.is_using_backup_path() is False
1369
1370 1
    @patch('napps.kytos.mef_eline.models.path.Path.status')
1371 1
    def test_is_using_dynamic_path(self, mock_status):
1372
        """Test is_using_dynamic_path method"""
1373 1
        mock_status.return_value = False
1374 1
        self.evc_deploy.backup_path = Path([])
1375 1
        self.evc_deploy.primary_path = Path([])
1376 1
        assert self.evc_deploy.is_using_dynamic_path() is False
1377
1378 1
    def test_get_path_status(self):
1379
        """Test get_path_status method"""
1380 1
        path = Path([])
1381 1
        assert self.evc_deploy.get_path_status(path) == EntityStatus.DISABLED
1382 1
        path = Path([
1383
            get_link_mocked(status=EntityStatus.UP),
1384
            get_link_mocked(status=EntityStatus.DOWN)
1385
        ])
1386 1
        assert self.evc_deploy.get_path_status(path) == EntityStatus.DOWN
1387 1
        path = Path([
1388
            get_link_mocked(status=EntityStatus.UP),
1389
            get_link_mocked(status=EntityStatus.UP)
1390
        ])
1391 1
        assert self.evc_deploy.get_path_status(path) == EntityStatus.UP
1392
1393 1
    @patch("napps.kytos.mef_eline.models.evc.EVC._prepare_uni_flows")
1394 1
    def test_get_failover_flows(self, prepare_uni_flows_mock):
1395
        """Test get_failover_flows method."""
1396 1
        evc = self.create_evc_inter_switch()
1397 1
        evc.failover_path = Path([])
1398 1
        assert len(evc.get_failover_flows()) == 0
1399
1400 1
        path = MagicMock()
1401 1
        evc.failover_path = path
1402 1
        evc.get_failover_flows()
1403 1
        prepare_uni_flows_mock.assert_called_with(path, skip_out=True)
1404
1405 1
    @patch("napps.kytos.mef_eline.models.evc.EVC._send_flow_mods")
1406 1
    @patch("napps.kytos.mef_eline.models.path.Path.make_vlans_available")
1407 1
    def test_remove_path_flows(self, *args):
1408
        """Test remove path flows."""
1409 1
        (
1410
            make_vlans_available_mock,
1411
            send_flow_mods_mock
1412
        ) = args
1413
1414 1
        evc = self.create_evc_inter_switch()
1415
1416 1
        evc.remove_path_flows()
1417 1
        make_vlans_available_mock.assert_not_called()
1418
1419 1
        expected_flows_1 = [
1420
            {
1421
                'cookie': 12249790986447749121,
1422
                'cookie_mask': 18446744073709551615,
1423
                'match': {'in_port': 9, 'dl_vlan':  5}
1424
            },
1425
        ]
1426 1
        expected_flows_2 = [
1427
            {
1428
                'cookie': 12249790986447749121,
1429
                'cookie_mask': 18446744073709551615,
1430
                'match': {'in_port': 10, 'dl_vlan': 5}
1431
            },
1432
            {
1433
                'cookie': 12249790986447749121,
1434
                'cookie_mask': 18446744073709551615,
1435
                'match': {'in_port': 11, 'dl_vlan': 6}
1436
            },
1437
        ]
1438 1
        expected_flows_3 = [
1439
            {
1440
                'cookie': 12249790986447749121,
1441
                'cookie_mask': 18446744073709551615,
1442
                'match': {'in_port': 12, 'dl_vlan': 6}
1443
            },
1444
        ]
1445
1446 1
        dpid_flows = evc.remove_path_flows(evc.primary_links)
1447 1
        assert dpid_flows
1448 1
        assert len(dpid_flows) == 3
1449 1
        assert sum(len(flows) for flows in dpid_flows.values()) == len(
1450
            expected_flows_1
1451
        ) + len(expected_flows_2) + len(expected_flows_3)
1452 1
        send_flow_mods_mock.assert_has_calls([
1453
            call(1, expected_flows_1, 'delete', force=True),
1454
            call(2, expected_flows_2, 'delete', force=True),
1455
            call(3, expected_flows_3, 'delete', force=True),
1456
        ], any_order=True)
1457
1458 1
        send_flow_mods_mock.side_effect = FlowModException("err")
1459 1
        with pytest.raises(EVCPathNotDeleted):
1460 1
            evc.remove_path_flows(evc.primary_links)
1461
1462 1
    @patch("httpx.put")
1463 1
    def test_run_bulk_sdntraces(self, put_mock):
1464
        """Test run_bulk_sdntraces method for bulk request."""
1465 1
        evc = self.create_evc_inter_switch()
1466 1
        response = MagicMock()
1467 1
        response.status_code = 200
1468 1
        response.json.return_value = {"result": "ok"}
1469 1
        put_mock.return_value = response
1470
1471 1
        expected_endpoint = f"{SDN_TRACE_CP_URL}/traces"
1472 1
        expected_payload = [
1473
                            {
1474
                                'trace': {
1475
                                    'switch': {'dpid': 1, 'in_port': 2},
1476
                                    'eth': {'dl_type': 0x8100, 'dl_vlan': 82}
1477
                                }
1478
                            }
1479
                        ]
1480 1
        arg_tuple = [(evc.uni_a.interface, evc.uni_a.user_tag.value)]
1481 1
        result = EVCDeploy.run_bulk_sdntraces(arg_tuple)
1482 1
        put_mock.assert_called_with(
1483
                                    expected_endpoint,
1484
                                    json=expected_payload,
1485
                                    timeout=30
1486
                                )
1487 1
        assert result['result'] == "ok"
1488
1489 1
        response.status_code = 400
1490 1
        result = EVCDeploy.run_bulk_sdntraces(arg_tuple)
1491 1
        assert result == {"result": []}
1492
1493 1
        put_mock.side_effect = TimeoutException('Timeout')
1494 1
        response.status_code = 200
1495 1
        result = EVCDeploy.run_bulk_sdntraces(arg_tuple)
1496 1
        assert result == {"result": []}
1497
1498 1
    @patch("httpx.put")
1499 1
    def test_run_bulk_sdntraces_special_vlan(self, put_mock):
1500
        """Test run_bulk_sdntraces method for bulk request."""
1501 1
        evc = self.create_evc_inter_switch()
1502 1
        response = MagicMock()
1503 1
        response.status_code = 200
1504 1
        put_mock.return_value = response
1505
1506 1
        expected_endpoint = f"{SDN_TRACE_CP_URL}/traces"
1507 1
        expected_payload = [
1508
                            {
1509
                                'trace': {
1510
                                    'switch': {'dpid': 1, 'in_port': 2}
1511
                                }
1512
                            }
1513
                        ]
1514 1
        evc.uni_a.user_tag.value = 'untagged'
1515 1
        EVCDeploy.run_bulk_sdntraces(
1516
            [(evc.uni_a.interface, evc.uni_a.user_tag.value)]
1517
        )
1518 1
        put_mock.assert_called_with(
1519
                                    expected_endpoint,
1520
                                    json=expected_payload,
1521
                                    timeout=30
1522
                                )
1523 1
        args = put_mock.call_args[1]['json'][0]
1524 1
        assert 'eth' not in args
1525
1526 1
        evc.uni_a.user_tag.value = 0
1527 1
        EVCDeploy.run_bulk_sdntraces(
1528
            [(evc.uni_a.interface, evc.uni_a.user_tag.value)]
1529
        )
1530 1
        put_mock.assert_called_with(
1531
                                    expected_endpoint,
1532
                                    json=expected_payload,
1533
                                    timeout=30
1534
                                )
1535 1
        args = put_mock.call_args[1]['json'][0]['trace']
1536 1
        assert 'eth' not in args
1537
1538 1
        evc.uni_a.user_tag.value = '5/2'
1539 1
        EVCDeploy.run_bulk_sdntraces(
1540
            [(evc.uni_a.interface, evc.uni_a.user_tag.value)]
1541
        )
1542 1
        put_mock.assert_called_with(
1543
                                    expected_endpoint,
1544
                                    json=expected_payload,
1545
                                    timeout=30
1546
                                )
1547 1
        args = put_mock.call_args[1]['json'][0]['trace']
1548 1
        assert 'eth' not in args
1549
1550 1
        expected_payload[0]['trace']['eth'] = {'dl_type': 0x8100, 'dl_vlan': 1}
1551 1
        evc.uni_a.user_tag.value = 'any'
1552 1
        EVCDeploy.run_bulk_sdntraces(
1553
            [(evc.uni_a.interface, evc.uni_a.user_tag.value)]
1554
        )
1555 1
        put_mock.assert_called_with(
1556
                                    expected_endpoint,
1557
                                    json=expected_payload,
1558
                                    timeout=30
1559
                                )
1560 1
        args = put_mock.call_args[1]['json'][0]['trace']
1561 1
        assert args['eth'] == {'dl_type': 33024, 'dl_vlan': 1}
1562
1563 1
        evc.uni_a.user_tag.value = '4096/4096'
1564 1
        EVCDeploy.run_bulk_sdntraces(
1565
            [(evc.uni_a.interface, evc.uni_a.user_tag.value)]
1566
        )
1567 1
        put_mock.assert_called_with(
1568
                                    expected_endpoint,
1569
                                    json=expected_payload,
1570
                                    timeout=30
1571
                                )
1572 1
        args = put_mock.call_args[1]['json'][0]['trace']
1573 1
        assert args['eth'] == {'dl_type': 33024, 'dl_vlan': 1}
1574
1575 1
        expected_payload[0]['trace']['eth'] = {
1576
            'dl_type': 0x8100,
1577
            'dl_vlan': 10
1578
            }
1579 1
        evc.uni_a.user_tag.value = '10/10'
1580 1
        EVCDeploy.run_bulk_sdntraces(
1581
            [(evc.uni_a.interface, evc.uni_a.user_tag.value)]
1582
        )
1583 1
        put_mock.assert_called_with(
1584
                                    expected_endpoint,
1585
                                    json=expected_payload,
1586
                                    timeout=30
1587
                                )
1588 1
        args = put_mock.call_args[1]['json'][0]['trace']
1589 1
        assert args['eth'] == {'dl_type': 33024, 'dl_vlan': 10}
1590
1591 1
        expected_payload[0]['trace']['eth'] = {
1592
            'dl_type': 0x8100,
1593
            'dl_vlan': 1
1594
            }
1595 1
        evc.uni_a.user_tag.value = '5/3'
1596 1
        EVCDeploy.run_bulk_sdntraces(
1597
            [(evc.uni_a.interface, evc.uni_a.user_tag.value)]
1598
        )
1599 1
        put_mock.assert_called_with(
1600
                                    expected_endpoint,
1601
                                    json=expected_payload,
1602
                                    timeout=30
1603
                                )
1604 1
        args = put_mock.call_args[1]['json'][0]['trace']
1605 1
        assert args['eth'] == {'dl_type': 33024, 'dl_vlan': 1}
1606
1607 1
        expected_payload[0]['trace']['eth'] = {
1608
            'dl_type': 0x8100,
1609
            'dl_vlan': 10
1610
            }
1611 1
        evc.uni_a.user_tag.value = 10
1612 1
        EVCDeploy.run_bulk_sdntraces(
1613
            [(evc.uni_a.interface, evc.uni_a.user_tag.value)]
1614
        )
1615 1
        put_mock.assert_called_with(
1616
                                    expected_endpoint,
1617
                                    json=expected_payload,
1618
                                    timeout=30
1619
                                )
1620
1621 1
    @patch("napps.kytos.mef_eline.models.evc.log")
1622 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.run_bulk_sdntraces")
1623 1
    def test_check_list_traces_ordered_unordered(self, run_bulk_mock, _):
1624
        """Test check_list_traces with UNIs ordered and unordered."""
1625 1
        evc = self.create_evc_inter_switch()
1626
1627 1
        for link in evc.primary_links:
1628 1
            link.metadata['s_vlan'] = MagicMock(value=link.metadata['s_vlan'])
1629 1
        evc.current_path = evc.primary_links
1630
1631 1
        trace_a = [
1632
            {
1633
                "dpid": 1,
1634
                "port": 2,
1635
                "time": "t1",
1636
                "type": "starting",
1637
                "vlan": 82
1638
            },
1639
            {
1640
                "dpid": 2,
1641
                "port": 10,
1642
                "time": "t2",
1643
                "type": "intermediary",
1644
                "vlan": 5
1645
            },
1646
            {"dpid": 3, "port": 12, "time": "t3", "type": "last", "vlan": 6},
1647
        ]
1648 1
        trace_z = [
1649
            {
1650
                "dpid": 3,
1651
                "port": 3,
1652
                "time": "t1",
1653
                "type": "starting",
1654
                "vlan": 83
1655
            },
1656
            {
1657
                "dpid": 2,
1658
                "port": 11,
1659
                "time": "t2",
1660
                "type": "intermediary",
1661
                "vlan": 6
1662
            },
1663
            {"dpid": 1, "port": 9, "time": "t3", "type": "last", "vlan": 5},
1664
        ]
1665
1666 1
        run_bulk_mock.return_value = {"result": [trace_a, trace_z]}
1667 1
        result = EVCDeploy.check_list_traces([evc])
1668 1
        assert result[evc.id]
1669
1670
        # swapped UNIs since uni_a and uni_z might not be ordered with cur path
1671 1
        run_bulk_mock.return_value = {"result": [trace_z, trace_a]}
1672 1
        evc.uni_a, evc.uni_z = evc.uni_z, evc.uni_a
1673 1
        result = EVCDeploy.check_list_traces([evc])
1674 1
        assert result[evc.id]
1675
1676 1
    @patch("napps.kytos.mef_eline.models.evc.log")
1677 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.run_bulk_sdntraces")
1678 1
    def test_check_list_traces(self, run_bulk_sdntraces_mock, _):
1679
        """Test check_list_traces method."""
1680 1
        evc = self.create_evc_inter_switch()
1681
1682 1
        for link in evc.primary_links:
1683 1
            link.metadata['s_vlan'] = MagicMock(value=link.metadata['s_vlan'])
1684 1
        evc.current_path = evc.primary_links
1685
1686 1
        trace_a = [
1687
            {
1688
                "dpid": 1,
1689
                "port": 2,
1690
                "time": "t1",
1691
                "type": "starting",
1692
                "vlan": 82
1693
            },
1694
            {
1695
                "dpid": 2,
1696
                "port": 10,
1697
                "time": "t2",
1698
                "type": "intermediary",
1699
                "vlan": 5
1700
            },
1701
            {"dpid": 3, "port": 12, "time": "t3", "type": "last", "vlan": 6},
1702
        ]
1703 1
        trace_z = [
1704
            {
1705
                "dpid": 3,
1706
                "port": 3,
1707
                "time": "t1",
1708
                "type": "starting",
1709
                "vlan": 83
1710
            },
1711
            {
1712
                "dpid": 2,
1713
                "port": 11,
1714
                "time": "t2",
1715
                "type": "intermediary",
1716
                "vlan": 6
1717
            },
1718
            {"dpid": 1, "port": 9, "time": "t3", "type": "last", "vlan": 5},
1719
        ]
1720
1721 1
        run_bulk_sdntraces_mock.return_value = {
1722
                                                "result": [trace_a, trace_z]
1723
                                            }
1724 1
        result = EVCDeploy.check_list_traces([evc])
1725 1
        assert result[evc.id] is True
1726
1727
        # case2: fail incomplete trace from uni_a
1728 1
        run_bulk_sdntraces_mock.return_value = {
1729
                                                "result": [
1730
                                                            trace_a[:2],
1731
                                                            trace_z
1732
                                                        ]
1733
        }
1734 1
        result = EVCDeploy.check_list_traces([evc])
1735 1
        assert result[evc.id] is False
1736
1737
        # case3: fail incomplete trace from uni_z
1738 1
        run_bulk_sdntraces_mock.return_value = {
1739
                                                "result": [
1740
                                                            trace_a,
1741
                                                            trace_z[:2]
1742
                                                        ]
1743
        }
1744 1
        result = EVCDeploy.check_list_traces([evc])
1745 1
        assert result[evc.id] is False
1746
1747
        # case4: fail wrong vlan id in trace from uni_a
1748 1
        trace_a[1]["vlan"] = 5
1749 1
        trace_z[1]["vlan"] = 99
1750 1
        run_bulk_sdntraces_mock.return_value = {
1751
                                                "result": [trace_a, trace_z]
1752
        }
1753 1
        result = EVCDeploy.check_list_traces([evc])
1754 1
        assert result[evc.id] is False
1755
1756
        # case5: fail wrong vlan id in trace from uni_z
1757 1
        trace_a[1]["vlan"] = 99
1758 1
        run_bulk_sdntraces_mock.return_value = {
1759
                                                "result": [trace_a, trace_z]
1760
        }
1761 1
        result = EVCDeploy.check_list_traces([evc])
1762 1
        assert result[evc.id] is False
1763
1764
        # case6: success when no output in traces
1765 1
        trace_a[1]["vlan"] = 5
1766 1
        trace_z[1]["vlan"] = 6
1767 1
        result = EVCDeploy.check_list_traces([evc])
1768 1
        assert result[evc.id] is True
1769
1770
        # case7: fail when output is None in trace_a or trace_b
1771 1
        trace_a[-1]["out"] = None
1772 1
        result = EVCDeploy.check_list_traces([evc])
1773 1
        assert result[evc.id] is False
1774 1
        trace_a[-1].pop("out", None)
1775 1
        trace_z[-1]["out"] = None
1776 1
        result = EVCDeploy.check_list_traces([evc])
1777 1
        assert result[evc.id] is False
1778
1779
        # case8: success when the output is correct on both uni
1780 1
        trace_a[-1]["out"] = {"port": 3, "vlan": 83}
1781 1
        trace_z[-1]["out"] = {"port": 2, "vlan": 82}
1782 1
        result = EVCDeploy.check_list_traces([evc])
1783 1
        assert result[evc.id] is True
1784
1785
        # case9: fail if any output is incorrect
1786 1
        trace_a[-1]["out"] = {"port": 3, "vlan": 99}
1787 1
        trace_z[-1]["out"] = {"port": 2, "vlan": 82}
1788 1
        result = EVCDeploy.check_list_traces([evc])
1789 1
        assert result[evc.id] is False
1790 1
        trace_a[-1]["out"] = {"port": 3, "vlan": 83}
1791 1
        trace_z[-1]["out"] = {"port": 2, "vlan": 99}
1792 1
        result = EVCDeploy.check_list_traces([evc])
1793 1
        assert result[evc.id] is False
1794
1795 1 View Code Duplication
    @patch("napps.kytos.mef_eline.models.evc.log")
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
1796 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.run_bulk_sdntraces")
1797 1
    def test_check_list_traces_any_cases(self, run_bulk_sdntraces_mock, _):
1798
        """Test check_list_traces method."""
1799 1
        evc = self.create_evc_inter_switch("any", "any")
1800
1801 1
        for link in evc.primary_links:
1802 1
            link.metadata['s_vlan'] = MagicMock(value=link.metadata['s_vlan'])
1803 1
        evc.current_path = evc.primary_links
1804
1805 1
        trace_a = [
1806
            {
1807
                "dpid": 1,
1808
                "port": 2,
1809
                "time": "t1",
1810
                "type": "starting",
1811
                "vlan": 1
1812
            },
1813
            {
1814
                "dpid": 2,
1815
                "port": 10,
1816
                "time": "t2",
1817
                "type": "intermediary",
1818
                "vlan": 5
1819
            },
1820
            {
1821
                "dpid": 3,
1822
                "port": 12,
1823
                'out': {'port': 3, 'vlan': 1},
1824
                "time": "t3",
1825
                "type": "last",
1826
                "vlan": 6
1827
            },
1828
        ]
1829 1
        trace_z = [
1830
            {
1831
                "dpid": 3,
1832
                "port": 3,
1833
                "time": "t1",
1834
                "type": "starting",
1835
                "vlan": 1
1836
            },
1837
            {
1838
                "dpid": 2,
1839
                "port": 11,
1840
                "time": "t2",
1841
                "type": "intermediary",
1842
                "vlan": 6
1843
            },
1844
            {
1845
                "dpid": 1,
1846
                "port": 9,
1847
                'out': {'port': 2, 'vlan': 1},
1848
                "time": "t3",
1849
                "type": "last",
1850
                "vlan": 5
1851
            },
1852
        ]
1853
1854 1
        run_bulk_sdntraces_mock.return_value = {
1855
                                                "result": [trace_a, trace_z]
1856
                                            }
1857 1
        result = EVCDeploy.check_list_traces([evc])
1858 1
        assert result[evc.id] is True
1859
1860 1 View Code Duplication
    @patch("napps.kytos.mef_eline.models.evc.log")
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
1861 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.run_bulk_sdntraces")
1862 1
    def test_check_list_traces_untagged_cases(self, bulk_sdntraces_mock, _):
1863
        """Test check_list_traces method."""
1864 1
        evc = self.create_evc_inter_switch("untagged", "untagged")
1865
1866 1
        for link in evc.primary_links:
1867 1
            link.metadata['s_vlan'] = MagicMock(value=link.metadata['s_vlan'])
1868 1
        evc.current_path = evc.primary_links
1869
1870 1
        trace_a = [
1871
            {
1872
                "dpid": 1,
1873
                "port": 2,
1874
                "time": "t1",
1875
                "type": "starting",
1876
                "vlan": 0
1877
            },
1878
            {
1879
                "dpid": 2,
1880
                "port": 10,
1881
                "time": "t2",
1882
                "type": "intermediary",
1883
                "vlan": 5
1884
            },
1885
            {
1886
                "dpid": 3,
1887
                "port": 12,
1888
                'out': {'port': 3},
1889
                "time": "t3", "type":
1890
                "last",
1891
                "vlan": 6
1892
                },
1893
        ]
1894 1
        trace_z = [
1895
            {
1896
                "dpid": 3,
1897
                "port": 3,
1898
                "time": "t1",
1899
                "type": "starting",
1900
                "vlan": 0
1901
            },
1902
            {
1903
                "dpid": 2,
1904
                "port": 11,
1905
                "time": "t2",
1906
                "type": "intermediary",
1907
                "vlan": 6
1908
            },
1909
            {
1910
                "dpid": 1,
1911
                "port": 9,
1912
                'out': {'port': 2},
1913
                "time": "t3",
1914
                "type": "last",
1915
                "vlan": 5
1916
            },
1917
        ]
1918
1919 1
        bulk_sdntraces_mock.return_value = {
1920
                                                "result": [trace_a, trace_z]
1921
                                            }
1922 1
        result = EVCDeploy.check_list_traces([evc])
1923 1
        assert result[evc.id] is True
1924
1925 1
    @patch("napps.kytos.mef_eline.models.evc.log")
1926 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.run_bulk_sdntraces")
1927 1
    def test_check_list_traces_invalid_types(self, run_bulk_sdntraces_mock, _):
1928
        """Test check_list_traces method for invalid traces by trace type."""
1929 1
        evc = self.create_evc_inter_switch()
1930
1931 1
        for link in evc.primary_links:
1932 1
            link.metadata['s_vlan'] = MagicMock(value=link.metadata['s_vlan'])
1933 1
        evc.current_path = evc.primary_links
1934
1935 1
        trace_a = [
1936
            {
1937
                "dpid": 1,
1938
                "port": 2,
1939
                "time": "t1",
1940
                "type": "starting",
1941
                "vlan": 82
1942
            },
1943
            {
1944
                "dpid": 2,
1945
                "port": 10,
1946
                "time": "t2",
1947
                "type": "intermediary",
1948
                "vlan": 5
1949
            },
1950
            {"dpid": 3, "port": 12, "time": "t3", "type": "last", "vlan": 6},
1951
        ]
1952 1
        trace_z = [
1953
            {
1954
                "dpid": 3,
1955
                "port": 3,
1956
                "time": "t1",
1957
                "type": "starting",
1958
                "vlan": 83
1959
            },
1960
            {
1961
                "dpid": 2,
1962
                "port": 11,
1963
                "time": "t2",
1964
                "type": "intermediary",
1965
                "vlan": 6
1966
            },
1967
            {
1968
                "dpid": 1,
1969
                "port": 9,
1970
                "time": "t3",
1971
                "type": "last",
1972
                "vlan": 5
1973
            },
1974
        ]
1975
1976 1
        run_bulk_sdntraces_mock.return_value = {
1977
                                                "result": [trace_a, trace_z]
1978
                                            }
1979 1
        result = EVCDeploy.check_list_traces([evc])
1980
1981 1
        assert result[evc.id] is True
1982
1983 1
        trace_z = [
1984
            {
1985
                "dpid": 3,
1986
                "port": 3,
1987
                "time": "t1",
1988
                "type": "starting",
1989
                "vlan": 83
1990
            },
1991
            {
1992
                "dpid": 2,
1993
                "port": 11,
1994
                "time": "t2",
1995
                "type": "loop",
1996
                "vlan": 6
1997
            },
1998
        ]
1999
2000 1
        run_bulk_sdntraces_mock.return_value = {
2001
                                                "result": [trace_a, trace_z]
2002
                                            }
2003 1
        result = EVCDeploy.check_list_traces([evc])
2004
        # type loop
2005 1
        assert result[evc.id] is False
2006
2007 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.check_trace")
2008 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.check_range")
2009 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.run_bulk_sdntraces")
2010 1
    def test_check_list_traces_vlan_list(self, *args):
2011
        """Test check_list_traces with vlan list"""
2012 1
        mock_bulk, mock_range, mock_trace = args
2013 1
        mask_list = [1, '2/4094', '4/4094']
2014 1
        evc = self.create_evc_inter_switch([[1, 5]], [[1, 5]])
2015 1
        evc.uni_a.user_tag.mask_list = mask_list
2016 1
        evc.uni_z.user_tag.mask_list = mask_list
2017 1
        mock_bulk.return_value = {"result": ["mock"] * 6}
2018 1
        mock_range.return_value = True
2019 1
        actual_return = EVC.check_list_traces([evc])
2020 1
        assert actual_return == {evc._id: True}
2021 1
        assert mock_trace.call_count == 0
2022 1
        assert mock_range.call_count == 1
2023 1
        args = mock_range.call_args[0]
2024 1
        assert args[0] == evc
2025 1
        assert args[1] == ["mock"] * 6
2026
2027 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.check_trace")
2028 1
    @patch("napps.kytos.mef_eline.models.evc.log")
2029 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.run_bulk_sdntraces")
2030 1
    def test_check_list_traces_empty(self, mock_bulk, mock_log, mock_trace):
2031
        """Test check_list_traces with empty return"""
2032 1
        evc = self.create_evc_inter_switch(1, 1)
2033 1
        actual_return = EVC.check_list_traces([])
2034 1
        assert not actual_return
2035
2036 1
        mock_bulk.return_value = {"result": []}
2037 1
        actual_return = EVC.check_list_traces([evc])
2038 1
        assert not actual_return
2039
2040 1
        mock_bulk.return_value = {"result": ["mock"]}
2041 1
        mock_trace.return_value = True
2042 1
        actual_return = EVC.check_list_traces([evc])
2043 1
        assert mock_log.error.call_count == 1
2044 1
        assert not actual_return
2045
2046 1
    @patch(
2047
        "napps.kytos.mef_eline.models.path.DynamicPathManager"
2048
        ".get_disjoint_paths"
2049
    )
2050 1
    def test_get_failover_path_vandidates(self, get_disjoint_paths_mock):
2051
        """Test get_failover_path_candidates method"""
2052 1
        self.evc_deploy.get_failover_path_candidates()
2053 1
        get_disjoint_paths_mock.assert_called_once()
2054
2055 1
    def test_is_failover_path_affected_by_link(self):
2056
        """Test is_failover_path_affected_by_link method"""
2057 1
        link1 = get_link_mocked(endpoint_a_port=1, endpoint_b_port=2)
2058 1
        link2 = get_link_mocked(endpoint_a_port=3, endpoint_b_port=4)
2059 1
        link3 = get_link_mocked(endpoint_a_port=5, endpoint_b_port=6)
2060 1
        self.evc_deploy.failover_path = Path([link1, link2])
2061 1
        assert self.evc_deploy.is_failover_path_affected_by_link(link1) is True
2062 1
        assert self.evc_deploy.is_failover_path_affected_by_link(link3) \
2063
               is False
2064
2065 1
    def test_is_eligible_for_failover_path(self):
2066
        """Test is_eligible_for_failover_path method"""
2067 1
        assert self.evc_deploy.is_eligible_for_failover_path() is False
2068 1
        self.evc_deploy.dynamic_backup_path = True
2069 1
        self.evc_deploy.primary_path = Path([])
2070 1
        self.evc_deploy.backup_path = Path([])
2071 1
        assert self.evc_deploy.is_eligible_for_failover_path() is True
2072
2073 1
    def test_get_value_from_uni_tag(self):
2074
        """Test _get_value_from_uni_tag"""
2075 1
        uni = get_uni_mocked(tag_value="any")
2076 1
        value = EVC._get_value_from_uni_tag(uni)
2077 1
        assert value == "4096/4096"
2078
2079 1
        uni.user_tag.value = "untagged"
2080 1
        value = EVC._get_value_from_uni_tag(uni)
2081 1
        assert value == 0
2082
2083 1
        uni.user_tag.value = 100
2084 1
        value = EVC._get_value_from_uni_tag(uni)
2085 1
        assert value == 100
2086
2087 1
        uni.user_tag = None
2088 1
        value = EVC._get_value_from_uni_tag(uni)
2089 1
        assert value is None
2090
2091 1
        uni = get_uni_mocked(tag_value=[[12, 20]])
2092 1
        uni.user_tag.mask_list = ['12/4092', '16/4092', '20/4094']
2093
2094 1
        value = EVC._get_value_from_uni_tag(uni)
2095 1
        assert value == ['12/4092', '16/4092', '20/4094']
2096
2097 1
    def test_get_priority(self):
2098
        """Test get_priority_from_vlan"""
2099 1
        evpl_value = EVC.get_priority(100)
2100 1
        assert evpl_value == EVPL_SB_PRIORITY
2101
2102 1
        untagged_value = EVC.get_priority(0)
2103 1
        assert untagged_value == UNTAGGED_SB_PRIORITY
2104
2105 1
        any_value = EVC.get_priority("4096/4096")
2106 1
        assert any_value == ANY_SB_PRIORITY
2107
2108 1
        epl_value = EVC.get_priority(None)
2109 1
        assert epl_value == EPL_SB_PRIORITY
2110
2111 1
        epl_value = EVC.get_priority([[1, 5]])
2112 1
        assert epl_value == EVPL_SB_PRIORITY
2113
2114 1
    def test_set_flow_table_group_id(self):
2115
        """Test set_flow_table_group_id"""
2116 1
        self.evc_deploy.table_group = {"epl": 3, "evpl": 4}
2117 1
        flow_mod = {}
2118 1
        self.evc_deploy.set_flow_table_group_id(flow_mod, 100)
2119 1
        assert flow_mod["table_group"] == "evpl"
2120 1
        assert flow_mod["table_id"] == 4
2121 1
        self.evc_deploy.set_flow_table_group_id(flow_mod, None)
2122 1
        assert flow_mod["table_group"] == "epl"
2123 1
        assert flow_mod["table_id"] == 3
2124
2125 1
    def test_get_endpoint_by_id(self):
2126
        """Test get_endpoint_by_id"""
2127 1
        link = MagicMock()
2128 1
        link.endpoint_a.switch.id = "01"
2129 1
        link.endpoint_b.switch.id = "02"
2130 1
        result = self.evc_deploy.get_endpoint_by_id(link, "01", operator.eq)
2131 1
        assert result == link.endpoint_a
2132 1
        result = self.evc_deploy.get_endpoint_by_id(link, "01", operator.ne)
2133 1
        assert result == link.endpoint_b
2134
2135 1
    @patch("napps.kytos.mef_eline.models.evc.EVC._prepare_pop_flow")
2136 1
    @patch("napps.kytos.mef_eline.models.evc.EVC.get_endpoint_by_id")
2137 1
    @patch("napps.kytos.mef_eline.models.evc.EVC._prepare_push_flow")
2138 1
    def test_prepare_uni_flows(self, mock_push, mock_endpoint, _):
2139
        """Test _prepare_uni_flows"""
2140 1
        mask_list = [1, '2/4094', '4/4094']
2141 1
        uni_a = get_uni_mocked(interface_port=1, tag_value=[[1, 5]])
2142 1
        uni_a.user_tag.mask_list = mask_list
2143 1
        uni_z = get_uni_mocked(interface_port=2, tag_value=[[1, 5]])
2144 1
        uni_z.user_tag.mask_list = mask_list
2145 1
        mock_endpoint.return_value = "mock_endpoint"
2146 1
        attributes = {
2147
            "table_group": {"evpl": 3, "epl": 4},
2148
            "controller": get_controller_mock(),
2149
            "name": "custom_name",
2150
            "uni_a": uni_a,
2151
            "uni_z": uni_z,
2152
        }
2153 1
        evc = EVC(**attributes)
2154 1
        link = get_link_mocked()
2155 1
        evc._prepare_uni_flows(Path([link]))
2156 1
        call_list = []
2157 1
        for i in range(0, 3):
2158 1
            call_list.append(call(
2159
                uni_a.interface,
2160
                "mock_endpoint",
2161
                mask_list[i],
2162
                None,
2163
                mask_list,
2164
                queue_id=-1
2165
            ))
2166 1
        for i in range(0, 3):
2167 1
            call_list.append(call(
2168
                uni_z.interface,
2169
                "mock_endpoint",
2170
                mask_list[i],
2171
                None,
2172
                mask_list,
2173
                queue_id=-1
2174
            ))
2175 1
        mock_push.assert_has_calls(call_list)
2176
2177 1
    def test_prepare_direct_uni_flows(self):
2178
        """Test _prepare_direct_uni_flows"""
2179 1
        mask_list = [1, '2/4094', '4/4094']
2180 1
        uni_a = get_uni_mocked(interface_port=1, tag_value=[[1, 5]])
2181 1
        uni_a.user_tag.mask_list = mask_list
2182 1
        uni_z = get_uni_mocked(interface_port=2, tag_value=[[1, 5]])
2183 1
        uni_z.user_tag.mask_list = mask_list
2184 1
        attributes = {
2185
            "table_group": {"evpl": 3, "epl": 4},
2186
            "controller": get_controller_mock(),
2187
            "name": "custom_name",
2188
            "uni_a": uni_a,
2189
            "uni_z": uni_z,
2190
        }
2191 1
        evc = EVC(**attributes)
2192 1
        flows = evc._prepare_direct_uni_flows()[1]
2193 1
        assert len(flows) == 6
2194 1
        for i in range(0, 3):
2195 1
            assert flows[i]["match"]["in_port"] == 1
2196 1
            assert flows[i]["match"]["dl_vlan"] == mask_list[i]
2197 1
            assert flows[i]["priority"] == EVPL_SB_PRIORITY
2198 1
        for i in range(3, 6):
2199 1
            assert flows[i]["match"]["in_port"] == 2
2200 1
            assert flows[i]["match"]["dl_vlan"] == mask_list[i-3]
2201 1
            assert flows[i]["priority"] == EVPL_SB_PRIORITY
2202
2203 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.check_trace")
2204 1
    def test_check_range(self, mock_check_range):
2205
        """Test check_range"""
2206 1
        mask_list = [1, '2/4094', '4/4094']
2207 1
        uni_a = get_uni_mocked(interface_port=1, tag_value=[[1, 5]])
2208 1
        uni_a.user_tag.mask_list = mask_list
2209 1
        uni_z = get_uni_mocked(interface_port=2, tag_value=[[1, 5]])
2210 1
        uni_z.user_tag.mask_list = mask_list
2211 1
        attributes = {
2212
            "table_group": {"evpl": 3, "epl": 4},
2213
            "controller": get_controller_mock(),
2214
            "name": "custom_name",
2215
            "uni_a": uni_a,
2216
            "uni_z": uni_z,
2217
        }
2218 1
        circuit = EVC(**attributes)
2219 1
        traces = list(range(0, 6))
2220 1
        mock_check_range.return_value = True
2221 1
        check = EVC.check_range(circuit, traces)
2222 1
        call_list = []
2223 1
        for i in range(0, 3):
2224 1
            call_list.append(call(
2225
                circuit.id, circuit.name,
2226
                mask_list[i], mask_list[i],
2227
                uni_a.interface,
2228
                uni_z.interface,
2229
                circuit.current_path,
2230
                i*2, i*2+1
2231
            ))
2232 1
        mock_check_range.assert_has_calls(call_list)
2233 1
        assert check
2234
2235 1
        mock_check_range.side_effect = [True, False, True]
2236 1
        check = EVC.check_range(circuit, traces)
2237 1
        assert check is False
2238
2239 1
    def test_add_tag_errors(self):
2240
        """Test add_tag_errors"""
2241 1
        msg = "No available path was found."
2242 1
        tag_errors = []
2243 1
        tag_errors.append('Mocked error 1')
2244 1
        actual = self.evc_deploy.add_tag_errors(msg, tag_errors)
2245 1
        assert actual == ('No available path was found. 1 path was rejected'
2246
                          f' with message: {tag_errors}')
2247
2248 1
        tag_errors.append('Mocked error 2')
2249 1
        actual = self.evc_deploy.add_tag_errors(msg, tag_errors)
2250 1
        assert actual == ('No available path was found. 2 paths were'
2251
                          f' rejected with messages: {tag_errors}')
2252
2253 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.setup_failover_path")
2254 1
    def test_try_setup_failover_path(self, setup_failover_mock):
2255
        """Test try_setup_failover_path"""
2256 1
        self.evc_deploy.failover_path = True
2257 1
        self.evc_deploy.current_path = False
2258 1
        self.evc_deploy.is_active = MagicMock(return_value=False)
2259 1
        self.evc_deploy.try_setup_failover_path()
2260 1
        assert setup_failover_mock.call_count == 0
2261
2262 1
        self.evc_deploy.failover_path = False
2263 1
        self.evc_deploy.current_path = True
2264 1
        self.evc_deploy.is_active = MagicMock(return_value=True)
2265 1
        self.evc_deploy.try_setup_failover_path()
2266 1
        assert setup_failover_mock.call_count == 1
2267
2268 1
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy._send_flow_mods")
2269 1
    @patch(
2270
        "napps.kytos.mef_eline.models.evc.EVCDeploy._prepare_direct_uni_flows"
2271
    )
2272 1
    def test_install_direct_uni_flows_error(self, prepare_mock, send_mock):
2273
        """Test _install_direct_uni_flows with errors"""
2274 1
        prepare_mock.return_value = True, True
2275 1
        send_mock.side_effect = FlowModException
2276 1
        with pytest.raises(EVCPathNotInstalled):
2277
            self.evc_deploy._install_direct_uni_flows()
2278