summaryrefslogtreecommitdiff
diff options
-rwxr-xr-xbin/network_device_info.py18
-rw-r--r--units/ethernet/jobs.pxu2
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