CA-120469: Fail gracefully in case rmdir returns ENOTEMPTY

Parallel vm-suspend operations on vm that has got vdi's in the same SR
could result in reference files, ignoring rmdir error (ENOTEMPTY)
instead of lsdir looks a better option.

Signed-off-by: Vineeth Thampi Raveendran <vineeth.thampi@citrix.com>
Reviewed-by:Germano Percossi <germano.percossi@citrix.com>
Imported-by: Vineeth Thampi Raveendran <vineeth.thampi@citrix.com>

(cherry picked from commit bc1da0cf34b3213b455523109e402da106a9bc65)

GitHub: closes #139 on xapi-project/sm
CA-118899: Support UTF-8 iSCSI target names.

Signed-off-by: Rob Dobson <rob@rdobson.co.uk>
Acked-by: Thanos Makatos <thanos.makatos@citrix.co.uk>
Imported-by: Vineeth Raveendran <vineeth.thampi@citrix.com>

(cherry picked from commit 9dbd30cde957ad19ef5ba0e950d15712946975e8)

GitHub: closes #140 on xapi-project/sm
CP-8580: Add pylint configuration file.

Signed-off-by: Siddharth Vinothkumar <siddharth.vinothkumar@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>

GitHub: closes #137 on xapi-project/sm
CP-8580: Add MAX_TIMEOUT to LUNperVDI.py

Signed-off-by: Siddharth Vinothkumar <siddharth.vinothkumar@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>

GitHub: closes #137 on xapi-project/sm
CP-8580: Fix undefined variables in RawHBASR.py

- Variables sr_ref and host_ref are undefined in '_add_pbd_other_config'.
  Use self.sr_ref and self.host_ref instead.

Signed-off-by: Siddharth Vinothkumar <siddharth.vinothkumar@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>

GitHub: closes #137 on xapi-project/sm
CP-8580: Fix method issues with blktap2.py

- '_mklink' is not a class method. Hence use 'self' instead of 'cls'.

Signed-off-by: Siddharth Vinothkumar <siddharth.vinothkumar@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>

GitHub: closes #137 on xapi-project/sm
CP-8580: Fix method issues with lcache.py

- 'from_tapdisk' is a class method. Hence use 'cls' instead of 'self'.

Signed-off-by: Siddharth Vinothkumar <siddharth.vinothkumar@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>

GitHub: closes #137 on xapi-project/sm
CP-8580: Fix method issues with mpathcount.py

- The original code overwrites 'add'/'remove' methods with internal
ones. Rename them to '_add'/'_remove' to prevent accidental shadowing.

Signed-off-by: Siddharth Vinothkumar <siddharth.vinothkumar@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>

GitHub: closes #137 on xapi-project/sm
CP-8580: Fix incorrect log print by adding '%'.

Signed-off-by: Siddharth Vinothkumar <siddharth.vinothkumar@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>

GitHub: closes #137 on xapi-project/sm
CP-8580: Fix undefined variable in srmetadata.py

- Undefined variable 'diff' was referenced in the else cause.
Fix dangling reference by adding the variable.

Signed-off-by: Siddharth Vinothkumar <siddharth.vinothkumar@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>

GitHub: closes #137 on xapi-project/sm
CP-8580: Don't import unused 'stat' module.

- The 'stat' module was imported but unused. Also, we define a function
 with the same name which causes the module to be shadowed.

Signed-off-by: Siddharth Vinothkumar <siddharth.vinothkumar@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>

GitHub: closes #137 on xapi-project/sm
CP-8629: Direct PPA install

A build system behind a firewall cannot use apt-add-repository directly.
To workaround the problem, including the public key and adding the
repository directly as part of
install_prerequisites_for_python_unittests.sh script.

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Acked-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>

GitHub: closes #141 on xapi-project/sm
CP-8629: Install to temporary directory

While making snapwatchd, the binaries are also installed. If DESTDIR is
not set, it means that the binaries will be installed to the /
directory. Create a temporary directory, and set that as DESTDIR to
avoid polluting the root directory.

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Acked-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>

GitHub: closes #141 on xapi-project/sm
CP-8629: Install coverage

Install coverage package, so unit test coverage could be measured.

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Acked-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>

GitHub: closes #141 on xapi-project/sm
CP-8629: Run unittests with coverage

Run unittests with coverage and report both unit test results and
coverage in computer consumable format.

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Acked-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>

GitHub: closes #141 on xapi-project/sm
CA-116545: SR detach could fail during a Find Open process check

This could happen if one pid, out of a list of pids, cease to exist.
Ignoring the error helps us move forward through the list checking
for any pid / file handles

Signed-off-by: Vineeth Thampi Raveendran <vineeth.thampi@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>
Imported-by: Siddharth Vinothkumar <siddharth.vinothkumar@citrix.com>

(cherry picked from commit 91c4e20eb09c21f715b3d9539d961963a74dd589)

GitHub: closes #129 on xapi-project/sm
CA-136654: Don't rely on a XAPI session existing

With static VDIs, the SR code is run without a XAPI session.  In this
case, set O_DIRECT to be on for safety since there is external knob to
adjust it.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>

GitHub: closes #142 on xapi-project/sm
CA-116160: Python exception in HBA SR create.

len() on dictionary iterkeys is not valid in Python 2.6.
Replaced it with len() directly on the dictionary.

Signed-off-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
Reviewed-by: Vineeth Thampi Raveendran <vineeth.thampi@citrix.com>

(cherry picked from commit e7720d8e83a24b61eb52885dae0027fd3f803c58)
Imported-by: Mate Lakat <mate.lakat@citrix.com>

GitHub: closes #144 on xapi-project/sm
CP-8629: Run all tests

Do not specify the testfile explicitly, just the directory - nose will
pick up all the test files.

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Acked-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CP-8629: Unit tests for devscan

Add unit tests for devscan.py Also added a test library with useful
helper commands.

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Acked-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>