CA-142595: [UnitTest] support non-block devices

Add testing framework enhancements to enable us to check what happens if
a given (SCSI) device does not have a block subdirectory.

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Reviewed-by: Flavien Quesnel <flavien.quesnel@citrix.com>
CA-142595: Non-block devices causing IndexError

Some device (e.g. a scsi security manager device.) has no subdir
"block/" , this will cause _extract_dev_name "IndexError: list index
out of range" error.
The following is the traceback info:
run this cmd: xe sr-probe type=lvmohba
There was an SR backend failure.
status: non-zero exit
stdout:
stderr: Traceback (most recent call last):
File "/opt/xensource/sm/LVMoHBASR", line 239, in ?
SRCommand.run(LVHDoHBASR, DRIVER_INFO)
File "/opt/xensource/sm/SRCommand.py", line 343, in run
sr = driver(cmd, cmd.sr_uuid)
File "/opt/xensource/sm/SR.py", line 139, in init
self.load(sr_uuid)
File "/opt/xensource/sm/LVMoHBASR", line 98, in load
print >>sys.stderr,self.hbasr.print_devs()
File "/opt/xensource/sm/HBASR.py", line 242, in print_devs
self._init_hbadict()
File "/opt/xensource/sm/HBASR.py", line 63, in _init_hbadict
dict = devscan.adapters(filterstr=self.type)
File "/opt/xensource/sm/devscan.py", line 75, in adapters
(dev, entry) = _extract_dev(dir, proc, id, lun)
File "/opt/xensource/sm/devscan.py", line 235, in _extract_dev
dev = _extract_dev_name(device_dir)
File "/opt/xensource/sm/devscan.py", line 226, in _extract_dev_name
dev = glob.glob(os.path.join(device_dir, 'block/*'))[0]
IndexError: list index out of range

Signed-off-by: Wang Yanbin wangyanbin@dayang.com.cn
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>
CA-142595: [UnitTest] Add tests for the fix

Add unit tests relating to the fix proposed by Wang Yanbin.

Signed-off-by: Flavien Quesnel <flavien.quesnel@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>
CA-142595: Refactor devscan.py

 * extract INVALID_DEVICE_NAME
 * extract update_devs_dict
 * extract _get_block_device_name_with_kernel_3x

Signed-off-by: Flavien Quesnel <flavien.quesnel@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>
CA-142595: [UnitTest] cover devscan.py

Add unit tests, following the refactoring of devscan.py

Signed-off-by: Flavien Quesnel <flavien.quesnel@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>
CA-142595: Merged into xs64bit

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>

GitHub: closes #216 on xapi-project/sm
CA-138452: Add Unit tests for SR.lock

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
CA-138452: Fix SR locking

If lock acquisition failed, SR._locked would still report that one lock
is acquired, thus leaving the SR object in an inconsistent state.

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>