Commit Graph

43 Commits

Author SHA1 Message Date
Ghanshyam Mann 1b6a6e3916 Convert features not supported error to HTTPBadRequest
There is inconsistency on return code nova API return
for "Feature not supported/implemented'. Current return
code are 400, 409, and 403.
- 400 case: Example: Multiattach Swap Volume Not Supported
- 403 case: Cyborg integration
- 409 case: Example: Operation Not Supported For SEV ,
  Operation Not Supported For VTPM

In xena PTG, we agreed to fix this by returning 400 in all cases
- L446: https://etherpad.opendev.org/p/nova-xena-ptg

This commit convert all the features not supported error to
HTTPBadRequest(400).

To avoid converting every NotSupported inherited exception
in API controller to HTTPBadRequest generic conversion is
added in expected_errors() decorator.

Closes-Bug: #1938093

Change-Id: I410924668a73785f1bfe5c79827915d72e1d9e03
2021-09-01 09:09:58 -05:00
Balazs Gibizer 8f5b7c67ca Reject server operations with extended resource req
As a precaution reject all the server lifecycle operations that currently
do not support port-resource-request-groups API extension. These
are:
* resize
* migrate
* live migrate
* evacuate
* unshelve after shelve offload
* interface attach

This rejection will be removed in the patch that adds support for the
given operation.

blueprint: qos-minimum-guaranteed-packet-rate
Change-Id: I12c25550b08be6854b71ed3ad4c411a244a6c813
2021-08-21 10:00:48 +02:00
Balazs Gibizer bfde686130 Remove unnecessary mocks from unit test
These mocks where added in the series [1] when we rejected server
operations with qos port. But then we forgot to remove them when
the support is added to those operations during [2].

[1] https://review.opendev.org/q/topic:bp/bandwidth-resource-provider
[2] https://review.opendev.org/q/topic:bp/support-move-ops-with-qos-ports-ussuri

Change-Id: Idbc2d6b2f8f50924dc84683f9701aa28007616af
2021-06-04 09:03:43 +02:00
Sean Mooney 45798adf5a api: Block unsupported actions with vDPA
There are a number of operations that are known not to work with vDPA
interfaces and another few that may work but haven't been tested. Start
blocking these. In all cases where an operation is blocked a HTTP 409
(Conflict) is returned. This will allow lifecycle operations to be
enabled as they are tested or bugs are addressed.

Change-Id: I7f3cbc57a374b2f271018a2f6ef33ef579798db8
Blueprint: libvirt-vdpa-support
2021-03-16 20:39:27 +00:00
Ghanshyam Mann cb56ae6aad Fix ForbiddenWithAccelerators to HTTPForbidden for shelve API
ForbiddenWithAccelerators is not converted to HTTPForbidden unless
that is explicitly converted in API controller. For example:
- https://github.com/openstack/nova/blob/46899968619e4ea0ff2ab380977619bb29578d43/nova/api/openstack/compute/migrate_server.py#L154

Otherwise it end up raising 500 because ForbiddenWithAccelerators is
not inherrited from nova.exception.Forbidden
- https://github.com/openstack/nova/blob/46899968619e4ea0ff2ab380977619bb29578d43/nova/exception.py#L158

and expected_errors() decorator convert it to 500.
- https://github.com/openstack/nova/blob/46899968619e4ea0ff2ab380977619bb29578d43/nova/api/openstack/wsgi.py#L689

Except shelve API, all other APIs which can get
ForbiddenWithAccelerators via block_accelerators decorator convert it
explicitly.

If we inherit ForbiddenWithAccelerators from nova.exception.Forbidden
then expected_errors() decorator will take care of convertion to
HTTPForbidden automatically for all APIs.

Also adding tests for APIs can get ForbiddenWithAccelerators.

Change-Id: I9335ddb2d72909a110c313d5b609f2be279b18ef
2021-01-26 00:51:27 +00:00
Takashi Natsume 1cf2431f4b Remove six.text_type (2/2)
Replace six.text_type with str.
This patch completes six removal.

