python35 is pretty old and often not available by default on some
operating systems, so we need to be testing python36.
Change-Id: I61a7b7f29add38f2164d9c6907af2a3f31105612
Official projects are doing this as part of enabling python3
first, but it matters more here as a way to manage with local
control.
Change-Id: Ia93cd1a45519f5fe2ddd32a89f896f896f21491f
We want to default to running all tox environments under python 3, so
set the basepython value in each environment.
We do not want to specify a minor version number, because we do not
want to have to update the file every time we upgrade python.
We do not want to set the override once in testenv, because that
breaks the more specific versions used in default environments like
py35 and py36.
Change-Id: Ia908e642ad1a3f67710d48a71d097c13b7743a5a
If no max or min is set, no Version should match, including
0.0. The test was already correct, but the associated
docstring was a pasto.
Change-Id: I925a9df3b044b1f581b2c62db1bda9ace0a5cc47
The __version__ in __init__.py is not used, and is out of date.
setup.cfg is adjusted to show that python 3.4 receives no attention.
Change-Id: Iaeff8dca06b7c4de2eff497dc2f1e49c4ee1f5e4
This change imports (with slight modification) the
MicroversionMiddleware created for the placement service.
For the time being the middleware relies on WebOb as that is
what it originally relied on. If there are requirements to do
otherwise, later, we can make adjustments then.
The README is updated with limited usage instructions.
Gabbi tests are added, requiring adjustments to the test configuration,
so the opportunity was taken to switch to using stestr instead of testr.
Though arguably "functional" tests because they are not strictly unit
tests, no distinction is made in the tests directory, for now, as it
is all nice and fast and we'd like to keep it that way.
Change-Id: I9d27b6fad35f7aea0085f08c0353f8e8acdb8b73
Use of Version within the placement service has made it clear
that the Version object knowing the min and max versions is
useful when making Version.matches comparisons.
Therefore the matches method has been updated to refer to
min_version and max_version attributes if they are not set
in the matches() request. The extract_version function now
sets those attributes based on the version_list that is
passed to it.
If min and max are not set on the Version object, they default
to negative versions, which are not possible in microversions
and mean matches() (without override args) will be false. The
use of explicit values (instead of None) is so python3 is happy
(and it is better anyway).
Change-Id: I71d091d037abcd068601b32722a09094ae74e658
This change imports two functions and a class from the microversion
handling implementation in the placement service. This code should be
generally useful for other implementations.
The added code provides functions for not just extracting the
microversion from HTTP headers, but for validating that the found
information is actually a properly formed microversion value.
'latest' is translated to whatever latest is in an ordered list of
versions and any found version is confirmed to be within the bounds of
and a member of that list of versions.
The README.rst has been updated to reflect the newly available methods.
This is a start at documentation, but we'll probably want more.
Change-Id: I267586c78308cc5520a88598c350a7e055783f3e
The get_version method accepts a dict or list of tuples that
represent HTTP request headers that will be processed to find a
microversion header. Sometimes, for example in some middlewares,
direct access to a headers dict will not be available and only the
WSGI environ will be present.
This change provides a utility method which creates a new dict of
headers: headers_from_wsgi_environ. This mode was chosen to make it
clear that a copy of the environ is being made, not the environ
itself as we really don't want to be passing that as some values in
it will not be simple objects (strings and numbers) and we do not
know what other middleware might have done or want to do with it.
Internal to get_version any attempt to get a header named 'FOO' will
fall back to looking for the WSGI equivalent of 'HTTP_FOO'.
README.rst has been updated to indicate the new style.
This change is backwards compatible, existing clients will not
notice.
Change-Id: I5262031d9cde0378eabe342c1913091658c3bf9b
Closes-Bug: #1579772
In the fold_headers function, if the headers behaves like a dict,
they were being retured unchanged. This would cause issues in the
later processing to extract the microversion header, which matches
on lower case strings.
Convert these headers to lowercase also provide a test case to
validate the header is being parsed correctly.
Change-Id: I8501c813d668c0a32905906e4ef3f8c6c6b12de2
Close-Bug:# 1606351
This removes the assert to ensure a value for service_type is set. The
keyword style of calling can still be used, so
microversion_parse.get_version(headers, service_type='compute')
will remain working.
Using an assert for this is probably inadvisable, since it will be
stripped away if python is run with -O.
Change-Id: I9775c5d87890c8ff4a6072c600d54fa47264fa9f
WebOb uses a Mapping class for headers which behaves like a dict
but does not inherit from dict, so the isinstance check in
fold_headers was not working as expected. This is now replaced
with a check for dict-like behaviors. It's a bit of a tossup
between doing a hasattr and simply trying to access a key. I chose
the former for readability and because we don't actually want to
do anything with the value we would retrieve were access by a key
legit.
Tests are added to specfically cover the use of a
webob.headers.EnvironHeaders object, which is what headers in
Nova and Nova derivations look like.
Change-Id: I31de49bcfd8822c53d3293b106de96138eaf4464
Initial setup for git review.
Add basic docs handling so that docs tests will pass. No
actual docs in place yet.
Align with global requirements.
Change-Id: I8ae7c2c6ce410c04f4ce53ce5278b2b85c141c93
See README.rst for details.
The basic gist is that a get_version method is provided. It takes a
dict or list of headers and returned a version for a service_type if
it can find it.