Commit Graph

39 Commits

Author SHA1 Message Date
Chris Dent ce2840539e Move test_report_client out of placement namespace
test_report_client provides functional tests of the report client using
a fully operating placement service (via wsgi-intercept) but it is not,
in itself, testing placement. Therefore this change moves the test
into nova/tests/functional where it can sit besides other genral purpose
nova-related functional tests.

As noted in the moved file, in a future where placement is extracted,
nova could choose to import a fixture that placement (installed as a
test dependency) provides so that this test and ones like it can
continue to run as desired.

compute/test_resource_tracker.py is updated to reflect the new location
of the module as it makes use of it.

partially implements blueprint placement-extract

Change-Id: I433700e833f97c0fec946dafc2cdda9d49e1100b
2018-04-06 22:56:03 +01:00
Eric Fried 7866a016f6 Make generation optional in ProviderTree
Since ProviderTree methods are expected to be used in
ComputeDriver.update_provider_tree [1], wherein the generation should
not be specified (it will be ignored by
SchedulerReportClient.update_from_provider_tree [2] anyway), this change
makes the generation argument optional for ProviderTree methods new_root
and update_inventory.  (It was already optional for all the other
methods.)

TODOs are added to deal with generation properly from some places in the
report client - see the related bug.

[1] https://review.openstack.org/#/c/521187/30/nova/virt/driver.py
[2] https://review.openstack.org/#/c/533821/15/nova/scheduler/client/report.py@1454

Change-Id: I0d979802865f22195f53d461ab0dd1df6334a066
Related-Bug: #1746075
blueprint: update-provider-tree
2018-04-02 07:58:38 +00:00
Eric Fried 32fdf52958 SchedulerReportClient.update_from_provider_tree
Once the resource tracker has asked the compute driver to
update_provider_tree, it needs to flush any changes back to placement.

This change set introduces update_from_provider_tree to
SchedulerReportClient.  This method accepts the ProviderTree as modified
by ComputeDriver.update_provider_tree, compares it to what the report
client has in its cache, and flushes any changes back to the placement
service.

Change-Id: I9064a2598d773a814269995eed8862d093d9100e
blueprint: update-provider-tree
Co-Authored-By: Radoslav Gerganov <rgerganov@vmware.com>
Depends-On: https://review.openstack.org/536545
2018-04-02 07:58:38 +00:00
Chris Dent 1a072eab33 Move placement exceptions into the placement package
This change moves the exceptions raised within the placement service
into the nova.api.openstack.placement package. This is part of the
process of unifying all placement code into one subdirectory so that
a future lift and shift is easier and cleaner.

This is mostly a straightforward change of imports and a moving of
existing exceptions in the placements handlers and objects with a few
caveats:

* Dealing with nova/db/sqlalchemy/resource_class_cache.py has not
  yet been accomplished, so it remains where it is and imports
  exceptions from the placement hierarchy. A TODO indicating some of the
  options is left for future work.
* Exceptions with the name ResourceProviderInUse and InventoryInUse are
  used on both sides of the nova/placement interaction. This is
  noted with comments in both nova/exception.py and
  placement/exception.py.
* test_report_client.py has had a TODO added to make it clear that the
  exceptions it uses are nova-side, and perhaps the test file should be
  moved.
* The base class of the original exceptions, NoveException, does a bit
  more than is required on the placement side so a new private class
  _BaseException is created which removes support for handling 'code'.
  This is not required because all exceptions in placement are supposed
  to be manually caught in handlers and explicitly transformed into http
  exceptions.

blueprint placement-extract

Change-Id: I2b94945a0963d6a61af931505b69afe2d4733759
2018-03-19 15:28:02 +00:00
Zuul 49a988182f Merge "New-style _set_inventory_for_provider" 2018-03-16 13:22:06 +00:00
Chris Dent f346913594 Move resource class fields
Move the ResourceClass field to its own package, and move that package
to the top of the nova hierarchy since it is used by both nova tooling
and placement tooling but we don't want the placement version to have to
incorporate the nova code. Eventually we'd like to see an
os-resource-classes library, similar to os-traits, which will serve this
functionality. This is a step in that direction.

