Skip to content

Commit cbac654

Browse files
committed
ci: cancel previous test_plans implementation
Signed-off-by: Austin Pham <austinpham@microsoft.com>
1 parent 9ca39a7 commit cbac654

3 files changed

Lines changed: 110 additions & 9 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
steps:
2+
- ${{ if not(contains(variables['BUILD.REPOSITORY.NAME'], 'sonic-mgmt')) }}:
3+
- script: |
4+
# If not sonic-mgmt/sonic-mgmt-int repo, need to download test_plan.py and pr_test_scripts.yaml
5+
set -ex
6+
curl "https://raw.githubusercontent.com/sonic-net/sonic-mgmt/master/.azure-pipelines/test_plan.py" -o ./.azure-pipelines/test_plan.py
7+
displayName: "Download Test Plan Script"
8+
- script: |
9+
# If not sonic-mgmt/sonic-mgmt-int repo, need to download pr_test_scripts.yaml
10+
set -ex
11+
12+
# If public build image repo, download pr test scripts from public sonic-mgmt repo
13+
if [[ "$(BUILD.REPOSITORY.NAME)" = "sonic-net/sonic-buildimage" || "$(BUILD.REPOSITORY.NAME)" = "Azure/sonic-buildimage-msft" ]]; then
14+
curl "${{ parameters.MGMT_URL }}/${{ parameters.MGMT_BRANCH }}/.azure-pipelines/pr_test_scripts.yaml" -o ./.azure-pipelines/pr_test_scripts.yaml
15+
16+
# Else, internal build image repo, download from internal sonic-mgmt repo
17+
else
18+
curl -u :$(System.AccessToken) "${{ parameters.MGMT_URL }}&commitOrBranch=${{ parameters.MGMT_BRANCH }}&api-version=5.0-preview.1&path=.azure-pipelines%2Fpr_test_scripts.yaml" -o ./.azure-pipelines/pr_test_scripts.yaml
19+
fi
20+
displayName: "Download Pr Script"
21+
- ${{ else }}:
22+
- script: |
23+
# Else, sonic-mgmt repo, if not master branch, need to download test_plan.py
24+
set -ex
25+
CURRENT_BRANCH=${{ parameters.MGMT_BRANCH }}
26+
echo "Current branch: $CURRENT_BRANCH"
27+
if [[ "$CURRENT_BRANCH" != "master" ]]; then
28+
echo "Current mgmt branch is not master, need to download test_plan.py"
29+
curl "https://raw.githubusercontent.com/sonic-net/sonic-mgmt/master/.azure-pipelines/test_plan.py" -o ./.azure-pipelines/test_plan.py
30+
else
31+
echo "Current mgmt branch is master, no need to download test_plan.py"
32+
fi
33+
displayName: "Download Test Plan Script"
34+
35+
- script: |
36+
# Check if azure cli is installed. If not, try to install it
37+
if ! command -v az; then
38+
echo "Azure CLI is not installed. Trying to install it..."
39+
40+
echo "Get packages needed for the installation process"
41+
sudo apt-get -o DPkg::Lock::Timeout=600 update
42+
sudo apt-get -o DPkg::Lock::Timeout=600 -y install apt-transport-https ca-certificates curl gnupg lsb-release
43+
44+
echo "Download and install the Microsoft signing key"
45+
sudo mkdir -p /etc/apt/keyrings
46+
curl -sLS https://packages.microsoft.com/keys/microsoft.asc |
47+
gpg --dearmor | sudo tee /etc/apt/keyrings/microsoft.gpg > /dev/null
48+
sudo chmod go+r /etc/apt/keyrings/microsoft.gpg
49+
50+
echo "Add the Azure CLI software repository"
51+
AZ_DIST=$(lsb_release -cs)
52+
echo "Types: deb
53+
URIs: https://packages.microsoft.com/repos/azure-cli/
54+
Suites: ${AZ_DIST}
55+
Components: main
56+
Architectures: $(dpkg --print-architecture)
57+
Signed-by: /etc/apt/keyrings/microsoft.gpg" | sudo tee /etc/apt/sources.list.d/azure-cli.sources
58+
59+
echo "Update repository information and install the azure-cli package"
60+
sudo apt-get -o DPkg::Lock::Timeout=600 update
61+
sudo apt-get -o DPkg::Lock::Timeout=600 -y install azure-cli
62+
else
63+
echo "Azure CLI is already installed"
64+
fi
65+
displayName: "Install Azure-CLI"
66+
67+
- script: |
68+
set -e
69+
echo "Step: cancel previous testplans for PR"
70+
71+
pip install PyYAML
72+
73+
rm -f new_test_plan_id.txt
74+
75+
# Enable verbose debugging output for the creation call in test_plan.py
76+
set -x
77+
78+
python ./.azure-pipelines/test_plan.py cancel_pr
79+
80+
echo -e "\033[33mSONiC PR system-level test is powered by SONiC Elastictest, for any issue, please send email to sonicelastictest@microsoft.com \033[0m"
81+
82+
displayName: "Cancel previously created testplans for PR"

