diff --git a/salt/beacons/adb.py b/salt/beacons/adb.py index 80d60459f9d5..003f2d6206d6 100644 --- a/salt/beacons/adb.py +++ b/salt/beacons/adb.py @@ -17,7 +17,7 @@ __virtualname__ = 'adb' last_state = {} -last_state_extra = {'value': False} +last_state_extra = {'value': False, 'no_devices': False} def __virtual__(): @@ -125,11 +125,11 @@ def beacon(config): # Maybe send an event if we don't have any devices if 'no_devices_event' in config and config['no_devices_event'] is True: - if len(lines) == 0 and not last_state_extra['no_devices']: + if len(found_devices) == 0 and not last_state_extra['no_devices']: ret.append({'tag': 'no_devices'}) # Did we have no devices listed this time around? - last_state_extra['no_devices'] = len(lines) == 0 + last_state_extra['no_devices'] = len(found_devices) == 0 return ret diff --git a/tests/unit/beacons/adb_beacon_test.py b/tests/unit/beacons/adb_beacon_test.py index 09d5431dd9c1..871a09478e97 100644 --- a/tests/unit/beacons/adb_beacon_test.py +++ b/tests/unit/beacons/adb_beacon_test.py @@ -137,6 +137,27 @@ def test_no_devices_with_different_states(self): def test_no_devices_no_repeat(self): config = {'states': ['offline', 'device'], 'no_devices_event': True} + out = [ + 'List of devices attached\nHTC\tdevice', + 'List of devices attached', + 'List of devices attached' + ] + + mock = Mock(side_effect=out) + with patch.dict(adb.__salt__, {'cmd.run': mock}): + + ret = adb.beacon(config) + self.assertEqual(ret, [{'device': 'HTC', 'state': 'device', 'tag': 'device'}]) + + ret = adb.beacon(config) + self.assertEqual(ret, [{'tag': 'no_devices'}]) + + ret = adb.beacon(config) + self.assertEqual(ret, []) + + def test_no_devices(self): + config = {'states': ['offline', 'device'], 'no_devices_event': True} + out = [ 'List of devices attached', 'List of devices attached'