shill: test-scripts: Make list-active-service exit(1) if nothing found
Currently list-active-service always returns 0. The test scripts for
Magic Tether want to use `list-active-service wifi` to check
whether wifi is active, so it is helpful to inform the calling script
if nothing matched.
BUG=b:76033351
TEST=./list-active-service wifi ; echo $?
TEST=./list-active-service foobar ; echo $?
Change-Id: I7ed32ab41c6d07d998110ad7cef2420ae027f1ee
Reviewed-on: https://chromium-review.googlesource.com/965397
Commit-Ready: Kevin Cernekee <cernekee@chromium.org>
Tested-by: Kevin Cernekee <cernekee@chromium.org>
Reviewed-by: Leslie Watkins <lesliewatkins@chromium.org>
Reviewed-by: Brian Norris <briannorris@chromium.org>
diff --git a/test-scripts/list-active-service b/test-scripts/list-active-service
index 34d9b00..6c53ec1 100755
--- a/test-scripts/list-active-service
+++ b/test-scripts/list-active-service
@@ -33,6 +33,9 @@
flim = flimflam.FlimFlam(dbus.SystemBus())
+ # Nothing found -> exit(1)
+ retval = 1
+
for service in flim.GetObjectList('Service'):
properties = service.GetProperties(utf8_strings = True)
if not bool(properties['IsActive']):
@@ -48,8 +51,11 @@
requested_keys = properties.keys()
for key in requested_keys:
+ retval = 0
print(' %s = %s' % (
key, flimflam.convert_dbus_value(properties[key], 4)))
+ return retval
+
if __name__ == '__main__':
- main()
+ sys.exit(main())