Fixing return value of function 'start' in init script

During fixing lock mechanism (http://gerrit.ovirt.org/#/c/17662) we
change to use locked_start function, this set to return "start ||
release_lock && return 1". Without surrender the second part with brackets,
this function returns always 1. This 1 returns as exit code and fail external
operations as hostDeploy.

Change-Id: If9a9e89594f136d8e7b41b713e43d64f3702d454
Signed-off-by: Ohad Basan <obasan@redhat.com>
Signed-off-by: Yaniv Bronhaim <ybronhei@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/17828
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
refactoring: rename variable in getVlanID function

In the function getVlanID we're using id as a variable
name, proposed refactoring changes this variable name,
so we don't redefine the built-in function 'id'.

Change-Id: I16f28ea07c3ba0a704a094f0fa08d4e03b07a9dc
Signed-off-by: Giuseppe Vallarelli <gvallare@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/17830
Reviewed-by: Antoni Segura Puimedon <asegurap@redhat.com>
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
tests: addNetwork bond with one or many vlans.

Added a couple of functional tests:

* testAddNetworkBondWithManyVlans
* testAddNetworkVlanBond

covering the behaviour related to addNetwork using bond
and vlans.

Change-Id: I84b1582bbc9de09009a7e076386658035317f7db
Signed-off-by: Giuseppe Vallarelli <gvallare@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/17387
Reviewed-by: Antoni Segura Puimedon <asegurap@redhat.com>
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
lint: providing a default pylintrc

We can use pylint to enable some further checks on the codebase.
This can help up to have a cleaner codebase. The proposed pylintrc
is adapted from the one used by the Python language to let us
use java-like coding conventions for functions, methods and such.

Change-Id: Ia41d2bf225e0b5e47a0e2718b906fbd44f5a54e9
Signed-off-by: Giuseppe Vallarelli <gvallare@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/17772
Reviewed-by: Sandro Bonazzola <sbonazzo@redhat.com>
Reviewed-by: Antoni Segura Puimedon <asegurap@redhat.com>
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
SecureXMLRPCServer: Work with Official M2Crypto Release

VDSM uses the "settimeout" method of M2Crypto.SSL.Connection. This
method is defined by a patch shipped in Fedora and RHEL m2crypto RPM.
The "settimeout" patch is not available in official code, so other
distro such as Ubuntu does not provide "settimeout".

We can detect if the "Connection" class provides "settimeout" and work
with both RPM and official release of M2Crypto. If it provides
"settimeout", use it, otherwise falls back to use "settimeout" from the
socket object.

Change-Id: Id8db9140f27ca17adf4db0275188511257ba9116
Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
Reviewed-on: http://gerrit.ovirt.org/17809
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
Management network is now kept in main routing table

Only the management network should add its default route
to the main routing table. Each NetDevice holds an IpConfig
instance who now holds defaultRoute='yes', 'no' or None.
Only the top level device will have a defaultRoute value.
When writing ifcfg files we check if we got a defaultRoute
value, if so we write it.

Patch Set 7 changed the implementation so that only the top
level device has DEFROUTE=yes/no in its ifcfg file.

Change-Id: I55c50269dd3d52fd058951200282c925a7014aca
Signed-off-by: Assaf Muller <amuller@redhat.com>
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=984028
Reviewed-on: http://gerrit.ovirt.org/17575
Reviewed-by: Antoni Segura Puimedon <asegurap@redhat.com>
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
Only remove dhcp source routing if the removal reason is "STOP"

If the reason is FAIL then the IP configuration is not lost
and source routing should not be removed. Only STOP actually
removes the ip configuration from the device.

Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=995142
Change-Id: Ie92a4b4a95e9f1a7855f3d276b4e4d5b8b4c6ad2
Signed-off-by: Assaf Muller <amuller@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/17961
Reviewed-by: Saggi Mizrahi <smizrahi@redhat.com>
Reviewed-by: Antoni Segura Puimedon <asegurap@redhat.com>
Reviewed-by: Federico Simoncelli <fsimonce@redhat.com>
Fix stale call to deactivateVolumes().

Calling deactivateImage() is correct due to the one volume (no
template limitation of Image._activateVolumeForImportExport().

This calls were introduced by a conflict in changes:
Ib208bb20d88633167b5c66b42febe912439a022d
I4b6a4e99cf3a657affb4f5e96aa1ac1978a297da

Change-Id: I79fa91ddb3f3c41052461ee768157e86442f6660
Signed-off-by: Eduardo <ewarszaw@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/17734
Reviewed-by: Federico Simoncelli <fsimonce@redhat.com>
Tested-by: Federico Simoncelli <fsimonce@redhat.com>
tests: setupNetworks add one or more vlans.

Added a couple of functional tests:

* testSetupNetworksAddVlan
* testSetupNetworksAddManyVlans

covering the behaviour of setupNetworks when adding
one or more vlans.

Change-Id: I62fa6de1faa7d4e886c45361a001b0009fd92502
Signed-off-by: Giuseppe Vallarelli <gvallare@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/17432
Reviewed-by: Antoni Segura Puimedon <asegurap@redhat.com>
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
Handling signals interrupts, using pidofproc and prevent lock over systemd

Under start lock, if signal is received, we should clean the lock file and
stop the instance. During stop we should not stop the process until
respawn and vdsm instances are cleared.

Instead of checking the existence of respawn.pid and vdsmd.pid files, using
pidofproc checks if the processes are actually run. The deletion of the
respawn.pid file is redundant and leads to conflicts.

Over systemd we don't require to use locking at all. Systemd takes care of
that.

Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=994912
Change-Id: I9b58672957840c9dc5d13dce6af8de1717a9cb2d
Signed-off-by: Yaniv Bronhaim <ybronhei@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/17926
Tested-by: Elad Ben Aharon <eladba1990@gmail.com>
Reviewed-by: Saggi Mizrahi <smizrahi@redhat.com>
Reviewed-by: Federico Simoncelli <fsimonce@redhat.com>
vdsmd and supervdsmd: extract common init tasks and add init adapter

Move common init tasks from vdsmd.init.in to a separated file,
vdsmd_init_common.sh. This enables SysV init script, SystemD and other
init systems re-use vdsm pre-start/post-stop scripts.

Add vdsm/init/daemonAdapter for various init systems. daemonAdapter can
start vdsm optionally with respawn and console redirection. On powerful
init systems, we call daemonAdapter with no/few options, on SysV init
system, we call it with respawn, console redirection and pid creation
option. In this way we can remedy the gap of powerful init systems and
less powerful ones.

This patch uses daemonAdapter in vdsmd.init.in, vdsmd.service,
supervdsmd.init.in and supervdsmd.service.in.
vdsmd systemd service does not relies on SysV init scripts to run init
tasks any more, it calls vdsmd_init_common.sh to run init tasks.

Change-Id: Id8e514df1ca88500f746242134ddb24c31588046
Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
packaging: rename supervdsmServer.py to supervdsmServer and add environment file

supervdsm process is started by "python supervdsmServer.pyc". This is a
bit verbose when it is put in the SysV init script and SystemD service
unit. This patch renames supervdsmServer.py to supervdsmServer to enable
the init script start supervdsmServer directly.

In this patch, an environment file is also add for supervdsmd service.

Change-Id: Ifbcfcfb6f22040d038541c79ac4d0e66ac106504
Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
Add vdsm upstart jobs

Add Upstart jobs for vdsmd, supervdsmd, vdsm-restore-net-config,
vdsm-tmpfiles.

vdsmd, supervdsmd, vdsm-restore-net-config jobs are Upstart counterpart
of vdsmd.service, supervdsmd.service and vdsm-restore-net-config.service
in systemd.

vdsm-tmpfiles is to create directories under /var/run/ for vdsm and
supervdsm. In Upstart there is no systemd-tmpfiles.sercice equivalent,
so we implement simple script in vdsm-tmpfiles to do the necessary job.

Change-Id: Id68ec0197bd1e09100f5da96ac4db24f2b90753a
Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
libvirt configure: use "ed" instead of "sed --copy -i"

"sed -i" generates a temp file for output, then renames the temp file to
the targeted file. Renaming a file means just changing the content of
the directory entry, and the edited file has different inode index from
the original version. So the sed edited file is a different file though
with the same file name as the original version. To use sed on
ovirt-node on bind-mounted files, we need "--copy" to copy the temp file
into targeted file instead of renaming. Unfortunately, "--copy" is
provided by a patch that is specific to the RPM packaged sed on Red Hat
family distros. The "--copy" option is neither in GNU sed [1] nor in
Single Unix Specification sed [2].

In this patch we use "ed" instead of "sed -i --copy". "ed" edits the
file in-place, by buffering the edited contents in memory and flushing
to the file at last.

[1] http://www.gnu.org/software/sed/manual/sed.html
[2] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html

Change-Id: Ic265df1a5abca0104d044f8c3048cf0643547c70
Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
xmlrpcTests: Detect Ubuntu initramfs when booting VM

Ubuntu initramfs file name is different from that in Fedora and RHEL.
This patch tries to detect possible initramfs file names. On failure,
generates an initramfs on demand.

Change-Id: I3d8754a297acb3dedbee51270b025eb284617506
Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
xmlrpcTests: Mount configfs automatically

In some systems such as Ubuntu, configfs is not mounted by default.

In this patch, configfs is mounted automatically for iscsi tests.

Change-Id: I2c507dc8e7cc8e48a9b0ee46ba958ec58b0bb91b
Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
vdsm: Load softdog if hardware watchdog is not available

On Ubuntu softdog is not loaded automatically. When there is not
hardware watchdog available, we have to load softdog to make wdmd and
sanlock work properly.

This patch detects /dev/watchdog during vdsmd startup and load softdog
if /dev/watchdog does not exist.

Change-Id: I17ca3dea7acd60b0ba5bb3634c06b656b41dde1d
Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
Ubuntu local: Record corresponding dependency packages in Ubuntu

Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
Ubuntu local: netinfo: Work with python-ethtool 0.7 on Ubuntu

python-ethtool 0.8 is not available yet, we should try to work with both
old and new versions. This patch detects the existence of an API and
adapt to the situation.

Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
Ubuntu local: adapt to Ubuntu libvirt conf file path

Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>