Commit Graph

54922 Commits

Author SHA1 Message Date
Adam Spiers 5df748b2ed Make it easier to run a selection of tests relevant to ongoing work
During development of a new git commit, locally running a whole unit
or functional test suite to check every minor code change is
prohibitively expensive.  For maximum developer productivity and
happiness, it's generally desirable to make the feedback loop of the
traditional red/green cycle as quick as possible.

So add run-tests-for-diff.sh and run-tests.py to the tools/
subdirectory, using a few tricks as explained below to help with this.

run-tests.py takes a list of files on STDIN, filters the list for
tests which can be run in the current tox virtualenv, and then runs
them with the correct stestr options.

run-tests-for-diff.sh is a simple wrapper around run-tests.py which
determines which tests to run using output from "git diff".  This
allows running only the test files changed/added in the working tree:

    tools/run-tests-for-diff.sh

or by a single commit:

    tools/run-tests-for-diff.sh mybranch^!

or a range of commits, e.g. a branch containing a whole patch series
for a blueprint:

    tools/run-tests-for-diff.sh gerrit/master..bp/my-blueprint

It supports the same "-HEAD" invocation syntax as flake8wrap.sh (as
used by the "fast8" tox environment):

    tools/run-tests-for-diff.sh -HEAD

run-tests.py uses two tricks to make test runs as quick as possible:

  1. It's (already) possible to speed up running of tests by
     source'ing the "activate" file for the desired tox virtualenv,
     e.g.

        source .tox/py36/bin/activate

     and then running stestr directly.  This saves a few seconds by
     skipping the overhead introduced by running tox.

  2. When only one test file needs to be run, specifying the -n option
     to stestr will skip the costly test discovery phase, saving
     several more valuable seconds.

Future commits could build on top of this work, harnessing a framework
such as watchdog / watchmedo[0] or Guard[1] in order to automatically
run relevant tests every time your editor saves changes to a .py file.

[0] https://github.com/gorakhargosh/watchdog - Python-based
[1] https://guardgem.org - probably best in class, but Ruby-based so
    maybe unacceptable for use within Nova.

Change-Id: I9a9bda5d29bbb8d8d77f769cd1abf7c42a18c36b
2019-08-19 17:48:39 +01:00
Zuul ee6b69cadc Merge "Fix libvirt driver tests to use LibvirtConfigCapsGuest instances" 2019-08-16 19:12:17 +00:00
Zuul 45a680cdf5 Merge "Allow assertXmlEqual() to pass options to matchers.XMLMatches" 2019-08-16 19:12:10 +00:00
Zuul 0311656d65 Merge "libvirt: Mock libvirt'y things in setUp" 2019-08-16 18:07:37 +00:00
Balazs Gibizer 588c513f3d Avoid timeout from service update api unit tests
Since If32bca070185937ef83f689b7163d965a89ec10a some of the service
update api tests are slow because setting a compute enabled or
disabled makes an RPC call to the given compute service. These tests
does not have the proper RPC setup so that call times out. The compute
api only logs an error for the timeout so the tests wasn't failing.

This patch stubs the RPC call as that is not necessary for the
api testing and therefore speeds up the tests.

Change-Id: If0960de896a67fd6bfca230b8915a45cb7af99b7
2019-08-16 14:23:33 +02:00
Stephen Finucane 85ea4f703d libvirt: Mock libvirt'y things in setUp
While addressing a nit from change
I8e5a122cc547222249973cf595d90c2d8d5658d4, I realized pretty much every
test using the nova.tests.functional.libvirt.base.ServersTestBase' base
class was now mocking the same things. This results in a lot of noise
and distracts from what the tests are trying to do. Centralize the
common mocks in the base class and clean up said noise.

Change-Id: I5895865751e8e1fb08b3515bc9f8119cfcb9f35e
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2019-08-16 11:13:25 +01:00
Zuul c7a32709b9 Merge "config: remove deprecated checksum options" 2019-08-16 07:25:48 +00:00
Zuul 839b3624ff Merge "Fix non-existent method of Mock" 2019-08-15 23:40:05 +00:00
Zuul 35485eacfb Merge "API microversion 2.76: Add 'power-update' external event" 2019-08-15 23:39:50 +00:00
Takashi NATSUME cf7d28eb6e Fix non-existent method of Mock
There is no method called_once_with() in Mock object.
Use assert_called_once_with() or assert_has_calls() instead.

