-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(network): add behave tests to ensure network errors are handled
- Loading branch information
Showing
1 changed file
with
92 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
@uses.config.contract_token | ||
Feature: Ensure network errors are handled gracefully across various services | ||
|
||
Scenario Outline: Various HTTP errors are handled gracefully on attaching contract token | ||
# This test simulates various HTTP errors by mocking the response from the serviceclient | ||
# when trying to attach contract token | ||
Given a `<release>` `<machine_type>` machine with ubuntu-advantage-tools installed | ||
When I create the file `/tmp/response-overlay.json` with the following: | ||
""" | ||
{ | ||
"https://contracts.canonical.com/v1/context/machines/token": [ | ||
{ | ||
"code": <response_code>, | ||
"response": { | ||
"error": <error_message> | ||
} | ||
} | ||
] | ||
} | ||
""" | ||
And I append the following on uaclient config: | ||
""" | ||
features: | ||
serviceclient_url_responses: "/tmp/response-overlay.json" | ||
""" | ||
When I attempt to attach `contract_token` with sudo | ||
Then stderr contains substring: | ||
""" | ||
Error connecting to <endpoint>: <response_code> {"error": <error_message>} | ||
""" | ||
Then the machine is unattached | ||
|
||
Examples: ubuntu release | ||
| release | machine_type | endpoint | response_code | error_message | | ||
| jammy | lxd-container | /v1/context/machines/token | 400 | "Bad Request" | | ||
| jammy | lxd-container | /v1/context/machines/token | 404 | "Not Found" | | ||
| jammy | lxd-container | /v1/context/machines/token | 503 | "Bad Gateway" | | ||
|
||
Scenario Outline: Network errors for attaching contract token are handled gracefully | ||
# This test simulates network failure by disabling internet connection | ||
# and then trying to attach contract token | ||
Given a `<release>` `<machine_type>` machine with ubuntu-advantage-tools installed | ||
When I disable any internet connection on the machine | ||
And I attempt to attach `contract_token` with sudo | ||
Then stderr contains substring: | ||
""" | ||
Failed to attach machine. See https://ubuntu.com/pro/dashboard | ||
""" | ||
Then the machine is unattached | ||
|
||
Examples: ubuntu release | ||
| release | machine_type | | ||
| jammy | lxd-container | | ||
|
||
Scenario Outline: Network errors for enabling Realtime kernel are handled gracefully | ||
# This test simulates network failure by disabling internet connection | ||
# and then trying to enable realtime-kernel | ||
Given a `<release>` `<machine_type>` machine with ubuntu-advantage-tools installed | ||
When I attach `contract_token` with sudo and options `--no-auto-enable` | ||
Then the machine is attached | ||
Then I verify that `realtime-kernel` is disabled | ||
When I disable any internet connection on the machine | ||
And I verify that running `pro enable realtime-kernel` `with sudo` and stdin `y\ny` exits `1` | ||
Then stderr contains substring: | ||
""" | ||
Failed to connect to https://contracts.canonical.com/v1/contracts/ | ||
""" | ||
Then I verify that `realtime-kernel` is disabled | ||
|
||
# Realtime kernel is not supported on LXD containers so we must use a VM | ||
Examples: ubuntu release | ||
| release | machine_type | | ||
| jammy | lxd-vm | | ||
|
||
Scenario Outline: Network errors for enabling Livepatch are handled gracefully | ||
# This test simulates network failure by disabling internet connection | ||
# and then trying to enable livepatch | ||
Given a `<release>` `<machine_type>` machine with ubuntu-advantage-tools installed | ||
When I attach `contract_token` with sudo and options `--no-auto-enable` | ||
Then the machine is attached | ||
Then I verify that `livepatch` is disabled | ||
When I disable any internet connection on the machine | ||
Then I verify that running `pro enable livepatch` `with sudo` exits `1` | ||
Then stderr contains substring: | ||
""" | ||
Failed to connect to https://contracts.canonical.com/v1/contracts/ | ||
""" | ||
Then I verify that `livepatch` is disabled | ||
|
||
Examples: ubuntu release | ||
| release | machine_type | | ||
| jammy | lxd-container | |