diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-01-24 20:52:57 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-01-24 20:52:57 +0000 |
| commit | ef50dd412b3e0ab569c85abc1b3637ff0f3f819d (patch) | |
| tree | 44c8ce804c5f16a8f21feb0efbe6a63b21bc1eed /nova/tests | |
| parent | 8dfd968e83cbcdc0796caa44289144d38a6a5ce8 (diff) | |
| parent | 35b3c08a463dd35a41f3c44f3fa8273b915cb378 (diff) | |
Merge "Add an API extension for creating+deleting flavors"
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/api/openstack/compute/contrib/test_flavor_manage.py | 130 | ||||
| -rw-r--r-- | nova/tests/api/openstack/compute/test_extensions.py | 1 | ||||
| -rw-r--r-- | nova/tests/test_instance_types_extra_specs.py | 2 |
3 files changed, 132 insertions, 1 deletions
diff --git a/nova/tests/api/openstack/compute/contrib/test_flavor_manage.py b/nova/tests/api/openstack/compute/contrib/test_flavor_manage.py new file mode 100644 index 000000000..1346e63d6 --- /dev/null +++ b/nova/tests/api/openstack/compute/contrib/test_flavor_manage.py @@ -0,0 +1,130 @@ +# Copyright 2011 Andrew Bogott for the Wikimedia Foundation +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import datetime + +import webob + +from nova import exception +from nova import test +from nova.tests.api.openstack import fakes +from nova.compute import instance_types +from nova.api.openstack.compute.contrib import flavormanage + + +def fake_get_instance_type_by_flavor_id(flavorid): + if flavorid == "failtest": + raise exception.NotFound("Not found sucka!") + + return { + 'root_gb': 1, + 'ephemeral_gb': 1, + 'name': u'frob', + 'deleted': False, + 'created_at': datetime.datetime(2012, 1, 19, 18, 49, 30, 877329), + 'updated_at': None, + 'memory_mb': 256, + 'vcpus': 1, + 'flavorid': flavorid, + 'swap': 0, + 'rxtx_factor': 1.0, + 'extra_specs': {}, + 'deleted_at': None, + 'vcpu_weight': None, + 'id': 7 + } + + +def fake_purge(flavorname): + pass + + +def fake_destroy(flavorname): + pass + + +def fake_create(name, memory_mb, vcpus, root_gb, ephemeral_gb, + flavorid, swap, rxtx_factor): + newflavor = fake_get_instance_type_by_flavor_id(flavorid) + + newflavor["name"] = name + newflavor["memory_mb"] = int(memory_mb) + newflavor["vcpus"] = int(vcpus) + newflavor["root_gb"] = int(root_gb) + newflavor["ephemeral_gb"] = int(ephemeral_gb) + newflavor["swap"] = swap + newflavor["rxtx_factor"] = float(rxtx_factor) + + return newflavor + + +class FlavorManageTest(test.TestCase): + def setUp(self): + super(FlavorManageTest, self).setUp() + self.stubs.Set(instance_types, + "get_instance_type_by_flavor_id", + fake_get_instance_type_by_flavor_id) + self.stubs.Set(instance_types, "destroy", fake_destroy) + self.stubs.Set(instance_types, "create", fake_create) + + self.controller = flavormanage.FlavorManageController() + + def tearDown(self): + super(FlavorManageTest, self).tearDown() + + def test_delete(self): + req = fakes.HTTPRequest.blank( + '/v2/123/flavor/delete/1234', + use_admin_context=True) + + res = self.controller._delete(req, id) + self.assertEqual(res.status_int, 202) + + self.assertRaises(webob.exc.HTTPNotFound, + self.controller._delete, req, "failtest") + + req = fakes.HTTPRequest.blank( + '/v2/123/flavor/delete/1234', + use_admin_context=False) + + res = self.controller._delete(req, id) + self.assertEqual(res.status_int, 403) + + def test_create(self): + body = { + "flavor": { + "name": "test", + "ram": 512, + "vcpus": 2, + "disk": 10, + "id": 1235, + "swap": 512, + "rxtx_factor": 1, + } + } + + req = fakes.HTTPRequest.blank( + '/v2/123/flavor/create/', + use_admin_context=True) + + res = self.controller._create(req, body) + for key in body["flavor"]: + self.assertEquals(res["flavor"][key], body["flavor"][key]) + + req = fakes.HTTPRequest.blank( + '/v2/123/flavor/create/', + use_admin_context=False) + res = self.controller._create(req, body) + self.assertEqual(res.status_int, 403) diff --git a/nova/tests/api/openstack/compute/test_extensions.py b/nova/tests/api/openstack/compute/test_extensions.py index 54d0e4625..4a03cacf6 100644 --- a/nova/tests/api/openstack/compute/test_extensions.py +++ b/nova/tests/api/openstack/compute/test_extensions.py @@ -162,6 +162,7 @@ class ExtensionControllerTest(ExtensionTestCase): "ExtendedStatus", "FlavorExtraSpecs", "FlavorExtraData", + "FlavorManage", "Floating_ips", "Floating_ip_dns", "Floating_ip_pools", diff --git a/nova/tests/test_instance_types_extra_specs.py b/nova/tests/test_instance_types_extra_specs.py index 8f4ea89d3..2bf09dd91 100644 --- a/nova/tests/test_instance_types_extra_specs.py +++ b/nova/tests/test_instance_types_extra_specs.py @@ -40,7 +40,7 @@ class InstanceTypeExtraSpecsTestCase(test.TestCase): values['extra_specs'] = specs ref = db.instance_type_create(self.context, values) - self.instance_type_id = ref.id + self.instance_type_id = ref["id"] def tearDown(self): # Remove the instance type from the database |