Change-Id: I779bd1446dc1f070fa5100ccccda7881fa508d79
Implements: blueprint six-removal
Signed-off-by: Takashi Natsume <takanattie@gmail.com>
2020-12-13 11:26:35 +00:00
Balazs Gibizer c163205489 Remove compute service level check for qos ops
To support move operations with qos ports both the source and the
destination compute hosts need to be on Ussuri level. We have service
level checks implemented in Ussuri. In Victoria we could remove those
checks as nova only supports compatibility between N and N-1 computes.
But we kept them there just for extra safety. In the meanwhile we
codified [1] the rule that nova does not support N-2 computes any
more. So in Wallaby we can assume that the oldest compute is already
on Victoria (Ussuri would be enough too).

So this patch removes the unnecessary service level checks and related
test cases.

[1] Ie15ec8299ae52ae8f5334d591ed3944e9585cf71

Change-Id: I14177e35b9d6d27d49e092604bf0f288cd05f57e
2020-11-09 16:13:51 +01:00
Stephen Finucane eb819c8c63 Add support for resize and cold migration of emulated TPM files
When using emulated TPM, libvirt will store the persistent TPM data
under '/var/lib/libvirt/swtpm/<instance_uuid>' which is owned by the
"tss" or "root" user depending how libvirt is configured (the parent
directory, '/var/lib/libvirt/swtpm' is always owned by root). When doing
a resize or a cold migration between nodes, this data needs to be copied
to the other node to ensure that the TPM data is not lost.  Libvirt
won't do this automatically for us since cold migrations, or offline
migrations in libvirt lingo, do not currently support "copying
non-shared storage or other file based storages", which includes the
vTPM device [1].

To complicate things further, even if migration/resize is supported,
only the user that nova-compute runs as is guaranteed to be able to have
SSH keys set up for passwordless access, and it's only guaranteed to be
able to copy files to the instance directory on the dest node.

The solution is to have nova (via privsep) copy the TPM files into the
local instance directory on the source and changes the ownership. This
is handled through an additional call in 'migrate_disk_and_power_off'.
As itself, nova then copies them into the instance directory on the
dest. Nova then (once again, via privsep) changes the ownership back and
moves the files to where libvirt expects to find them. This second step
is handled by 'finish_migration'. Confirming the resize will result in
the original TPM data at '/var/lib/libvirt/swtpm' being deleted by
libvirt and the copied TPM data in the instance data being cleaned up by
nova (via 'confirm_migration'), while reverting it will result on the
same on the host.

Part of blueprint add-emulated-virtual-tpm

[1] https://libvirt.org/migration.html#offline

Change-Id: I9b053919bb499c308912c8c9bff4c1fc396c1193
Signed-off-by: Chris Friesen <chris.friesen@windriver.com>
Co-authored-by: Stephen Finucane <stephenfin@redhat.com>
2020-09-08 09:58:21 +01:00
Stephen Finucane eef4b5435e api: Reject non-spawn operations for vTPM
We're going to gradually introduce support for the various instance
operations when using vTPM due to the complications of having to worry
about the state of the vTPM device on the host. Add in API checks to
reject all manner of requests until we get to include support for each
one. With this change, the upcoming patch to turn everything on will
allow a user to create, delete and reboot an instance with vTPM, while
evacuate, rebuild, cold migration, live migration, resize, rescue and
shelve will not be supported immediately.

While we're here, we rename two unit test files so that their names
match the files they are testing and one doesn't have to spend time
finding them.

Change-Id: I3862a06ca28b383d525bcc9dcbc6fb1d4062f193
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2020-08-24 19:37:01 +01:00
Ghanshyam Mann 9d98d8b1a4 Add test coverage of existing migrate server policies
Current tests do not have good test coverage of existing policies.
Either tests for policies do not exist or if they exist then they
do not cover the actual negative and positive testing.

For Example, if any policy with default rule as admin only then
test should verify:
- policy check pass with context having admin or server owner
- policy check fail with context having non-admin and not server owner

As discussed in policy-defaults-refresh, to change the policies
with new default roles and scope_type, we need to have the enough
testing coverage of existing policy behavior.

When we will add the scope_type in policies or new default roles,
then these test coverage will be extended to adopt the new changes
and also make sure we do not break the existing behavior.

