Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes for test results #2732

Merged
merged 3 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions tests_e2e/orchestrator/scripts/run-scenarios
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ lisa \
--log_path "$lisa_logs" \
--working_path "$lisa_logs" \
-v subscription_id:"$SUBSCRIPTION_ID" \
-v identity_file:"$HOME/.ssh/id_rsa" \
|| true # force a success exit code to allow execution to continue when a test fails
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now this is handled in execute_tests.sh

-v identity_file:"$HOME/.ssh/id_rsa"

10 changes: 9 additions & 1 deletion tests_e2e/pipeline/scripts/execute_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ docker pull waagenttests.azurecr.io/waagenttests:latest
sudo chown 1000 "$BUILD_SOURCESDIRECTORY"
sudo chown 1000 "$BUILD_ARTIFACTSTAGINGDIRECTORY"

# A test failure will cause automation to exit with an error code and we don't want this script to stop so we force the command
# to succeed and capture the exit code to return it at the end of the script.
echo "exit 0" > /tmp/exit.sh

docker run --rm \
--volume "$BUILD_SOURCESDIRECTORY:/home/waagent/WALinuxAgent" \
--volume "$DOWNLOADSSHKEY_SECUREFILEPATH:/home/waagent/id_rsa" \
Expand All @@ -23,7 +27,8 @@ docker run --rm \
--env AZURE_CLIENT_SECRET \
--env AZURE_TENANT_ID \
waagenttests.azurecr.io/waagenttests \
bash --login -c '$HOME/WALinuxAgent/tests_e2e/orchestrator/scripts/run-scenarios'
bash --login -c '$HOME/WALinuxAgent/tests_e2e/orchestrator/scripts/run-scenarios' \
|| echo "exit $?" > /tmp/exit.sh

# Retake ownership of the source and staging directory (note that the former does not need to be done recursively)
sudo chown "$USER" "$BUILD_SOURCESDIRECTORY"
Expand All @@ -43,3 +48,6 @@ sudo find "$BUILD_ARTIFACTSTAGINGDIRECTORY" -exec chown "$USER" {} \;
#
mv "$BUILD_ARTIFACTSTAGINGDIRECTORY"/lisa/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/*/* "$BUILD_ARTIFACTSTAGINGDIRECTORY"/lisa
rm -r "$BUILD_ARTIFACTSTAGINGDIRECTORY"/lisa/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]

cat /tmp/exit.sh
bash /tmp/exit.sh
13 changes: 8 additions & 5 deletions tests_e2e/pipeline/templates/execute-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,23 @@ jobs:

- bash: $(Build.SourcesDirectory)/tests_e2e/pipeline/scripts/execute_tests.sh
displayName: "Execute tests"
continueOnError: true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test failures should not stop the pipeline, so we allow this task to continue on error

env:
# Add all KeyVault secrets explicitly as they're not added by default to the environment vars
AZURE_CLIENT_ID: $(AZURE-CLIENT-ID)
AZURE_CLIENT_SECRET: $(AZURE-CLIENT-SECRET)
AZURE_TENANT_ID: $(AZURE-TENANT-ID)
SUBSCRIPTION_ID: $(SUBSCRIPTION-ID)

- publish: $(Build.ArtifactStagingDirectory)
artifact: 'artifacts'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should I be accessing the test artifacts/logs?

I thought you were going to the pipeline's published items, but when I go to check the published artifacts on the test run I don't see the same hierarchy you shared on our call:
image

displayName: 'Publish test artifacts'

- task: PublishTestResults@2
displayName: 'Publish test results'
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '**/*junit.xml'
testResultsFiles: 'lisa/agent.junit.xml'
searchFolder: $(Build.ArtifactStagingDirectory)
testRunTitle: 'Publish test results'
failTaskOnFailedTests: true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the Execute Tests tasks fails, the build is declared as a Partial Success. This forces the build to Fail on test failures

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how this flag(failTaskOnFailedTests) is related and only checks for execute-tests status?

will this not run if I have test failures? I think we need all the time to know summary of failures and successes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task will mark itself as Failed, but it won't prevent it from publishing the results

from https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/publish-test-results-v2

failTaskOnFailedTests - Fail if there are test failures
boolean. Default value: false.

Optional. When this boolean's value is true, the task will fail if any of the tests in the results file are marked as failed. The default is false, which will simply publish the results from the results file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(see run 5534 for an example)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining, makes sense. I see few runs with warning sign. what is that mean? we have some warnings in test but no failures?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are partial success (reported as "[Build partially succeeded] ...- WALinuxAgent - 0eeb2c4")

The test execution failed (either because we could not execute the tests, or because some test failed), but I forced the Pipeline to continueOnError when the test execution task fails.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW - In those test runs there are no test results due to a bug in LISA. I reported it this morning and they will fix it.


- publish: $(Build.ArtifactStagingDirectory)
artifact: 'test-logs'
displayName: 'Publish test logs'
2 changes: 1 addition & 1 deletion tests_e2e/scenarios/runbooks/daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ concurrency: 10

notifier:
- type: env_stats
- type: junit
- type: agent.junit
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a custom JUnit notifier for the Agent


include:
- path: ./include/ssh_proxy.yml
Expand Down
2 changes: 1 addition & 1 deletion tests_e2e/scenarios/runbooks/samples/existing_vm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ platform:

notifier:
- type: env_stats
- type: junit
- type: agent.junit

include:
- path: ../include/ssh_proxy.yml
50 changes: 50 additions & 0 deletions tests_e2e/scenarios/testsuites/agent_junit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Microsoft Azure Linux Agent
#
# Copyright 2018 Microsoft Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from dataclasses import dataclass
from typing import Type

from dataclasses_json import dataclass_json

from lisa.notifiers.junit import JUnit
from lisa import schema
from lisa.messages import (
MessageBase,
TestResultMessage,
)


@dataclass_json()
@dataclass
class AgentJUnitSchema(schema.Notifier):
path: str = "agent.junit.xml"


class AgentJUnit(JUnit):
@classmethod
def type_name(cls) -> str:
return "agent.junit"

@classmethod
def type_schema(cls) -> Type[schema.TypedSchema]:
return AgentJUnitSchema

def _received_message(self, message: MessageBase) -> None:
if isinstance(message, TestResultMessage):
distro = message.information.get('distro_version')
if distro is not None:
message.name = distro
super()._received_message(message)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We replace the test name (which is always "main" in our test runs) with the distro name