Skip to content

Commit 41ca571

Browse files
Merge branch 'master' into master
2 parents 5ad146e + faea291 commit 41ca571

File tree

1,759 files changed

+462433
-42351
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,759 files changed

+462433
-42351
lines changed

.azure-pipelines/baseline_test/baseline.test.mgmt.public.yml

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,53 +11,78 @@ schedules:
1111
- master
1212
always: true
1313

14-
stages:
14+
parameters:
15+
- name: BUILD_REASON
16+
type: string
17+
default: "BaselineTest"
1518

16-
- stage: Test_round_1
17-
variables:
19+
- name: TEST_PLAN_NUM
20+
type: string
21+
default: $(BASELINE_MGMT_PUBLIC_MASTER_TEST_NUM)
22+
23+
- name: RETRY_TIMES
24+
type: string
25+
default: "0"
26+
27+
- name: TEST_PLAN_STOP_ON_FAILURE
28+
type: string
29+
default: "False"
30+
31+
variables:
1832
- group: SONiC-Elastictest
1933
- name: inventory
2034
value: veos_vtb
2135
- name: testbed_file
2236
value: vtestbed.yaml
37+
- name: BUILD_BRANCH
38+
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
39+
value: $(System.PullRequest.TargetBranch)
40+
${{ else }}:
41+
value: $(Build.SourceBranchName)
42+
43+
stages:
44+
45+
- stage: Test_round_1
2346
jobs:
24-
- template: baseline.test.template.yml
47+
- template: ../pr_test_template.yml
48+
parameters:
49+
BUILD_REASON: ${{ parameters.BUILD_REASON }}
50+
RETRY_TIMES: ${{ parameters.RETRY_TIMES }}
51+
STOP_ON_FAILURE: ${{ parameters.TEST_PLAN_STOP_ON_FAILURE }}
52+
TEST_PLAN_NUM: ${{ parameters.TEST_PLAN_NUM }}
2553

2654
- stage: Test_round_2
2755
dependsOn:
2856
- Test_round_1
2957
condition: succeededOrFailed('Test_round_1')
30-
variables:
31-
- group: SONiC-Elastictest
32-
- name: inventory
33-
value: veos_vtb
34-
- name: testbed_file
35-
value: vtestbed.yaml
3658
jobs:
37-
- template: baseline.test.template.yml
59+
- template: ../pr_test_template.yml
60+
parameters:
61+
BUILD_REASON: ${{ parameters.BUILD_REASON }}
62+
RETRY_TIMES: ${{ parameters.RETRY_TIMES }}
63+
STOP_ON_FAILURE: ${{ parameters.TEST_PLAN_STOP_ON_FAILURE }}
64+
TEST_PLAN_NUM: ${{ parameters.TEST_PLAN_NUM }}
3865

3966
- stage: Test_round_3
4067
dependsOn:
4168
- Test_round_2
4269
condition: succeededOrFailed('Test_round_2')
43-
variables:
44-
- group: SONiC-Elastictest
45-
- name: inventory
46-
value: veos_vtb
47-
- name: testbed_file
48-
value: vtestbed.yaml
4970
jobs:
50-
- template: baseline.test.template.yml
71+
- template: ../pr_test_template.yml
72+
parameters:
73+
BUILD_REASON: ${{ parameters.BUILD_REASON }}
74+
RETRY_TIMES: ${{ parameters.RETRY_TIMES }}
75+
STOP_ON_FAILURE: ${{ parameters.TEST_PLAN_STOP_ON_FAILURE }}
76+
TEST_PLAN_NUM: ${{ parameters.TEST_PLAN_NUM }}
5177

5278
- stage: Test_round_4
5379
dependsOn:
5480
- Test_round_3
5581
condition: succeededOrFailed('Test_round_3')
56-
variables:
57-
- group: SONiC-Elastictest
58-
- name: inventory
59-
value: veos_vtb
60-
- name: testbed_file
61-
value: vtestbed.yaml
6282
jobs:
63-
- template: baseline.test.template.yml
83+
- template: ../pr_test_template.yml
84+
parameters:
85+
BUILD_REASON: ${{ parameters.BUILD_REASON }}
86+
RETRY_TIMES: ${{ parameters.RETRY_TIMES }}
87+
STOP_ON_FAILURE: ${{ parameters.TEST_PLAN_STOP_ON_FAILURE }}
88+
TEST_PLAN_NUM: ${{ parameters.TEST_PLAN_NUM }}