This commit covers the testing coverage of existing migrate server policies.

Partial implement blueprint policy-defaults-refresh

Change-Id: I1de770bd17d3b8bd2e4f3381ae73a1f6cdf30c80
2020-03-30 23:39:34 -05:00
Balazs Gibizer a4c3260f56 Enable unshelve with qos ports
Previous patches in the blueprint implemented the support for unshelve
with qos ports and added functional test coverage for the
various scenarios. So this patch changes the API check
that rejected such operation to check for the service version and therefore
conditionally enable the feature.

Change-Id: Iaf70ee41f1bfb1a4964da3f59cd3a0b4b5e20d36
blueprint: support-move-ops-with-qos-ports-ussuri
2020-03-18 17:38:55 +01:00
Stephen Finucane fadeedcdea nova-net: Remove layer of indirection in 'nova.network'
At some point in the past, there was only nova-network and its code
could be found in 'nova.network'. Neutron was added and eventually found
itself (mostly!) in the 'nova.network.neutronv2' submodule. With
nova-network now gone, we can remove one layer of indirection and move
the code from 'nova.network.neutronv2' back up to 'nova.network',
mirroring what we did with the old nova-volume code way back in 2012
[1]. To ensure people don't get nova-network and 'nova.network'
confused, 'neutron' is retained in filenames.

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

Change-Id: I329f0fd589a4b2e0426485f09f6782f94275cc07
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2020-01-15 14:57:49 +00:00
Matt Riedemann ea2ea492a3 Ensure source service is up before resizing/migrating
If the source compute service is down when a resize or
cold migrate is initiated the prep_resize cast from the
selected destination compute service to the source will
fail/hang. The API can validate the source compute service
is up or fail the operation with a 409 response if the
source service is down. Note that a host status of
"MAINTENANCE" means the service is up but disabled by
an administrator which is OK for resize/cold migrate.

The solution here works the validation into the
check_instance_host decorator which surprisingly isn't
used in more places where the source host is involved
like reboot, rebuild, snapshot, etc. This change just
handles the resize method but is done in such a way that
the check_instance_host decorator could be applied to
those other methods and perform the is-up check as well.
The decorator is made backward compatible by default.

Note that Instance._save_services is added because during
resize the Instance is updated and the services field
is set but not actually changed, but Instance.save()
handles object fields differently so we need to implement
the no-op _save_services method to avoid a failure.

Change-Id: I85423c7bcacff3bc465c22686d0675529d211b59
Closes-Bug: #1856925
2019-12-19 15:24:34 -05:00
Matt Riedemann fb283dab57 Remove unused CannotMigrateWithTargetHost
Before [1] this could be raised from the API resize()
method if getting a RequestSpec failed and a target host
was specified for cold migration. Since that change the
usage of the exception was removed so we can remove it
altogether since only unit test code is using it.

[1] I34ffaf285718059b55f90e812b57f1e11d566c6f

Change-Id: I19db48bd03855d1a1edbeff5adf15a28abcb5d92
2019-11-12 09:47:54 -05:00
Balazs Gibizer 8999769605 Use admin neutron client to see if instance has qos ports
The nova-api checks at each move* operation if the instance has qos port
attached as not all the move operations are supported for such servers.
Nova uses the request context to initialize the neutron client for the
port query. However neutron does not return the value of the
resource_request of the port if it is queried with a non admin client.
This causes that if the move operation is initiated by a non admin
then nova thinks that the ports do not have resource request.

This patch creates an admin context for this neutron query.

The new functional tests are not added before this patch in a regression
test like way as existing functional tests are reused with different
setup and doing that without the fix causes a lot of different failure
scenarios.

Note that neutron fixture is changed to simulate the different behavior
in case of different request context are used to initialize the client.

*: Note that Id5f2f4f22b856c989e2eef8ed56b9829d1bcefb6 removed the check
   for evacuate in Ussuri but exists in Train and Stein.

Change-Id: I3cf6eb4654663865d9258c38f05cd05974ffcf9d
Closes-Bug: #1850280
2019-11-06 15:54:03 -05:00
Adam Spiers 84db8b3f3d Reject live migration and suspend on SEV guests
As per the spec[0], live migration and suspend are not (yet) supported
for SEV guests, so reject them at the API level with an HTTP
409 (Conflict).

