Skip to content

Commit d4152b3

Browse files
Add new checkpoint parameter for date assert (sonic-net#21610)
What is the motivation for this PR? Enhance the usability of the tool by adding verification for the new -t parameter. This parameter enables displaying the checkpoint datetime, which improves transparency and debugging capabilities for users. Tools PR: sonic-net/sonic-utilities#3746 How did you do it? Implemented logic to parse and validate the -t parameter in the command-line interface. Updated the relevant code paths to ensure the checkpoint datetime is correctly retrieved and displayed. Added error handling for invalid or missing -t values to maintain robustness. How did you verify/test it? Ran integration tests to confirm that the checkpoint datetime is displayed accurately when the parameter is used. Signed-off-by: xincunli-sonic <xincun.li@microsoft.com>
1 parent 490e6fa commit d4152b3

1 file changed

Lines changed: 42 additions & 5 deletions

File tree

tests/common/checkpoint.py

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
1+
import json
2+
import re
13
import logging
24
from tests.common.helpers.assertions import pytest_assert
5+
from sonic_py_common import device_info
36

47
logger = logging.getLogger(__name__)
58

69
DEFAULT_CHECKPOINT_NAME = "backup"
710

811

9-
def list_checkpoints(duthost):
10-
"""List checkpoint on target duthost
12+
def list_checkpoints(duthost, with_date=False):
13+
"""
14+
List checkpoints on target duthost.
1115
1216
Args:
1317
duthost: Device Under Test (DUT)
14-
cp: checkpoint filename
18+
with_date (bool): If True, include checkpoint creation date/time in the output
19+
(requires SONiC version >= 202505 or master).
20+
21+
Returns:
22+
dict: Output from duthost.shell command.
1523
"""
1624
cmds = 'config list-checkpoints'
25+
if with_date:
26+
cmds += " -t"
1727

1828
logger.info("Commands: {}".format(cmds))
1929
output = duthost.shell(cmds, module_ignore_errors=True)
@@ -29,8 +39,35 @@ def list_checkpoints(duthost):
2939
def verify_checkpoints_exist(duthost, cp):
3040
"""Check if checkpoint file exist in duthost
3141
"""
32-
output = list_checkpoints(duthost)
33-
return '"{}"'.format(cp) in output['stdout']
42+
checkpoints_output = list_checkpoints(duthost)
43+
checkpoint_exists = f'"{cp}"' in checkpoints_output['stdout']
44+
45+
output_version = device_info.get_sonic_version_info()
46+
build_version = output_version['build_version']
47+
48+
# Detect version_number or bail out early
49+
if not (re.match(r'^(\d{6})', build_version) or "master" in build_version):
50+
return checkpoint_exists
51+
52+
# Resolve version_number
53+
if "master" in build_version:
54+
version_number = 999999
55+
else:
56+
version_number = int(re.findall(r'\d{6}', build_version)[0])
57+
58+
# Old versions: simple check
59+
if version_number < 202505:
60+
return checkpoint_exists
61+
62+
# Newer versions: need date-aware check
63+
checkpoints_output = list_checkpoints(duthost, with_date=True)
64+
try:
65+
checkpoints = json.loads(checkpoints_output['stdout'])
66+
except Exception:
67+
checkpoints = []
68+
69+
checkpoint_exists_with_date = any(item.get("name") == cp for item in checkpoints)
70+
return checkpoint_exists and checkpoint_exists_with_date
3471

3572

3673
def create_checkpoint(duthost, cp=DEFAULT_CHECKPOINT_NAME):

0 commit comments

Comments
 (0)