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

test(network): add behave tests to ensure network errors are handled #3272

Merged
merged 1 commit into from
Sep 10, 2024

Conversation

a-dubs
Copy link
Collaborator

@a-dubs a-dubs commented Aug 20, 2024

Why is this needed?

This PR adds functionality that ensures that the various networking exception handling issues that have been raised on various LP bugs, which were resolved during the work for #2647 was completed, are properly caught, handled, and raised.

Test Steps

Run the new behave tests locally:

tox -e behave -- features/network_failures.feature

  • (un)check this to re-run the checklist action

Copy link

github-actions bot commented Aug 20, 2024

PR Checklist

How to use this checklist

How to use this checklist

PR Author

For each section, check a box when it is true.
Uncheck a box if it becomes un-true.
Then check the box at the bottom of the PR description to re-run the action that creates this checklist.
The action that creates and updates this comment will retain your edits.
The action will fail if the checklist is not completed.

PR Reviewer

Check that the PR checklist action did not fail.
Double check that the author filled out the checklist accurately.
If you disagree with a checklist item, start a conversation.
For example, the author may say they don't think integration tests are necessary, but you may disagree.

Bug References

None.

Confirm

  • I've properly referenced all bugs that this PR fixes
How to properly reference fixed bugs
  • If this PR is related to a Jira item, include an SC-1234 reference in the PR title
  • If this PR is fixes a GitHub issue, include a Fixes: #1234 reference in the commit that fixes the issue
  • If this PR is fixes a Launchpad bug, include a LP: #12345678 reference in the commit that fixes the issue

Test Updates

Unit Tests

  • I have updated or added any unit tests accordingly
  • No unit test changes are necessary for this change

Integration Tests

  • I have updated or added any integration tests accordingly
  • No integration test changes are necessary for this change

Documentation

  • Changes here need to be documented and I have referenced the docs PR in the description
  • No documentation updates are necessary for this change

Does this PR require review from someone outside the core ubuntu-pro-client team?

  • Yes, and I have requested those reviews via GitHub
  • No

Copy link
Contributor

@dheyay dheyay left a comment

Choose a reason for hiding this comment

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

Looks good 💯 , some minor nits

features/network_failures.feature Outdated Show resolved Hide resolved
features/network_failures.feature Outdated Show resolved Hide resolved
features/network_failures.feature Outdated Show resolved Hide resolved
features/network_failures.feature Outdated Show resolved Hide resolved
@a-dubs a-dubs marked this pull request as ready for review August 26, 2024 14:21
@a-dubs a-dubs force-pushed the SC-1824-add-network-failure-behave-tests branch from 81a332a to 745dc59 Compare August 26, 2024 14:22
@a-dubs
Copy link
Collaborator Author

a-dubs commented Aug 26, 2024

okay ready for re-review now 🫡 @dheyay

@a-dubs a-dubs force-pushed the SC-1824-add-network-failure-behave-tests branch from 745dc59 to 0b91f75 Compare August 26, 2024 19:10
@renanrodrigo
Copy link
Member

@a-dubs seems flake8 is not fond of your message strings

@a-dubs a-dubs marked this pull request as draft September 2, 2024 21:10
@a-dubs a-dubs force-pushed the SC-1824-add-network-failure-behave-tests branch from 8cceb87 to 657d0a7 Compare September 2, 2024 21:13
@a-dubs
Copy link
Collaborator Author

a-dubs commented Sep 2, 2024

Tests have been constrained to only xenial and noble since the functionality being tested by this is unlikely to break and only needs tested on the oldest and newest LTS releases.

@a-dubs a-dubs marked this pull request as ready for review September 2, 2024 21:29
Copy link
Contributor

@dheyay dheyay left a comment

Choose a reason for hiding this comment

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

Looks good to me, would just need to squash commits before merging

@renanrodrigo renanrodrigo force-pushed the SC-1824-add-network-failure-behave-tests branch from 66f33d2 to 28907b0 Compare September 3, 2024 21:01
@renanrodrigo
Copy link
Member

took the liberty to rebase this after merging #3267 - I'll take a last look and probably merge it