[0] http://specs.openstack.org/openstack/nova-specs/specs/train/approved/amd-sev-libvirt-support.html#limitations

blueprint: amd-sev-libvirt-support
Change-Id: I69b6e153324a3e5680e096cd714e5d4dd05bae34
2019-09-10 13:59:02 +01:00
Balazs Gibizer a061b0ea2e migrate: Add bw min service level check of source compute
During cold migrate the RequestSpec goes from the dest compute to the
source compute and then back to the dest. The previous patch [1] added
service level check for the dest compute. However the source compute also
needs to be new enough so the RequestSpec is passed through it.

Please note that the functional coverage for this api change is in a
later patch [2].

[1] https://review.opendev.org/#/c/680394
[2] https://review.opendev.org/#/c/655113

blueprint: support-move-ops-with-qos-ports
Change-Id: I09cac780b9ee5b5726874d4e6f895fd0cd4bff8c
2019-09-06 16:41:52 +02:00
Takashi NATSUME 8f78dc68d9 Avoid lazy-loading instance.flavor in cold migration
The instance.flavor is lazy-loaded currently in the resize method
in nova/compute/api.py.

Set expected_attrs=['flavor'] at the common.get_instance
in the _migrate method
in nova/api/openstack/compute/migrate_server.py
to avid lazy-loading instance.flavor.

