Check the return value of query in ConnectToInstanceConsole

When running gnt-instance console for an instance name that doesn't
exist, I got the following raw error:

...
    cl.QueryInstances([instance_name], ["console", "oper_state"], False)
ValueError: need more than 0 values to unpack

In this case we should raise the OpPrereqError to notify that the
instance which having that name doesn't exist.
This patch adds a check for the return value of the QueryInstances and
raise the OpPrereqError when the result of the query is a blank list.

Signed-off-by: Yuto KAWAMURA(kawamuray) <kawamuray.dadada@gmail.com>
Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>
Fix FIXME comment

As Ganeti supports jump-upgrades, we cannot anywhere in the
2.x series assume that we have not just been upgraded form
a 2.10 or earlier system. Hence the bootstrap code needs to
remain. Change the comment accordingly.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Helga Velroyen <helgav@google.com>
Read if IPv6 is used directly in SshRunner

Moved check if the Primary Network is running on IPv6 into the SshRunner.
Until now SshRunner was only initialized correctly in the bootstrap.py
and not in the other 5 places.

Fixing issue #892

Signed-off-by: Neal Oakey <neal.oakey@googlemail.com>
Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>
Merge branch 'stable-2.10' into stable-2.11

* stable-2.10
  Check the return value of query in ConnectToInstanceConsole

Conflicts:
	lib/client/gnt_instance.py
Resolution:
	follow the switch to query socket

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Niklas Hambuechen <niklash@google.com>
break too long line

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Niklas Hambuechen <niklash@google.com>
Merge branch 'stable-2.11' into stable-2.12

* stable-2.11
  break too long line
  Read if IPv6 is used directly in SshRunner

* stable-2.10
  Check the return value of query in ConnectToInstanceConsole

Conflicts:
	lib/client/gnt_instance.py
Resolution:
	follow the client switch

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
Merge branch 'stable-2.12' into master

* stable-2.12
  Fix FIXME comment

* stable-2.11
  break too long line
  Read if IPv6 is used directly in SshRunner

* stable-2.10
  Check the return value of query in ConnectToInstanceConsole

Conflicts:
	lib/bootstrap.py
	lib/ssh.py
(all trivial)

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Helga Velroyen <helgav@google.com>
Drop ipv6 keyword argument for SshRunner

...as the SshRunner now determines by itself the address
family. This is a semantic conflict of merging 9f8f740
into master.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Niklas Hambuechen <niklash@google.com>
Drop unused argument from RunSshCmdWithStdin

Due to merging up 9f8f740 the ssconf_store (positional) argument
became unused in 6a06c42. So remove it from the interface.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Niklas Hambuechen <niklash@google.com>
Query.Server: Fix GHC 7.8 `bitSize` deprecation warning

This makes Ganeti compile on GHC 7.8 with our -Werror.

Signed-off-by: Niklas Hambuechen <niklash@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>
Fix API doc

...by also removing the unused parameter from the doc string.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Niklas Hambuechen <niklash@google.com>
ConfigReader: Simplify `initConfigReader` argument passing

We passed in a cfg_transform and an IORef, just to apply the
cfg_transform and write it to the IORef.

Instead, directly pass in a function that decides what to do
with the read config, so that `ConfigReader` now is solely
responsible for reading the config, not for writing it somewhere.

Signed-off-by: Niklas Hambuechen <niklash@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>
JQScheduler: Allow triggering scheduler if config changes

Some changes to the config need the scheduler to be re-run,
e.g. when job filters change.

This commit adds the infrastructure for that, with no things
triggering rescheduling.

Signed-off-by: Niklas Hambuechen <niklash@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>
JQScheduler: Run scheduler when filters change in config

Until now, job filters being added, modified, or deleted triggered
a scheduler run (`scheduleSomeJobs`) from the place where the filter
modification request is handled (Query.Server).

This could lead to a race:
If the config change containing the updated filters doesn't propagate
fast enough (it is asynchronous), `scheduleSomeJobs` will be triggered
with the old config.

This race only showed up in QAs with larger clusters.

This commit fixes the issue by moving the re-scheduling from the
request-for-config-change location to the place where the
new config is read, so that old and new filters can be compared.

Signed-off-by: Niklas Hambuechen <niklash@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>
QA: Move `GetJobStatus`/`RetryingWhileJobStatus` to utils

We would like to use them from other QAs involving jobs.

Signed-off-by: Niklas Hambuechen <niklash@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
qa: qa_job_utils: add `RetryingUntilJobStatus`

Dual to `RetryingWhileJobStatus`.
It retries until the given status is reached.

Signed-off-by: Niklas Hambuechen <niklash@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
qa: qa_filters: Make status check less flaky by using retry

The time needed to delete a filter and have jobs that were paused
by that filter be scheduled depends on the size of the cluster.

The polling retry introduced here is more robust than a sleep.

Signed-off-by: Niklas Hambuechen <niklash@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
Add nodes field in class Disk

Add a field called "nodes" in the Disk class. This field will be a list
of Ganeti node UUIDs from which this disk is accessible.
Populate disk nodes when creating disks

When creating a Disk using the GenerateDiskTemplate function, fill the
nodes field depending on the disk template. There are three cases:

1) Internally mirrored disks (DRBD):
   These disks are accessible from two nodes, so the nodes field will
   include these. Their children (data, meta) are also accessible from
   two nodes, therefore they will inherit the nodes of the parent.
2) Externally mirrored disks (Blockdev, Ext, Gluster, RBD, Shared File):
   These disks should be accessible from any node in the cluster,
   therefore the nodes field will be empty.
3) Single-node disks (Plain, File):
   These disks are accessible from one node only, therefore the nodes
   field will consist only of the primary instance node.
Maintain consistency of nodes field

There are four scenarios in which the nodes field can change after the
disk's creation; when moving, replacing, converting or recreating disks.
For each scenario, update the nodes field accordingly.