.azure-pipelines/baseline_test/baseline.test.template.yml

Lines changed: 0 additions & 101 deletions
This file was deleted.

.azure-pipelines/collect_dump.py

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env python3
22

33
import argparse
4+
import datetime
5+
import gzip
46
import logging
57
import os
68
import sys
7-
import datetime
8-
import traceback
99
import tarfile
10-
import gzip
10+
import traceback
1111
from concurrent.futures import ThreadPoolExecutor
1212

1313
_self_dir = os.path.dirname(os.path.abspath(__file__))
@@ -21,26 +21,36 @@
2121
from devutil.devices.factory import init_testbed_sonichosts # noqa: E402
2222

2323
logger = logging.getLogger(__name__)
24+
logger.setLevel(logging.INFO)
25+
26+
if not logger.handlers: # prevent adding multiple handlers
27+
console_handler = logging.StreamHandler(sys.stdout)
28+
console_handler.setLevel(logging.INFO)
29+
formatter = logging.Formatter("%(asctime)s [%(levelname)s] %(message)s")
30+
console_handler.setFormatter(formatter)
31+
logger.addHandler(console_handler)
2432

2533
RC_INIT_FAILED = 1
2634
RC_GET_TECHSUPPORT_FAILED = 2
2735
TECHSUPPORT_SAVE_PATH = '../tests/logs/'
2836
LOGS_DIR = os.path.join(_self_dir, TECHSUPPORT_SAVE_PATH)
2937

3038

31-
def get_techsupport(sonichost, time_since):
32-
"""Runs 'show techsupport' on SONiC devices and saves the output to logs/"""
39+
def get_techsupport(sonichost, time_since, dump_dir):
40+
"""Runs 'show techsupport' on SONiC devices and saves the output to dump_dir/"""
3341
try:
34-
# Run "show techsupport" command
42+
logger.info(f"[{sonichost.hostname}] Running 'show techsupport --since {time_since}' ...")
3543
result = sonichost.command(f"show techsupport --since {time_since}")
3644
if result['rc'] == 0:
3745
tar_file = result['stdout_lines'][-1]
38-
tar_file_name = tar_file.split("/")[-1]
39-
sonichost.fetch_no_slurp(src=tar_file, dest=TECHSUPPORT_SAVE_PATH, flat=True)
46+
tar_file_name = os.path.basename(tar_file)
47+
sonichost.fetch_no_slurp(src=tar_file, dest=dump_dir, flat=True)
4048
return tar_file_name
49+
logger.error(f"[{sonichost.hostname}] Failed to generate techsupport (rc={result['rc']})")
50+
return None
4151

4252
except Exception as e:
43-
logger.info(f"Failed to get techsupport for {e}")
53+
logger.info(f"[{sonichost.hostname}] Failed to get techsupport: {e}")
4454
sys.exit(RC_GET_TECHSUPPORT_FAILED)
4555

4656

@@ -69,38 +79,49 @@ def extract_gz_file(gz_file_path):
6979
traceback.print_exc()
7080

7181

72-
def extract_dump_file(testbed_name_with_idx, hostname, tar_file_name):
82+
def extract_dump_file(testbed_name_with_idx, hostname, tar_file_name, dump_dir):
7383
try:
7484
# extract dump file
75-
dump_file_path = os.path.join(TECHSUPPORT_SAVE_PATH, tar_file_name)
76-
extract_dump_tar_gz(dump_file_path, TECHSUPPORT_SAVE_PATH)
85+
dump_file_path = os.path.join(dump_dir, tar_file_name)
86+
logger.info(f"[{hostname}] Extracting dump file {dump_file_path}")
87+
extract_dump_tar_gz(dump_file_path, dump_dir)
7788

