Lease creation should fail if affinity is passed with invalid input

Bug #1821576 reported by Asmita Singh on 2019-03-25
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Blazar
Medium
Asmita Singh

Bug Description

Description
===========

Lease for resource_type virtual:instance should not be created with invalid string values(affinity="abc") or invalid integer value(affinity=2).

Steps to reproduce
==================

Create lease for instance reservation with affinity="abc".

Command:

blazar lease-create --reservation resource_type=virtual:instance,vcpus=1,memory_mb=1024,disk_gb=20,amount=0,affinity="abc" --start-date "2020-07-24 20:00" --end-date "2020-08-09 21:00" lease-1

Expected result
===============

Lease create for instance reservation should fail with 400 BadRequest.

Actual Result
=============

Lease create for instance reservation with affinity="abc" is created successfully and the value of affinity is stored as null in DB.

Changed in blazar:
assignee: nobody → Asmita Singh (asmita2018)
status: New → In Progress
Tetsuro Nakamura (tetsuro0907) wrote :

Thank you for reporting this.

It is *now* supposed to be exactly what oslo.strutils.bool_from_string() supports [1]. It can be a boolean, a string or an integer. Namely, boolean type value will be returned directly, otherwise the subject will be converted to a string. And case-insensitive match is performed.

TRUE_STRINGS = ('1', 't', 'true', 'on', 'y', 'yes')
FALSE_STRINGS = ('0', 'f', 'false', 'off', 'n', 'no')
NONE_STRINGS = [anything else]

According to this bug report, I assume we are going to restrict the value to boolean or string of either 'False'/'True'/'None' including their lower and capital cases.

[1] https://github.com/openstack/oslo.utils/blob/master/oslo_utils/strutils.py#L115

Changed in blazar:
importance: Undecided → Medium
Asmita Singh (asmita2018) wrote :

I agree Tetsuro san. Also please correct me if I'm wrong ,but NONE_STRINGS = ('None', 'none').
I will push the patch soon.

Tetsuro Nakamura (tetsuro0907) wrote :

Note that it is good to update the api-ref as well accordingly fixing this bug.

[1] https://github.com/openstack/blazar/blob/ff8239cd0d30f6b9be20def4a891ea3c4a2944a1/api-ref/source/v1/parameters.yaml#L378-L389

Asmita Singh (asmita2018) wrote :

Sure thing. Thank you for your suggestion.

Reviewed: https://review.opendev.org/649536
Committed: https://git.openstack.org/cgit/openstack/blazar/commit/?id=0ce6c7f6c02dd196057f3c2e750758cd04b9978e
Submitter: Zuul
Branch: master

commit 0ce6c7f6c02dd196057f3c2e750758cd04b9978e
Author: asmita singh <email address hidden>
Date: Thu Mar 28 06:18:39 2019 +0000

    Lease creation/updation should fail for invalid affinity

    If user passes invalid affinity values (abc, 2), the lease is getting
    created/updated successfully.

    This patch will return 400 error if user passes invalid affinity values
    to lease create and update APIs.

    APIImpact:
    1)Return 400 instead of 201 when lease is created with invalid affinity
    for resource_type 'virtual:instance'.
    2)Return 400 instead of 200 when lease is updated with invalid affinity
    for resource_type 'virtual:instance'.

    Change-Id: I3170a0957de43fd2b7bcd32eca375da2d1f17360
    Closes-Bug: #1821576

Changed in blazar:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers