CP-5330: Replace open-iscsi-auth.patch with discoverydb solution

This is part of the CP-5330 work to get rid of our customized patches
against open-iscsi and to use the stock version open-iscsi of upstream.
This changset replace open-iscsi-auth.patch with the mechanics provided
by the discoverydb mode, to allow CHAP authentication while doing iscsi
targets discovery.

Signed-off-by: Zheng Li <zheng.li@eu.citrix.com>
Suggested-by: Robert Breker <robert.breker@citrix.com>
Reviewed-by: Germano Percossi <germano.percossi@citrix.com>
CP-5330: Remove dependencies on iscsid-mpath.conf/iscsid-default.conf

This is part of the CP-5330 work to get rid of our customized patches
against open-iscsi and to use the stock version open-iscsi of upstream.

Previously we ship two customized versions of /etc/iscsi.conf only for
the purpose of switching one single configuration variable:
"replacement_timeout" (depending on whether multipath is enabled or not).

This is overkilled, and demand us to ship a customized build of open-iscsi.
As suggested by @robertbreker, the same effect can be possibly archived
by tweaking timeouts in the multipath layer, namely dev_loss_cmo etc.,
which we've already done in our multipath package.

This is a patch to remove SM's dependency on iscsi-mpath.conf and
iscsi-default.conf. One can still make use of them optionally by
manually creating these two files. This is useful if a customer still
needs a customized setting for some reason or for debugging purpose,
and the code is also backward compatible this way.

Signed-off-by: Zheng Li <zheng.li@eu.citrix.com>
Suggested-by: Robert Breker <robert.breker@citrix.com>
Reviewed-by: Germano Percossi <germano.percossi@citrix.com>
CP-5330: Dynamic set replacement_timeout during iscsi session establishment

Instead of linking/patching iscsid.conf statically, we now set
replacement_timeout dynamically whenever we establish a new iscsi session. As
part of the CP-5330 effort, this helps us to avoid monkey patching the upstream
open-iscsi.

Signed-off-by: Zheng Li <zheng.li@eu.citrix.com>
Suggested-by: Robert Breker <robert.breker@citrix.com>
Reviewed-by: Germano Percossi <germano.percossi@citrix.com>
Merge changes for CP-5330

GitHub: closes #25 on xapi-project/sm
CP-5817: Productise removal of lvm2-environment-device.patch

Part of the change for rolling back lvm2-environment-device.patch. Removed code
that exports special environment variable to direct LVM to look for an
abbreviated device cache.

The second part of the change (actual removal of lvm patch) is under
guest-packages.

Signed-off-by: Chandrikas Srinivasan <chandrika.srinivasan@citrix.com>
Reviewed-by: Zheng Li <zheng.li@eu.citrix.com>

Github: close #28 on xapi-project/sm
CP-5831: Productise removal of lvm2-lvchange-idempotent.patch

Part of changes required to remove lvm2-lvchange-idempotent.patch. LVM throws
an error if an LV that is already RO is set to RO again or an RW lv is set to
RW. Added additional check on XS side to check LV status before changing access
permissions.

Signed-off-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>

GitHub: closes #26 on xapi-project/sm
CP-5830: Productise removal of lvm2-master-mode.patch

Removed the --master switch from lvm commands. We now use two separate lvm
conf files for master and slave nodes. Appropriate conf file is chosen
through an environment variable.

Signed-off-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>

GitHub: closes #29 on xapi-project/sm
CP-5818: Productise removal of lvm2-lvcreate-inactive-flag.patch

Snapshot creation process uses a temp file with all snapshot information in
the name of the file. Since this name is too long and not liked my mapper,
the file is created in an inactive mode. Changed the logic to create a file
with shorter name and all informaton is written inside the file. Inactive flag
for lvcreate is no longer required.

Signed-off-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>

GitHub: closes #31 on xapi-project/sm
CA-113840: Add support for the Adaptec Raid Driver

Signed-off-by: Robert Breker <robert.breker@citrix.com>
Reviewed-by: Vineeth Thampi Raveendran <vineeth.thampi@citrix.com>

