Skip to content

Commit

Permalink
Merge "Create Flavors without Optional Arguments"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Oct 22, 2012
2 parents 4011a76 + 62a4aa3 commit 16d653a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bin/nova-manage
Expand Up @@ -832,7 +832,7 @@ class InstanceTypeCommands(object):
help='rxtx_factor')
@args('--is_public', dest="is_public", metavar='<is_public>',
help='Make flavor accessible to the public')
def create(self, name, memory, vcpus, root_gb, ephemeral_gb, flavorid=None,
def create(self, name, memory, vcpus, root_gb, ephemeral_gb=0, flavorid=None,
swap=0, rxtx_factor=1, is_public=True):
"""Creates instance types / flavors"""
try:
Expand Down
4 changes: 3 additions & 1 deletion nova/compute/instance_types.py
Expand Up @@ -35,7 +35,7 @@
INVALID_NAME_REGEX = re.compile("[^\w\.\- ]")


def create(name, memory, vcpus, root_gb, ephemeral_gb, flavorid=None,
def create(name, memory, vcpus, root_gb, ephemeral_gb=None, flavorid=None,
swap=None, rxtx_factor=None, is_public=True):
"""Creates instance types."""

Expand All @@ -45,6 +45,8 @@ def create(name, memory, vcpus, root_gb, ephemeral_gb, flavorid=None,
swap = 0
if rxtx_factor is None:
rxtx_factor = 1
if ephemeral_gb is None:
ephemeral_gb = 0

kwargs = {
'memory_mb': memory,
Expand Down
24 changes: 24 additions & 0 deletions nova/tests/test_instance_types.py
Expand Up @@ -56,6 +56,30 @@ def _existing_flavor(self):
"""return first instance type name"""
return instance_types.get_all_types().keys()[0]

def test_instance_type_create(self):
"""Ensure instance types can be created"""
name = 'Instance create test'
flavor_id = '512'

original_list = instance_types.get_all_types()

# create new type and make sure values stick
inst_type = instance_types.create(name, 256, 1, 120,
flavorid=flavor_id)
self.assertEqual(inst_type['flavorid'], flavor_id)
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'], 0)
self.assertEqual(inst_type['swap'], 0)
self.assertEqual(inst_type['rxtx_factor'], 1)

# make sure new type shows up in list
new_list = instance_types.get_all_types()
self.assertNotEqual(len(original_list), len(new_list),
'instance type was not created')

def test_instance_type_create_then_delete(self):
"""Ensure instance types can be created"""
name = 'Small Flavor'
Expand Down

0 comments on commit 16d653a

Please sign in to comment.