-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add sample remote tests * add pass * review feedback --------- Co-authored-by: narrieta <narrieta>
- Loading branch information
Showing
15 changed files
with
311 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
name: "Fail" | ||
tests: | ||
- "fail_test.py" | ||
- "error_test.py" | ||
images: "ubuntu_1804" | ||
- "samples/fail_test.py" | ||
- "samples/fail_remote_test.py" | ||
- "samples/error_test.py" | ||
- "samples/error_remote_test.py" | ||
images: "ubuntu_2004" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
name: "Pass" | ||
tests: | ||
- "pass_test.py" | ||
- "samples/pass_test.py" | ||
- "samples/pass_remote_test.py" | ||
images: "ubuntu_2004" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env pypy3 | ||
|
||
# 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. | ||
# | ||
import sys | ||
|
||
from typing import Callable | ||
|
||
from tests_e2e.tests.lib.logging import log | ||
|
||
SUCCESS_EXIT_CODE = 0 | ||
FAIL_EXIT_CODE = 100 | ||
ERROR_EXIT_CODE = 200 | ||
|
||
|
||
def run_remote_test(test_method: Callable[[], int]) -> None: | ||
""" | ||
Helper function to run a remote test; implements coding conventions for remote tests, e.g. error message goes | ||
to stderr, test log goes to stdout, etc. | ||
""" | ||
try: | ||
test_method() | ||
log.info("*** PASSED") | ||
except AssertionError as e: | ||
print(f"{e}", file=sys.stderr) | ||
log.error("%s", e) | ||
sys.exit(FAIL_EXIT_CODE) | ||
except Exception as e: | ||
print(f"UNEXPECTED ERROR: {e}", file=sys.stderr) | ||
log.exception("*** UNEXPECTED ERROR") | ||
sys.exit(ERROR_EXIT_CODE) | ||
|
||
sys.exit(SUCCESS_EXIT_CODE) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# 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 tests_e2e.tests.lib.agent_test import AgentTest | ||
|
||
|
||
class ErrorRemoteTest(AgentTest): | ||
""" | ||
A trivial remote test that fails | ||
""" | ||
def run(self): | ||
self._run_remote_test("samples-error_remote_test.py") | ||
|
||
|
||
if __name__ == "__main__": | ||
ErrorRemoteTest.run_from_command_line() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# 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 tests_e2e.tests.lib.agent_test import AgentTest | ||
|
||
|
||
class FailRemoteTest(AgentTest): | ||
""" | ||
A trivial remote test that fails | ||
""" | ||
def run(self): | ||
self._run_remote_test("samples-fail_remote_test.py") | ||
|
||
|
||
if __name__ == "__main__": | ||
FailRemoteTest.run_from_command_line() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# 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 tests_e2e.tests.lib.agent_test import AgentTest | ||
|
||
|
||
class PassRemoteTest(AgentTest): | ||
""" | ||
A trivial remote test that succeeds | ||
""" | ||
def run(self): | ||
self._run_remote_test("samples-pass_remote_test.py") | ||
|
||
|
||
if __name__ == "__main__": | ||
PassRemoteTest.run_from_command_line() |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env pypy3 | ||
|
||
# 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. | ||
# | ||
|
||
# | ||
# A sample remote test that simulates an unexpected error | ||
# | ||
|
||
from tests_e2e.tests.lib.logging import log | ||
from tests_e2e.tests.lib.remote_test import run_remote_test | ||
|
||
|
||
def main(): | ||
log.info("Setting up test") | ||
log.info("Doing some operation") | ||
log.warning("Something went wrong, but the test can continue") | ||
log.info("Doing some other operation") | ||
raise Exception("Something went wrong") # simulate an unexpected error | ||
|
||
|
||
run_remote_test(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env pypy3 | ||
|
||
# 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. | ||
# | ||
|
||
# | ||
# A sample remote test that fails | ||
# | ||
|
||
from assertpy import fail | ||
from tests_e2e.tests.lib.logging import log | ||
from tests_e2e.tests.lib.remote_test import run_remote_test | ||
|
||
|
||
def main(): | ||
log.info("Setting up test") | ||
log.info("Doing some operation") | ||
log.warning("Something went wrong, but the test can continue") | ||
log.info("Doing some other operation") | ||
fail("Verification of the operation failed") | ||
|
||
|
||
run_remote_test(main) |
Oops, something went wrong.