Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .azure-pipelines/run-test-elastictest-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ steps:
curl -u :$(MSSONIC-TOKEN) "${{ 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
fi
displayName: "Download pr script"
- ${{ else }}:
- ${{ if ne(parameters.MGMT_BRANCH, 'master') }}:
- script: |
# Else, sonic-mgmt repo, if not master branch, need to download test_plan.py
set -ex
curl "https://raw.githubusercontent.com/sonic-net/sonic-mgmt/master/.azure-pipelines/test_plan.py" -o ./.azure-pipelines/test_plan.py
displayName: "Download test plan script"
# - ${{ else }}:
# - ${{ if ne(parameters.MGMT_BRANCH, 'master') }}:
# - script: |
# # Else, sonic-mgmt repo, if not master branch, need to download test_plan.py
# set -ex
# curl "https://raw.githubusercontent.com/sonic-net/sonic-mgmt/master/.azure-pipelines/test_plan.py" -o ./.azure-pipelines/test_plan.py
# displayName: "Download test plan script"

- script: |
# Check if azure cli is installed. If not, try to install it
Expand Down
30 changes: 19 additions & 11 deletions .azure-pipelines/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_plan_status_factory(status):
raise Exception("The status is not correct.")


class AbstractStatus():
class AbstractStatus:
def __init__(self, status):
self.status = status

Expand Down Expand Up @@ -380,7 +380,7 @@ def poll(self, test_plan_id, interval=60, timeout=-1, expected_state="", expecte
}
start_time = time.time()
http_exception_times = 0
while (timeout < 0 or (time.time() - start_time) < timeout):
while timeout < 0 or (time.time() - start_time) < timeout:
try:
if self.with_auth:
headers["Authorization"] = "Bearer {}".format(self.get_token())
Expand All @@ -402,13 +402,15 @@ def poll(self, test_plan_id, interval=60, timeout=-1, expected_state="", expecte
if not resp_data:
raise Exception("No valid data in response: {}".format(str(resp)))

status = resp_data.get("status", None)
result = resp_data.get("result", None)
current_tp_status = resp_data.get("status", None)
current_tp_result = resp_data.get("result", None)

if expected_state:
current_status = test_plan_status_factory(status)
current_status = test_plan_status_factory(current_tp_status)
expected_status = test_plan_status_factory(expected_state)

print("current status: {}, expected status: {}".format(current_tp_status, expected_state))

if expected_status.get_status() == current_status.get_status():
current_status.print_logs(test_plan_id, resp_data, start_time)
elif expected_status.get_status() < current_status.get_status():
Expand All @@ -430,7 +432,13 @@ def poll(self, test_plan_id, interval=60, timeout=-1, expected_state="", expecte

# We fail the step only if the step_status is "FAILED".
# Other status such as "SKIPPED", "CANCELED" are considered successful.
if step_status == "FAILED":
"""
If step_status is None, means that current step was not executed but current status is in a post
status. For example: current is Failed, expect is Executing, and after prepare tb it went to fail,
so executing not started. In this scenario, step_status is None but current status is Failed.
So, return to failure. Otherwise, it will return to pass and cause inconsistency issues.
"""
if step_status == "FAILED" or (step_status is None and current_tp_status == "FAILED"):

# Print error type and message
err_code = resp_data.get("runtime", {}).get("err_code", None)
Expand All @@ -443,23 +451,23 @@ def poll(self, test_plan_id, interval=60, timeout=-1, expected_state="", expecte

raise Exception("Test plan id: {}, status: {}, result: {}, Elapsed {:.0f} seconds. "
"Check {}/scheduler/testplan/{} for test plan status"
.format(test_plan_id, step_status, result, time.time() - start_time,
.format(test_plan_id, step_status, current_tp_result, time.time() - start_time,
self.frontend_url,
test_plan_id))
if expected_result:
if result != expected_result:
if current_tp_result != expected_result:
raise Exception("Test plan id: {}, status: {}, result: {} not match expected result: {}, "
"Elapsed {:.0f} seconds. "
"Check {}/scheduler/testplan/{} for test plan status"
.format(test_plan_id, step_status, result,
.format(test_plan_id, step_status, current_tp_result,
expected_result, time.time() - start_time,
self.frontend_url,
test_plan_id))

print("Current status is {}".format(step_status))
print("Current step status is {}".format(step_status))
return
else:
print("Current state is {}, waiting for the state {}".format(status, expected_state))
print("Current state is {}, waiting for the state {}".format(current_tp_status, expected_state))

time.sleep(interval)

Expand Down
Loading