nova.compute.api.create don't validate max_count is a valid number

Bug #872615 reported by Nachi Ueno
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Invalid
Low
Shanthkumar Khandre
OpenStack Quality Assurance
Invalid
Medium
Unassigned

Bug Description

nova.compute.api.create don't validate max_count is a valid number or not.
When the user input a string value as max_count, then nova.compute creates max quota number of instances .

Thierry Carrez (ttx)
Changed in nova:
importance: Undecided → Low
status: New → Confirmed
Nachi Ueno (nati-ueno)
Changed in nova:
assignee: nobody → Nachi Ueno (nati-ueno)
Changed in openstack-qa:
assignee: nobody → Nachi Ueno (nati-ueno)
Changed in nova:
status: Confirmed → In Progress
Changed in openstack-qa:
status: New → In Progress
importance: Undecided → Medium
Nachi Ueno (nati-ueno)
Changed in nova:
assignee: Nachi Ueno (nati-ueno) → nobody
Changed in openstack-qa:
assignee: Nachi Ueno (nati-ueno) → nobody
Revision history for this message
Mark McLoughlin (markmc) wrote :

Moving from InProgress to Confirmed since nobody is assigned

Changed in nova:
status: In Progress → Confirmed
Changed in nova:
assignee: nobody → shanthkumar khandre (shanthkumar09)
status: Confirmed → In Progress
Revision history for this message
shanthkumar khandre (shanthkumar09) wrote :

Hi all,

I have used the following code to reproduce the bug.

from novaclient.v1_1 import client
from os import environ as env
nt = client.Client(env['NOVA_USERNAME'], env['NOVA_API_KEY'],
env['NOVA_PROJECT_ID'], env['NOVA_URL'])
nt.servers.create("name4","c0b242ce-0b7c-4b18-b42b-0275c847b968",1, max_count="20")

It succeeded and max_quota number of instances are created if max_count is greater than the max_quota.

if max_count > num_instances:
    raise exception.QuotaError(code="InstanceLimitExceeded")

The above condition is added in def _create_instance method of compute.api file to validate the max count.

num_instances = quota.allowed_instances(context, max_count,
                                                instance_type) (add the above condition after this line)

If the above code is executed, then the following error will be produced.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/novaclient/v1_1/servers.py", line 430, in create
    **boot_kwargs)
  File "/usr/lib/python2.7/dist-packages/novaclient/v1_1/base.py", line 153, in _boot
    return_raw=return_raw, **kwargs)
  File "/usr/lib/python2.7/dist-packages/novaclient/base.py", line 147, in _create
    resp, body = self.api.client.post(url, body=body)
  File "/usr/lib/python2.7/dist-packages/novaclient/client.py", line 137, in post
    return self._cs_request(url, 'POST', **kwargs)
  File "/usr/lib/python2.7/dist-packages/novaclient/client.py", line 122, in _cs_request
    **kwargs)
  File "/usr/lib/python2.7/dist-packages/novaclient/client.py", line 105, in request
    raise exceptions.from_response(resp, body)
novaclient.exceptions.OverLimit: Quota exceeded: code=%(code)s (HTTP 413)

But when a string value is passed in max_count (max_count = "any_string") following exception is thrown:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/novaclient/v1_1/servers.py", line 430, in create
    **boot_kwargs)
  File "/usr/lib/python2.7/dist-packages/novaclient/v1_1/base.py", line 153, in _boot
    return_raw=return_raw, **kwargs)
  File "/usr/lib/python2.7/dist-packages/novaclient/base.py", line 147, in _create
    resp, body = self.api.client.post(url, body=body)
  File "/usr/lib/python2.7/dist-packages/novaclient/client.py", line 137, in post
    return self._cs_request(url, 'POST', **kwargs)
  File "/usr/lib/python2.7/dist-packages/novaclient/client.py", line 122, in _cs_request
    **kwargs)
  File "/usr/lib/python2.7/dist-packages/novaclient/client.py", line 105, in request
    raise exceptions.from_response(resp, body)
novaclient.exceptions.ClientException: The server has either erred or is incapable of performing the requested operation. (HTTP 500)

Please let me know if there are any comments on the same.

Changed in nova:
assignee: shanthkumar khandre (shanthkumar09) → Shanthkumar Khandre (shanth-khandre)
Revision history for this message
shanthkumar khandre (shanthkumar09) wrote :

Hi,

I have used the following code to reproduce the bug.
(max_quota is 10 in my environment.)

from novaclient.v1_1 import client
from os import environ as env
nt = client.Client(env['NOVA_USERNAME'], env['NOVA_API_KEY'],
env['NOVA_PROJECT_ID'], env['NOVA_URL'])
nt.servers.create("name4","c0b242ce-0b7c-4b18-b42b-0275c847b968",1, max_count="20")

From the above, user tries to create 20 instances and it got succeded and only max_quota number
of instances created. But user will think that 20 instances got created.

For example if already 5 instances are existing then if we execute the above command it creates only
5 instances. But user might think that 10 instances got created. Thats the reason i am checking the
below condition and throwing the exception(Quota exceeded) if max_count value is greater than the
num_instances i.e., allowed_instances.

if max_count > num_instances:
    raise exception.QuotaError(code="InstanceLimitExceeded")

Please let me know if there are any comments on the same.

Revision history for this message
Brian Waldon (bcwaldon) wrote :

max_count is not the number of requested instances, it is the *maximum* number of instances you would like created. The lower bound defaults to 1, so asking for a max of 20 will get you anywhere from 1 to 20. If you want a specific number of instances greater than 1, you will need to specify both max_cound AND min_count. Test that out and see if you get the expected behavior.

Revision history for this message
shanthkumar khandre (shanthkumar09) wrote :

I have tested by passing both min_count(20) and max_count(20), then its throwing an exception (Quota exceeded).
Because min_count value is greater than the max_quota(10).

I have tested by passing string value in max_count("2s") then its throwing an exception as expected. But when
I pass integer value in string like max_count="2", its validating and only those many instances got created.

Eg. nt.servers.create("name4","47b2171b-61e5-4ffc-877f-99e6c00ae53f",1,max_count="2")
Only 2 instances got created.
So marking the bug as invalid.

Changed in nova:
status: In Progress → Invalid
Nachi Ueno (nati-ueno)
Changed in openstack-qa:
status: In Progress → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.