Change-Id: Iba3b7c3e027ec78395a102c1fed46fa7a2ffa7be
Closes-Bug: #1829877
2019-06-03 15:28:21 +09:00
Matt Riedemann 2ed304e9cc Follow up (#2) for the bw resource provider series
This addresses review comments from the following changes:

  I61a3e8902a891bac36911812e4e7c080570e3850

  I48e6db9693e470b177bf4c75211d8b883c768433

  Ic70d2bb781b6a844849a5cf2fe4d271b5a81093d

  I5a956513f3485074023e027430cc52ee7a3f92e4

  Ica6152ccb97dce805969d964d6ed032bfe22a33f

Part of blueprint bandwidth-resource-provider

Change-Id: Idffaa6d206cda3f507e6be095356537f22302ad7
2019-02-11 14:35:15 -05:00
Stephen Finucane 36a91936a8 API: Remove evacuate/live-migrate 'force' parameter
Add a new microversion that removes support for the aforementioned
argument, which cannot be adequately guaranteed in the new placement
world.

Change-Id: I2a395aa6eccad75a97fa49e993b0300bdcfc7258
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Implements: blueprint remove-force-flag-from-live-migrate-and-evacuate
APIImpact
2019-02-08 17:05:19 -05:00
Balazs Gibizer 3730bd0791 Reject migrate with port having resource request
Nova does not consider the resource request of a Neutron port as of now.
So this patch makes sure that server migrate and live migrate requests are
rejected if they involve a port that has resource request. When the feature
is ready on the nova side this limitation will be lifted.

blueprint: bandwidth-resource-provider

Change-Id: I48e6db9693e470b177bf4c75211d8b883c768433
2019-01-28 15:51:10 +01:00
Stephen Finucane ae2e5650d1 Fail to live migration if instance has a NUMA topology
Live migration is currently totally broken if a NUMA topology is
present. This affects everything that's been regrettably stuffed in with
NUMA topology including CPU pinning, hugepage support and emulator
thread support. Side effects can range from simple unexpected
performance hits (due to instances running on the same cores) to
complete failures (due to instance cores or huge pages being mapped to
CPUs/NUMA nodes that don't exist on the destination host).

Until such a time as we resolve these issues, we should alert users to
the fact that such issues exist. A workaround option is provided for
operators that _really_ need the broken behavior, but it's defaulted to
False to highlight the brokenness of this feature to unsuspecting
operators.

Change-Id: I217fba9138132b107e9d62895d699d238392e761
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Related-bug: #1289064
2018-12-14 14:08:35 -05:00
Surya Seetharaman ef5aa8a818 Minimal construct plumbing for nova show when a cell is down
This patch sets the stage for modifying the behavior of nova show
which currently gives a 500 when the cell in which the instance
lives is down. The new behavior will return a partial construct
consisting of uuid, project_id, created_at from instance_mappings
table and user_id, flavor, image_ref and availability_zone info
from request_specs table.  Note that the rest of the keys will be
missing. This behavior will be enabled by passing a new enough
microversion, handling for which is introduced later in this series.

Related to blueprint handling-down-cell

Change-Id: Iaea1cb4ed93bb98f451de4f993106d7891ca3682
2018-10-31 15:22:09 -04: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
Corey Bryant 2d532963fa In Python3.7 async is a keyword [1]
Change all instances of "async" to "async_"

[1] https://docs.python.org/3/whatsnew/3.7.html

Change-Id: I974b1177ba8313ac502910ca358cf386ef00bc02
Closes-Bug: #1782746
2018-07-20 12:21:34 -04:00
Zuul c8b93fa249 Merge "Drop API compat handling for old compute error cases" 2018-06-27 14:24:02 +00:00
Takashi NATSUME 399554a518 Remove mox in tests/unit/api/openstack/compute
Replace mox with mock or stub_out in the following files
in nova/tests/unit/api/openstack/compute directory.

* admin_only_action_common.py
* test_admin_actions.py
* test_lock_server.py
* test_migrate_server.py
* test_pause_server.py
* test_suspend_server.py

Change-Id: I83b473e9ba557545b5c186f979e068e442de2424
Implements: blueprint mox-removal
2018-05-24 21:31:44 +00:00
Matt Riedemann 26f000ebb9 Drop API compat handling for old compute error cases
Change Ibcb6bf912b3fb69c8631665fef2832906ba338aa dropped
the compute RPC API code for checking old computes from the
API and raising specific errors if the API is trying to perform
some action on an instance running on an old compute that can't
handle that action.

With that change, the API now expects that computes should be
able to handle at least Queens level operations, i.e. the
can_send_version checks for those operations in the compute RPC
API code would not be False.

Since those compute RPC API checks are removed, the handling in
the API is dead code now, so we can cleanup that handling.

Change-Id: Ibd05139c5f6a0548f17e24d3807746b93d76f446
2018-05-16 17:24:14 -04:00
Zuul 450be218da Merge "Return 400 when compute host is not found" 2018-03-07 13:42:56 +00:00
Sivasathurappan Radhakrishnan fb68fd12e2 Return 400 when compute host is not found
Previously user was getting a 500 error code for ComputeHostNotFound
if they are using latest microversion that does live migration in
async. This patches changes return response to 400 as 500 internal
server error should not be returned to the user for failures due to
user error that can be fixed by changing to request on client side.

Change-Id: I7a9de211ecfaa7f2816fbf8bcd73ebbdd990643c
closes-bug:1643623
2018-02-20 11:29:29 +05:30
jichenjc 13f4127c9d Remove MigrationPreCheckClientException
Commit c2f57a126f
removes last raise place of this exception

Change-Id: I9ab1b2a064e09f8af69d1783675070e24ede5cf8
2018-02-09 04:48:30 +08:00
Takashi NATSUME d2ce4ca9ec Enable cold migration with target host(2/2)
This function enables users to specify a target host
when cold migrating a VM instance.

This patch modifies the migration API.

APIImpact
    Add an optional parameter 'host' in cold migration action.

Change-Id: Iee356c4dd097c846b6ca8617ead6a061300c83f8
Implements: blueprint cold-migration-with-target-queens
2017-11-29 20:48:16 -05:00
Takashi NATSUME 7e4082d271 Fix calling super function in setUp method
TrivialFix
Change-Id: Ia45af0923c467d373b87f4f81f89ceb7d6bf2728
2016-10-01 15:47:46 +09:00
Pawel Koniszewski 89bf80202b Add missing ComputeHostNotFound exception in live-migration
Commit c824982e6a did not update
expected exceptions. Therefore we end up with 500 internal server
error when triggering targeted live migration to non-existing compute
node. This patch adds ComputeHostNotFound to expected exception list
in both, conductor and API.

Change-Id: If515a90217a8e329d932dcacb357b78081c505c1
Related-bug: 1538837
2016-07-29 10:17:26 +02:00
Timofey Durakov 452be384cd rest api version bumped for async pre live migration checks
pre live-migration checks now are done in async way. This patch
updates rest api version to keep this tracked.

bp: async-live-migration-rest-check

Change-Id: I9fed3079d0f1b7de3ad1b3ecd309c93785fd11fe
2016-07-11 14:57:54 -07:00
Sylvain Bauza 7aa2285e72 API change for verifying the scheduler when live migrating
After modifying the evacuate action, we now add a new microversion
change for modifying the live-migrate call so that the scheduler is
called when the admin user provides an hostname unless the force
field is provided.

APIImpact

Implements: blueprint check-destination-on-migrations-newton

Change-Id: I212cbb44f46d7cb36b5d8c74a79065d38fc526d8
2016-06-06 11:44:06 +02:00
Jenkins 7ec1472380 Merge "Added new exception to handle CinderClientException" 2016-05-11 19:25:42 +00:00
Sujitha 2c52aca796 Added new exception to handle CinderClientException
When Cinder client exception is thrown in initialize_connection
(which is called during prechecks for Live migration),
instance is moved to ERROR state. It is not sensible
to move the instance to ERROR state when the precheck fails.
Adding new exception changes this behavior. Instance will be reset
to Active state when the precheck fails.

Closes bug: #1544744

Change-Id: I7a5fcc070ff53086f37417f12e2b9f383e220747
2016-05-10 18:46:44 +00:00
Ken'ichi Ohmichi 7eb7a3dbb2 Remove legacy v2 unit tests[f-n]
There are two implementation code for similar API in Nova repository.
One is newer: v2.1 API, another is legacy: v2 API. v2.1 API has been
used as the default API since Liberty and legacy v2 API has been marked
as deprecated. We have used and tested v2.1 API so well and now is nice
time to remove legacy API code based on the consensus of the design
summit of Austin. This patch removes unit tests of legacy v2 API[f-n].

Partially implements blueprint remove-legacy-v2-api-code

Change-Id: I543bc2a9c068aae2c755f8159c7d2a9fff2c67ee
2016-05-06 13:58:40 +09:00
Marcellin Fom Tchassem c52442a01f Cleanup the exception LiveMigrationWithOldNovaNotSafe
It has been reported that the exception LiveMigrationWithOldNovaNotSafe
is not useful since the change
I5651fb7ba95f38e2e2f8a48a98ff04072c6bb885.
This patch will cleanup the definition and the occurences of
that exception.

Change-Id: I7a5b677904d83104c4f5367b0245eebd422e2338
Closes-Bug: #1550282
2016-03-29 21:18:33 +00:00
Eli Qiao f18a46c072 API: Improve os-migrateLive input parameters
This is os-migrateLive API changes:

    * 2.25 - Make block_migration to support 'auto' value, remove
             disk_over_commit.

Partially implements: blueprint making-live-migration-api-friendly
APIImpact
DocImpact
Change-Id: Ibb0d50f0f7444028ef9d0c294aea41edf0024b31
2016-02-29 17:44:17 +00:00
Rui Chen 79fe4d8e07 Fix incomplete error message of quota exceeded
When we boot and resize instance, if multiple requested
resource(core, ram and instances) exceeded quota,
only the detail of core resource will been outputed to
user in the exception, the loss of core and instances number
will make end user have no idea which flavor can be
used to boot instance successfully.

Fix this issue and update related test cases.

Change-Id: I969d73e2f222278ea8a2bb4c21474c13ab213d81
Closes-Bug: #1469942
2015-09-02 11:45:27 +08:00
He Jie Xu 74328ce719 Move V2.1 API unittest to top level directory
This patch moves the tests in contrib/ and plugins/v3/ into the
base directory.

Note that some of the tests have both v2 and v21 tests, The v2
tests will be deleted when V2 API removed.

Co-Authored-By: Ed Leafe <ed@leafe.com>
Change-Id: I6ff1d6594e7a44f2bcb6bbb04a4277b98d1cac74
Partial-Bug: #1462901
2015-08-17 11:15:26 +10:00