7889
# rename dump file
7990
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
80-
new_file_name = testbed_name_with_idx + "_" + hostname + "_" + timestamp
81-
new_file_path = os.path.join(LOGS_DIR, new_file_name)
82-
os.rename(os.path.join(_self_dir, dump_file_path), os.path.join(LOGS_DIR, new_file_name + ".tar.gz"))
83-
os.rename(os.path.join(_self_dir, dump_file_path.split(".tar.gz")[0]), new_file_path)
91+
new_file_name = f"{testbed_name_with_idx}_{hostname}_{timestamp}"
92+
new_file_path = os.path.join(dump_dir, new_file_name)
93+
94+
logger.info(f"[{hostname}] Renaming dump to {new_file_path}")
95+
os.rename(dump_file_path, os.path.join(dump_dir, new_file_name + ".tar.gz"))
96+
os.rename(dump_file_path.split(".tar.gz")[0], new_file_path)
8497

8598
# extract syslog gz files
8699
syslog_dir = os.path.join(new_file_path, "log")
87-
syslog_gz_files = [file for file in os.listdir(os.path.join(LOGS_DIR, syslog_dir))
88-
if file.startswith("syslog") and file.endswith(".gz")]
89-
logger.info("Syslog files: {}".format(syslog_gz_files))
100+
syslog_gz_files = [
101+
file for file in os.listdir(syslog_dir)
102+
if file.startswith("syslog") and file.endswith(".gz")
103+
]
104+
logger.info(f"[{hostname}] Extracting {len(syslog_gz_files)} syslog files")
90105
for syslog_gz in syslog_gz_files:
91106
syslog_gz_files_path = os.path.join(syslog_dir, syslog_gz)
92107
extract_gz_file(syslog_gz_files_path)
93108

109+
logger.info(f"[{hostname}] Dump extraction completed")
94110
except Exception as e:
95-
logger.info("Extract dump file failed: " + str(e))
111+
logger.exception(f"[{hostname}] ERROR during extraction: {e}")
96112
traceback.print_exc()
97113

98114

99-
def collect_dump_and_extract(sonichost, time_since, testbed_name_with_idx):
100-
"""Function to run tasks in parallel per sonichost"""
101-
tar_file_name = get_techsupport(sonichost, time_since=time_since)
102-
extract_dump_file(testbed_name_with_idx=testbed_name_with_idx,
103-
hostname=sonichost.hostname, tar_file_name=tar_file_name)
115+
def collect_dump_and_extract(sonichost, time_since, testbed_name_with_idx, dump_dir):
116+
logger.info(f"[{sonichost.hostname}] Starting dump collection ...")
117+
tar_file_name = get_techsupport(sonichost, time_since=time_since, dump_dir=dump_dir)
118+
if tar_file_name:
119+
extract_dump_file(testbed_name_with_idx=testbed_name_with_idx,
120+
hostname=sonichost.hostname,
121+
tar_file_name=tar_file_name,
122+
dump_dir=dump_dir)
123+
else:
124+
logger.warning(f"[{sonichost.hostname}] No dump file collected.")
104125

105126

106127
def main(args):
@@ -112,12 +133,13 @@ def main(args):
112133
if not sonichosts:
113134
sys.exit(RC_INIT_FAILED)
114135

115-
if not os.path.exists(LOGS_DIR):
116-
os.makedirs(LOGS_DIR)
136+
if not os.path.exists(args.dump_dir):
137+
os.makedirs(args.dump_dir)
117138

118139
with ThreadPoolExecutor(max_workers=len(sonichosts)) as executor:
119140
futures = [
120-
executor.submit(collect_dump_and_extract, sonichost, args.time_since, args.testbed_name_with_idx)
141+
executor.submit(collect_dump_and_extract,
142+
sonichost, args.time_since, args.testbed_name_with_idx, args.dump_dir)
121143
for sonichost in sonichosts
122144
]
123145
for future in futures:
@@ -177,5 +199,13 @@ def main(args):
177199
help="Log verbosity (0-3)."
178200
)
179201

202+
parser.add_argument(
203+
"--dump-dir",
204+
type=str,
205+
dest="dump_dir",
206+
default=LOGS_DIR,
207+
help="Directory to store collected dumps."
208+
)
209+
180210
args = parser.parse_args()
181211
main(args)

0 commit comments

Comments
 (0)