Changes in this patch are quite widespread, but are mostly only changes
of imports.

Change-Id: Iea182341f9419cb514a044f76864d6bec60a3683
2018-03-13 09:01:30 +00:00
Eric Fried 3921cbc9ec New-style _set_inventory_for_provider
Given the UUID of a provider, set the inventory records for the provider
to the supplied dict of resources.

Compare and contrast with the existing set_inventory_for_provider, which
was created for the simpler get_inventory code path from the resource
tracker.

This one is specially formulated for use by update_from_provider_tree,
because from there, whereas we DO need to _ensure_resource_class(), we
ALSO want to short out if inv_data matches what's already cached, but we
DON'T want to:
- _ensure_resource_provider
- refresh_and_get_inventory
- DELETE if inventory is empty, else PUT
- retry
- invalidate the cache on failure

This version is more in the spirit of set_traits_for_provider.

Change-Id: I45f1df6ca5618f76337319ba225493625a5ee2d6
blueprint: update-provider-tree
2018-03-12 10:37:36 -05:00
Eric Fried d2152f3094 Only pull associated *sharing* providers
It was discussed and decided [1] that we only want to be pulling down,
caching, and passing to update_provider_tree providers associated via
aggregate with the compute node's provider tree if they are sharing
providers. Otherwise we'll get e.g. all the *other* compute nodes which
are also associated with a sharing provider.

[1] https://review.openstack.org/#/c/540111/4/specs/rocky/approved/update-provider-tree.rst@48

Change-Id: Iab366da7623e5e31b8416e89fee7d418f7bf9b30
Closes-Bug: #1750084
2018-02-16 18:18:32 -06:00
Zuul 87036b4b27 Merge "Ensure resource classes correctly" 2018-02-13 23:25:48 +00:00
Takashi NATSUME ab4efbba61 [placement] Add sending global request ID in get
Add the 'X-Openstack-Request-Id' header
in the request of GET in SchedulerReportClient.

Change-Id: I306ac6f5c6b67d77d91a7ba24d4d863ab3e1bf5c
Closes-Bug: #1734625
2018-02-10 10:28:04 +09:00
Takashi NATSUME f66bd7369a [placement] Add sending global request ID in put (3)
Add the 'X-Openstack-Request-Id' header
in the request of PUT in SchedulerReportClient.
When removing a resource provider from an instance allocation
and putting allocations to a resource provider,
the header is added.

Subsequent patches will add the header in the other cases.

Change-Id: I7891b98f225f97ad47f189afb9110ef31c810717
Partial-Bug: #1734625
2018-02-10 09:49:38 +09:00
Eric Fried 02a1551f64 Ensure resource classes correctly
Previously, SchedulerReportClient.set_inventory_for_provider used this
logic to pre-create custom resource classes found in the input
inventory.

        list(map(self._ensure_resource_class,
                 (rc_name for rc_name in inv_data
                  if rc_name not in fields.ResourceClass.STANDARD)))

...where _ensure_resource_class would always attempt to create the
resource class it was given, and raise an exception if that failed for
any reason.  Note in particular that attempting to create an
already-extant "standard" resource class will fail just the same as
attempting to create any nonexistent resource class that doesn't conform
to the schema (i.e. beginning with "CUSTOM_").

The problem is that this relies on the local system's notion of the set
of standard resource classes. If the placement service is running newer
code, standard resource classes may have been added that the compute
service doesn't know about yet.

This change set solves the problem by only attempting to create resource
classes with the 'CUSTOM_' prefix.

self._ensure_resource_class (which worked on a single resource class) is
replaced with self._ensure_resource_classes (plural) which accepts a
list of *all* the desired resource classes (including the standard
ones), filters down to the CUSTOM_* ones, and attempts to create the
remainder.

