# API Microversion Testing Support in Tempest

## Framework to support API Microversion testing

Many of the OpenStack components have implemented API microversions. It is important to test those microversions in Tempest or external plugins. Tempest now provides stable interfaces to support to test the API microversions. Based on the microversion range coming from the combination of both configuration and each test case, APIs request will be made with selected microversion.

This document explains the interfaces needed for microversion testing.

### The api_version_request module

class APIVersionRequest(version_string=None)

  This class represents an API Version Request.

  This class provides convenience methods for manipulation and comparison of version numbers that we need to do to implement microversions.

  Parameters:

    version_string – String representation of APIVersionRequest. Correct format is ‘X.Y’, where ‘X’ and ‘Y’ are int values. None value should be used to create Null APIVersionRequest, which is equal to 0.0

### The api_version_utils module

class BaseMicroversionTest

  Mixin class for API microversion test class.

assert_version_header_matches_request(api_microversion_header_name, api_microversion, response_header)

  Checks API microversion in response header

  Verify whether microversion is present in response header and with specified ‘api_microversion’ value.

  Parameters:

    - api_microversion_header_name – Microversion header name Example- “X-OpenStack-Nova-API-Version”

    - api_microversion – Microversion number like “2.10”, type str.

    - response_header – Response header where microversion is expected to be present.

check_skip_with_microversion(test_min_version, test_max_version, cfg_min_version, cfg_max_version)

  Checks API microversions range and returns whether test needs to be skip

  Compare the test and configured microversion range and returns whether test microversion range is out of configured one. This method can be used to skip the test based on configured and test microversion range.

  Parameters:

    - test_min_version – Test Minimum Microversion

    - test_max_version – Test Maximum Microversion

    - cfg_min_version – Configured Minimum Microversion

    - cfg_max_version – Configured Maximum Microversion

  Returns:

    boolean

compare_version_header_to_response(api_microversion_header_name, api_microversion, response_header, operation='eq')

  Compares API microversion in response header to `api_microversion`.

  Compare the `api_microversion` value in response header if microversion header is present in response, otherwise return false.

  To make this function work for APIs which do not return microversion header in response (example compute v2.0), this function does not raise InvalidHTTPResponseHeader.

  Parameters:

    - api_microversion_header_name – Microversion header name. Example: ‘Openstack-Api-Version’.

    - api_microversion –

      Microversion number. Example:

      - ’2.10’ for the old-style header name, ‘X-OpenStack-Nova-API-Version’

      - ’Compute 2.10’ for the new-style header name, ‘Openstack-Api-Version’

    - response_header – Response header where microversion is expected to be present.

    - operation – The boolean operation to use to compare the `api_microversion` to the microversion in `response_header`. Can be ‘lt’, ‘eq’, ‘gt’, ‘le’, ‘ne’, ‘ge’. Default is ‘eq’. The operation type should be based on the order of the arguments: `api_microversion` <operation> `response_header` microversion.

  Returns:

    True if the comparison is logically true, else False if the comparison is logically false or if `api_microversion_header_name` is missing in the `response_header`.

  Raises:

    InvalidParam – If the operation is not lt, eq, gt, le, ne or ge.

select_request_microversion(test_min_version, cfg_min_version)

  Select microversion from test and configuration min version.

  Compare requested microversion and return the maximum microversion out of those.

  Parameters:

    - test_min_version – Test Minimum Microversion

    - cfg_min_version – Configured Minimum Microversion

  Returns:

    Selected microversion string

this page last updated: 2024-01-19 12:36:24

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.

found an error? report a bug