Skip to content

Commit

Permalink
Merge pull request saltstack#39352 from Unity-Technologies/hotfix/adb…
Browse files Browse the repository at this point in the history
…_no_devices

Fix adb beacon when there are no devices
  • Loading branch information
Mike Place committed Feb 13, 2017
2 parents 0647dc8 + 3a3ef25 commit 1b5c1fc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 3 additions & 3 deletions salt/beacons/adb.py
Expand Up @@ -17,7 +17,7 @@
__virtualname__ = 'adb'

last_state = {}
last_state_extra = {'value': False}
last_state_extra = {'value': False, 'no_devices': False}


def __virtual__():
Expand Down Expand Up @@ -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
21 changes: 21 additions & 0 deletions tests/unit/beacons/adb_beacon_test.py
Expand Up @@ -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'
Expand Down

0 comments on commit 1b5c1fc

Please sign in to comment.