提交 ae200011 编写于 作者: M Mike Qiu 提交者: Lucas Meneghel Rodrigues

virt.virttest.storage: Change the cmp method of the sorted function

Currently, function sorted inside the python was not suitable for
storage, for example, if ls -1d /dev/sd* gets result like this
after split('\n'):
['/dev/sda', '/dev/sda1', '/dev/sda2', '/dev/sda3',
 '/dev/sdaa', '/dev/sdab','/dev/sdac', '/dev/sdad', '/dev/sdae',
 '/dev/sdaf', '/dev/sdag', '/dev/sdah', '/dev/sdai', '/dev/sdaj',
 '/dev/sdak', '/dev/sdal', '/dev/sdam', '/dev/sdan', '/dev/sdao',
 '/dev/sdap', '/dev/sdaq', '/dev/sdar', '/dev/sdas', '/dev/sdb',
 '/dev/sdb1', '/dev/sdb2', '/dev/sdb3', '/dev/sdc', '/dev/sdd',
 '/dev/sde', '/dev/sdf', '/dev/sdg', '/dev/sdg1', '/dev/sdg2',
 '/dev/sdg3', '/dev/sdh', '/dev/sdh1', '/dev/sdh2', '/dev/sdh3',
 '/dev/sdi', '/dev/sdj', '/dev/sdk', '/dev/sdl', '/dev/sdm',
 '/dev/sdn', '/dev/sdo', '/dev/sdp', '/dev/sdq', '/dev/sdr',
 '/dev/sds', '/dev/sdt', '/dev/sdu', '/dev/sdv', '/dev/sdw',
 '/dev/sdx', '/dev/sdy', '/dev/sdz']

it will make no any change if just use sorted. As the default,
it will choose last 9 disk:
['/dev/sdr', '/dev/sds', '/dev/sdt', '/dev/sdu', '/dev/sdv', '/dev/sdw',
 '/dev/sdx', '/dev/sdy', '/dev/sdz']

Sometimes this is very dangerous, for lots of them may be the disk contains
lots of important data. Actually, maybe you just use scsi_debug just create:
['/dev/sdak','/dev/sdal', '/dev/sdam', '/dev/sdan', '/dev/sdao',
 '/dev/sdap', '/dev/sdaq', '/dev/sdar', '/dev/sdas']

But select the wrong disks as mentioned above.

To solve this problem, add param cmp to sorted and get the right order.
Signed-off-by: NMike Qiu <qiudayu@linux.vnet.ibm.com>
上级 3eca4fe5
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册