-
Notifications
You must be signed in to change notification settings - Fork 738
/
test_reload_config.py
143 lines (109 loc) · 5.83 KB
/
test_reload_config.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
"""
Check platform status after config is reloaded
This script is to cover the test case 'Reload configuration' in the SONiC platform test plan:
https://github.com/sonic-net/SONiC/blob/master/doc/pmon/sonic_platform_test_plan.md
"""
import logging
import pytest
import re
from tests.common.fixtures.conn_graph_facts import conn_graph_facts # noqa F401
from tests.common.utilities import wait_until
from tests.common.platform.processes_utils import wait_critical_processes
from tests.common.platform.transceiver_utils import check_transceiver_basic
from tests.common.platform.interface_utils import check_all_interface_information, get_port_map
from tests.common.reboot import reboot
from tests.common.config_reload import config_force_option_supported, config_system_checks_passed
pytestmark = [
pytest.mark.disable_loganalyzer,
pytest.mark.topology('any')
]
def test_reload_configuration(duthosts, rand_one_dut_hostname, conn_graph_facts, xcvr_skip_list): # noqa F811
"""
@summary: This test case is to reload the configuration and check platform status
"""
duthost = duthosts[rand_one_dut_hostname]
interfaces = conn_graph_facts["device_conn"][duthost.hostname]
asic_type = duthost.facts["asic_type"]
if config_force_option_supported(duthost):
assert wait_until(300, 20, 0, config_system_checks_passed, duthost)
logging.info("Reload configuration")
duthost.shell("sudo config reload -y &>/dev/null", executable="/bin/bash")
logging.info("Wait until all critical services are fully started")
wait_critical_processes(duthost)
logging.info("Wait some time for all the transceivers to be detected")
assert wait_until(300, 20, 0, check_all_interface_information, duthost, interfaces, xcvr_skip_list), \
"Not all transceivers are detected in 300 seconds"
logging.info("Check transceiver status")
for asic_index in duthost.get_frontend_asic_ids():
# Get the interfaces pertaining to that asic
interface_list = get_port_map(duthost, asic_index)
interfaces_per_asic = {k: v for k, v in list(interface_list.items()) if k in interfaces}
check_transceiver_basic(duthost, asic_index,
interfaces_per_asic, xcvr_skip_list)
if asic_type in ["mellanox"]:
from .mellanox.check_hw_mgmt_service import check_hw_management_service
from .mellanox.check_sysfs import check_sysfs
logging.info("Check the hw-management service")
check_hw_management_service(duthost)
logging.info("Check sysfs")
check_sysfs(duthost)
def check_database_status(duthost):
# check global database docker is running
if not duthost.is_service_fully_started('database'):
return False
# For multi-asic check each asics database
if duthost.is_multi_asic:
for asic in duthost.asics:
if not duthost.is_service_fully_started('database{}'.format(asic.asic_index)):
return False
return True
def test_reload_configuration_checks(duthosts, rand_one_dut_hostname,
localhost, conn_graph_facts, xcvr_skip_list): # noqa F811
"""
@summary: This test case is to test various system checks in config reload
"""
duthost = duthosts[rand_one_dut_hostname]
if not config_force_option_supported(duthost):
return
reboot(duthost, localhost, reboot_type="cold", wait=5)
# Check if all database containers have started
wait_until(60, 1, 0, check_database_status, duthost)
# Check if interfaces-config.service is exited
wait_until(60, 1, 0, check_interfaces_config_service_status, duthost)
logging.info("Reload configuration check")
out = duthost.shell("sudo config reload -y",
executable="/bin/bash", module_ignore_errors=True)
# config reload command shouldn't work immediately after system reboot
assert "Retry later" in out['stdout']
assert wait_until(300, 20, 0, config_system_checks_passed, duthost)
# After the system checks succeed the config reload command should not throw error
out = duthost.shell("sudo config reload -y",
executable="/bin/bash", module_ignore_errors=True)
assert "Retry later" not in out['stdout']
# Immediately after one config reload command, another shouldn't execute and wait for system checks
logging.info("Checking config reload after system is up")
out = duthost.shell("sudo config reload -y",
executable="/bin/bash", module_ignore_errors=True)
assert "Retry later" in out['stdout']
assert wait_until(300, 20, 0, config_system_checks_passed, duthost)
logging.info("Stopping swss docker and checking config reload")
if duthost.is_multi_asic:
for asic in duthost.asics:
duthost.shell("sudo service swss@{} stop".format(asic.asic_index))
else:
duthost.shell("sudo service swss stop")
# Without swss running config reload option should not proceed
out = duthost.shell("sudo config reload -y",
executable="/bin/bash", module_ignore_errors=True)
assert "Retry later" in out['stdout']
# However with force option config reload should proceed
logging.info("Performing force config reload")
out = duthost.shell("sudo config reload -y -f", executable="/bin/bash")
assert "Retry later" not in out['stdout']
assert wait_until(300, 20, 0, config_system_checks_passed, duthost)
def check_interfaces_config_service_status(duthost):
# check interfaces-config.service status
regx_interface_config_service_exit = r'.*Main PID: \d+ \(code=exited, status=0\/SUCCESS\).*'
interface_config_server_status = duthost.command(
'systemctl status interfaces-config.service', module_ignore_errors=True)['stdout']
return re.search(regx_interface_config_service_exit, interface_config_server_status)