Commit Graph

509 Commits

Author SHA1 Message Date
Dan Smith a21c4678c5 Make API fixture pass roles
This makes our API fixture pass roles in line with the user that
is being used. For admin_api, the admin role is included, and two
other clients are added for "reader" and "other".

Change-Id: I4aa985072103aeab50a1a3db4784081a492dcb7b
2021-11-30 12:42:50 -08:00
Takashi Natsume 1d0a0e8c20 Remove six.moves
Replace the following items with Python 3 style code.

- six.moves.configparser
- six.moves.StringIO
- six.moves.cStringIO
- six.moves.urllib
- six.moves.builtins
- six.moves.range
- six.moves.xmlrpc_client
- six.moves.http_client
- six.moves.http_cookies
- six.moves.queue
- six.moves.zip
- six.moves.reload_module
- six.StringIO
- six.BytesIO

Subsequent patches will replace other six usages.

Change-Id: Ib2c406327fef2fb4868d8050fc476a7d17706e23
Implements: blueprint six-removal
Signed-off-by: Takashi Natsume <takanattie@gmail.com>
2020-11-07 03:25:02 +00:00
Zuul 19cb983800 Merge "func: Remove references to attachment_id when volume_id is used" 2020-09-11 12:45:32 +00:00
Lee Yarwood a77f44a6c5 func: Remove references to attachment_id when volume_id is used
GET [1], PUT [2] and DELETE [3] os-volume_attachments APIs all take the
server and volume ids as part of the request path. This change simply
replaces any reference to attachment_id when calling these APIs from the
functional API client.

[1] https://docs.openstack.org/api-ref/compute/#show-a-detail-of-a-volume-attachment
    GET /servers/{server_id}/os-volume_attachments/{volume_id}

[2] https://docs.openstack.org/api-ref/compute/#update-a-volume-attachment
    PUT /servers/{server_id}/os-volume_attachments/{volume_id}

[3] https://docs.openstack.org/api-ref/compute/#detach-a-volume-from-an-instance
    DELETE /servers/{server_id}/os-volume_attachments/{volume_id}

Change-Id: Ie9e65c93a1abc3778094ab18f2f7916f7f2d0cb8
2020-09-02 20:53:56 +01:00
melanie witt 38bc8b871a Add regression test for bug 1893284
This adds a regression test for a bug where quota limit checking during
server creates is not properly scoped per-user when per-user quota has
been defined.

As a result, users who should be able to create a server are rejected
with a 403 "quota exceeded" error when they should be allowed to create
a server because servers owned by other users in the project are
incorrectly being counted for the current user.

Related-Bug: #1893284

Change-Id: I615ada45ffcbac081474c0a0cf005afdb8eec953
2020-08-28 23:22:35 +00:00
Stephen Finucane d8e9daafe8 api: Add microversion for extra spec validation
Enable support for API-based extra spec validation. Since most of the
hard work has been done in previous patches, all that's necessary here
is to wire up the microversion handling and turn things on.

Part of blueprint flavor-extra-spec-validators

Change-Id: If67f0d924ea372746a6dc440ea7bdc655e4f0bea
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2020-04-08 13:20:02 +00:00
zhangbailin 7ef623e6ec Add api for instance action details
There is the List Actions For Server API already provide in [1],
but the Show Server Action Details API [2] is often used too, so
add the show instance action details api, and replace it into the
used use case.

[1]https://docs.openstack.org/api-ref/compute/?expanded=#list-actions-for-server
   https://github.com/openstack/nova/blob/stable/train/nova/tests/functional/api/client.py#L428
[2]https://docs.openstack.org/api-ref/compute/?expanded=#show-server-action-details

Change-Id: I4d02f9ab3b87d741642cbc9ac263b0dd7617ad97
2019-12-20 16:40:20 +08:00
Zuul efdc734832 Merge "Stop using NoAuthMiddleware in tests" 2019-11-15 02:59:54 +00:00
zhangbailin ac165112b7 Filter migrations by user_id/project_id
In microversion 2.80, the ``GET /os-migrations`` API will have
optional ``user_id`` and ``project_id`` query parameters for
filtering migrations by user and/or project:

