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

Eth hotplug check cable and routable before pinging (Bugfix) #1694

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

seankingyang
Copy link
Contributor

@seankingyang seankingyang commented Jan 22, 2025

Description

Some of the machines (most of the IOT devices) can't ping after plugging the eth cable.
Some of the machines (most of the PC devices) can ping after plugging the eth cable.

In Desktop image, the networking renderer is Networkmanager

It will delay to turn down the eth interface and keep the ip (will not send req to DHCP to get the IP) when unpluggin the cable.

  • If the tester remove the cable and connect the cable immediatly, the test case can be pass (This is the work around method for the original script)
  • If the tester remove the cable, make sure the NetworkMangager trun the eth interface down, and reconnect the cable back. In this situation, some of the device will get the ip slowly and this test case will fail. But it really can get the original ip and available to ping.

In Server/UC image, the networking renderer is systemd-networkd

It will immediatly turn the interface down when unplugging the cable.

  • If the tester remove the cable and reconnect the cable immedatly, this test case will still fail. But it really can get the original ip and available to ping.

Change

Need to make sure the networking renderer actually not routable if remove the cable; it actually routable if reconnect the cable before ping.

Flow

1, Check interface cable state (make sure this eth interface is existed)
2. Ask Tester to remove the eth cable
3. check cable is remove
4. check network renderer is Not routable
5. Ask Tester to reconnect the eth cable
6. check cable is connect
7. check network renderer is routable
8. Ping the gateway

Resolved issues

#1197 ethernet/hotplug-{{ interface }} fails without potential latency
#1260 ethernet/hotplug-.* failed due to unable to ping the host

Tests

PC Desktop image with NetworkManager: https://certification.canonical.com/hardware/202411-35941/submission/409179/
IOT UC image with systemd-networkd: https://certification.canonical.com/hardware/202307-31859/submission/409181/

@seankingyang seankingyang changed the title Fix: Eth hotplug check cable and routable before pinging(BugFix) Fix: Eth hotplug check cable and routable before pinging(Bugfix) Jan 22, 2025
@seankingyang seankingyang marked this pull request as draft January 22, 2025 10:22
@seankingyang seankingyang changed the title Fix: Eth hotplug check cable and routable before pinging(Bugfix) Eth hotplug check cable and routable before pinging (Bugfix) Jan 22, 2025
Copy link

codecov bot commented Jan 23, 2025

Codecov Report

Attention: Patch coverage is 97.91667% with 2 lines in your changes missing coverage. Please review.

Project coverage is 49.18%. Comparing base (4305ba1) to head (ef6091d).
Report is 21 commits behind head on main.

Files with missing lines Patch % Lines
providers/base/bin/eth_hotplugging.py 97.91% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1694      +/-   ##
==========================================
+ Coverage   48.99%   49.18%   +0.19%     
==========================================
  Files         372      372              
  Lines       40321    40397      +76     
  Branches     6811     6826      +15     
==========================================
+ Hits        19757    19871     +114     
+ Misses      19842    19802      -40     
- Partials      722      724       +2     
Flag Coverage Δ
provider-base 25.40% <97.91%> (+0.60%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@seankingyang seankingyang marked this pull request as ready for review January 23, 2025 05:46
Copy link
Collaborator

@pieqq pieqq left a comment

Choose a reason for hiding this comment

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

Thanks for undertaking this big change!

I noticed you used your own retry mechanism for different functions in the script. I recommend using the retry decorator available in checkbox-support (see comments inline below).

return (routable, state)


def wait_for_routable_state(
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should check the retry helper decorator available in checkbox-support. (you can check how it's used here for instance). This decorator was written to prevent multiple implementations of a retry mechanism in our different test scripts.

(and we provide a mock_retry object for writing unit tests, see the different examples available in the repo)

@@ -17,6 +126,47 @@ def has_cable(iface):
return carrier.read()[0] == "1"


def wait_for_cable_state(iface, do_cable=True, max_wait=30):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, using the retry decorator would be better.

Comment on lines +87 to +89
except sp.CalledProcessError as e:
print("Error running {} command: {}".format(renderer, e))
return info
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a case where you would want to return an empty dictionary and keep executing the script, even though the command returned something wrong?

Wouldn't it be better to just let the CalledProcessError exception bubble up?

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.

2 participants