Skip to content

Commit

Permalink
Check if flavor id is an empty string
Browse files Browse the repository at this point in the history
Now once a flavor is created with empty string id, its id and
name cannot be specified when we use or delete the flavor.

This checks if flavorid is empty when creating a new flavor.
And if so, assigns auto-generated flavorid.

Fixes bug: 1148563

Change-Id: Ib48c4cc4ebd993d1f3f3d60a7bb856eff3c279d5
  • Loading branch information
Mitsuhiko Yamazaki committed Mar 10, 2013
1 parent 9248245 commit 101f0e2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nova/compute/instance_types.py
Expand Up @@ -69,7 +69,7 @@ def create(name, memory, vcpus, root_gb, ephemeral_gb=None, flavorid=None,
swap=None, rxtx_factor=None, is_public=True):
"""Creates instance types."""

if flavorid is None:
if flavorid is None or flavorid == '':
flavorid = uuid.uuid4()
if swap is None:
swap = 0
Expand Down
14 changes: 14 additions & 0 deletions nova/tests/test_instance_types.py
Expand Up @@ -122,6 +122,20 @@ def test_instance_type_create_without_flavorid(self):
self.assertEqual(inst_type['swap'], 0)
self.assertEqual(inst_type['rxtx_factor'], 1.0)

def test_instance_type_create_with_empty_flavorid(self):
# Ensure that auto-generated uuid is assigned.
name = 'Empty String ID Flavor'
flavorid = ''
inst_type = instance_types.create(name, 256, 1, 120, 100, flavorid)
self.assertEqual(len(inst_type['flavorid']), 36)
self.assertEqual(inst_type['name'], name)
self.assertEqual(inst_type['memory_mb'], 256)
self.assertEqual(inst_type['vcpus'], 1)
self.assertEqual(inst_type['root_gb'], 120)
self.assertEqual(inst_type['ephemeral_gb'], 100)
self.assertEqual(inst_type['swap'], 0)
self.assertEqual(inst_type['rxtx_factor'], 1.0)

def test_instance_type_create_with_custom_rxtx_factor(self):
name = 'Custom RXTX Factor'
inst_type = instance_types.create(name, 256, 1, 120, 100,
Expand Down

0 comments on commit 101f0e2

Please sign in to comment.