* GET /os-migrations?user_id=ef9d34b4-45d0-4530-871b-3fb535988394
* GET /os-migrations?project_id=011ee9f4-8f16-4c38-8633-a254d420fd54
* GET /os-migrations?user_id=ef9d34b4-45d0-4530-871b-3fb535988394&project_id=011ee9f4-8f16-4c38-8633-a254d420fd54

And expose the ``user_id`` and ``project_id`` fields in the following APIs:

* GET /os-migrations
* GET /servers/{server_id}/migrations
* GET /servers/{server_id}/migrations/{migration_id}

Co-Authored-By: Qiu Fossen <qiujunting>
Part of blueprint add-user-id-field-to-the-migrations-table
Change-Id: I7313d6cde1a5e1dc7dd6f3c0dff9f30bbf4bee2c
2019-10-14 11:35:11 -07:00
Eric Fried 52fe8c0285 Stop using NoAuthMiddleware in tests
This rips NoAuthMiddleware completely out of functional tests by:
- Removing our override of [api]auth_strategy in ConfFixture, allowing
  it to default to ``keystone``. This causes the fake wsgi setup to go
  through the same pipeline as real API requests; so making that work
  entails...
- Mocking out the keystonecontext piece of the paste pipeline to create
  the context previously mashed (somewhat inappropriately) into
  NoAuthMiddleware. In the future we may want to mock this more
  shallowly or find a way to make the req more realistic so it needn't
  be mocked at all, but for now this is close to what the noauth2
  pipeline used to do.
- Stubbing out the keystonemiddleware piece of the paste pipeline. In
  the future we should try to use keystonemiddleware's AuthTokenFixture
  so our tests can occur in a more realistic environment, but for now
  this is just mimicking what the noauth2 pipeline used to do; except
  for...
- Removing the authentication portion of the TestOpenStackClient. This
  used to make an actual request(), which landed in NoAuthMiddleware,
  which was hacking together some headers (based, it appears, on a
  protocol which is many years out of date and no longer approximates
  what keystone does, which should be the point if it's going to exist
  at all). So now we just hack up the necessary headers inline.
