diff options
-rw-r--r-- | doc/api_samples/os-volumes/snapshot-create-resp.json | 23 | ||||
-rw-r--r-- | doc/api_samples/os-volumes/snapshot-create-resp.xml | 2 | ||||
-rw-r--r-- | nova/api/openstack/compute/contrib/flavormanage.py | 16 | ||||
-rw-r--r-- | nova/cmd/manage.py | 5 | ||||
-rw-r--r-- | nova/compute/flavors.py | 37 | ||||
-rw-r--r-- | nova/tests/api/openstack/compute/contrib/test_snapshots.py | 4 | ||||
-rw-r--r-- | nova/tests/api/openstack/fakes.py | 4 | ||||
-rw-r--r-- | nova/tests/compute/test_compute.py | 22 | ||||
-rw-r--r-- | nova/tests/integrated/api_samples/os-volumes/snapshot-create-resp.json.tpl | 23 | ||||
-rw-r--r-- | nova/tests/integrated/api_samples/os-volumes/snapshot-create-resp.xml.tpl | 2 | ||||
-rw-r--r-- | nova/tests/test_instance_types.py | 296 |
11 files changed, 185 insertions, 249 deletions
diff --git a/doc/api_samples/os-volumes/snapshot-create-resp.json b/doc/api_samples/os-volumes/snapshot-create-resp.json index 1a14bea01..a8dd57d84 100644 --- a/doc/api_samples/os-volumes/snapshot-create-resp.json +++ b/doc/api_samples/os-volumes/snapshot-create-resp.json @@ -6,27 +6,6 @@ "id": 100, "size": 100, "status": "available", - "volumeId": { - "attach_status": "attached", - "availability_zone": "fakeaz", - "created_at": "1999-01-01T01:01:01.000000", - "display_description": "displaydesc", - "display_name": "displayname", - "host": "fakehost", - "id": "521752a6-acf6-4b2d-bc7a-119f9148cd8c", - "instance_uuid": "fakeuuid", - "mountpoint": "/", - "name": "vol name", - "project_id": "fakeproject", - "size": 1, - "snapshot_id": null, - "status": "fakestatus", - "user_id": "fakeuser", - "volume_metadata": [], - "volume_type": { - "name": "vol_type_name" - }, - "volume_type_id": "fakevoltype" - } + "volumeId": "521752a6-acf6-4b2d-bc7a-119f9148cd8c" } }
\ No newline at end of file diff --git a/doc/api_samples/os-volumes/snapshot-create-resp.xml b/doc/api_samples/os-volumes/snapshot-create-resp.xml index ad815f723..654bf3d34 100644 --- a/doc/api_samples/os-volumes/snapshot-create-resp.xml +++ b/doc/api_samples/os-volumes/snapshot-create-resp.xml @@ -1,2 +1,2 @@ <?xml version='1.0' encoding='UTF-8'?> -<snapshot status="available" displayDescription="Daily backup" displayName="snap-001" volumeId="{'instance_uuid': 'fakeuuid', 'status': 'fakestatus', 'user_id': 'fakeuser', 'name': 'vol name', 'display_name': 'displayname', 'availability_zone': 'fakeaz', 'created_at': datetime.datetime(1999, 1, 1, 1, 1, 1), 'attach_status': 'attached', 'display_description': 'displaydesc', 'host': 'fakehost', 'volume_type_id': 'fakevoltype', 'volume_metadata': [], 'volume_type': {'name': 'vol_type_name'}, 'snapshot_id': None, 'mountpoint': '/', 'project_id': 'fakeproject', 'id': u'521752a6-acf6-4b2d-bc7a-119f9148cd8c', 'size': 1}" id="100" createdAt="2013-02-25 16:27:36.840121" size="100"/>
\ No newline at end of file +<snapshot status="available" displayDescription="Daily backup" displayName="snap-001" volumeId="521752a6-acf6-4b2d-bc7a-119f9148cd8c" id="100" createdAt="2013-02-25 16:27:36.840121" size="100"/>
\ No newline at end of file diff --git a/nova/api/openstack/compute/contrib/flavormanage.py b/nova/api/openstack/compute/contrib/flavormanage.py index c36b40125..086c541dc 100644 --- a/nova/api/openstack/compute/contrib/flavormanage.py +++ b/nova/api/openstack/compute/contrib/flavormanage.py @@ -58,18 +58,20 @@ class FlavorManageController(wsgi.Controller): vals = body['flavor'] name = vals['name'] flavorid = vals.get('id') - memory_mb = vals.get('ram') + memory = vals.get('ram') vcpus = vals.get('vcpus') root_gb = vals.get('disk') - ephemeral_gb = vals.get('OS-FLV-EXT-DATA:ephemeral') - swap = vals.get('swap') - rxtx_factor = vals.get('rxtx_factor') + ephemeral_gb = vals.get('OS-FLV-EXT-DATA:ephemeral', 0) + swap = vals.get('swap', 0) + rxtx_factor = vals.get('rxtx_factor', 1.0) is_public = vals.get('os-flavor-access:is_public', True) try: - flavor = flavors.create(name, memory_mb, vcpus, - root_gb, ephemeral_gb, flavorid, - swap, rxtx_factor, is_public) + flavor = flavors.create(name, memory, vcpus, root_gb, + ephemeral_gb=ephemeral_gb, + flavorid=flavorid, swap=swap, + rxtx_factor=rxtx_factor, + is_public=is_public) req.cache_db_flavor(flavor) except (exception.InstanceTypeExists, exception.InstanceTypeIdExists) as err: diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py index ce77ce92a..599b9a299 100644 --- a/nova/cmd/manage.py +++ b/nova/cmd/manage.py @@ -886,8 +886,9 @@ class InstanceTypeCommands(object): """Creates instance types / flavors.""" try: flavors.create(name, memory, vcpus, root_gb, - ephemeral_gb, flavorid, swap, rxtx_factor, - is_public) + ephemeral_gb=ephemeral_gb, flavorid=flavorid, + swap=swap, rxtx_factor=rxtx_factor, + is_public=is_public) except exception.InvalidInput as e: print _("Must supply valid parameters to create instance_type") print e diff --git a/nova/compute/flavors.py b/nova/compute/flavors.py index c4ce550eb..0f29405e2 100644 --- a/nova/compute/flavors.py +++ b/nova/compute/flavors.py @@ -65,18 +65,11 @@ system_metadata_instance_type_props = { } -def create(name, memory, vcpus, root_gb, ephemeral_gb=None, flavorid=None, - swap=None, rxtx_factor=None, is_public=True): +def create(name, memory, vcpus, root_gb, ephemeral_gb=0, flavorid=None, + swap=0, rxtx_factor=1.0, is_public=True): """Creates instance types.""" - - if flavorid is None or flavorid == '': + if not flavorid: flavorid = uuid.uuid4() - if swap is None: - swap = 0 - if rxtx_factor is None: - rxtx_factor = 1.0 - if ephemeral_gb is None: - ephemeral_gb = 0 kwargs = { 'memory_mb': memory, @@ -96,13 +89,23 @@ def create(name, memory, vcpus, root_gb, ephemeral_gb=None, flavorid=None, msg = _("names can only contain [a-zA-Z0-9_.- ]") raise exception.InvalidInput(reason=msg) - # ensure some attributes are integers and greater than or equal to 0 - for option in ['memory_mb', 'vcpus', 'root_gb', 'ephemeral_gb', 'swap']: + # Some attributes are positive ( > 0) integers + for option in ['memory_mb', 'vcpus']: + try: + kwargs[option] = int(kwargs[option]) + assert kwargs[option] > 0 + except (ValueError, AssertionError): + msg = _("'%s' argument must be greater than 0") % option + raise exception.InvalidInput(reason=msg) + + # Some attributes are non-negative ( >= 0) integers + for option in ['root_gb', 'ephemeral_gb', 'swap']: try: kwargs[option] = int(kwargs[option]) assert kwargs[option] >= 0 except (ValueError, AssertionError): - msg = _("'%s' argument must be a positive integer") % option + msg = _("'%s' argument must be greater than or equal" + " to 0") % option raise exception.InvalidInput(reason=msg) # rxtx_factor should be a positive float @@ -113,14 +116,6 @@ def create(name, memory, vcpus, root_gb, ephemeral_gb=None, flavorid=None, msg = _("'rxtx_factor' argument must be a positive float") raise exception.InvalidInput(reason=msg) - # some value are required to be nonzero, not just positive - for option in ['memory_mb', 'vcpus']: - try: - assert kwargs[option] > 0 - except AssertionError: - msg = _("'%s' argument must be greater than 0") % option - raise exception.InvalidInput(reason=msg) - kwargs['name'] = name # NOTE(vish): Internally, flavorid is stored as a string but it comes # in through json as an integer, so we convert it here. diff --git a/nova/tests/api/openstack/compute/contrib/test_snapshots.py b/nova/tests/api/openstack/compute/contrib/test_snapshots.py index a890abe6f..8e042adf8 100644 --- a/nova/tests/api/openstack/compute/contrib/test_snapshots.py +++ b/nova/tests/api/openstack/compute/contrib/test_snapshots.py @@ -67,6 +67,8 @@ class SnapshotApiTest(test.TestCase): snapshot['display_name']) self.assertEqual(resp_dict['snapshot']['displayDescription'], snapshot['display_description']) + self.assertEqual(resp_dict['snapshot']['volumeId'], + snapshot['volume_id']) def test_snapshot_create_force(self): snapshot = {"volume_id": 12, @@ -88,6 +90,8 @@ class SnapshotApiTest(test.TestCase): snapshot['display_name']) self.assertEqual(resp_dict['snapshot']['displayDescription'], snapshot['display_description']) + self.assertEqual(resp_dict['snapshot']['volumeId'], + snapshot['volume_id']) # Test invalid force paramter snapshot = {"volume_id": 12, diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py index 0a78020bd..24566d4d0 100644 --- a/nova/tests/api/openstack/fakes.py +++ b/nova/tests/api/openstack/fakes.py @@ -611,8 +611,8 @@ def stub_snapshot(id, **kwargs): return snapshot -def stub_snapshot_create(self, context, volume_id, name, description): - return stub_snapshot(100, volume_id=volume_id, display_name=name, +def stub_snapshot_create(self, context, volume, name, description): + return stub_snapshot(100, volume_id=volume['id'], display_name=name, display_description=description) diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index d185c6867..9560fc78c 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -6050,11 +6050,8 @@ class ComputeAPITestCase(BaseTestCase): name = 'test_resize_new_flavor' flavorid = 11 - memory_mb = 128 - root_gb = 0 - vcpus = 1 - flavors.create(name, memory_mb, vcpus, root_gb, 0, - flavorid, 0, 1.0, True) + flavors.create(name, 128, 1, 0, ephemeral_gb=0, flavorid=flavorid, + swap=0, rxtx_factor=1.0, is_public=True) flavors.destroy(name) self.assertRaises(exception.FlavorNotFound, self.compute_api.resize, self.context, instance, flavorid) @@ -6082,11 +6079,8 @@ class ComputeAPITestCase(BaseTestCase): name = 'test_resize_with_big_mem' flavorid = 11 - memory_mb = 102400 - root_gb = 0 - vcpus = 1 - flavors.create(name, memory_mb, vcpus, root_gb, 0, - flavorid, 0, 1.0, True) + flavors.create(name, 102400, 1, 0, ephemeral_gb=0, flavorid=flavorid, + swap=0, rxtx_factor=1.0, is_public=True) self.assertRaises(exception.TooManyInstances, self.compute_api.resize, self.context, instance, flavorid) @@ -6096,11 +6090,9 @@ class ComputeAPITestCase(BaseTestCase): def test_resize_revert_deleted_flavor_fails(self): orig_name = 'test_resize_revert_orig_flavor' orig_flavorid = 11 - memory_mb = 128 - root_gb = 0 - vcpus = 1 - flavors.create(orig_name, memory_mb, vcpus, root_gb, 0, - orig_flavorid, 0, 1.0, True) + flavors.create(orig_name, 128, 1, 0, ephemeral_gb=0, + flavorid=orig_flavorid, swap=0, rxtx_factor=1.0, + is_public=True) instance = self._create_fake_instance(type_name=orig_name) instance = db.instance_get_by_uuid(self.context, instance['uuid']) diff --git a/nova/tests/integrated/api_samples/os-volumes/snapshot-create-resp.json.tpl b/nova/tests/integrated/api_samples/os-volumes/snapshot-create-resp.json.tpl index 73cd02d9d..ddffd97a3 100644 --- a/nova/tests/integrated/api_samples/os-volumes/snapshot-create-resp.json.tpl +++ b/nova/tests/integrated/api_samples/os-volumes/snapshot-create-resp.json.tpl @@ -6,27 +6,6 @@ "id": 100, "size": 100, "status": "available", - "volumeId": { - "attach_status": "attached", - "availability_zone": "fakeaz", - "created_at": "%(timestamp)s", - "display_description": "displaydesc", - "display_name": "displayname", - "host": "fakehost", - "id": "%(uuid)s", - "instance_uuid": "fakeuuid", - "mountpoint": "/", - "name": "vol name", - "project_id": "fakeproject", - "size": 1, - "snapshot_id": null, - "status": "fakestatus", - "user_id": "fakeuser", - "volume_metadata": [], - "volume_type": { - "name": "vol_type_name" - }, - "volume_type_id": "fakevoltype" - } + "volumeId": "%(uuid)s" } } diff --git a/nova/tests/integrated/api_samples/os-volumes/snapshot-create-resp.xml.tpl b/nova/tests/integrated/api_samples/os-volumes/snapshot-create-resp.xml.tpl index aa713311f..d75ae7ddd 100644 --- a/nova/tests/integrated/api_samples/os-volumes/snapshot-create-resp.xml.tpl +++ b/nova/tests/integrated/api_samples/os-volumes/snapshot-create-resp.xml.tpl @@ -1,2 +1,2 @@ <?xml version='1.0' encoding='UTF-8'?> -<snapshot status="available" displayDescription="%(description)s" displayName="%(snapshot_name)s" volumeId="{'instance_uuid': 'fakeuuid', 'status': 'fakestatus', 'user_id': 'fakeuser', 'name': 'vol name', 'display_name': 'displayname', 'availability_zone': 'fakeaz', 'created_at': datetime.datetime(1999, 1, 1, 1, 1, 1), 'attach_status': 'attached', 'display_description': 'displaydesc', 'host': 'fakehost', 'volume_type_id': 'fakevoltype', 'volume_metadata': [], 'volume_type': {'name': 'vol_type_name'}, 'snapshot_id': None, 'mountpoint': '/', 'project_id': 'fakeproject', 'id': u'521752a6-acf6-4b2d-bc7a-119f9148cd8c', 'size': 1}" id="100" createdAt="%(timestamp)s" size="100"/> +<snapshot status="available" displayDescription="%(description)s" displayName="%(snapshot_name)s" volumeId="521752a6-acf6-4b2d-bc7a-119f9148cd8c" id="100" createdAt="%(timestamp)s" size="100"/> diff --git a/nova/tests/test_instance_types.py b/nova/tests/test_instance_types.py index 5afa4005f..e20845f1d 100644 --- a/nova/tests/test_instance_types.py +++ b/nova/tests/test_instance_types.py @@ -51,119 +51,6 @@ class InstanceTypeTestCase(test.TestCase): """return first instance type name.""" return flavors.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 = flavors.get_all_types() - - # create new type and make sure values stick - inst_type = flavors.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.0) - - # make sure new type shows up in list - new_list = flavors.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' - flavorid = 'flavor1' - - original_list = flavors.get_all_types() - - # create new type and make sure values stick - inst_type = flavors.create(name, 256, 1, 120, 100, flavorid) - inst_type_id = inst_type['id'] - self.assertEqual(inst_type['flavorid'], flavorid) - 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) - - # make sure new type shows up in list - new_list = flavors.get_all_types() - self.assertNotEqual(len(original_list), len(new_list), - 'instance type was not created') - - flavors.destroy(name) - self.assertRaises(exception.InstanceTypeNotFound, - flavors.get_instance_type, inst_type_id) - - # deleted instance should not be in list anymoer - new_list = flavors.get_all_types() - self.assertEqual(original_list, new_list) - - def test_instance_type_create_without_flavorid(self): - name = 'Small Flavor' - inst_type = flavors.create(name, 256, 1, 120, 100) - self.assertNotEqual(inst_type['flavorid'], None) - 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_empty_flavorid(self): - # Ensure that auto-generated uuid is assigned. - name = 'Empty String ID Flavor' - flavorid = '' - inst_type = flavors.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 = flavors.create(name, 256, 1, 120, 100, - rxtx_factor=9.9) - self.assertNotEqual(inst_type['flavorid'], None) - 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'], 9.9) - - def test_instance_type_create_with_special_characters(self): - # Ensure instance types raises InvalidInput for invalid characters. - name = "foo.bar!@#$%^-test_name" - flavorid = "flavor1" - self.assertRaises(exception.InvalidInput, flavors.create, - name, 256, 1, 120, 100, flavorid) - - def test_instance_type_create_with_long_flavor_name(self): - # Flavor name with 255 characters or less is valid. - name = 'a' * 255 - inst_type = flavors.create(name, 64, 1, 120, flavorid=11) - self.assertEqual(inst_type['name'], name) - - # Flavor name which is more than 255 characters will cause error. - name = 'a' * 256 - self.assertRaises(exception.InvalidInput, flavors.create, - name, 64, 1, 120, flavorid=11) - def test_add_instance_type_access(self): user_id = 'fake' project_id = 'fake' @@ -233,55 +120,12 @@ class InstanceTypeTestCase(test.TestCase): inst_types = flavors.get_all_types() self.assertEqual(total_instance_types, len(inst_types)) - def test_invalid_create_args_should_fail(self): - # Ensures that instance type creation fails with invalid args. - invalid_sigs = [ - (('Zero memory', 0, 1, 10, 20, 'flavor1'), {}), - (('Negative memory', -256, 1, 10, 20, 'flavor1'), {}), - (('Non-integer memory', 'asdf', 1, 10, 20, 'flavor1'), {}), - - (('Zero vcpus', 256, 0, 10, 20, 'flavor1'), {}), - (('Negative vcpus', 256, -1, 10, 20, 'flavor1'), {}), - (('Non-integer vcpus', 256, 'a', 10, 20, 'flavor1'), {}), - - (('Negative storage', 256, 1, -1, 20, 'flavor1'), {}), - (('Non-integer storage', 256, 1, 'a', 20, 'flavor1'), {}), - - (('Negative swap', 256, 1, 10, 20, 'flavor1'), {'swap': -1}), - (('Non-integer swap', 256, 1, 10, 20, 'flavor1'), {'swap': -1}), - - (('Negative rxtx_factor', 256, 1, 10, 20, 'f1'), - {'rxtx_factor': -1}), - (('Non-integer rxtx_factor', 256, 1, 10, 20, 'f1'), - {'rxtx_factor': "d"}), - ] - - for (args, kwargs) in invalid_sigs: - self.assertRaises(exception.InvalidInput, - flavors.create, *args, **kwargs) - def test_non_existent_inst_type_shouldnt_delete(self): # Ensures that instance type creation fails with invalid args. self.assertRaises(exception.InstanceTypeNotFoundByName, flavors.destroy, 'unknown_flavor') - def test_duplicate_names_fail(self): - # Ensures that name duplicates raise InstanceTypeCreateFailed. - name = 'some_name' - flavors.create(name, 256, 1, 120, 200, 'flavor1') - self.assertRaises(exception.InstanceTypeExists, - flavors.create, - name, 256, 1, 120, 200, 'flavor2') - - def test_duplicate_flavorids_fail(self): - # Ensures that flavorid duplicates raise InstanceTypeCreateFailed. - flavorid = 'flavor1' - flavors.create('name one', 256, 1, 120, 200, flavorid) - self.assertRaises(exception.InstanceTypeIdExists, - flavors.create, - 'name two', 256, 1, 120, 200, flavorid) - def test_will_not_destroy_with_no_name(self): # Ensure destroy said path of no name raises error. self.assertRaises(exception.InstanceTypeNotFoundByName, @@ -452,3 +296,143 @@ class InstanceTypeFilteringTest(test.TestCase): filters = dict(min_memory_mb=16384, min_root_gb=80) expected = ['m1.xlarge'] self.assertFilterResults(filters, expected) + + +class CreateInstanceTypeTest(test.TestCase): + + def assertInvalidInput(self, *create_args, **create_kwargs): + self.assertRaises(exception.InvalidInput, flavors.create, + *create_args, **create_kwargs) + + def test_name_with_special_characters(self): + # Names can contain [a-zA-Z0-9_.- ] + flavors.create('_foo.bar-123', 64, 1, 120) + + # Ensure instance types raises InvalidInput for invalid characters. + self.assertInvalidInput('foobar#', 64, 1, 120) + + def test_name_length_checks(self): + MAX_LEN = 255 + + # Flavor name with 255 characters or less is valid. + flavors.create('a' * MAX_LEN, 64, 1, 120) + + # Flavor name which is more than 255 characters will cause error. + self.assertInvalidInput('a' * (MAX_LEN + 1), 64, 1, 120) + + # Flavor name which is empty should cause an error + self.assertInvalidInput('', 64, 1, 120) + + def test_memory_must_be_positive_integer(self): + self.assertInvalidInput('flavor1', 'foo', 1, 120) + self.assertInvalidInput('flavor1', -1, 1, 120) + self.assertInvalidInput('flavor1', 0, 1, 120) + flavors.create('flavor1', 1, 1, 120) + + def test_vcpus_must_be_positive_integer(self): + self.assertInvalidInput('flavor`', 64, 'foo', 120) + self.assertInvalidInput('flavor1', 64, -1, 120) + self.assertInvalidInput('flavor1', 64, 0, 120) + flavors.create('flavor1', 64, 1, 120) + + def test_root_gb_must_be_nonnegative_integer(self): + self.assertInvalidInput('flavor1', 64, 1, 'foo') + self.assertInvalidInput('flavor1', 64, 1, -1) + flavors.create('flavor1', 64, 1, 0) + flavors.create('flavor2', 64, 1, 120) + + def test_swap_must_be_nonnegative_integer(self): + self.assertInvalidInput('flavor1', 64, 1, 120, swap='foo') + self.assertInvalidInput('flavor1', 64, 1, 120, swap=-1) + flavors.create('flavor1', 64, 1, 120, swap=0) + flavors.create('flavor2', 64, 1, 120, swap=1) + + def test_rxtx_factor_must_be_positive_float(self): + self.assertInvalidInput('flavor1', 64, 1, 120, rxtx_factor='foo') + self.assertInvalidInput('flavor1', 64, 1, 120, rxtx_factor=-1.0) + self.assertInvalidInput('flavor1', 64, 1, 120, rxtx_factor=0.0) + + flavor = flavors.create('flavor1', 64, 1, 120, rxtx_factor=1.0) + self.assertEqual(1.0, flavor['rxtx_factor']) + + flavor = flavors.create('flavor2', 64, 1, 120, rxtx_factor=1.1) + self.assertEqual(1.1, flavor['rxtx_factor']) + + def test_is_public_must_be_valid_bool_string(self): + self.assertInvalidInput('flavor1', 64, 1, 120, is_public='foo') + + flavors.create('flavor1', 64, 1, 120, is_public='TRUE') + flavors.create('flavor2', 64, 1, 120, is_public='False') + flavors.create('flavor3', 64, 1, 120, is_public='Yes') + flavors.create('flavor4', 64, 1, 120, is_public='No') + flavors.create('flavor5', 64, 1, 120, is_public='Y') + flavors.create('flavor6', 64, 1, 120, is_public='N') + flavors.create('flavor7', 64, 1, 120, is_public='1') + flavors.create('flavor8', 64, 1, 120, is_public='0') + flavors.create('flavor9', 64, 1, 120, is_public='true') + + def test_flavorid_populated(self): + flavor1 = flavors.create('flavor1', 64, 1, 120) + self.assertIsNot(None, flavor1['flavorid']) + + flavor2 = flavors.create('flavor2', 64, 1, 120, flavorid='') + self.assertIsNot(None, flavor2['flavorid']) + + flavor3 = flavors.create('flavor3', 64, 1, 120, flavorid='foo') + self.assertEqual('foo', flavor3['flavorid']) + + def test_default_values(self): + flavor1 = flavors.create('flavor1', 64, 1, 120) + + self.assertIsNot(None, flavor1['flavorid']) + self.assertEqual(flavor1['ephemeral_gb'], 0) + self.assertEqual(flavor1['swap'], 0) + self.assertEqual(flavor1['rxtx_factor'], 1.0) + + def test_basic_create(self): + # Ensure instance types can be created. + original_list = flavors.get_all_types() + + # Create new type and make sure values stick + flavor = flavors.create('flavor', 64, 1, 120) + self.assertEqual(flavor['name'], 'flavor') + self.assertEqual(flavor['memory_mb'], 64) + self.assertEqual(flavor['vcpus'], 1) + self.assertEqual(flavor['root_gb'], 120) + + # Ensure new type shows up in list + new_list = flavors.get_all_types() + self.assertNotEqual(len(original_list), len(new_list), + 'flavor was not created') + + def test_create_then_delete(self): + original_list = flavors.get_all_types() + + flavor = flavors.create('flavor', 64, 1, 120) + + # Ensure new type shows up in list + new_list = flavors.get_all_types() + self.assertNotEqual(len(original_list), len(new_list), + 'instance type was not created') + + flavors.destroy('flavor') + self.assertRaises(exception.InstanceTypeNotFound, + flavors.get_instance_type, flavor['id']) + + # Deleted instance should not be in list anymore + new_list = flavors.get_all_types() + self.assertEqual(original_list, new_list) + + def test_duplicate_names_fail(self): + # Ensures that name duplicates raise InstanceTypeCreateFailed. + flavors.create('flavor', 256, 1, 120, 200, 'flavor1') + self.assertRaises(exception.InstanceTypeExists, + flavors.create, + 'flavor', 64, 1, 120) + + def test_duplicate_flavorids_fail(self): + # Ensures that flavorid duplicates raise InstanceTypeCreateFailed. + flavors.create('flavor1', 64, 1, 120, flavorid='flavorid') + self.assertRaises(exception.InstanceTypeIdExists, + flavors.create, + 'flavor2', 64, 1, 120, flavorid='flavorid') |