Change-Id: I9f73fcbe7c3dfd64e75ac8224c13934b03443cd5
Closes-Bug: #1544522
2019-08-15 21:20:08 +00:00
Adam Spiers d5b9b0052a Fix libvirt driver tests to use LibvirtConfigCapsGuest instances
test_driver.LibvirtConnTestCase.test_cpu_info() and
test_driver.LibvirtConnTestCase.test_get_instance_capabilities() were
incorrectly adding LibvirtConfigGuest fixture objects to the guests
attribute of LibvirtConfigCaps, rather than LibvirtConfigCapsGuest
objects which is what the parse_dom() method of LibvirtConfigCaps
does.  LibvirtConfigCaps is intended to capture all useful information
returned by libvirt's getCapabilities API call, and
LibvirtConfigCapsGuest is intended to capture a small subset of that.
In contrast, LibvirtConfigGuest is intended for holding the entire
configuration of a libvirt guest domain.

So fix this to instead add LibvirtConfigCapsGuest fixtures.

Note that despite this bug, the tests previously passed through
duck-typing because LibvirtConfigCaps does not define __slots__ or any
other mechanism for limiting how attributes can be set on instances.

This is required by another commit in the SEV series in the near
future which will alter the fields within LibvirtConfigCapsGuest.

blueprint: amd-sev-libvirt-support
Change-Id: Ic4cbbaf81938fc88980e44c4a17fe388f9c2b92b
2019-08-15 19:24:26 +01:00
Adam Spiers 1e05b9e61c Allow assertXmlEqual() to pass options to matchers.XMLMatches
matchers.XMLMatches supports three options:

  - allow_mixed_nodes
  - skip_empty_text_nodes
  - skip_values

However these are not accessible when using the matcher via
assertXmlEqual().  So extend the latter with an *options
dictionary to allow options to be passed through.

This will be used by another commit in the SEV series in the near
future which needs the allow_mixed_nodes option to be enabled to
compare XML fragments with elements in different orders.

blueprint: amd-sev-libvirt-support
Change-Id: I31c60771891c3a2eb06fbc780ba2d369465498ec
2019-08-15 19:24:26 +01:00
Surya Seetharaman 62f6a0a1bc API microversion 2.76: Add 'power-update' external event
This patch adds a new external event called "power-update"
through which ironic will convey all (power_off and power_on)
power state changes (running -> shutdown or shutdown -> running
will be the only ones handled by nova and the rest will be ignored)
on a physical instance to nova. The database will be updated
accordingly to reflect the real vm_state and power_state of the
instance. This way nova will not be able to enforce
an incorrect power state on the physical instance during
the periodic "sync_power_states" task.

Implements blueprint nova-support-instance-power-update
Story: 2004969
Task: 29423

Change-Id: I2b292050cc3ce5ef625659f5a1fe56bb76072496
2019-08-15 13:19:44 -04:00
Mohammed Naser e141bcdb25 config: remove deprecated checksum options
This patch removes the legacy code for image checksumming
as well as configuration values that are not longer being
used.

Change-Id: I9c552e33456bb862688beaabe69f2b72bb8ebcce
2019-08-15 11:47:51 -04:00
Zuul 872a823d9a Merge "Enhance SDK fixture for 0.34.0" 2019-08-15 09:23:08 +00:00
Eric Fried 5f412cadbd Enhance SDK fixture for 0.34.0
As we work out the kinks in openstacksdk to smooth the road for nova's
usage thereof, and until openstacksdk can provide opaque fixtures that
it can keep up to date as its internals change, we've been needing to
stub things out incrementally.

This commit more aggressively mocks the piece of openstacksdk that
keeps changing under us. It effectively does what [1] does, but without
the get_endpoint() sanity check, which blows up in unit/functional test
because it tries to do real ksa auth.

[1] https://review.opendev.org/#/c/675135/

Change-Id: I1ef2ca51da2dc25026a2fbdcfb1ed5199aaa518b
2019-08-14 17:15:15 -05:00
Zuul 79d1c884b2 Merge "Restore soft-deleted compute node with same uuid" 2019-08-14 20:14:47 +00:00
Zuul dbe267aba5 Merge "Add functional regression recreate test for bug 1839560" 2019-08-14 20:14:37 +00:00
Zuul 7bcf8c5a7e Merge "lxc: make use of filter python3 compatible" 2019-08-14 18:25:57 +00:00
Zuul 778a986a65 Merge "api-ref: Fix collapse of 'host_status' description" 2019-08-14 07:27:09 +00:00
Zuul 77916e6d7b Merge "Execute TargetDBSetupTask" 2019-08-14 04:05:29 +00:00
Takashi NATSUME abfb28291a api-ref: Fix collapse of 'host_status' description
Fix collapse of 'host_status' description in the follwoing APIs
in the compute API reference.

- PUT /servers/{server_id}
- POST /servers/{server_id}/action (rebuild)

Change-Id: I003f9a81ac6f7e0ec13a24db3fda1b7ff6612bc5
Closes-Bug: #1840094
2019-08-14 10:46:26 +09:00
Sean Mooney fc9fb383c1 lxc: make use of filter python3 compatible
_detect_nbd_devices uses the filter
builtin internally to filter valid devices.