- Doing the addition of project_id in request URIs in OSAPIFixture.
  This is another thing that NoAuthMiddleware was doing inappropriately
  (IRL the project_id will either be part of the request from the start,
  or it won't). It was also only doing it part of the time; as a result,
  a couple of tests requesting version documents, which were previously
  not expecting the project ID to be present, needed to be modified to
  expect it. This better reflects reality.

Change-Id: I459a605b4a9390f0e36356ca1fe432948159acd4
2019-10-14 11:43:52 -05:00
He Jie Xu d6c96436d6 Include both VCPU and PCPU in core quota count
This patch enables counting both VCPU and PCPU when
`CONF.quota.count_usage_from_placement` enabled. Also add functional
test ensure the quota usage as expected.

Change-Id: I8377cbd1fb601d91deb7bb667a1ad5271c667399
Part of blueprint cpu-resources
2019-09-18 00:21:10 +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
Francois Palin ab7c968b6f Include all network devices in nova diagnostics
get_instance_diagnostics expected all interfaces
to have a <target> element with a "dev" attribute in
the instance XML. This is not the case for VFIO
interfaces (<interface type="hostdev">).
This caused an IndexError when looping over
the interfaces.

This patch fixes this issue by retrieving interfaces
data directly from the guest XML and adding nics
appropriately to the diagnostics object.

Change-Id: I8ef852d449e9e637d45e4ac92ffc5d1abd8d31c5
Closes-Bug: #1821798
2019-04-15 11:10:08 -04:00
Chris Dent 787bb33606 Use external placement in functional tests
Adjust the fixtures used by the functional tests so they
use placement database and web fixtures defined by placement
code. To avoid making redundant changes, the solely placement-
related unit and functional tests are removed, but the placement
code itself is not (yet).

openstack-placement is required by the functional tests. It is not
added to test-requirements as we do not want unit tests to depend
on placement in any way, and we enforce this by not having placement
in the test env.

The concept of tox-siblings is used to ensure that the
placement requirement will be satisfied correctly if there is a
depends-on. To make this happen, the functional jobs defined in
.zuul.yaml are updated to require openstack/placement.

tox.ini has to be updated to use a envdir that is the same
name as job. Otherwise the tox siblings role in ansible cannot work.

The handling of the placement fixtures is moved out of nova/test.py
into the functional tests that actually use it because we do not
want unit tests (which get the base test class out of test.py) to
have anything to do with placement. This requires adjusting some
test files to use absolute import.

Similarly, a test of the comparison function for the api samples tests
is moved into functional, because it depends on placement functionality,

TestUpgradeCheckResourceProviders in unit.cmd.test_status is moved into
a new test file: nova/tests/functional/test_nova_status.py. This is done
because it requires the PlacementFixture, which is only available to
functional tests. A MonkeyPatch is required in the test to make sure that
the right context managers are used at the right time in the command
itself (otherwise some tables do no exist). In the test itself, to avoid
speaking directly to the placement database, which would require
manipulating the RequestContext objects, resource providers are now
created over the API.

Co-Authored-By: Balazs Gibizer <balazs.gibizer@ericsson.com>
Change-Id: Idaed39629095f86d24a54334c699a26c218c6593
2018-12-12 18:46:49 +00:00
Kevin_Zheng 3cd439ad8a Handle tags in _bury_in_cell0
We allowed add instance tags when booting in
Iac54b9627cb4398e45f1f15a2f4e7d6f86242093, conductor
will create tags for us in the selected cell, but
we forgot to consider the case that no valid host
was found.

So we will be unable to filter those instances in
cell0 with tags.

Change-Id: Idfe37d356b349024dfe963c934728111e1a1d314
closes-bug: #1806515
2018-12-11 12:40:22 -05:00
Tetsuro Nakamura cdbedac920 Consider root id is None in the database case
There are cases where ``root_provider_id`` of a resource provider is
set to NULL just after it is upgraded to the Rocky release. In such
cases getting allocation candidates raises a Keyerror.

This patch fixes that bug for cases there is no sharing or nested
providers in play.

Change-Id: I9639d852078c95de506110f24d3f35e7cf5e361e
Closes-Bug:#1799892
2018-11-20 14:53:59 +00:00
Zuul ed5e7fb2c2 Merge "Add recreate test for bug 1799892" 2018-11-09 23:20:34 +00:00
Balazs Gibizer b93b40c6c0 Add bandwidth related standard resource classes
Introduce NET_BW_EGR_KILOBIT_PER_SEC and
NET_BW_IGR_KILOBIT_PER_SEC resource classes.

blueprint bandwidth-resource-provider

Change-Id: I996bf705b14b564106426a2e57299638fb178750
2018-11-05 17:47:13 -05:00
Balazs Gibizer d4f8974f87 Add request_spec.RequestGroup versioned object
Later patches will introduce a field in RequestSpec using this type as
the field type to store the resource requests coming from outside of
Nova like the bandwidth request coming from the Neutron ports.

This patch refactors the usage of placement.lib.RequestGroup. Until now
this class was used both by placement and nova services and they used
it only as a util class. However after this series the nova services
would like to use such a class via RPC which requires an OVO. This
patch makes sure that the new OVO is used by nova and the old plain
object is used by placement. This way placement is not forced to use
an OVO where no OVO functionality is required.

The minimum required version of oslo.versionedobjects is updated to
1.33.3 to include the fix for bug 1771804.

Change-Id: I46c97d2641d9685ef59771314665a17a5236097d
blueprint: bandwidth-resource-provider
2018-11-05 17:47:06 -05:00
Tetsuro Nakamura 95d0ebc3d8 Add recreate test for bug 1799892
There are cases where ``root_provider_id`` of a resource provider is
set to NULL just after it is upgraded to the Rocky release. In such
cases getting allocation candidates raises a Keyerror.

This patch recreate that bug by simulating the situation by
inserting the records to the database directly.

Change-Id: Iaed912314f3e8fef2f46453a6bf12011702ae1dd
Related-Bug:#1799892
2018-10-26 07:27:28 +00:00
Mohammed Naser 730936e535 Use unique consumer_id when doing online data migration
If there are multiple consumers having allocations to the same
resource provider, with different classes, it will attempt
multiple INSERTs with the same consumer_id which is not allowed
because of the database constraints.

This patch adds a simple GROUP BY in order to ensure that the
database server only provides us with unique values to avoid
trying to INSERT duplicate values.

Change-Id: I1acba5e65cd562472f29e354c6077f82844fa87d
Closes-Bug: #1798163
2018-10-16 15:30:38 -04:00
Matt Riedemann 618b47627d Add recreate test for bug 1798163
Change Icae5038190ab8c7bbdb38d54ae909fcbf9048912 in Rocky
attempts to online migrate missing consumers table records
when listing allocations for a given resource provider. The
problem is when it's doing an insert-from-select, it's not
handling multiple allocations on the same provider for the
same consumer, like you'd have with a compute instance that
has VCPU, MEMORY_MB and DISK_GB allocations against a single
compute node resource provider. As a result, the insert
statement has duplicate consumer IDs in it which results in
a unique constraint violation.

The existing tests never caught this because they tested with
3 unique consumers with a single allocation each.

The functional test added here hits both online data migration
routines: via the API when listing allocations for a resource
provider and the direct online data migration CLI.

Change-Id: Iba56aa6b227b6455d2437e4fabcd296b1b0f06ee
Related-Bug: #1798163
2018-10-16 15:21:35 -04:00
Zuul 00dc4483b7 Merge "Transform missing delete notifications" 2018-09-26 20:51:26 +00:00
Eric Fried 8e1ca5bf34 Use uuidsentinel from oslo.utils
oslo.utils release 3.37.0 [1] introduced uuidsentinel [2]. This change
rips out nova's uuidsentinel and replaces it with the one from
oslo.utils.

[1] https://review.openstack.org/#/c/599754/
[2] https://review.openstack.org/#/c/594179/

Change-Id: I7f5f08691ca3f73073c66c29dddb996fb2c2b266
Depends-On: https://review.openstack.org/600041
2018-09-05 09:08:54 -05:00
Zuul 3779211031 Merge "Fix race condition in reshaper handler" 2018-08-30 17:35:09 +00:00
Zuul 18e801d4de Merge "reshaper gabbit: Nix comments re doubled max_unit" 2018-08-30 17:21:13 +00:00
Zuul 06e5a22bc6 Merge "reshaper: Look up provider if not in inventories" 2018-08-30 01:12:50 +00:00
Balazs Gibizer d3097e52b3 Transform missing delete notifications
The Iddbe50ce0ad3c14562df800bbc09ec5a7e840485 patch only considered
instance delete in the happy case when the instance is scheduled to a
compute successfully and the compute is available when the delete
action is executed. If the instance is never scheduled to a compute or
the compute is not available when the instance is deleted legacy delete
notifications are emitted from different places, compute.api instead of
compute.manager. The original patch missed these places.

There will be subsequent patch(es) handling the same edge cases
for soft_delete and force_delete.

Change-Id: If0693eab2ed31b5fbfe6cbafa5d67b69c2ed8442
Implements: bp versioned-notification-transformation-stein
2018-08-29 13:39:57 +02:00
Zuul 7116d8daf8 Merge "[placement] Add /reshaper handler for POST" 2018-08-29 09:22:10 +00:00
Eric Fried 2a50107606 reshaper gabbit: Nix comments re doubled max_unit
As noted in a review [1] on the reshaper series, the comments about
doubling max_unit were obsolete (fixed via [2]), and are hereby removed.

[1] https://review.openstack.org/#/c/576927/35/nova/tests/functional/api/openstack/placement/gabbits/reshaper.yaml@222
[2] I8ba378ff5eeaf6c9cca11c5874708a17d4640097

Change-Id: Iaf3df651a76705d0f64182c46c665f037ea51b68
2018-08-28 14:46:00 -05:00
Eric Fried d98986415c Fix race condition in reshaper handler
Fix the race condition identified at [1] by indexing the `inventories`
argument to the resource_provider.reshape method by ResourceProvider
object rather than its UUID. That means we never have to do a fresh
lookup for the provider.

[1] https://review.openstack.org/#/c/585033/18/nova/api/openstack/placement/objects/resource_provider.py@4195

Change-Id: Ie21bddc186364db2b10af45546c35b9ad5a0208b
2018-08-25 10:45:49 -05:00
Zuul 7107eff2a2 Merge "[placement] Add functional test to verify presence of policy" 2018-08-23 21:30:55 +00:00
Eric Fried d13e5a5011 reshaper: Look up provider if not in inventories
Per the referenced bug, we weren't accounting for the scenario where a
reshape operation was removing *all* inventories for a provider (which
could be fairly common). With this fix, we do a three-stage lookup of
the provider object: If it's not in the inventories, we look in the
allocations; if it's not in the allocations, we look it up in the
database.

Change-Id: I594bb64f87c61b7ffd39c19e0fd42c4c087a3a11
Closes-Bug: #1783130
2018-08-23 08:45:34 -05:00
Chris Dent 3a24000514 [placement] Add functional test to verify presence of policy
Add a test that traverses all available placement URLs at the latest
microversion and tries to access them as non-admin. If something other
than a 403 response is given a failed test with a message like

    method POST on route /resource_providers/{uuid}/inventories
    is open for user, status: 404

is produced.

This works because we do authZ handling early in each handler, before
data processing and path parameter handling.

The method is pretty straightforward: traverse ROUTE_DECLARATIONS, visit
every url with each the declared methods, except the root version document,
and confirm a 403 response when the provided auth token is non-admin.

This has been created to avoid situations where a route is added without
policy like happened on https://review.openstack.org/#/c/576927/ . Until
recently we had a failover where any route not defined to have policy
would default to admin. That went away so now we need some test
automation to catch our forgetful humanness.

Change-Id: Id582886ec4b621b97d7cc7237b4670ad7bb12295
2018-08-23 10:27:53 +01:00
rajat29 d27d8e44a3 Normalize dashless 'resource provider create' uuid
When creating resource provider with '--uuid' argument, nova
accept uuid without dash('-') too, which some time results in,
resource provider with same uuid i.e one with dash and one without.

This patch attempts to fix it by transforming dashless UUID into
dashed one before inserting it into the database.

Co-Authored-By: Chen <dstbtgagt@foxmail.com>

Change-Id: I2685eb65907adbd22b2d09264b110692e100eaf9
Closes-Bug: #1758057
2018-08-23 11:20:42 +08:00
Chris Dent 4d525b4ec1 [placement] Add /reshaper handler for POST
/reshaper provides a way to atomically modify some allocations and
inventory in a single transaction, allowing operations like migrating
some inventory from a parent provider to a new child.

A fair amount of code is reused from handler/inventory.py, some
refactoring is in order before things get too far with that.

In handler/allocation.py some code is extracted to its own methods
so it can be reused from reshaper.py.

This is done as microversion 1.30.

A suite of gabbi tests is provided which attempt to cover various
failures including schema violations, generation conflicts, and
data conflicts.

api-ref, release notes and rest history are updated

Change-Id: I5b33ac3572bc3789878174ffc86ca42ae8035cfa
Partially-Implements: blueprint reshape-provider-tree
2018-08-23 00:36:17 +00:00
Chris Dent 2b46354d5a Set policy_opt defaults in placement gabbi fixture
Without this change, tests can intermittently fail with NoSuchOptError
when a single process does not have other tests running prior to
gabbi tests. This change ensure the opts are registered and defaulted.

Change-Id: I1c7e347b6e788928bef96e32c3365d0fdc5ba00f
Related-Bug: #1786498
Closes-Bug: #1788176
2018-08-21 14:28:32 +01:00
Eric Fried 327448e7cb Test case for multiple forbidden traits
Test case to expose a bug at [1] where symmetric difference (^) is being
used instead of difference (-).

[1] https://review.openstack.org/#/c/590041/6/nova/api/openstack/placement/objects/resource_provider.py@2911

Change-Id: I2e80fe75da1d1104d0562f087c74117fbe6b457b
2018-08-10 16:19:41 -04:00
Tetsuro Nakamura dc26780ef8 Adds a test for _get_provider_ids_matching()
This patch adds a test for _get_provider_ids_matching()
to verify it works correctly with required traits.

Related-Bug: #1786519
Change-Id: I2512e361f5eaa4e60701be7c8bf57b2e0a02a146
2018-08-10 16:19:41 -04:00
Zuul 681cb7f21f Merge "Use common functions in granular fixture" 2018-08-07 23:16:15 +00:00
Zuul 41692fc5e9 Merge "Use common functions in NonSharedStorageFixture" 2018-08-07 05:01:48 +00:00
Tetsuro Nakamura 45e34808f5 Use common functions in granular fixture
For code refactoring purpose in the placement granular fixture
setup, this patch substitutes common functions in test_base.py
for existing local functions of _create_providers(),
_add_inventory(), and _set_traits().

Change-Id: I76a3f7d7e446e0f3af379f83c9d8333279884c73
2018-08-07 11:03:37 +09:00
Zuul 5f3b4aa44f Merge "Not use project table for user table" 2018-08-07 01:11:39 +00:00
Zuul 1d97b663d3 Merge "Adds a test for getting allocations API" 2018-08-07 00:50:17 +00:00
Zuul 954038d795 Merge "Refactor AllocationFixture in placement test" 2018-08-07 00:46:16 +00:00
Zuul ef50733478 Merge "Increase max_unit in placement test fixture" 2018-08-06 20:21:40 +00:00
Tetsuro Nakamura e13b765e55 Not use project table for user table
`GET /resource_provider/{uuid}/allocations` API didn't
return all the allocations made by multiple users.

This was because the placement wrongly used project table
for user table. This patch fixes it with the test case.

Change-Id: I7c808dec5de1204ced0d1f1b31d8398de8c51679
Closes-Bug: #1785382
2018-08-04 19:34:04 +09:00
Tetsuro Nakamura 9cfc598acf Adds a test for getting allocations API
`GET /resource_provider/{uuid}/allocations` API currently doesn't
return all the allocations made by multiple users.

This patch adds a test to describe this bug. The fix for this
is coming in a follow up.

Change-Id: I2b01e27922f11bef2defcb01fe415692de1578ea
Partial-Bug: #1785382
2018-08-04 19:20:30 +09:00
Chris Dent 08f23b5810 [placement] Move resource_class_cache into placement hierarchy
Since only placement uses the resource_class_cache, move it
into the placement hierarchy.

Change-Id: I837d4b691f94af0487a66dacf5ae563e4423f6a3
2018-08-03 14:55:49 +01:00
Tetsuro Nakamura 7d824e6d37 Refactor AllocationFixture in placement test
This patch refactors the allocation fixture used in some placement
api tests by substituting common functions in test_base.py for the
existing object management functions.

Change-Id: Ide6544d1cf9e1ed154b42075acdd7af986c3afe8
2018-08-02 14:46:10 +09:00