diff --git a/cloudroast/compute/fixtures.py b/cloudroast/compute/fixtures.py index e9248c60..ea9aea8c 100644 --- a/cloudroast/compute/fixtures.py +++ b/cloudroast/compute/fixtures.py @@ -14,8 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. """ +from cafe.drivers.unittest.datasets import DatasetList from cafe.drivers.unittest.fixtures import BaseTestFixture - from cloudcafe.common.resources import ResourcePool from cloudcafe.compute.common.exceptions import TimeoutException, \ BuildErrorException @@ -24,7 +24,7 @@ from cloudcafe.compute.common.types import NovaServerStatusTypes \ from cloudcafe.common.tools.datagen import rand_name from cloudcafe.compute.config import ComputeEndpointConfig, \ - ComputeAdminEndpointConfig, MarshallingConfig + ComputeAdminEndpointConfig, MarshallingConfig, ComputeFuzzingConfig from cloudcafe.compute.common.exception_handler import ExceptionHandler from cloudcafe.compute.extensions.vnc_console_api.client\ @@ -291,3 +291,30 @@ class ComputeAdminFixture(ComputeFixture): super(ComputeAdminFixture, cls).tearDownClass() cls.flavors_client.delete_exception_handler(ExceptionHandler()) cls.resources.release() + + +class FlavorIdNegativeDataList(DatasetList): + def __init__(self): + super(FlavorIdNegativeDataList, self).__init__() + fuzz_config = ComputeFuzzingConfig() + with open(fuzz_config.input_fuzzing_file) as f: + for line in f: + self.append_new_dataset(line, {'flavor_id': line}) + + +class ImageIdNegativeDataList(DatasetList): + def __init__(self): + super(ImageIdNegativeDataList, self).__init__() + fuzz_config = ComputeFuzzingConfig() + with open(fuzz_config.input_fuzzing_file) as f: + for line in f: + self.append_new_dataset(line, {'image_id': line}) + + +class ServerIdNegativeDataList(DatasetList): + def __init__(self): + super(ServerIdNegativeDataList, self).__init__() + fuzz_config = ComputeFuzzingConfig() + with open(fuzz_config.input_fuzzing_file) as f: + for line in f: + self.append_new_dataset(line, {'server_id': line}) diff --git a/cloudroast/compute/fuzz/__init__.py b/cloudroast/compute/fuzz/__init__.py new file mode 100644 index 00000000..59ab77fa --- /dev/null +++ b/cloudroast/compute/fuzz/__init__.py @@ -0,0 +1,15 @@ +""" +Copyright 2013 Rackspace + +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. +""" diff --git a/cloudroast/compute/fuzz/flavors_fuzz.py b/cloudroast/compute/fuzz/flavors_fuzz.py new file mode 100644 index 00000000..70b56144 --- /dev/null +++ b/cloudroast/compute/fuzz/flavors_fuzz.py @@ -0,0 +1,31 @@ +""" +Copyright 2013 Rackspace + +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. +""" + +from cafe.drivers.unittest.decorators import (tags, data_driven_test, + DataDrivenFixture) +from cloudcafe.compute.common.exceptions import ItemNotFound +from cloudroast.compute.fixtures import (ComputeFixture, + FlavorIdNegativeDataList) + + +@DataDrivenFixture +class FuzzFlavorsAPI(ComputeFixture): + + @data_driven_test(dataset_source=FlavorIdNegativeDataList()) + @tags(type='negative') + def ddtest_negative_get_flavor(self, flavor_id=None): + with self.assertRaises(ItemNotFound): + self.flavors_client.get_flavor_details(flavor_id) diff --git a/cloudroast/compute/fuzz/images_fuzz.py b/cloudroast/compute/fuzz/images_fuzz.py new file mode 100644 index 00000000..65468d62 --- /dev/null +++ b/cloudroast/compute/fuzz/images_fuzz.py @@ -0,0 +1,44 @@ +""" +Copyright 2013 Rackspace + +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. +""" + +from cafe.drivers.unittest.decorators import (tags, data_driven_test, + DataDrivenFixture) +from cloudcafe.compute.common.exceptions import ItemNotFound +from cloudroast.compute.fixtures import (ComputeFixture, + ImageIdNegativeDataList, + ServerIdNegativeDataList) + + +@DataDrivenFixture +class FuzzImageAPI(ComputeFixture): + + @data_driven_test(dataset_source=ImageIdNegativeDataList()) + @tags(type='negative') + def ddtest_negative_get_image(self, image_id=None): + with self.assertRaises(ItemNotFound): + self.images_client.get_image(image_id) + + @data_driven_test(dataset_source=ImageIdNegativeDataList()) + @tags(type='negative') + def ddtest_negative_delete_image(self, image_id=None): + with self.assertRaises(ItemNotFound): + self.images_client.delete_image(image_id) + + @data_driven_test(dataset_source=ServerIdNegativeDataList()) + @tags(type='negative') + def ddtest_negative_create_image(self, server_id=None): + with self.assertRaises(ItemNotFound): + self.servers_client.create_image(server_id, 'test') diff --git a/cloudroast/compute/fuzz/servers_fuzz.py b/cloudroast/compute/fuzz/servers_fuzz.py new file mode 100644 index 00000000..6c53e7a0 --- /dev/null +++ b/cloudroast/compute/fuzz/servers_fuzz.py @@ -0,0 +1,53 @@ +""" +Copyright 2013 Rackspace + +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. +""" + +from cafe.drivers.unittest.decorators import (tags, data_driven_test, + DataDrivenFixture) +from cloudcafe.compute.common.exceptions import BadRequest, ItemNotFound +from cloudroast.compute.fixtures import (ComputeFixture, + FlavorIdNegativeDataList, + ImageIdNegativeDataList, + ServerIdNegativeDataList) + + +@DataDrivenFixture +class FuzzServersAPI(ComputeFixture): + + @data_driven_test(dataset_source=ServerIdNegativeDataList()) + @tags(type='negative') + def ddtest_negative_get_server(self, server_id=None): + with self.assertRaises(ItemNotFound): + self.servers_client.get_server(server_id) + + @data_driven_test(dataset_source=ServerIdNegativeDataList()) + @tags(type='negative') + def ddtest_negative_delete_server(self, server_id=None): + with self.assertRaises(ItemNotFound): + self.servers_client.delete_server(server_id) + + @data_driven_test(dataset_source=FlavorIdNegativeDataList()) + @tags(type='negative', net='no') + def test_create_server_with_unknown_flavor(self, flavor_id): + with self.assertRaises(BadRequest): + self.servers_client.create_server( + 'testserver', self.image_ref, flavor_id) + + @data_driven_test(dataset_source=ImageIdNegativeDataList()) + @tags(type='negative', net='no') + def test_create_server_with_unknown_image(self, image_id): + with self.assertRaises(BadRequest): + self.servers_client.create_server( + 'testserver', image_id, self.flavor_ref)