In python 2, filter returns a list. In python 3,
filter returns an iterable or generator function.
This change eagerly converts the result of calling filter
to a list to preserve the python 2 behaviour under python 3.

Closes-Bug: #1840068

Change-Id: I25616c5761ea625a15d725777ae58175651558f8
2019-08-13 22:29:57 +00:00
Zuul 0b290050b2 Merge "Add CrossCellMigrationTask" 2019-08-13 22:23:34 +00:00
Zuul 4467506437 Merge "rt: only map compute node if we created it" 2019-08-13 22:23:18 +00:00
Zuul 878d68ea8f Merge "Fix misuse of nova.objects.base.obj_equal_prims" 2019-08-13 22:08:39 +00:00
Zuul 8292cb9013 Merge "Prevent init_host test to interfere with other tests" 2019-08-13 18:48:32 +00:00
Zuul e0c8375e9f Merge "Add TargetDBSetupTask" 2019-08-13 18:48:24 +00:00
Matt Riedemann e7e6dfb7de Execute TargetDBSetupTask
This adds the code to CrossCellMigrationTask which
executes the TargetDBSetupTask sub-task and stores
some fields on the main task for use later when
dealing with the target cell.

Part of blueprint cross-cell-resize

Change-Id: I00683acee216c0c0ad87be3eb5ec832f20f054c7
2019-08-13 16:13:33 +00:00
Matt Riedemann b910af3b41 Add CrossCellMigrationTask
This adds the main conductor task that will orchestrate
a cross-cell resize. This will get called from the
existing conductor MigrationTask when that task determines
the scheduler picked a target host in another cell for the
resize operation.

The only thing CrossCellMigrationTask does in this change
is perform checks on the neutron and cinder APIs to make
sure they are new enough for what we need before we go any
further with the resize.

Part of blueprint cross-cell-resize

Change-Id: I4d181b44494f3b0b04537d5798537831c8fdf400
2019-08-13 16:11:46 +00:00
Balazs Gibizer f875c9d12f Prevent init_host test to interfere with other tests
The test_migrate_disk_and_power_off_crash_finish_revert_migration test
needs to simulate a compute host crash at a certain point. It stops the
execution at a certain point by injecting a sleep then simulating a
compute restart. However the sleep is just 30 seconds which allows the
stopped function to return while other functional tests are running in
the same test worker process making those tests fail in a weird way.

One simple solution is to add a big enough sleep to the test that will
never return before the whole functional test execution. This patch
proposes a million seconds which is more than 277 hours. Similar to how
the other test in this test package works. This solution is hacky but
simple. A better solution would be to further enhance the capabilities
of the functional test env supporting nova-compute service crash / kill
+ restart.

Change-Id: Ib0d142806804e9113dd61d3a7ec15a98232775c8
Closes-Bug: #1839515
2019-08-13 08:36:48 -04:00
Zuul e3a55493ba Merge "Add Instance.hidden field" 2019-08-13 02:52:00 +00:00
Zuul 1a0d1ce736 Merge "Add InstanceAction/Event create() method" 2019-08-13 02:51:49 +00:00
Zuul 9c2f563866 Merge "DRY get_flavor in flavor manage tests" 2019-08-13 02:51:41 +00:00
Zuul 87484b8bba Merge "Multiple API cleanup changes" 2019-08-13 02:51:32 +00:00
Takashi NATSUME 5c1d9dcbb2 Fix misuse of nova.objects.base.obj_equal_prims
The nova.objects.base.obj_equal_prims returns True or False.
It does not assert anything.
So the return value should be asserted in tests.

Add assertTrue where the nova.objects.base.obj_equal_prims is called.

Change-Id: I49460ec3b572ee14b32229e771a5499ff91e8722
Closes-Bug: #1839853
2019-08-13 09:38:54 +09:00
Zuul 26cf1b5701 Merge "Avoid timeout from service update notification tests" 2019-08-12 22:16:52 +00:00
Matt Riedemann 8b007266f4 Restore soft-deleted compute node with same uuid
There is a unique index on the compute_nodes.uuid column which
means we can't have more than one compute_nodes record in the
same DB with the same UUID even if one is soft deleted because
the deleted column is not part of that unique index constraint.

This is a problem with ironic nodes where the node is 1:1 with
the compute node record, and when a node is undergoing maintenance
the driver doesn't return it from get_available_nodes() so the
ComputeManager.update_available_resource periodic task (soft)
deletes the compute node record, but when the node is no longer
under maintenance in ironic and the driver reports it, the
ResourceTracker._init_compute_node code will fail to create the
ComputeNode record again because of the duplicate uuid.

This change handles the DBDuplicateEntry error in compute_node_create
by finding the soft-deleted compute node with the same uuid and
simply updating it to no longer be (soft) deleted.