.azure-pipelines/pr_test_template.yml

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,23 @@ jobs:
8282
BUILD_BRANCH: $(BUILD_BRANCH)
8383
IMPACT_AREA_INFO: ${{ parameters.IMPACT_AREA_INFO }}
8484

85+
- job: cancel_previous_test_plan_for_same_pr
86+
displayName: "Cancel previous test plans for same PR"
87+
continueOnError: true
88+
pool: ${{ parameters.AGENT_POOL }}
89+
timeoutInMinutes: 10
90+
steps:
91+
- template: cancel-previous-elastictest-testplan.yml
92+
8593
- job: impacted_area_t0_elastictest
8694
displayName: "impacted-area-kvmtest-t0 by Elastictest"
8795
dependsOn:
8896
- get_impacted_area
97+
- cancel_previous_test_plan_for_same_pr
8998
variables:
9099
TEST_SCRIPTS: $[ dependencies.get_impacted_area.outputs['SetVariableTask.TEST_SCRIPTS'] ]
91100
RUN_BY_INCLUDE_JOBS: ${{ or(eq(parameters.INCLUDE_JOBS, 'all'), contains(parameters.INCLUDE_JOBS, 't0_job')) }}
92-
condition: and(contains(dependencies.get_impacted_area.outputs['SetVariableTask.PR_CHECKERS'], 't0_checker'), eq(variables['RUN_BY_INCLUDE_JOBS'], 'True'))
101+
condition: and(not(canceled()), succeeded(), contains(dependencies.get_impacted_area.outputs['SetVariableTask.PR_CHECKERS'], 't0_checker'), eq(variables['RUN_BY_INCLUDE_JOBS'], 'True'))
93102
timeoutInMinutes: ${{ parameters.TIMEOUT_IN_MINUTES_PR_TEST }}
94103
continueOnError: false
95104
pool: ${{ parameters.AGENT_POOL }}
@@ -128,10 +137,11 @@ jobs:
128137
displayName: "impacted-area-kvmtest-t0-2vlans by Elastictest"
129138
dependsOn:
130139
- get_impacted_area
140+
- cancel_previous_test_plan_for_same_pr
131141
variables:
132142
TEST_SCRIPTS: $[ dependencies.get_impacted_area.outputs['SetVariableTask.TEST_SCRIPTS'] ]
133143
RUN_BY_INCLUDE_JOBS: ${{ or(eq(parameters.INCLUDE_JOBS, 'all'), contains(parameters.INCLUDE_JOBS, 't0_2vlans_job')) }}
134-
condition: and(contains(dependencies.get_impacted_area.outputs['SetVariableTask.PR_CHECKERS'], 't0-2vlans_checker'), eq(variables['RUN_BY_INCLUDE_JOBS'], 'True'))
144+
condition: and(not(canceled()), succeeded(), contains(dependencies.get_impacted_area.outputs['SetVariableTask.PR_CHECKERS'], 't0-2vlans_checker'), eq(variables['RUN_BY_INCLUDE_JOBS'], 'True'))
135145
timeoutInMinutes: ${{ parameters.TIMEOUT_IN_MINUTES_PR_TEST }}
136146
continueOnError: false
137147
pool: ${{ parameters.AGENT_POOL }}
@@ -171,10 +181,11 @@ jobs:
171181
displayName: "impacted-area-kvmtest-t1-lag by Elastictest"
172182
dependsOn:
173183
- get_impacted_area
184+
- cancel_previous_test_plan_for_same_pr
174185
variables:
175186
TEST_SCRIPTS: $[ dependencies.get_impacted_area.outputs['SetVariableTask.TEST_SCRIPTS'] ]
176187
RUN_BY_INCLUDE_JOBS: ${{ or(eq(parameters.INCLUDE_JOBS, 'all'), contains(parameters.INCLUDE_JOBS, 't1_job')) }}
177-
condition: and(contains(dependencies.get_impacted_area.outputs['SetVariableTask.PR_CHECKERS'], 't1_checker'), eq(variables['RUN_BY_INCLUDE_JOBS'], 'True'))
188+
condition: and(not(canceled()), succeeded(), contains(dependencies.get_impacted_area.outputs['SetVariableTask.PR_CHECKERS'], 't1_checker'), eq(variables['RUN_BY_INCLUDE_JOBS'], 'True'))
178189
timeoutInMinutes: ${{ parameters.TIMEOUT_IN_MINUTES_PR_TEST }}
179190
continueOnError: false
180191
pool: ${{ parameters.AGENT_POOL }}
@@ -213,10 +224,11 @@ jobs:
213224
displayName: "impacted-area-kvmtest-dualtor by Elastictest"
214225
dependsOn:
215226
- get_impacted_area
227+
- cancel_previous_test_plan_for_same_pr
216228
variables:
217229
TEST_SCRIPTS: $[ dependencies.get_impacted_area.outputs['SetVariableTask.TEST_SCRIPTS'] ]
218230
RUN_BY_INCLUDE_JOBS: ${{ or(eq(parameters.INCLUDE_JOBS, 'all'), contains(parameters.INCLUDE_JOBS, 'dualtor_job')) }}
219-
condition: and(contains(dependencies.get_impacted_area.outputs['SetVariableTask.PR_CHECKERS'], 'dualtor_checker'), eq(variables['RUN_BY_INCLUDE_JOBS'], 'True'))
231+
condition: and(not(canceled()), succeeded(), contains(dependencies.get_impacted_area.outputs['SetVariableTask.PR_CHECKERS'], 'dualtor_checker'), eq(variables['RUN_BY_INCLUDE_JOBS'], 'True'))
220232
timeoutInMinutes: ${{ parameters.TIMEOUT_IN_MINUTES_PR_TEST }}
221233
continueOnError: false
222234
pool: ${{ parameters.AGENT_POOL }}
@@ -255,10 +267,11 @@ jobs:
255267
displayName: "impacted-area-kvmtest-t0-sonic by Elastictest"
256268
dependsOn:
257269
- get_impacted_area
270+
- cancel_previous_test_plan_for_same_pr
258271
variables:
259272
TEST_SCRIPTS: $[ dependencies.get_impacted_area.outputs['SetVariableTask.TEST_SCRIPTS'] ]
260273
RUN_BY_INCLUDE_JOBS: ${{ or(eq(parameters.INCLUDE_JOBS, 'all'), contains(parameters.INCLUDE_JOBS, 't0_sonic_job')) }}
261-
condition: and(contains(dependencies.get_impacted_area.outputs['SetVariableTask.PR_CHECKERS'], 't0-sonic_checker'), eq(variables['RUN_BY_INCLUDE_JOBS'], 'True'))
274+
condition: and(not(canceled()), succeeded(), contains(dependencies.get_impacted_area.outputs['SetVariableTask.PR_CHECKERS'], 't0-sonic_checker'), eq(variables['RUN_BY_INCLUDE_JOBS'], 'True'))
262275
timeoutInMinutes: ${{ parameters.TIMEOUT_IN_MINUTES_PR_TEST }}
263276
continueOnError: false
264277
pool: ${{ parameters.AGENT_POOL }}
@@ -302,10 +315,11 @@ jobs:
302315
displayName: "impacted-area-kvmtest-dpu by Elastictest"
303316
dependsOn:
304317
- get_impacted_area
318+
- cancel_previous_test_plan_for_same_pr
305319
variables:
306320
TEST_SCRIPTS: $[ dependencies.get_impacted_area.outputs['SetVariableTask.TEST_SCRIPTS'] ]
307321
RUN_BY_INCLUDE_JOBS: ${{ or(eq(parameters.INCLUDE_JOBS, 'all'), contains(parameters.INCLUDE_JOBS, 'dpu_job')) }}
308-
condition: and(contains(dependencies.get_impacted_area.outputs['SetVariableTask.PR_CHECKERS'], 'dpu_checker'), eq(variables['RUN_BY_INCLUDE_JOBS'], 'True'))
322+
condition: and(not(canceled()), succeeded(), contains(dependencies.get_impacted_area.outputs['SetVariableTask.PR_CHECKERS'], 'dpu_checker'), eq(variables['RUN_BY_INCLUDE_JOBS'], 'True'))
309323
timeoutInMinutes: ${{ parameters.TIMEOUT_IN_MINUTES_PR_TEST }}
310324
continueOnError: false
311325
pool: ${{ parameters.AGENT_POOL }}
@@ -348,10 +362,11 @@ jobs:
348362
displayName: "impacted-area-kvmtest-multi-asic-t1 by Elastictest"
349363
dependsOn:
350364
- get_impacted_area
365+
- cancel_previous_test_plan_for_same_pr
351366
variables:
352367
TEST_SCRIPTS: $[ dependencies.get_impacted_area.outputs['SetVariableTask.TEST_SCRIPTS'] ]
353368
RUN_BY_INCLUDE_JOBS: ${{ or(eq(parameters.INCLUDE_JOBS, 'all'), contains(parameters.INCLUDE_JOBS, 't1_multi_asic_job')) }}
354-
condition: and(contains(dependencies.get_impacted_area.outputs['SetVariableTask.PR_CHECKERS'], 't1_checker'), eq(variables['RUN_BY_INCLUDE_JOBS'], 'True'))
369+
condition: and(not(canceled()), succeeded(), contains(dependencies.get_impacted_area.outputs['SetVariableTask.PR_CHECKERS'], 't1_checker'), eq(variables['RUN_BY_INCLUDE_JOBS'], 'True'))
355370
timeoutInMinutes: ${{ parameters.TIMEOUT_IN_MINUTES_PR_TEST }}
356371
continueOnError: false
357372
pool: ${{ parameters.AGENT_POOL }}
@@ -391,10 +406,11 @@ jobs:
391406
displayName: "impacted-area-kvmtest-t2 by Elastictest"
392407
dependsOn:
393408
- get_impacted_area
409+
- cancel_previous_test_plan_for_same_pr
394410
variables:
395411
TEST_SCRIPTS: $[ dependencies.get_impacted_area.outputs['SetVariableTask.TEST_SCRIPTS'] ]
396412
RUN_BY_INCLUDE_JOBS: ${{ or(eq(parameters.INCLUDE_JOBS, 'all'), contains(parameters.INCLUDE_JOBS, 't2_job')) }}
397-
condition: and(contains(dependencies.get_impacted_area.outputs['SetVariableTask.PR_CHECKERS'], 't2_checker'), eq(variables['RUN_BY_INCLUDE_JOBS'], 'True'))
413+
condition: and(not(canceled()), succeeded(), not(canceled()), succeeded(), contains(dependencies.get_impacted_area.outputs['SetVariableTask.PR_CHECKERS'], 't2_checker'), eq(variables['RUN_BY_INCLUDE_JOBS'], 'True'))
398414
timeoutInMinutes: ${{ parameters.TIMEOUT_IN_MINUTES_PR_TEST }}
399415
continueOnError: false
400416
pool: ${{ parameters.AGENT_POOL }}
@@ -432,6 +448,9 @@ jobs:
432448

433449
# - job: t1_lag_vpp_elastictest
434450
# displayName: "kvmtest-t1-lag-vpp by Elastictest [OPTIONAL]"
451+
# dependsOn:
452+
# - get_impacted_area
453+
# - cancel_previous_test_plan_for_same_pr
435454
# timeoutInMinutes: ${{ parameters.TIMEOUT_IN_MINUTES_PR_TEST }}
436455
# continueOnError: true
437456
# pool: ${{ parameters.AGENT_POOL }}

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ stages:
8585

8686
- stage: Test
8787
dependsOn: Pre_test
88-
condition: and(succeeded(), in(dependencies.Pre_test.result, 'Succeeded'))
88+
condition: and(succeeded(), not(canceled()), in(dependencies.Pre_test.result, 'Succeeded'))
8989
variables:
9090
- group: SONiC-Elastictest
9191
- name: BUILD_BRANCH

0 commit comments

Comments
 (0)