Note that if placement ever decides to start allowing creation of
resource classes with prefixes other than CUSTOM_, it will have to do so
under a new microversion, so we can't future-proof this by e.g.
prefetching all the known resource classes from placement and attempting
to create any not found in that list.

In the process of doing this rework, obsolete code paths relying on
pre-1.7 placement microversions are removed.

Change-Id: I600ed262e1b5d11facbf461e28291193665280cf
Closes-Bug: #1746615
2018-02-09 14:18:05 -06:00
Zuul b29c921962 Merge "Test case: new standard resource class unusable" 2018-02-07 16:56:42 +00:00
Eric Fried caeab76468 Test case: new standard resource class unusable
If the placement service code is newer than that of the compute service,
new standard resource classes may have been introduced in placement
which compute doesn't yet know about.  These resource classes will be
unusable due to the noted bug.

This change set adds a test case demonstrating the bug.

Change-Id: I71ce6796beb23c4bb3d637dab5ca0e620274b2fc
Partial-Bug: #1746615
2018-02-05 16:57:06 -06:00
Takashi NATSUME 5d928ae2e0 [placement] Add sending global request ID in put (1)
Add the 'X-Openstack-Request-Id' header
in the request of PUT in SchedulerReportClient.
When updating inventories, deleting inventories
(microversion 1.5 not available) and ensuring
a resource class, the header is added.

Subsequent patches will add the header in the other cases.

Change-Id: I02b9f2ef1cbd16d5bf9c4084bc652e94875a6c2a
Partial-Bug: #1734625
2018-02-04 23:41:09 +00:00
Takashi NATSUME 6079b722cb [placement] Add sending global request ID in post
Add the 'X-Openstack-Request-Id' header
in the request of POST in SchedulerReportClient.
When creating a resource provider and creating a resource class,
the header is added.

Subsequent patches will add the header in the other cases.

Change-Id: I39d8c71432b3adf7e5bdde1c6cb6f089a9c79614
Partial-Bug: #1734625
2018-02-04 23:40:53 +00:00
Eric Fried a7a1f72dd4 set_{aggregates|traits}_for_provider: tolerate set
Report client's set_aggregates_for_provider and set_traits_for_provider
methods declare in their docstring that they accept an iterable for the
aggregates/traits parameter.  However, passing in a set results in a
JSON serialization error.  We could solve this by changing the docstring
(accept only lists).  Or, as is done here, by tolerating other kinds of
iterables, converting them to lists.

Change-Id: I749ffbd9a55ee71d5dbd266ef6faa4be4a1d395b
blueprint: nested-resource-providers
2018-01-31 08:35:35 -06:00
Eric Fried 8014449f2c ProviderTree.get_provider_uuids: Top-down ordering
It will become important in update_from_provider_tree to be able to walk
the providers in a ProviderTree in a sane and predictable order.
Otherwise, when flushing multiple adds/deletes, we will have no reliable
way to avoid creating orphans (which will fail).

Here we change ProviderTree.get_provider_uuids from returning a set() to
returning a list which is guaranteed to be in top-down order.  We do not
guarantee the order in which siblings appear, or where nephews appear
relative to their uncles; just that a child will always appear after its
parent (and, by extension, after all its ancestors).

Change-Id: I2fb691e019177c502ec651390faf3740a2d49045
blueprint: nested-resource-providers
2018-01-31 08:35:35 -06:00
Eric Fried e3de95e3b3 SchedulerReportClient._delete_provider
SchedulerReportClient._delete_provider is a new private helper method to
delete a resource provider, appropriately logging errors and raising
appropriate exceptions.

The existing public delete_resource_provider method is refactored to use
the new helper in a backward-compatible way.  In a future patch, we
should a) rename this method to delete_compute_provider or similar, and
b) make it actually raise exceptions on error (today it just logs and
carries on).

