diff options
author | Maciej Kisielewski <maciej.kisielewski@canonical.com> | 2018-07-12 15:15:44 +0200 |
---|---|---|
committer | Maciej Kisielewski <maciej.kisielewski@canonical.com> | 2018-07-12 17:26:03 +0200 |
commit | 5605a1ad8664fcb4dfd2ee0b70b93aa62e0292b3 (patch) | |
tree | b18fdc22fe1ecf5f7c0ecfeedb9a336240a7c8c9 /bin | |
parent | 49c7c4ea43d24a1c061f3e82b99189c1813062de (diff) |
add usb type-c to ethernet test
Signed-off-by: Maciej Kisielewski <maciej.kisielewski@canonical.com>
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/net_if_watcher.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/bin/net_if_watcher.py b/bin/net_if_watcher.py new file mode 100755 index 0000000..0ba61df --- /dev/null +++ b/bin/net_if_watcher.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +# Copyright 2018 Canonical Ltd. +# All rights reserved. +# +# Written by: +# Maciej Kisielewski <maciej.kisielewski@canonical.com> +""" +Detect insertion of a new network interface. +""" + +from pathlib import Path +import time + + +def get_ifaces(): + return set([i.name for i in Path("/sys/class/net").iterdir()]) + + +def main(): + print("INSERT NOW") + starting_ifaces = get_ifaces() + attempts = 20 + while attempts > 0: + now_ifaces = get_ifaces() + # check if something disappeared + if not starting_ifaces == now_ifaces & starting_ifaces: + raise SystemExit("Interface(s) disappeared: {}".format( + ", ".join(list(starting_ifaces - now_ifaces)))) + new_ifaces = now_ifaces - starting_ifaces + if new_ifaces: + print() + print("New interface(s) detected: {}".format( + ", ".join(list(new_ifaces)))) + return + time.sleep(1) + print('.', end='', flush=True) + attempts -= 1 + print() + raise SystemExit("Failed to detect new network interface") + + +if __name__ == '__main__': + main() |