Skip to content

Commit

Permalink
sort devices in scan by id (#221)
Browse files Browse the repository at this point in the history
* sort devices in scan by id

* bump version
  • Loading branch information
edaniszewski committed Oct 25, 2018
1 parent 6650dbc commit 695a382
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
2 changes: 1 addition & 1 deletion synse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

__title__ = 'synse'
__version__ = '2.2.1'
__version__ = '2.2.2'
__description__ = 'Synse Server'
__author__ = 'Vapor IO'
__author_email__ = 'vapor@vapor.io'
Expand Down
2 changes: 1 addition & 1 deletion synse/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ def _build_scan_cache(device_info):
# Sort all devices on each board by plugin and sort ordinal
board['devices'] = sorted(
board['devices'],
key=lambda d: (d['plugin'], d['sort_ordinal'])
key=lambda d: (d['plugin'], d['sort_ordinal'], d['id'])
)

# Delete the plugin and sort_ordinal from the scan result after sorting.
Expand Down
47 changes: 43 additions & 4 deletions tests/unit/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,51 @@ def test_build_scan_cache_ok():
device_info = {
'rack-1-vec-12345': make_device_info_response('rack-1', 'vec', '12345'),
'rack-1-board-12345': make_device_info_response('rack-1', 'board', '12345'),
'rack-1-board-56789': make_device_info_response('rack-1', 'board', '456789')
'rack-1-board-56789': make_device_info_response('rack-1', 'board', '456789'),
'rack-1-board-abcd': make_device_info_response('rack-1', 'board', 'abcd')
}
scan_cache = cache._build_scan_cache(device_info)
validate_scan_cache(scan_cache, 'rack-1', 'vec', '12345')
validate_scan_cache(scan_cache, 'rack-1', 'board', '12345')
validate_scan_cache(scan_cache, 'rack-1', 'board', '456789')

# Test that the scan cache comes back in the expected sorted order
assert scan_cache == {
'racks': [
{
'id': 'rack-1',
'boards': [
{
'id': 'board',
'devices': [
{
'id': '12345',
'info': 'bar',
'type': 'thermistor'
},
{
'id': '456789',
'info': 'bar',
'type': 'thermistor'
},
{
'id': 'abcd',
'info': 'bar',
'type': 'thermistor'
},
]
},
{
'id': 'vec',
'devices': [
{
'id': '12345',
'info': 'bar',
'type': 'thermistor'
}
]
}
]
}
]
}


def test_build_scan_cache_no_device_info():
Expand Down

0 comments on commit 695a382

Please sign in to comment.