Change-Id: I05c838faca626d2ef238157a8d8cdee5df16aa01
2018-01-31 08:35:34 -06:00
Eric Fried f1d6b74845 report client: get_provider_tree_and_ensure_root
SchedulerReportClient.get_provider_tree_and_ensure_root retrieves from
the placement API all providers associated with a specified provider via
its tree or aggregates.  It returns a fresh ProviderTree populated with
these providers and their inventory.  This is the data structure which
will be passed into the virt driver's update_provider_tree method.

In its current incarnation, this method will create and/or load into
cache the root provider (associated with the compute node) if not
already present.  This is because the resource tracker is currently
structured to handle init and update in the same code path.  At some
point in the future we may want to split that out and make this method
*just* return a deepcopy of the cache.

Change-Id: I9469dec80c2b357185645ef1705f098f25dcb8c8
blueprint: nested-resource-providers
2018-01-31 08:35:32 -06:00
Takashi NATSUME a326b03339 [placement] Add sending global request ID in delete (3)
Add the 'X-Openstack-Request-Id' header in the request of DELETE.
When deleteing resource provider inventories, the header is added.

Subsequent patches will add the header in the other cases.

Change-Id: I1dac3d340fe7077095d68f803cf5335ffd5b3364
Partial-Bug: #1734625
2018-01-22 02:23:12 +00:00
Zuul 0fc702cc08 Merge "[placement] Add sending global request ID in delete (2)" 2018-01-17 06:59:39 +00:00
Eric Fried 31de9273cc Track provider traits in report client
With this change, SchedulerReportClient keeps track of resource provider
traits in the same way as aggregates.  Specifically:

- We use ProviderTree methods to save trait information for each
  provider.
- We refresh trait information along with aggregate information whenever
  we "ensure" a provider exists.

Note that this change set consolidates the refreshing (including cache
expiry) of aggregate and trait associations into a single method.  The
theory being that both aggregate associations and trait associations
should change out of band with roughly the same frequency (i.e. very
rarely).

Change-Id: I33d01d8cab43ce6cdde151d2e9429921a140e88d
2018-01-12 15:08:59 -06:00
Takashi NATSUME 0cbe9b2333 [placement] Add sending global request ID in delete (2)
Add the 'X-Openstack-Request-Id' header in the request of DELETE.
When deleting allocations for a server (instance),
the header is added.

Subsequent patches will add the header in the other cases.

Change-Id: If38e4a6d49910f0aa5016e1bcb61aac2be416fa7
Partial-Bug: #1734625
2018-01-11 00:34:20 +00:00
Eric Fried fb5e7464ef Move aggregates from report client to ProviderTree
Previously SchedulerReportClient cached a private mapping of the
aggregate associations of each resource provider it knew about.  We're
going to want to give the virt driver the opportunity to query/update
aggregate associations when we pass it the ProviderTree, so this change
removes the cache from the SchedulerReportClient and uses the aggregate
affordance recently added to ProviderTree instead.

On the way, this also fixes a couple of memory leaks where we weren't
cleaning up the "last updated" cache.

Change-Id: I1e3b739692e6adebecd80ee8220f1d7b9790d80f
2018-01-02 14:44:56 -06:00
Takashi NATSUME c647865bf6 [placement] Add sending global request ID in delete
Add the 'X-Openstack-Request-Id' header
in the request of DELETE.
When deleteing a resource provider, the header is added.

Subsequent patches will add the header in the other cases.

Change-Id: Id78b849fe0f874d7a8e13c72f63b10724faf1aa7
Partial-Bug: #1734625
2017-12-24 22:41:27 +00:00
Eric Fried cc5d662992 SchedulerReportClient._get_providers_in_aggregates
Introducing SchedulerReportClient._get_providers_in_aggregates, a
private method to retrieve the list of resource providers associated
with some number of aggregate UUIDs.  Returns the empty list (not None)
if no aggregate UUIDs are specified, or if there are no providers
associated with that aggregate.  Logs an error and raises on any
HTTP response other than 200.