Closes-Bug: #1839560

Change-Id: Iafba419fe86446ffe636721f523fb619f8f787b3
2019-08-12 14:39:16 -04:00
Matt Riedemann 89dd74ac7f Add functional regression recreate test for bug 1839560
This adds a functional test which recreates bug 1839560
where the driver reports a node, then no longer reports
it so the compute manager deletes it, and then the driver
reports it again later (this can be common with ironic
nodes as they undergo maintenance). The issue is that since
Ia69fabce8e7fd7de101e291fe133c6f5f5f7056a in Rocky, the
ironic node uuid is re-used for the compute node uuid but
there is a unique constraint on the compute node uuid so
when trying to create the compute node once the ironic node
is available again, the compute node create fails with a
duplicate entry error due to the duplicate uuid. To recreate
this in the functional test, a new fake virt driver is added
which provides a predictable uuid per node like the ironic
driver. The test also shows that archiving the database is
a way to workaround the bug until it's properly fixed.

Change-Id: If822509e906d5094f13a8700b2b9ed3c40580431
Related-Bug: #1839560
2019-08-12 12:25:14 -04:00
Matt Riedemann f578146f37 rt: only map compute node if we created it
If ComputeNode.create() fails, the update_available_resource
periodic will not try to create it again because it will be
mapped in the compute_nodes dict and _init_compute_node will
return early but trying to save changes to that ComputeNode
object later will fail because there is no id on the object,
since we failed to create it in the DB.

This simply reverses the logic such that we only map the
compute node if we successfully created it.

Some existing _init_compute_node testing had to be changed
since it relied on the order of when the ComputeNode object
is created and put into the compute_nodes dict in order
to pass the object along to some much lower-level PCI
tracker code, which was arguably mocking too deep for a unit
test. That is changed to avoid the low-level mocking and
assertions and just assert that _setup_pci_tracker is called
as expected.

Change-Id: I9fa1d509a3de405d6246fb8670612c65c10cc93b
Closes-Bug: #1839674
2019-08-12 12:23:35 -04:00
Balazs Gibizer ce42b6d494 Avoid timeout from service update notification tests
Since If32bca070185937ef83f689b7163d965a89ec10a some of the service
update notification tests are slow because setting a compute enabled or
disabled makes an RPC call to the given compute service. These tests
does not have the proper RPC setup so that call times out. Since the
notification is still generated the test passes. Waiting for this
timeout steals 16 minutes of test execution time unnecessary.

This patch stubs the RPC call as that is not necessary for the
notification testing and therefore speeds up the tests.

Change-Id: I0269c4bd3da0e58593811b11985deb237eefe59e
2019-08-12 17:49:11 +02:00
Eric Fried 3b2787584f DRY get_flavor in flavor manage tests
Followup from [1], cause it was bugging me.

[1] https://review.opendev.org/#/c/667600/3/nova/tests/unit/api/openstack/compute/test_flavor_manage.py@450

Change-Id: I481d4ed4af1d62b1174aa27b63231312e77024bc
2019-08-12 14:06:27 +00:00
Ghanshyam Mann b26bc7fd7a Multiple API cleanup changes
This microversion implements below API cleanups:

1. 400 for unknown param for query param and for request body.

2. Making server representation always consistent among all APIs
   returning the complete server representation.

3. Change the default return value of ``swap`` field from the empty string
   to 0 (integer) in flavor APIs.

4. Return ``servers`` field always in the response of GET
   hypervisors API even there are no servers on hypervisor

Details: https://specs.openstack.org/openstack/nova-specs/specs/train/approved/api-consistency-cleanup.html

Partial-Implements: blueprint api-consistency-cleanup

Change-Id: I9d257a003d315b84b937dcef91f3cb41f3e24b53
2019-08-12 08:52:38 -05:00
Zuul 52b9359d6c Merge "Update comments in HostManager._get_instance_info" 2019-08-12 12:55:53 +00:00
Zuul e373761b49 Merge "Cache host to cell mapping in HostManager" 2019-08-12 12:55:46 +00:00
Zuul 790f628883 Merge "Add a document that describes profiling eventlet services" 2019-08-12 10:05:45 +00:00
Zuul 370c727954 Merge "Use :oslo.config:* in nova-manage doc" 2019-08-10 16:32:20 +00:00
Zuul d3018d42fc Merge "Clean up docstrings for archive_deleted_rows" 2019-08-10 16:32:12 +00:00
Zuul a89838a4e9 Merge "Don't mention CONF.api_database.connection in user-facing messages/docs" 2019-08-10 16:32:05 +00:00
Zuul ca3761a4b7 Merge "Rename 'map' variable to avoid shadowing keywords" 2019-08-10 10:49:29 +00:00