Github closes: #21 on xapi-projects/sm
CA-115712: Add support for the Cisco fnic FCoE driver

Signed-off-by: Robert Breker <robert.breker@citrix.com>
Reviewed-by: Vineeth Thampi Raveendran <vineeth.thampi@citrix.com>

Github closes: #32 on xapi-projects/sm
CA-113322: avoid using realpath wrt the new devmapper convention

Due to the change on dev mapper linking/naming conventions, we should
avoid using realpath to chase to the final path. Also, we can now
rely on vhd-util itself to canonicalize the path.

Signed-off-by: Zheng Li <zheng.li@eu.citrix.com>
Reviewed-by: Vineeth Thampi Raveendran <vineeth.thampi@citrix.com>

GitHub: closes #20 on xapi-project/sm
CA-116958: "VM.copy locking failed" error observed on build - 75698

Override slave mode lvm.conf for lvchange --refresh command on slaves

Signed-off-by: Chandrikas Srinivasan <chandrika.srinivasan@citrix.com>
Acked-by: Germano Percossi <germano.percossi@citrix.com>

GitHub: closes #36 on xapi-project/sm
Revert "CA-116958: "VM.copy locking failed" .."

This reverts commit f3899834a557d61989fa3a59dfed23b77ec0b204.

Signed-off-by: Germano Percossi <germano.percossi@citrix.com>
Revert all "Productise removal of lvm2.."

Reverts:
35754c0be5e8a985695aead8af02383a9a3db875.
e603b0a268f8e8140d44ceff6ecec85adf990099.
185e24fc3f219d1101b56ce79996015139227d9e.
71289160b71f3a24b51bd94ebd1f6b3a57164975.
CP-6167: Fix a bug reported by pylint

There is no variable 'uuid' in scope.

Signed-off-by: Zheng Li <zheng.li@eu.citrix.com>
CP-6167: Fix some bad practice reported by pylint

We conditionally assign a variable with either an object or a string.
Though this might not cause problems at runtime if we can guarantee
that we'll always branch by inspecting the runtime value, it is a
dangerous practice nonetheless.

Pylint complained with the following error: "Instance of 'str' has no
'xenapi' member".

Signed-off-by: Zheng Li <zheng.li@eu.citrix.com>
CP-6167: Fix an issue reported by pylint

Inside util module, we do not need to reference SMlog as util.SMlog.

Though this is not strictly a bug.

Signed-off-by: Zheng Li <zheng.li@eu.citrix.com>
CP-6167: Work around an issue pylint isn't clever to understand

This is not a bug, it's because pylint can't figure out magics
like runtime types based dispatching with isinstance etc. and
will issue an E1103 error.

We don't want to disable E1103 all together, as this could shadow
some real issues later on, so we work around the issue here. We'd
better refactor our code to implement the same functionality
differently.

Another way to work around this is to annotate the specific
occurrence in the source code with the pylint ignore tag.

Signed-off-by: Zheng Li <zheng.li@eu.citrix.com>
CP-6167: Fix an issue reported by pylint

Abstract class VDI referenced undefined property self.path. We
rely on subclasses to always instantiate this property but there
is no guarantee. Better to use Abstract Base Class module when we
move to Python 2.6.

With this change, the unusual instantiation order in ISOVDI class
was exposed (as it caused us some trouble). we resorted the order
to normal and solved the issue.

Signed-off-by: Zheng Li <zheng.li@eu.citrix.com>
CP-6167: Work around a pylint bug

This is a known bug that pylint misunderstands the return types
of 'stdout'/'stderr' of 'subprocess.Popen.communicate' as lists
(instead of strings). This is because these variables were initially
used as lists inside the function and only being converted to strings
at the end.

The python 3.x lib code doesn't cause this confusion for pylint.
Here we introduce this work around for the time being.

Usually the proper way to workaround pylint limitation is to add
pylint ignore tag around a piece of probmatic code, but in this
circumstance, it would demand us to tag all the callers (lots of)
rather than a single callee here.

[1] http://www.logilab.org/ticket/46273

Signed-off-by: Zheng Li <zheng.li@eu.citrix.com>