This is in anticipation of ComputeDriver.update_provider_tree, which
will need to be supplied a ProviderTree that's fully populated with all
the providers associated with that of the compute node.  This includes
all providers in the compute RP's tree *and* those directly associated
via aggregates (but not *their* trees or aggregate associations).

Change-Id: Ia7f95a17fd00bea414459b90adc04a8bf309c396
blueprint: nested-resource-providers
2017-12-14 15:21:22 +00:00
Eric Fried 108991c6b1 SchedulerReportClient._get_providers_in_tree
Introducing SchedulerReportClient._get_providers_in_tree, a private
method to retrieve the list of resource providers associated with one
provider UUID.  Returns the empty list (not None) if there's no provider
with the specified UUID.  Logs an error and raises an exception on any
HTTP response other than 200.

Change-Id: Ifcaa1c9c0432af17ccc91a8bf0a85e37c9b00de5
blueprint: nested-resource-providers
2017-12-07 09:12:39 -06:00
Takashi NATSUME d1098b1f82 Fix wrong argument order in functional test
Fix the wrong order of mock arguments.
The mocks are not used in the test,
but fix it to privent mistakes in the future.

TrivialFix
Change-Id: Iad694b900180a310589483aeda46244a7fc5b408
2017-12-05 11:22:36 +09:00
Eric Fried 987d451f4d Use ksa adapter for placement conf & requests
Switch usage of the placement API over to using the new
nova.utils.get_ksa_adapter method.  Now REST calls with the placement
API go through the resulting keystoneauth1 Adapter - which already
incorporates endpoint filtering - rather than a keystoneauth1 Session.

To make this fit, switch the placement conf over to using
nova.conf.utils.register_ksa_opts and get_ksa_adapter_opts.  In so
doing, deprecate os_interface and os_region_name in favor of the
imported Adapter opts valid_interfaces and region_name, respectively.

Change-Id: I69e9b30d96390a70198b12d74e7efa9bd61db217
Partial-Implements: bp use-ksa-adapter-for-endpoints
2017-10-28 01:52:21 +00:00
Dan Smith a22ae8baa2 Consider instance flavor resource overrides in allocations
This makes the scheduler reporting client consider resource overrides
stored in instance flavors when making allocations against placement.
This should ensure that compute nodes and scheduler calculate the same
allocations for resource overrides, and will mean that ironic computes
will start allocating custom resource amounts after existing instances
have their flavors healed.

Related to blueprint custom-resource-classes-in-flavors

Change-Id: Ib1b05e33e2a2f4ed1c3f8949df19d1c0f48ae07f
2017-07-18 15:10:35 -07:00
melanie witt a909673682 placement project_id, user_id in PUT /allocations
This adds project_id and user_id required request parameters as part of
a new microversion 1.8 of the placement API.

Two new fields, for project and user ID, have been added to the
AllocationList object, and the method AllocationList.create_all() has
been changed to ensure that records are written to the consumers,
projects, and users tables when project_id and user_id are not None.

After an upgrade, new allocations will write consumer records and
existing allocations will have corresponding consumer records written
when they are updated as part of the resource tracker periodic task for
updating available resources.

Part of blueprint placement-project-user

Co-Authored-By: Jay Pipes <jaypipes@gmail.com>
Change-Id: I3c3b0cfdd33da87160255ead51a0d9ff73667655
2017-06-15 18:23:37 +00:00
Matt Riedemann 70b141968e Add functional test for bad res class in set_inventory_for_provider
The unit tests covering the case that an invalid resource class
name was passed to set_inventory_for_provider were a bit too
unit-y and we can get the same coverage down the full stack with
a simple addition to the existing functional tests for the report
client. This adds the simple change to the functional test and removes
the now redundant unit tests.

Change-Id: Idb579acf6852650d4d5a6bc7704f123a40258f2d
2017-03-06 22:48:00 -05:00
Jay Pipes fbc5a67de9 virt: add get_inventory() virt driver API method
Adds a new get_inventory() method to the virt driver API for returning a
dict of inventory records in a format that the placement API
understands.

