Merge "Fix upper bound checking for flavor create parameters"

This commit is contained in:
Jenkins 2014-03-03 15:00:36 +00:00 committed by Gerrit Code Review
commit d3246ba9cf
3 changed files with 15 additions and 14 deletions

View File

@ -19,7 +19,6 @@
"""Built-in instance properties."""
import re
import sys
import uuid
from oslo.config import cfg
@ -134,12 +133,12 @@ def create(name, memory, vcpus, root_gb, ephemeral_gb=0, flavorid=None,
# Some attributes are positive ( > 0) integers
for option in ['memory_mb', 'vcpus']:
kwargs[option] = utils.validate_integer(kwargs[option], option, 1,
sys.maxint)
db.MAX_INT)
# Some attributes are non-negative ( >= 0) integers
for option in ['root_gb', 'ephemeral_gb', 'swap']:
kwargs[option] = utils.validate_integer(kwargs[option], option, 0,
sys.maxint)
db.MAX_INT)
# rxtx_factor should be a positive float
try:

View File

@ -56,6 +56,8 @@ _BACKEND_MAPPING = {'sqlalchemy': 'nova.db.sqlalchemy.api'}
IMPL = db_api.DBAPI(backend_mapping=_BACKEND_MAPPING)
LOG = logging.getLogger(__name__)
# The maximum value a signed INT type may have
MAX_INT = 0x7FFFFFFF
###################

View File

@ -13,7 +13,6 @@
"""
Unit Tests for flavors code
"""
import sys
import time
from nova.compute import flavors
@ -431,39 +430,40 @@ class CreateInstanceTypeTest(test.TestCase):
# Flavor ID which is more than 255 characters will cause error.
self.assertInvalidInput('a', 64, 1, 120, flavorid='a' * (MAX_LEN + 1))
def test_memory_must_be_positive_integer(self):
def test_memory_must_be_positive_db_integer(self):
self.assertInvalidInput('flavor1', 'foo', 1, 120)
self.assertInvalidInput('flavor1', -1, 1, 120)
self.assertInvalidInput('flavor1', 0, 1, 120)
self.assertInvalidInput('flavor1', sys.maxint + 1, 1, 120)
self.assertInvalidInput('flavor1', db.MAX_INT + 1, 1, 120)
flavors.create('flavor1', 1, 1, 120)
def test_vcpus_must_be_positive_integer(self):
def test_vcpus_must_be_positive_db_integer(self):
self.assertInvalidInput('flavor`', 64, 'foo', 120)
self.assertInvalidInput('flavor1', 64, -1, 120)
self.assertInvalidInput('flavor1', 64, 0, 120)
self.assertInvalidInput('flavor1', 64, sys.maxint + 1, 120)
self.assertInvalidInput('flavor1', 64, db.MAX_INT + 1, 120)
flavors.create('flavor1', 64, 1, 120)
def test_root_gb_must_be_nonnegative_integer(self):
def test_root_gb_must_be_nonnegative_db_integer(self):
self.assertInvalidInput('flavor1', 64, 1, 'foo')
self.assertInvalidInput('flavor1', 64, 1, -1)
self.assertInvalidInput('flavor1', 64, 1, sys.maxint + 1)
self.assertInvalidInput('flavor1', 64, 1, db.MAX_INT + 1)
flavors.create('flavor1', 64, 1, 0)
flavors.create('flavor2', 64, 1, 120)
def test_ephemeral_gb_must_be_nonnegative_integer(self):
def test_ephemeral_gb_must_be_nonnegative_db_integer(self):
self.assertInvalidInput('flavor1', 64, 1, 120, ephemeral_gb='foo')
self.assertInvalidInput('flavor1', 64, 1, 120, ephemeral_gb=-1)
self.assertInvalidInput('flavor1', 64, 1, 120,
ephemeral_gb=sys.maxint + 1)
ephemeral_gb=db.MAX_INT + 1)
flavors.create('flavor1', 64, 1, 120, ephemeral_gb=0)
flavors.create('flavor2', 64, 1, 120, ephemeral_gb=120)
def test_swap_must_be_nonnegative_integer(self):
def test_swap_must_be_nonnegative_db_integer(self):
self.assertInvalidInput('flavor1', 64, 1, 120, swap='foo')
self.assertInvalidInput('flavor1', 64, 1, 120, swap=-1)
self.assertInvalidInput('flavor1', 64, 1, 120, swap=sys.maxint + 1)
self.assertInvalidInput('flavor1', 64, 1, 120,
swap=db.MAX_INT + 1)
flavors.create('flavor1', 64, 1, 120, swap=0)
flavors.create('flavor2', 64, 1, 120, swap=1)