-
Notifications
You must be signed in to change notification settings - Fork 741
/
dual_tor_common.py
107 lines (78 loc) · 3.37 KB
/
dual_tor_common.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"""DualToR related common utilities for other modules."""
import json
import pytest
from tests.common.helpers.assertions import pytest_require
__all__ = [
'cable_type',
'CableType',
'mux_config',
'active_standby_ports',
'active_active_ports',
'ActiveActivePortID',
'active_active_ports_config'
]
class CableType(object):
"""Dualtor cable type."""
active_active = "active-active"
active_standby = "active-standby"
default_type = "active-standby"
class ActiveActivePortID(object):
"""Port id for active-active."""
UPPER_TOR = 1
LOWER_TOR = 0
@pytest.fixture(params=[CableType.active_standby, CableType.active_active])
def cable_type(request, active_active_ports, active_standby_ports, tbinfo):
"""Dualtor cable type."""
cable_type = request.param
has_enable_active_active_marker = False
skip_active_standby_marker = False
for marker in request.node.iter_markers():
if marker.name == "enable_active_active":
has_enable_active_active_marker = True
elif marker.name == "skip_active_standby":
skip_active_standby_marker = True
pytest_require('dualtor' in tbinfo['topo']['name'], skip_message="Skip on non-dualtor testbed")
if ((not has_enable_active_active_marker) and (cable_type == CableType.active_active)):
pytest.skip("Skip cable type 'active-active'")
if skip_active_standby_marker and cable_type == CableType.active_standby:
pytest.skip("Skip cable type 'active-standby'")
if cable_type == CableType.active_active and not active_active_ports:
pytest.skip("Skip as no mux ports of 'active-active' cable type")
elif cable_type == CableType.active_standby and not active_standby_ports:
pytest.skip("Skip as no mux ports of 'active-standby' cable type")
return cable_type
@pytest.fixture(scope="session")
def mux_config(duthosts, tbinfo):
if 'dualtor' not in tbinfo['topo']['name']:
return {}
# NOTE: assume both ToRs have the same mux config
duthost = duthosts[0]
cmd = 'show mux config --json'
return json.loads(duthost.shell(cmd)['stdout'])["MUX_CABLE"]["PORTS"]
@pytest.fixture(scope="session")
def active_active_ports(mux_config, tbinfo):
if 'dualtor' not in tbinfo['topo']['name']:
return []
active_active_ports = []
for port, port_config in list(mux_config.items()):
if port_config["SERVER"].get("cable_type", CableType.default_type) == CableType.active_active:
active_active_ports.append(port)
return active_active_ports
@pytest.fixture(scope="session")
def active_standby_ports(mux_config, tbinfo):
if 'dualtor' not in tbinfo['topo']['name']:
return []
active_standby_ports = []
for port, port_config in list(mux_config.items()):
if port_config["SERVER"].get("cable_type", CableType.default_type) == CableType.active_standby:
active_standby_ports.append(port)
return active_standby_ports
@pytest.fixture(scope="session")
def active_active_ports_config(mux_config, tbinfo):
if 'dualtor' not in tbinfo['topo']['name']:
return {}
active_active_ports_config = {}
for port, port_config in list(mux_config.items()):
if port_config["SERVER"].get("cable_type", CableType.default_type) == CableType.active_active:
active_active_ports_config[port] = port_config
return active_active_ports_config