We also move the ComputeNode.save() call out of the scheduler reporting
client and into the resource tracker. The resource tracker's _update()
method now attempts to call the new get_inventory() virt driver method
and falls back on the existing update_resource_stats() (renamed to
update_compute_node() in this patch) method when get_inventory() is not
implemented.

The next patch implements get_inventory() for the Ironic virt driver.

Change-Id: I921daea7f6d5776b19561f0ca457e604a372eb9e
blueprint: custom-resource-classes-pike
2017-03-06 16:01:52 -05:00
Matt Riedemann 2c1e134121 Cleanup some issues with CONF.placement.os_interface
This change fixes a few things with the recently added
"os_interface" option in the [placement] config group.

1. It adds tests for the scheduler report client that
   were missing in the original change that added the
   config option.

2. It uses the option in the "nova-status upgrade check"
   command so it is consistent with how the scheduler
   report client uses it.

3. It removes the restrictive choices list from the
   config option definition. keystoneauth1 allows an
   "auth" value for the endpoint interface which means
   don't use the service catalog to find the endpoint
   but instead just read it from the "auth_url" config
   option. Also, the Keystone v3 API performs strict
   validation of the endpoint interface when creating
   an endpoint record. The list of supported interfaces
   may change over time, so we shouldn't encode that
   list within Nova.

4. As part of removing the choices, the release note
   associated with the new option is updated and changed
   from a 'feature' release note to simply 'other' since
   it's not really a feature as much as it is a bug fix.

Change-Id: Ia5af05cc4d8155349bab942280c83e7318749959
Closes-Bug: #1664334
2017-02-13 17:13:14 -05:00
Jay Pipes 7d04c78c1e placement: create aggregate map in report client
This patch adds a map of provider UUID to a set of aggregate UUIDs for
each resource provider the scheduler report client knows about. We call
the new 1.1 placement API microversion to grab the list of aggregates
associated with a provider. The code currently isn't highly efficient;
we call the placement REST API each time _ensure_resource_provider() is
called. The alternative to this is to require operators to restart their
nova-compute workers in order to have aggregate information picked up
when providers are associated with aggregates.

Change-Id: I8474d4d7a46c8bc42eb6e97c2403e2bd7716012e
blueprint: generic-resource-pools-ocata
2017-01-19 23:02:48 -05:00
Jay Pipes 3c217acb9c placement: Do not save 0-valued inventory
Ironic nodes that are not available or operable have 0 values for vcpus,
memory_mb, and local_gb in the returned dict from the Ironic virt driver's
get_available_resource() call. Don't try to save these 0 values in the
placement API inventory records, since the placement REST API will return an
error. Instead, attempt to delete any inventory records for that Ironic node
resource provider by PUT'ing an empty set of inventory records to the placement
API.

Closes-bug: #1651678

Change-Id: I10b22606f704abcb970939fb2cd77f026d4d6322
2017-01-03 17:42:43 -05:00
Maciej Szankin b7b282ed08 conf: Move api options to a group
Change-Id: Ida4ee57d6e1822e35e3198f6d3a89410e211d57d
Implements: bp centralize-config-options-ocata
2016-11-25 16:32:31 -06:00
Chris Dent b922af9ee8 [placement] functional test for report client
This sets up a scheduler report client that talks to a real
placement API (running via a wsgi-intercept). It then calls methods
to verify that a resource provider is created, some inventory set,
and some allocations written and deleted. For now this checks
simply that when things are done right, the right things happen
without any explosions. Additional tests could be added for unhappy
paths.

Some mocking of keystoneauth1 is required to get auth and endpoint
handling to work properly without a real keystone.

wsgi-intercept is added to requirements.txt to make the use of it in
these tests explicit. wsgi-intercept is already in global
requirements and is already required in nova (at a higher version)
by gabbi.

Change-Id: Ic28ace11796d7d746a16bdfa27cef9b8640f8c0e
2016-09-13 20:10:44 +00:00