CA-119888: Fix logical volume deletion error.

Signed-off-by: Siddharth Vinothkumar <siddharth.vinothkumar@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>

GitHub: closes #191 on xapi-project/sm
UnitTest: log to stdout

By printing the log messages to stdout, they will be captured by nose,
thus not disturbing the user. Should a test fail, the messages will
still be displayed.

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Acked-by: Germano Percossi <germano.percossi@citrix.com>
UnitTest: Enable custom context

Should the user want to use a custom context implementation, he can use
the with_custom_context decorator to do that. It enables users to
inherit from TestContext, extend its functionality, and use the extended
version in a test. This could be useful if someone wanted to use a
custom implementation for `open`.

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Acked-by: Germano Percossi <germano.percossi@citrix.com>
CA-140596: [UnitTest] Test to reproduce gc error

This test will reproduce the issue that was seen in the referenced
ticket. Whenever a new Lock instance is created, and the file() call
fails, the instance's lockfile attribute remained uninitialised. As the
instance has a custom destructor, that will be called by the garbage
collector. That function assumes that the instance has a lockfile
attribute, and thus prints a message.

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Acked-by: Germano Percossi <germano.percossi@citrix.com>
CA-140596: Fix lockfile attribute in Lock

As Lock's destructor was assuming that lockfile attribute exists, it
printed out an AttributeError on stdout while the GC was cleaning it up.
This fix initialises the lockfile field in the constructor.

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Reviewed-by: Germano Percossi <germano.percossi@citrix.com>
CA-140596: Add seam for file call

Extract the file call to a separate method, so that the extracted method
could be used in tests as a seam, emulating situations like: what would
happen if the file call failed.

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Reviewed-by: Germano Percossi <germano.percossi@citrix.com>
CA-140596: [UnitTest] Test file not found in Lock

These are test cases covering the lock module, and also testing what
happens if file() raises an IOError. This can happen as a race
condition, if two locks - A and B are created in the same namespace and
by the time A gets to open the lockfile, B already cleaned up the
namespace.

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Acked-by: Germano Percossi <germano.percossi@citrix.com>
CA-140596: Fix file creation error

If creating the lockfile failed with IOError having ENOENT error code,
that means that another lock within the same namespace already cleaned
up the namespace. With this change, should IOError happen with ENOENT,
the lock will re-create the namespace, and the file 10 times, and only
bubble up the exception if it failed all those retries.

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Reviewed-by: Germano Percossi <germano.percossi@citrix.com>
Merge fixes for CA-140596 (plus unit test improvements) into xs64bit

Signed-off-by: Germano Percossi <germano.percossi@citrix.com>

GitHub: closes #197 on xapi-project/sm
UnitTest: tests for NFSSR.py, ISOSR.py and nfs.py

Test mount calls.

Signed-off-by: Robert Breker <robert.breker@citrix.com>
Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Acked-by: Germano Percossi <germano.percossi@citrix.com>
CA-135612: Add experimental support for NFSv4

This enables the specification of the NFS version (3,4) in the
device-config of ISOSRs(type=nfs) and NFSSRs.

For example:

    device-config:nfsversion=4

Signed-off-by: Robert Breker <robert.breker@citrix.com>
Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Reviewed-by: Germano Percossi <germano.percossi@citrix.com>
CA-135612: [UnitTest] Tests for nfsversions

Test NFSSR, ISOSR and nfs

Signed-off-by: Robert Breker <robert.breker@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>
Acked-by: Germano Percossi <germano.percossi@citrix.com>
Merged "Experimental NFSv4 support" into xs64bit

Signed-off-by: Germano Percossi <germano.percossi@citrix.com>

GitHub: closes #189 on xapi-project/sm
CP-5330: Update scsi_id call

Because scsi_id call syntax has changed, now we use the new syntax and,
if failed, fallback to the old syntax.
Another failure raises an exception.

Signed-off-by: Germano Percossi <germano.percossi@citrix.com>
Reviewed-by: Zheng Li <zheng.li@citrix.com>

(cherry picked from commit eec518e9 for [CP-8634])
Signed-off-by: Germano Percossi <germano.percossi@citrix.com>
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>

(cherry picked from commit b196cbcf for [CP-8634])
Signed-off-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>

(cherry picked from commit e9224399 for [CP-8634])
Signed-off-by: Germano Percossi <germano.percossi@citrix.com>
CP-5330: Dynamic set replacement_timeout during iscsi session establishment

From: Zheng Li <zheng.li@eu.citrix.com>

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>

(based on commit f79046a0 for [CP-8634])
[modified because the OCFSSR is not present]
Signed-off-by: Germano Percossi <germano.percossi@citrix.com>
CP-5330: Start iSCSI properly.

Recent iSCSI package (iscsi-initiator-utils) has a different way to start
(there is no more the open-iscsi script). Also use service to start
the service properly.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
Reviewed-by: Zheng Li <zheng.li@citrix.com>

(cherry picked from commit 4ed41096 for [CP-8634])
Signed-off-by: Germano Percossi <germano.percossi@citrix.com>
CP-5330: Ignore innocuous errors from iscsiadm

When asked for open sessions, recent versions of iscsiadm return a code
different than 0 if list is empty.
Our function exn_on_failure raises an exception if return code is not
zero, so we must trap the exception and continue because an empty list
is fine.

The exception could be handled in a better way but our
exception system needs to be made better.

This patch does not affect old iscsiadm behaviour

Signed-off-by: Germano Percossi <germano.percossi@citrix.com>
Reviewed-by: Zheng Li <zheng.li@citrix.com>

(cherry picked from commit 3af8a6e8 for [CP-8634])
Signed-off-by: Germano Percossi <germano.percossi@citrix.com>
CP-8634: Update open-iscsi userspace in Creedence

Back-porting changes for master created for CP-5330

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

GitHub: closes #201 on xapi-project/sm