Sort buckets topologically rather than by id

Criteria:
If a depends on b, b < a
If a only depends on devices and b does not, a < b
If both or neither a and b depend only on devices, sort by id

Signed-off-by: Dan Mick <dan.mick@inktank.com>