And I attempt to attach `contract_token` with sudo
Then stderr contains substring:
"""
Failed to attach machine. See https://ubuntu.com/pro/dashboard
Copy link
Member

Choose a reason for hiding this comment

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

I think this actually needs to be fixed for us to consider the respective LP bug closed. The problem here is that you don't have internet connection:

  • there is no indication that lack of connection was the problem
  • how are people supposed to access their dashboard if the network is down?

Copy link
Member

Choose a reason for hiding this comment

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

@a-dubs if you want, we can land the tests and then you change this message on a next step?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh shoot yeah you're right. That's not exactly a very useful or specific message. So you're right we definitely need to update the message to consider those bugs closed. As such, I think it would be best if I put this back in draft state and make the changes to the source code such that the source code changes and tests are bundled together into one logical commit, so that when I say "fixes lp #XXXX", I mean fixes

Comment on lines 106 to 109
Examples: ubuntu release
| release | machine_type |
| xenial | lxd-container |
| noble | lxd-container |
Copy link
Member

Choose a reason for hiding this comment

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

See how this test is similar to the upper one, except for the service to be disabled?
You can create another column in the table below with "service to disable" so it looks like this:

Suggested change
Examples: ubuntu release
| release | machine_type |
| xenial | lxd-container |
| noble | lxd-container |
Examples: ubuntu release
| release | machine_type | service |
| xenial | lxd-container | livepatch |
| xenial | lxd-container | realtime-kernel |
| noble | lxd-container | livepatch |
| noble | lxd-container | realtime-kernel |

Feel free to ignore this though - if you think this is good as is, keep it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

At first glance, I was initially onboard because i love reducing duplicate code where reasonable, but then I noticed the and stdin 'y\ny' that only exists in the realtime kernel tests and not the livepatch tests.

Copy link
Member

Choose a reason for hiding this comment

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

good catch forget what I said

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

okay i am unable to forget and got the following working but its a bit jank and not sure how to feel about it:

  Scenario Outline: Network errors for enabling Realtime kernel and Livepatch are handled gracefully
    # This test simulates network failure by disabling internet connection
    # and then trying to enable realtime-kernel or 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 `<service>` is disabled
    When I disable any internet connection on the machine
    And I verify that running `pro enable <service>` `with sudo` <exit_with_optional_stdin_clause>
    Then stderr contains substring:
      """
      Failed to connect to https://contracts.canonical.com/v1/contracts/
      """
    Then I verify that `<service>` is disabled

    # Realtime kernel is not supported on LXD containers so we must use a VM
    Examples: ubuntu release
      | release | machine_type | service         | exit_with_optional_stdin_clause |
      | xenial  | lxd-vm       | realtime-kernel | and stdin `y\ny` exits `1`      |
      | noble   | lxd-vm       | realtime-kernel | and stdin `y\ny` exits `1`      |
      | xenial  | lxd-vm       | livepatch       | exits `1`                       |
      | noble   | lxd-vm       | livepatch       | exits `1`                       |

Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead, would using --assume-yes on the enable call allow you to avoid the and stdin so that they can be the same for livepatch and realtime?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh you can do that??? That would be way better!

@a-dubs a-dubs marked this pull request as draft September 4, 2024 04:17
@a-dubs a-dubs force-pushed the SC-1824-add-network-failure-behave-tests branch from 28907b0 to f94ce30 Compare September 5, 2024 20:41
@a-dubs a-dubs force-pushed the SC-1824-add-network-failure-behave-tests branch from f94ce30 to b03a6a1 Compare September 5, 2024 20:43
@a-dubs a-dubs marked this pull request as ready for review September 5, 2024 20:43
@a-dubs
Copy link
Collaborator Author

a-dubs commented Sep 5, 2024

@dheyay @renanrodrigo this should be ready for review now. let's just get this in and then i'll work on actually improving the exception handling and messaging for networking errors

Copy link
Member

@renanrodrigo renanrodrigo left a comment

Choose a reason for hiding this comment

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

testing it good

@renanrodrigo renanrodrigo merged commit 1accb8c into next-v35 Sep 10, 2024
20 of 24 checks passed
@renanrodrigo renanrodrigo deleted the SC-1824-add-network-failure-behave-tests branch September 10, 2024 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants