Should finish allocating network before VM reaches ACTIVE

This patch can fix issues like tempest caused by async
network allocation. Nova uses NetworkInfoAsyncWrapper
to allocate network in an async manner, and this allows
one to start querying for network info before you know
you will need it. Nova will invoke refresh_cache method
to update instance_cache_info after excuting the
allocate_for_instance method as well.

However, nova rest api will query instance_cache_info
directly, thus maybe get the empty network info before
instance_cache_info table has been updated asynchronously.
Thus will cause VM can exist without a known address
accidentally, the caller is difficult to distinguish
this situation, unless waiting for some internal process
or it will not have an address. So should finish
allocating network before the VM reaches ACTIVE status.
For more detail can refer the bug description.

BTW, almost all create server related unit tests have
coverred this case.

Closes-Bug: #1210483
Change-Id: Iab542df1be7d5c9661d717ec596d2a37b975169a
Add test cases for resume_state_on_host_boot

part of blueprint libvirt-driver-tests

Co-authored-by: Hirofumi Ichihara <ichihara.hirofumi@lab.ntt.co.jp>
Change-Id: I234c3613eb30a593fd1b0e29655551694b7e24f7
Fix changes_since for V3 API

The V3 API changed the changes-since parameter to changes_since
for consistency with other parameters. However, the db level
expects changes-since as the filter. So this change transforms
changes_since to changes-since before passing it to the compute
layer.

Closes-Bug: 1220045

Change-Id: Id34ffe8aa75b20d11dcb1b4a9ba36e2586dae1e3
Increase volume created checking retries to 60

In some cases 30 retries with 1 sec interval is not enough for
volume to be created.
Increased max tries to 60

Fixes bug 1213953

Change-Id: I6bcd395a4bac940387384cc85691d7219cf90e63
xenapi: Fix download_handler fallback

In order to make image-download a bit more robust, we attempt to download from
a preferred handler and if that fails, we fall back to a default handler.

If the preferred handler *is* the default-handler, then we should just raise
the exception instead of retrying.

The existing code was checking to see with whether the handler *instance*
compared as equal to the default-handler *instance*. Since the two objects are
instantiated separately, they'll always be different objects, so never compare
as equal.

The correct check is to see if the handler is an instance of the default
handler's class.

Fixes bug 1210659

Change-Id: Id038d221fd2f90c36673f30d4ff8acdc8dbf098e
Add V3 API samples for instance-actions,extenions

Partially implements blueprint v3-api-unittests

Change-Id: Ie90973734943b3d22cb288b18916a6ef2d9f51de
Add V3 API samples for flavors,flavor-rxtx,flavor-access

Partially implements blueprint v3-api-unittests

Change-Id: I2b572ec13190b946daebec4e64f9b9b362d5ac6e
xenapi: move kernel/ramdisk methods to vm_utils

A previous change has now removed the duplication between spawn and
finish_migration, into create_kernel_and_ramdisk. This change moves the
code into vm_utils, and covers the code with some unit tests.

This will makes is easier to share code between spawn and finish_resize
and gives a more logical public interface to vm_utils.

I have also simplified the call to destroy_kernel_ramdisk in spawn so
that can be shared more easily between spawn and finish_migration in a
later change.

Change-Id: I73523d93be0a7afa9fe814af280c582e47064d69
xenapi: tidy ups to some spawn related methods

There were server methods using during spawn that are only used
internally, but not named that way. They have been renamed in this
change.

There were also several methods that are currently called in a single
place, but had logic around the call that should have been inside that
method. This has been tided up, so it will be easier to re-use and/or
move those calls in future refactoring.

This is one of the building blocks towards sharing more code between
spawn and finish_migration.

Change-Id: I424daf8334ad9904572b9df511d8e6bc1ff6d21f
Fix console api pass tuple as topic to console rpc api

The topic should be string, not a tuple

Fix bug 1221541

Change-Id: I4bbb9bdeb5108436fe76db69f1546ac2bd0c7a40
Fix migration 211 to downgrade with MySQL

Suspend the Foreign Key Constraint and add it back in to stop from
preventing the unique constraint from being deleted.

Fixes bug/1216706

Change-Id: I7e77c9c5e50ec3580bca3f95f59189b33d9af306
Fix the order of query output for postgres

Sorts the query results and dictionary of expected results by two columns
rather than one which isn't unqiue.

Fixes bug 1208701

Change-Id: Icd21a008f7736a4d9027effb0633a506aae0f602
Only return requested network ID's

Only return the requested network ID's and not all of the
public networks. This will also include 'shared' networks.

Fixes bug 1221320

Change-Id: I21ba4586c6e431b0dd1a87a9e5e493fae1b08357
Remove _assert_compute_node_has_enough_memory from filter_scheduler.py

Now the function _assert_compute_node_has_enough_memory has no use
in filter_scheduler.py, just remove it to make code more clean.

Change-Id: Ie6f104368140b69a60e124ea96ef6bf7715fe34e
Fixes misuse of assertTrue in test scripts

Misuse of assertTrue in places where assertEqual or assertIn should be used.

If assertTrue is used, the test will always pass
if the first argument's boolean cast is True. The second argument
passed to assertTrue() will be regarded as the error message
when the assertion fails.

Fixes bug #1223620

Change-Id: I46b51bf944ba22247901172650ea6867dd525aa7
Add alias as prefix to request params for config_drive v3

fix bug 1215705

DocImpact

Change-Id: Ic236e306c64000a5556a55a0d168f15692c0106b
Change the duplicate class name TestDictMatches in test_matches.py

There are two classes with the same name 'TestDictMatches' ,let's change one to
TestIsSubDictOf.

Change-Id: I1f1059054070228265bca74cb8aaad2c8d3f8812
Remove duplication in disk checks

Split the image and fs resize checks into separate methods since they
are used in different ways. This also strips one redundant size check.

Change-Id: Ie2381fa4ecd5264f2dd3ec3b0350df40376d0e34
Wrong arguments when calling safe_utils.getcallargs()

When calling safe_utils.getcallargs(), it will get all argnames from
definition of a function. As every function in Nova has a argument named
`context`, so argnames will always start with `context`.

In nova/exception.py#81, *args is a list of arguments which does not
start with
`context`, however, argnames starts with `context`, this will lead to a
mismatching when zip it into a dict.

Solution for this is that when calling getcallargs(), pass context as
one argument.

Change-Id: I4ce81e1862fb2d741f15747b04aa6bf1a2243364
Fixes: bug #1207153
Use test.TestingException where possible

Instead of calling 'raise Exception()' in a stub, use
tests.TestingException and only catch that exception.  This will make
sure the test have less false positives and hide other exceptions.

Change-Id: I384c93e220d570abec25dcbacead0aa3bc33cbcf
Partial-Bug: #1223605