Commit Graph

8 Commits

Author SHA1 Message Date
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
Zuul b23dc3de50 Merge "Add more functional test for placement.usage" 2018-03-28 15:46:46 +00:00
jichenjc 62efb808a0 Add more functional test for placement.usage
Add more test cases for placement.usage to cover some
edge case.

blueprint placement-test-enhancement

Change-Id: I7c06f1f13f2af84d48e1a5ccc6990024c27cc75a
2018-03-21 15:53:08 +08:00
Chris Dent 83030804cc [placement] Add cache headers to placement api requests
In relevant requests to the placement API add last-modified
and cache-control headers.

According the HTTP 1.1 RFC headers last-modified headers SHOULD always
be sent and should have a tie to the real last modified time. If we do
send them, we need Cache-Control headers to prevent inadvertent caching
of resources.

This change adds a microversion 1.15 which adds the headers to GET
requests and some PUT or POST requests.

Despite what it says 'no-cache' means "check to see if the version you
have is still valid as far as the server is concerned". Since our server
doesn't currently validate conditional requests and will always return an
entity, it ends up meaning "don't cache" (which is what we want).

The main steps in the patch are:

* To both the get single entity and get collection handlers add
  response.cache_control = 'no-cache'
* For single entity add response.last_modified = obj.updated_at or
  obj.created_at
* For collections, discover the max modified time when traversing the
  list of objects to create the serialized JSON output. In most of
  those loops an optimization is done where we only check for
  last-modified information if we have a high enough microversion such
  that the information will be used. This is not done when listing
  inventories because the expectation is that no single resource
  provider will ever have a huge number of inventory records.
* Both of the prior steps are assisted by a new util method:
  pick_last_modfied.

Where a time cannot be determined the current time is used.

In typical placement framework fashion this has been done in a very
explicit way, as it makes what the handler is doing very visible, even
though it results in a bit of boilerplate.

For those requests that are created from multiple objects or by doing
calculations, such as usages and aggregate associations, the current time
is used.

The handler for PUT /traits is modified a bit more extensively than some
of the others: This is because the method can either create or validate
the existence of the trait. In the case where the trait already exists,
we need to get it from the DB to get its created_at time. We only do
this if the microversion is high enough (at least 1.15) to warrant
needing the info.

Because these changes add new headers (even though they don't do
anything) a new microversion, 1.15, is added.

Partial-Bug: #1632852
Partially-Implements: bp placement-cache-headers

Change-Id: I727d4c77aaa31f0ef31c8af22c2d46cad8ab8b8e
2017-12-12 15:51:58 +00:00
melanie witt 77224c1feb placement: Add GET /usages to placement API
This adds GET /usages as part of a new microversion 1.9 of the
placement API. Usages can be queried by project or project/user:

  GET /usages?project_id=<project id>
  GET /usages?project_id=<project id>&user_id=<user id>

and will be returned as a sum of usages, for example:

  200 OK
  Content-Type: application/json

  {
    "usages": {
      "VCPU": 2,
      "MEMORY_MB": 1024,
      "DISK_GB": 50,
      ...
    }
  }

A new method UsageList.get_all_by_project_user() has been added
for usage queries.

Part of blueprint placement-project-user

Change-Id: I8b948a4dfe6a50bea053b5dcae8f039229e2e364
2017-06-15 18:23:37 +00:00
Pushkar Umaranikar 9923c1570b Placement api: set custom json_error_formatter in aggregate and usage
Change decorator for resource based actions in aggreagate and usage
handlers to wsgi_wrapper.PlacementWsgify

This is a newly introduced wrapper class around webob.dec.wsgify
to set json formatter in case of webob exceptions.

Change-Id: I44ab22befad347b23ddb8d93d840ba594b988ce3
Partial-Bug: #1635182
2017-02-13 18:34:10 +00:00
Pushkar Umaranikar 6a422d23e7 Placement api: Add informative message to 404 response.
Add informative messages to the 404 error response from
inventory.py and usage.py

This change also includes adding/altering existing Gabbi tests
for 404 response and add resonse_strings validation checks for
that.

Change-Id: Ica46a5479dec06b035f8b43d6738e9d124f6ae37
Related-Bug: #1634115
2016-11-23 22:51:07 +00:00
Chris Dent 8aa87b348c Add support for usages in the placement API
GET /resources_providers/{uuid}/usages returns a dictionary of resource
usage by resource class.

Change-Id: I3ad0d16594301635966bd9e9352bc3f1f29dab14
Partially-Implements: blueprint generic-resource-pools
2016-08-18 21:30:03 +00:00