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: [UnitTest] Tests for cleanup.SR.lock

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@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>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>
CA-138452: Merged into xs64bit

GitHub: closes #218 on xapi-project/sm
CA-146822: fix intermittent test failures

As the lock test was querying the GC for the collected locks, it might
be possible that when the test starts, there is already an uncollected
lock in the GC. To avoid this situation, run the GC, so only the garbage
created by the test will be collected.

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

GitHub: closes #222 on xapi-project/sm
CA-146138: don't refresh slaves for local SRs

Don't try to synchronise logical volumes on other slaves for a SR that
is local to the host, it doesn't make any sense and can cause all sorts
of problems.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>
CA-146138: improve error message when srcmd.params is malformed

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>
CA-146138: unit test for LV refresh on other hosts

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>
CA-146138: various improvements over unit test

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>
Merge branch 'CA-146138' into xs64bit

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>

GitHub: closes #221 on xapi-project/sm
CA-146822: Remove TestLockDestruction

Remove TestLockDestruction to avoid intermittent test failures

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

GitHub: closes #224 on xapi-project/sm
CP-8514: [UnitTest] Add fake LVM subsystem

This test helper makes it possible to fake the lvm layer. This first
patch emulates the lvcreate command.

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Reviewed-by: Vineeth Thampi Raveendran <vineeth.thampi@citrix.com>
CP-8514: [UnitTest] Add tests for lvutil.create

These changes test the lvutil.create method just before the TRIM
functionality was added.

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Reviewed-by: Vineeth Thampi Raveendran <vineeth.thampi@citrix.com>
CP-8514: [UnitTest] Mock out os.stat

As the LVM operations use os.stat to detect the existence of a given
path, it needs to be mocked out. This change adds a simple
implementation, which does not return the expected stat information,
just raises an OSError if the file does not exists.

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Reviewed-by: Vineeth Thampi Raveendran <vineeth.thampi@citrix.com>
CP-8514: [UnitTest] Mock out lvremove and dmsetup

To test lvutil.remove, the /usr/bin/lvremove and /sbin/dmsetup system
utilities mocked out with a primitive implementation. dmsetup will just
return 0 with empty stdout and stderr, which seems to be enough for now.

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Reviewed-by: Vineeth Thampi Raveendran <vineeth.thampi@citrix.com>