diff options
author | PMR <pmr@pmr-lander> | 2020-09-14 07:36:15 +0000 |
---|---|---|
committer | PMR <pmr@pmr-lander> | 2020-09-14 07:36:15 +0000 |
commit | eeea3b9285f2e3566536f9f578a6321c69ae4484 (patch) | |
tree | 05cea372db7605c69cbf1e51237ad6ae1cc46e43 | |
parent | d61e14170e5330d9b2e6366f675a1abbb613c990 (diff) | |
parent | 10a5beb2ddac5a49e9468408cc2d4b7e12625397 (diff) |
Merge #390510 from ~bladernr/plainbox-provider-checkbox:1895048-fail-on-carrier-disconnected
-rwxr-xr-x | bin/network_device_info.py | 18 | ||||
-rw-r--r-- | units/ethernet/jobs.pxu | 2 |
2 files changed, 19 insertions, 1 deletions
diff --git a/bin/network_device_info.py b/bin/network_device_info.py index 925b3f5..bba546b 100755 --- a/bin/network_device_info.py +++ b/bin/network_device_info.py @@ -148,6 +148,10 @@ class NetworkDeviceInfo(): self._interface_populate() @property + def carrier_status(self): + return self._carrier_status + + @property def driver(self): return self._driver @@ -342,9 +346,13 @@ if __name__ == "__main__": help='Don\'t attempt to get info from network manager') parser.add_argument('--interface', help='Restrict info action to specified interface') + parser.add_argument('--fail-on-disconnected', action='store_true', + help=('Script will exit with a non-zero return code if' + ' any interface is not connected')) args = parser.parse_args() udev = UdevDevices(args.category) + disconnected_ifaces = [] # The detect action should indicate presence of a device belonging to the # category and cause the job to fail if none present @@ -371,6 +379,8 @@ if __name__ == "__main__": print("[ Devices found by udev ]".center(80, '-')) for device in udev.devices(): print(device) + if device.carrier_status == "Disconnected": + disconnected_ifaces.append(device.interface) # Attempt to report devices found by NetworkManager. This can be # skipped as doesn't make sense for server installs @@ -379,3 +389,11 @@ if __name__ == "__main__": print("[ Devices found by Network Manager ]".center(80, '-')) for device in nm.devices(): print(device) + + if disconnected_ifaces and args.fail_on_disconnected: + print("WARNING: The following interfaces are not connected:") + for iface in disconnected_ifaces: + print(iface) + sys.exit(1) + + sys.exit(0) diff --git a/units/ethernet/jobs.pxu b/units/ethernet/jobs.pxu index 36c25f4..69e7760 100644 --- a/units/ethernet/jobs.pxu +++ b/units/ethernet/jobs.pxu @@ -32,7 +32,7 @@ id: ethernet/info_automated_server requires: device.category == 'NETWORK' user: root -command: network_device_info.py info NETWORK --no-nm +command: network_device_info.py info NETWORK --no-nm --fail-on-disconnected estimated_duration: 2.0 _summary: Provide information about detected ethernet devices |