예제 #1
0
def _validate_bug_and_bug_type(bug, bug_type):
    """Validates ``bug`` and ``bug_type`` values.

    :param bug: bug number causing the test to skip (launchpad or storyboard)
    :param bug_type: 'launchpad' or 'storyboard', default 'launchpad'
    :raises: InvalidParam if ``bug`` is not a digit or ``bug_type`` is not
        a valid value
    """
    if not bug.isdigit():
        invalid_param = '%s must be a valid %s number' % (bug, bug_type)
        raise lib_exc.InvalidParam(invalid_param=invalid_param)
    if bug_type not in _SUPPORTED_BUG_TYPES:
        invalid_param = 'bug_type "%s" must be one of: %s' % (
            bug_type, ', '.join(_SUPPORTED_BUG_TYPES.keys()))
        raise lib_exc.InvalidParam(invalid_param=invalid_param)
예제 #2
0
    def get_server_ip(cls, server, validation_resources=None):
        """Get the server fixed or floating IP.

        Based on the configuration we're in, return a correct ip
        address for validating that a guest is up.

        :param server: The server dict as returned by the API
        :param validation_resources: The dict of validation resources
            provisioned for the server.
        """
        if CONF.validation.connect_method == 'floating':
            if validation_resources:
                return validation_resources['floating_ip']['ip']
            else:
                msg = ('When validation.connect_method equals floating, '
                       'validation_resources cannot be None')
                raise lib_exc.InvalidParam(invalid_param=msg)
        elif CONF.validation.connect_method == 'fixed':
            addresses = server['addresses'][CONF.validation.network_for_ssh]
            for address in addresses:
                if address['version'] == CONF.validation.ip_version_for_ssh:
                    return address['addr']
            raise exceptions.ServerUnreachable(server_id=server['id'])
        else:
            raise lib_exc.InvalidConfiguration()
예제 #3
0
def 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.

    :param api_microversion_header_name: Microversion header name. Example:
        'Openstack-Api-Version'.
    :param 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'

    :param response_header: Response header where microversion is
        expected to be present.
    :param 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.
    """
    api_microversion_header_name = api_microversion_header_name.lower()
    if api_microversion_header_name not in response_header:
        return False

    op = getattr(api_version_request.APIVersionRequest, '__%s__' % operation,
                 None)

    if op is None:
        msg = ("Operation %s is invalid. Valid options include: lt, eq, gt, "
               "le, ne, ge." % operation)
        LOG.debug(msg)
        raise exceptions.InvalidParam(invalid_param=msg)

    # Remove "volume" from "volume <microversion>", for example, so that the
    # microversion can be converted to `APIVersionRequest`.
    api_version = api_microversion.split(' ')[-1]
    resp_version = response_header[api_microversion_header_name].split(' ')[-1]
    if not op(api_version_request.APIVersionRequest(api_version),
              api_version_request.APIVersionRequest(resp_version)):
        return False

    return True