Skip to content

Commit f0063b8

Browse files
kanchanavelusamyKanchana-HCLTech
authored andcommitted
Skip GNMI check during teardown and disable LogAnalyzer for reboot tests
1 parent 9fcacf4 commit f0063b8

File tree

2 files changed

+44
-15
lines changed

2 files changed

+44
-15
lines changed

tests/gnmi/conftest.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,13 @@ def setup_gnmi_server(duthosts, rand_one_dut_hostname, localhost, ptfhost):
210210

211211
# Rollback configuration
212212
rollback(duthost, SETUP_ENV_CP)
213-
recover_cert_config(duthost)
213+
# Get the skip_gnmi_check flag from duthost options
214+
skip_gnmi_check = duthost.host.options.get('skip_gnmi_check', False)
215+
# Skip GNMI restart if the reboot flag is set
216+
if not skip_gnmi_check:
217+
recover_cert_config(duthost)
218+
else:
219+
logging.info("Skipping GNMI restart due to skip_gnmi_check flag")
214220

215221

216222
@pytest.fixture(scope="module", autouse=True)

tests/gnmi/test_gnoi_system.py

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
pytest.mark.topology('any')
1212
]
1313

14+
MAX_TIME_TO_REBOOT = 300
1415

1516
"""
1617
This module contains tests for the gNOI System API.
@@ -42,45 +43,58 @@ def test_gnoi_system_reboot(duthosts, rand_one_dut_hostname, localhost):
4243
"""
4344
duthost = duthosts[rand_one_dut_hostname]
4445

46+
# Set flag to indicate that this test involves reboot
47+
duthost.host.options['skip_gnmi_check'] = True
48+
4549
# Trigger reboot
46-
ret, msg = gnoi_request(duthost, localhost, "Reboot", '{"method": 1}')
50+
ret, msg = gnoi_request(duthost, localhost, "Reboot", '{"method": 1,"delay":0,"message":"Cold Reboot"}')
4751
pytest_assert(ret == 0, "System.Reboot API reported failure (rc = {}) with message: {}".format(ret, msg))
4852
logging.info("System.Reboot API returned msg: {}".format(msg))
4953

50-
54+
@pytest.mark.disable_loganalyzer
5155
def test_gnoi_system_reboot_fail_invalid_method(duthosts, rand_one_dut_hostname, localhost):
5256
"""
5357
Verify the gNOI System Reboot API fails with invalid method.
5458
"""
5559
duthost = duthosts[rand_one_dut_hostname]
5660

61+
# Set flag to indicate that this test involves reboot
62+
duthost.host.options['skip_gnmi_check'] = True
63+
5764
# Trigger reboot with invalid method
5865
ret, msg = gnoi_request(duthost, localhost, "Reboot", '{"method": 99}')
5966
pytest_assert(ret != 0, "System.Reboot API did not report failure with invalid method")
6067

61-
68+
@pytest.mark.disable_loganalyzer
6269
def test_gnoi_system_reboot_when_reboot_active(duthosts, rand_one_dut_hostname, localhost):
6370
"""
6471
Verify the gNOI System Reboot API fails if a reboot is already active.
6572
"""
6673
duthost = duthosts[rand_one_dut_hostname]
6774

75+
# Set flag to indicate that this test involves reboot
76+
duthost.host.options['skip_gnmi_check'] = True
77+
6878
# Trigger first reboot
69-
ret, msg = gnoi_request(duthost, localhost, "Reboot", '{"method": 1}')
79+
ret, msg = gnoi_request(duthost, localhost, "Reboot", '{"method": 1,"delay":0,"message":"Cold Reboot"}')
7080
pytest_assert(ret == 0, "System.Reboot API reported failure (rc = {}) with message: {}".format(ret, msg))
7181
logging.info("System.Reboot API returned msg: {}".format(msg))
7282

7383
# Trigger second reboot while the first one is still active
74-
ret, msg = gnoi_request(duthost, localhost, "Reboot", '{"method": 1}')
84+
ret, msg = gnoi_request(duthost, localhost, "Reboot", '{"method": 1,"delay":0,"message":"Cold Reboot"}')
7585
pytest_assert(ret != 0, "System.Reboot API did not report failure when reboot is already active")
7686

7787

88+
@pytest.mark.disable_loganalyzer
7889
def test_gnoi_system_reboot_status_immediately(duthosts, rand_one_dut_hostname, localhost):
7990
"""
8091
Verify the gNOI System RebootStatus API returns the correct status immediately after reboot.
8192
"""
8293
duthost = duthosts[rand_one_dut_hostname]
8394

95+
# Set flag to indicate that this test involves reboot
96+
duthost.host.options['skip_gnmi_check'] = True
97+
8498
# Trigger reboot
8599
ret, msg = gnoi_request(duthost, localhost, "Reboot", '{"method": 1, "message": "test"}')
86100
pytest_assert(ret == 0, "System.Reboot API reported failure (rc = {}) with message: {}".format(ret, msg))
@@ -107,6 +121,9 @@ def gnoi_system_reboot_status_after_startup(duthosts, rand_one_dut_hostname, loc
107121
"""
108122
duthost = duthosts[rand_one_dut_hostname]
109123

124+
# Set flag to indicate that this test involves reboot
125+
duthost.host.options['skip_gnmi_check'] = True
126+
110127
# Trigger reboot
111128
ret, msg = gnoi_request(duthost, localhost, "Reboot", '{"method": 1, "message": "test"}')
112129
pytest_assert(ret == 0, "System.Reboot API reported failure (rc = {}) with message: {}".format(ret, msg))
@@ -138,12 +155,18 @@ def extract_first_json_substring(s):
138155
:return: The first JSON substring if found, otherwise None.
139156
"""
140157

141-
json_pattern = re.compile(r'\{.*?\}')
142-
match = json_pattern.search(s)
143-
if match:
144-
try:
145-
return json.loads(match.group())
146-
except json.JSONDecodeError:
147-
logging.error("Failed to parse JSON: {}".format(match.group()))
148-
return None
149-
return None
158+
start_index = s.find('{') # Find the first '{' in the string
159+
if start_index == -1:
160+
logging.error("No JSON found in response: {}".format(s))
161+
return None
162+
json_str = s[start_index:] # Extract substring starting from '{'
163+
try:
164+
parsed_json = json.loads(json_str) # Attempt to parse the JSON
165+
# Handle cases where "status": {} is empty
166+
if "status" in parsed_json and parsed_json["status"] == {}:
167+
logging.warning("Replacing empty 'status' field with a default value.")
168+
parsed_json["status"] = {"unknown": "empty_status"}
169+
return parsed_json
170+
except json.JSONDecodeError as e:
171+
logging.error("Failed to parse JSON: {} | Error: {}".format(json_str, e))
172+
return None

0 commit comments

Comments
 (0)