diff --git a/integration_tests/base_api_testcase.py b/integration_tests/base_api_testcase.py index 64a7fbf..bcc1cb6 100644 --- a/integration_tests/base_api_testcase.py +++ b/integration_tests/base_api_testcase.py @@ -14,8 +14,9 @@ import unittest +from retry import retry from uuid import uuid4 -from hamcrest import equal_to, assert_that +from hamcrest import equal_to, assert_that, has_entry from helpers.rabbit_mq_helper import RabbitMqHelper from helpers.almanach_helper import AlmanachHelper @@ -40,3 +41,15 @@ class BaseApiTestCase(unittest.TestCase): response = self.almanachHelper.post(url="{url}/project/{project}/instance", data=data, project=project_id) assert_that(response.status_code, equal_to(201)) return instance_id + + @classmethod + @retry(exceptions=AssertionError, delay=10, max_delay=300) + def _wait_until_volume_type_is_created(cls, volume_type_id): + assert_that(cls._get_volume_types(volume_type_id), + has_entry("volume_type_id", volume_type_id)) + + @classmethod + def _get_volume_types(cls, type_id): + query = "{url}/volume_type/{type_id}" + response = cls.almanachHelper.get(url=query, type_id=type_id) + return response.json() diff --git a/integration_tests/base_api_volume_testcase.py b/integration_tests/base_api_volume_testcase.py new file mode 100644 index 0000000..3467dfb --- /dev/null +++ b/integration_tests/base_api_volume_testcase.py @@ -0,0 +1,36 @@ +# Copyright 2016 Internap. +# +# 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 base_api_testcase import BaseApiTestCase +from builders import messages +from helpers.mongo_helper import MongoHelper + + +class BaseApiVolumeTestCase(BaseApiTestCase): + + @classmethod + def setUpClass(cls): + cls.setup_volume_type() + + @classmethod + def tearDownClass(cls): + MongoHelper().drop_database() + + @classmethod + def setup_volume_type(cls): + cls.rabbitMqHelper.push( + message=messages.get_volume_type_create_sample(volume_type_id=messages.DEFAULT_VOLUME_TYPE, + volume_type_name=messages.DEFAULT_VOLUME_TYPE), + ) + cls._wait_until_volume_type_is_created(volume_type_id=messages.DEFAULT_VOLUME_TYPE) diff --git a/integration_tests/test_api_almanach.py b/integration_tests/test_api_almanach.py deleted file mode 100644 index d0d51b9..0000000 --- a/integration_tests/test_api_almanach.py +++ /dev/null @@ -1,352 +0,0 @@ -# Copyright 2016 Internap. -# -# 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 uuid import uuid4 - -from hamcrest import assert_that, has_item, equal_to, has_entry -from base_api_testcase import BaseApiTestCase - - -class ApiAlmanachTest(BaseApiTestCase): - - def test_the_info_page(self): - response = self.almanachHelper.get(url="{url}/info") - self.assertEqual(response.status_code, 200) - - def test_list_entities_unauthorized(self): - list_query = "{url}/project/{project}/instances?start={start}&end={end}" - response = self.almanachHelper.get(url=list_query, headers={'Accept': 'application/json'}, - project="e455d65807cb4796bd72abecdc8a76ba", - start="2014-02-28 18:50:00.000", end="2014-03-21 22:00:00.000") - assert_that(response.status_code, equal_to(401)) - - def test_instance_create_missing_type_name_param(self): - volume_type_query = "{url}/volume_type" - volume_type_id = str(uuid4()) - data = dict( - type_id=volume_type_id - ) - - response = self.almanachHelper.post(url=volume_type_query, data=data) - - assert_that(response.status_code, equal_to(400)) - assert_that(response.json(), has_entry( - "error", - "The 'type_name' param is mandatory for the request you have made." - )) - - def test_instance_create(self): - instance_create_query = "{url}/project/{project}/instance" - project_id = "my_test_project_id" - instance_id = str(uuid4()) - data = {'id': instance_id, - 'created_at': '2016-01-01T18:30:00Z', - 'name': 'integration_test_instance_FlavorA', - 'flavor': 'FlavorA', - 'os_type': 'Linux', - 'os_distro': 'Ubuntu', - 'os_version': '14.04'} - - response = self.almanachHelper.post(url=instance_create_query, data=data, project=project_id) - assert_that(response.status_code, equal_to(201)) - - list_query = "{url}/project/{project}/instances?start={start}&end={end}" - response = self.almanachHelper.get(url=list_query, project=project_id, - start="2016-01-01 18:29:00.000", end="2016-01-01 18:31:00.000") - - assert_that(response.status_code, equal_to(200)) - assert_that(response.json(), has_item({'entity_id': instance_id, - 'end': None, - 'entity_type': 'instance', - 'flavor': data['flavor'], - 'last_event': '2016-01-01 18:30:00+00:00', - 'name': data['name'], - 'os': { - 'distro': data['os_distro'], - 'os_type': data['os_type'], - 'version': data['os_version'] - }, - 'project_id': project_id, - 'start': '2016-01-01 18:30:00+00:00', - 'metadata': {}})) - - def test_instance_create_bad_date_format(self): - instance_create_query = "{url}/project/{project}/instance" - project_id = "my_test_project_id" - instance_id = str(uuid4()) - data = {'id': instance_id, - 'created_at': 'A_BAD_DATE_FORMAT', - 'name': 'integration_test_instance_FlavorA', - 'flavor': 'FlavorA', - 'os_type': 'Linux', - 'os_distro': 'Ubuntu', - 'os_version': '14.04'} - - response = self.almanachHelper.post(url=instance_create_query, data=data, project=project_id) - - assert_that(response.status_code, equal_to(400)) - assert_that(response.json(), has_entry( - 'error', - 'The provided date has an invalid format. Format should be of yyyy-mm-ddThh:mm:ss.msZ, ' - 'ex: 2015-01-31T18:24:34.1523Z' - )) - - def test_instance_create_missing_flavor_param(self): - instance_create_query = "{url}/project/{project}/instance" - project_id = "my_test_project_id" - instance_id = str(uuid4()) - data = {'id': instance_id, - 'created_at': '2016-01-01T18:30:00Z', - 'name': 'integration_test_instance_FlavorA', - 'os_type': 'Linux', - 'os_distro': 'Ubuntu', - 'os_version': '14.04'} - - response = self.almanachHelper.post(url=instance_create_query, data=data, project=project_id) - - assert_that(response.status_code, equal_to(400)) - assert_that(response.json(), has_entry( - "error", - "The 'flavor' param is mandatory for the request you have made." - )) - - def test_instance_delete(self): - instance_create_query = "{url}/project/{project}/instance" - project_id = "my_test_project_id" - instance_id = str(uuid4()) - create_data = {'id': instance_id, - 'created_at': '2016-01-01T18:30:00Z', - 'name': 'integration_test_instance_FlavorA', - 'flavor': 'FlavorA', - 'os_type': 'Linux', - 'os_distro': 'Ubuntu', - 'os_version': '14.04'} - - response = self.almanachHelper.post(url=instance_create_query, data=create_data, project=project_id) - assert_that(response.status_code, equal_to(201)) - - instance_delete_query = "{url}/instance/{instance_id}" - delete_data = {'date': '2016-01-01T18:50:00Z'} - response = self.almanachHelper.delete(url=instance_delete_query, data=delete_data, instance_id=instance_id) - assert_that(response.status_code, equal_to(202)) - - list_query = "{url}/project/{project}/instances?start={start}&end={end}" - response = self.almanachHelper.get(url=list_query, - project=project_id, - start="2016-01-01 18:49:00.000", - end="2016-01-01 18:51:00.000") - - assert_that(response.status_code, equal_to(200)) - assert_that(response.json(), has_item({'entity_id': instance_id, - 'end': '2016-01-01 18:50:00+00:00', - 'entity_type': 'instance', - 'flavor': create_data['flavor'], - 'last_event': '2016-01-01 18:50:00+00:00', - 'name': create_data['name'], - 'os': { - 'distro': create_data['os_distro'], - 'os_type': create_data['os_type'], - 'version': create_data['os_version'] - }, - 'project_id': project_id, - 'start': '2016-01-01 18:30:00+00:00', - 'metadata': {}})) - - def test_instance_delete_bad_date_format(self): - instance_create_query = "{url}/project/{project}/instance" - project_id = str(uuid4()) - instance_id = str(uuid4()) - data = {'id': instance_id, - 'created_at': '2016-01-01T18:30:00Z', - 'name': 'integration_test_instance_FlavorA', - 'flavor': 'FlavorA', - 'os_type': 'Linux', - 'os_distro': 'Ubuntu', - 'os_version': '14.04'} - - response = self.almanachHelper.post(url=instance_create_query, data=data, project=project_id) - assert_that(response.status_code, equal_to(201)) - - instance_delete_query = "{url}/instance/{instance_id}" - delete_data = {'date': 'A_BAD_DATE'} - - response = self.almanachHelper.delete(url=instance_delete_query, data=delete_data, instance_id=instance_id) - assert_that(response.status_code, equal_to(400)) - assert_that(response.json(), has_entry( - 'error', - 'The provided date has an invalid format. Format should be of yyyy-mm-ddThh:mm:ss.msZ, ' - 'ex: 2015-01-31T18:24:34.1523Z' - )) - - def test_instance_delete_missing_param(self): - instance_delete_query = "{url}/instance/{instance_id}" - - response = self.almanachHelper.delete(url=instance_delete_query, data=dict(), instance_id="my_instance_id") - assert_that(response.status_code, equal_to(400)) - assert_that(response.json(), has_entry( - "error", - "The 'date' param is mandatory for the request you have made." - )) - - def test_instance_resize(self): - instance_create_query = "{url}/project/{project}/instance" - project_id = "my_test_project_id" - instance_id = str(uuid4()) - create_data = {'id': instance_id, - 'created_at': '2016-01-01T18:30:00Z', - 'name': 'integration_test_instance_FlavorA', - 'flavor': 'FlavorA', - 'os_type': 'Linux', - 'os_distro': 'Ubuntu', - 'os_version': '14.04'} - - response = self.almanachHelper.post(url=instance_create_query, data=create_data, project=project_id) - assert_that(response.status_code, equal_to(201)) - - instance_resize_query = "{url}/instance/{instance_id}/resize" - resize_data = {'date': '2016-01-01T18:40:00Z', - 'flavor': 'FlavorC'} - - response = self.almanachHelper.put(url=instance_resize_query, data=resize_data, instance_id=instance_id) - assert_that(response.status_code, equal_to(200)) - - list_query = "{url}/project/{project}/instances?start={start}&end={end}" - response = self.almanachHelper.get(url=list_query, - project=project_id, - start="2016-01-01 18:39:00.000", - end="2016-01-01 18:41:00.000") - - assert_that(response.status_code, equal_to(200)) - assert_that(response.json(), has_item({'entity_id': instance_id, - 'end': None, - 'entity_type': 'instance', - 'flavor': resize_data['flavor'], - 'last_event': '2016-01-01 18:40:00+00:00', - 'name': create_data['name'], - 'os': { - 'distro': create_data['os_distro'], - 'os_type': create_data['os_type'], - 'version': create_data['os_version'] - }, - 'project_id': project_id, - 'start': '2016-01-01 18:40:00+00:00', - 'metadata': {}})) - - def test_instance_resize_bad_date_format(self): - instance_resize_query = "{url}/instance/{instance_id}/resize" - resize_data = {'date': 'A_BAD_DATE', - 'flavor': 'FlavorC'} - - response = self.almanachHelper.put(url=instance_resize_query, data=resize_data, instance_id="my_instance_id") - assert_that(response.status_code, equal_to(400)) - assert_that(response.json(), has_entry( - 'error', - 'The provided date has an invalid format. Format should be of yyyy-mm-ddThh:mm:ss.msZ, ' - 'ex: 2015-01-31T18:24:34.1523Z' - )) - - def test_instance_resize_missing_param(self): - instance_resize_query = "{url}/instance/{instance_id}/resize" - resize_data = {'flavor': 'FlavorC'} - - response = self.almanachHelper.put(url=instance_resize_query, data=resize_data, instance_id="my_instance_id") - assert_that(response.status_code, equal_to(400)) - assert_that(response.json(), has_entry( - "error", - "The 'date' param is mandatory for the request you have made." - )) - - def test_instance_rebuild(self): - instance_create_query = "{url}/project/{project}/instance" - project_id = "my_test_project_id" - instance_id = str(uuid4()) - create_data = {'id': instance_id, - 'created_at': '2016-01-01T18:30:00Z', - 'name': 'integration_test_instance_FlavorA', - 'flavor': 'FlavorA', - 'os_type': 'Linux', - 'os_distro': 'Ubuntu', - 'os_version': '12.04'} - - response = self.almanachHelper.post(url=instance_create_query, data=create_data, project=project_id) - - assert_that(response.status_code, equal_to(201)) - - update_instance_rebuild_query = "{url}/instance/{instance_id}/rebuild" - rebuild_data = { - 'distro': 'Ubuntu', - 'version': '14.04', - 'os_type': 'Linux', - 'rebuild_date': '2016-01-01T18:40:00Z' - } - - response = self.almanachHelper.put(url=update_instance_rebuild_query, data=rebuild_data, - instance_id=instance_id) - - assert_that(response.status_code, equal_to(200)) - - list_query = "{url}/project/{project}/instances?start={start}&end={end}" - response = self.almanachHelper.get(url=list_query, project=project_id, - start="2016-01-01 18:39:00.000", end="2016-01-01 18:41:00.000") - - assert_that(response.status_code, equal_to(200)) - assert_that(response.json(), has_item({'entity_id': instance_id, - 'end': None, - 'entity_type': 'instance', - 'flavor': create_data['flavor'], - 'last_event': '2016-01-01 18:40:00+00:00', - 'name': create_data['name'], - 'os': { - 'distro': create_data['os_distro'], - 'os_type': create_data['os_type'], - 'version': rebuild_data['version'] - }, - 'project_id': project_id, - 'start': '2016-01-01 18:40:00+00:00', - 'metadata': {}})) - - def test_instance_rebuild_bad_date_format(self): - update_instance_rebuild_query = "{url}/instance/{instance_id}/rebuild" - instance_id = str(uuid4()) - rebuild_data = { - 'distro': 'Ubuntu', - 'version': '14.04', - 'os_type': 'Linux', - 'rebuild_date': 'A_BAD_DATE' - } - response = self.almanachHelper.put(url=update_instance_rebuild_query, data=rebuild_data, - instance_id=instance_id) - assert_that(response.status_code, equal_to(400)) - assert_that(response.json(), has_entry( - 'error', - 'The provided date has an invalid format. Format should be of yyyy-mm-ddThh:mm:ss.msZ, ' - 'ex: 2015-01-31T18:24:34.1523Z' - )) - - def test_instance_rebuild_missing_param(self): - update_instance_rebuild_query = "{url}/instance/{instance_id}/rebuild" - instance_id = str(uuid4()) - rebuild_data = { - 'distro': 'Ubuntu', - 'os_type': 'Linux', - 'rebuild_date': 'A_BAD_DATE' - } - - response = self.almanachHelper.put(url=update_instance_rebuild_query, data=rebuild_data, - instance_id=instance_id) - assert_that(response.status_code, equal_to(400)) - assert_that(response.json(), has_entry( - "error", - "The 'version' param is mandatory for the request you have made." - )) diff --git a/integration_tests/test_api_authentication.py b/integration_tests/test_api_authentication.py new file mode 100644 index 0000000..61b2c7a --- /dev/null +++ b/integration_tests/test_api_authentication.py @@ -0,0 +1,26 @@ +# Copyright 2016 Internap. +# +# 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 hamcrest import assert_that, equal_to +from base_api_testcase import BaseApiTestCase + + +class ApiAuthenticationTest(BaseApiTestCase): + + def test_list_entities_unauthorized(self): + list_query = "{url}/project/{project}/instances?start={start}&end={end}" + response = self.almanachHelper.get(url=list_query, headers={'Accept': 'application/json'}, + project="e455d65807cb4796bd72abecdc8a76ba", + start="2014-02-28 18:50:00.000", end="2014-03-21 22:00:00.000") + assert_that(response.status_code, equal_to(401)) diff --git a/integration_tests/test_api_info.py b/integration_tests/test_api_info.py new file mode 100644 index 0000000..688b223 --- /dev/null +++ b/integration_tests/test_api_info.py @@ -0,0 +1,22 @@ +# Copyright 2016 Internap. +# +# 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 base_api_testcase import BaseApiTestCase + + +class ApiInfoTest(BaseApiTestCase): + + def test_the_info_page(self): + response = self.almanachHelper.get(url="{url}/info") + self.assertEqual(response.status_code, 200) diff --git a/integration_tests/test_api_instance_create.py b/integration_tests/test_api_instance_create.py new file mode 100644 index 0000000..5138919 --- /dev/null +++ b/integration_tests/test_api_instance_create.py @@ -0,0 +1,111 @@ +# Copyright 2016 Internap. +# +# 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 uuid import uuid4 +from hamcrest import assert_that, equal_to, has_item, has_entry + +from base_api_testcase import BaseApiTestCase + + +class ApiInstanceCreateTest(BaseApiTestCase): + + def test_instance_create(self): + instance_create_query = "{url}/project/{project}/instance" + project_id = "my_test_project_id" + instance_id = str(uuid4()) + data = {'id': instance_id, + 'created_at': '2016-01-01T18:30:00Z', + 'name': 'integration_test_instance_FlavorA', + 'flavor': 'FlavorA', + 'os_type': 'Linux', + 'os_distro': 'Ubuntu', + 'os_version': '14.04'} + + response = self.almanachHelper.post(url=instance_create_query, data=data, project=project_id) + assert_that(response.status_code, equal_to(201)) + + list_query = "{url}/project/{project}/instances?start={start}&end={end}" + response = self.almanachHelper.get(url=list_query, project=project_id, + start="2016-01-01 18:29:00.000", end="2016-01-01 18:31:00.000") + + assert_that(response.status_code, equal_to(200)) + assert_that(response.json(), has_item({'entity_id': instance_id, + 'end': None, + 'entity_type': 'instance', + 'flavor': data['flavor'], + 'last_event': '2016-01-01 18:30:00+00:00', + 'name': data['name'], + 'os': { + 'distro': data['os_distro'], + 'os_type': data['os_type'], + 'version': data['os_version'] + }, + 'project_id': project_id, + 'start': '2016-01-01 18:30:00+00:00', + 'metadata': {}})) + + def test_instance_create_bad_date_format(self): + instance_create_query = "{url}/project/{project}/instance" + project_id = "my_test_project_id" + instance_id = str(uuid4()) + data = {'id': instance_id, + 'created_at': 'A_BAD_DATE_FORMAT', + 'name': 'integration_test_instance_FlavorA', + 'flavor': 'FlavorA', + 'os_type': 'Linux', + 'os_distro': 'Ubuntu', + 'os_version': '14.04'} + + response = self.almanachHelper.post(url=instance_create_query, data=data, project=project_id) + + assert_that(response.status_code, equal_to(400)) + assert_that(response.json(), has_entry( + 'error', + 'The provided date has an invalid format. Format should be of yyyy-mm-ddThh:mm:ss.msZ, ' + 'ex: 2015-01-31T18:24:34.1523Z' + )) + + def test_instance_create_missing_flavor_param(self): + instance_create_query = "{url}/project/{project}/instance" + project_id = "my_test_project_id" + instance_id = str(uuid4()) + data = {'id': instance_id, + 'created_at': '2016-01-01T18:30:00Z', + 'name': 'integration_test_instance_FlavorA', + 'os_type': 'Linux', + 'os_distro': 'Ubuntu', + 'os_version': '14.04'} + + response = self.almanachHelper.post(url=instance_create_query, data=data, project=project_id) + + assert_that(response.status_code, equal_to(400)) + assert_that(response.json(), has_entry( + "error", + "The 'flavor' param is mandatory for the request you have made." + )) + + def test_instance_create_missing_type_name_param(self): + volume_type_query = "{url}/volume_type" + volume_type_id = str(uuid4()) + data = dict( + type_id=volume_type_id + ) + + response = self.almanachHelper.post(url=volume_type_query, data=data) + + assert_that(response.status_code, equal_to(400)) + assert_that(response.json(), has_entry( + "error", + "The 'type_name' param is mandatory for the request you have made." + )) diff --git a/integration_tests/test_api_instance_delete.py b/integration_tests/test_api_instance_delete.py new file mode 100644 index 0000000..8759390 --- /dev/null +++ b/integration_tests/test_api_instance_delete.py @@ -0,0 +1,99 @@ +# Copyright 2016 Internap. +# +# 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 uuid import uuid4 +from hamcrest import assert_that, equal_to, has_item, has_entry + +from base_api_testcase import BaseApiTestCase + + +class ApiInstanceDelete(BaseApiTestCase): + + def test_instance_delete(self): + instance_create_query = "{url}/project/{project}/instance" + project_id = "my_test_project_id" + instance_id = str(uuid4()) + create_data = {'id': instance_id, + 'created_at': '2016-01-01T18:30:00Z', + 'name': 'integration_test_instance_FlavorA', + 'flavor': 'FlavorA', + 'os_type': 'Linux', + 'os_distro': 'Ubuntu', + 'os_version': '14.04'} + + response = self.almanachHelper.post(url=instance_create_query, data=create_data, project=project_id) + assert_that(response.status_code, equal_to(201)) + + instance_delete_query = "{url}/instance/{instance_id}" + delete_data = {'date': '2016-01-01T18:50:00Z'} + response = self.almanachHelper.delete(url=instance_delete_query, data=delete_data, instance_id=instance_id) + assert_that(response.status_code, equal_to(202)) + + list_query = "{url}/project/{project}/instances?start={start}&end={end}" + response = self.almanachHelper.get(url=list_query, + project=project_id, + start="2016-01-01 18:49:00.000", + end="2016-01-01 18:51:00.000") + + assert_that(response.status_code, equal_to(200)) + assert_that(response.json(), has_item({'entity_id': instance_id, + 'end': '2016-01-01 18:50:00+00:00', + 'entity_type': 'instance', + 'flavor': create_data['flavor'], + 'last_event': '2016-01-01 18:50:00+00:00', + 'name': create_data['name'], + 'os': { + 'distro': create_data['os_distro'], + 'os_type': create_data['os_type'], + 'version': create_data['os_version'] + }, + 'project_id': project_id, + 'start': '2016-01-01 18:30:00+00:00', + 'metadata': {}})) + + def test_instance_delete_bad_date_format(self): + instance_create_query = "{url}/project/{project}/instance" + project_id = str(uuid4()) + instance_id = str(uuid4()) + data = {'id': instance_id, + 'created_at': '2016-01-01T18:30:00Z', + 'name': 'integration_test_instance_FlavorA', + 'flavor': 'FlavorA', + 'os_type': 'Linux', + 'os_distro': 'Ubuntu', + 'os_version': '14.04'} + + response = self.almanachHelper.post(url=instance_create_query, data=data, project=project_id) + assert_that(response.status_code, equal_to(201)) + + instance_delete_query = "{url}/instance/{instance_id}" + delete_data = {'date': 'A_BAD_DATE'} + + response = self.almanachHelper.delete(url=instance_delete_query, data=delete_data, instance_id=instance_id) + assert_that(response.status_code, equal_to(400)) + assert_that(response.json(), has_entry( + 'error', + 'The provided date has an invalid format. Format should be of yyyy-mm-ddThh:mm:ss.msZ, ' + 'ex: 2015-01-31T18:24:34.1523Z' + )) + + def test_instance_delete_missing_param(self): + instance_delete_query = "{url}/instance/{instance_id}" + + response = self.almanachHelper.delete(url=instance_delete_query, data=dict(), instance_id="my_instance_id") + assert_that(response.status_code, equal_to(400)) + assert_that(response.json(), has_entry( + "error", + "The 'date' param is mandatory for the request you have made." + )) diff --git a/integration_tests/test_api_instance_rebuild.py b/integration_tests/test_api_instance_rebuild.py new file mode 100644 index 0000000..d186850 --- /dev/null +++ b/integration_tests/test_api_instance_rebuild.py @@ -0,0 +1,105 @@ +# Copyright 2016 Internap. +# +# 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 uuid import uuid4 +from hamcrest import assert_that, equal_to, has_item, has_entry + +from base_api_testcase import BaseApiTestCase + + +class ApiInstanceRebuildTest(BaseApiTestCase): + + def test_instance_rebuild(self): + instance_create_query = "{url}/project/{project}/instance" + project_id = "my_test_project_id" + instance_id = str(uuid4()) + create_data = {'id': instance_id, + 'created_at': '2016-01-01T18:30:00Z', + 'name': 'integration_test_instance_FlavorA', + 'flavor': 'FlavorA', + 'os_type': 'Linux', + 'os_distro': 'Ubuntu', + 'os_version': '12.04'} + + response = self.almanachHelper.post(url=instance_create_query, data=create_data, project=project_id) + + assert_that(response.status_code, equal_to(201)) + + update_instance_rebuild_query = "{url}/instance/{instance_id}/rebuild" + rebuild_data = { + 'distro': 'Ubuntu', + 'version': '14.04', + 'os_type': 'Linux', + 'rebuild_date': '2016-01-01T18:40:00Z' + } + + response = self.almanachHelper.put(url=update_instance_rebuild_query, data=rebuild_data, + instance_id=instance_id) + + assert_that(response.status_code, equal_to(200)) + + list_query = "{url}/project/{project}/instances?start={start}&end={end}" + response = self.almanachHelper.get(url=list_query, project=project_id, + start="2016-01-01 18:39:00.000", end="2016-01-01 18:41:00.000") + + assert_that(response.status_code, equal_to(200)) + assert_that(response.json(), has_item({'entity_id': instance_id, + 'end': None, + 'entity_type': 'instance', + 'flavor': create_data['flavor'], + 'last_event': '2016-01-01 18:40:00+00:00', + 'name': create_data['name'], + 'os': { + 'distro': create_data['os_distro'], + 'os_type': create_data['os_type'], + 'version': rebuild_data['version'] + }, + 'project_id': project_id, + 'start': '2016-01-01 18:40:00+00:00', + 'metadata': {}})) + + def test_instance_rebuild_bad_date_format(self): + update_instance_rebuild_query = "{url}/instance/{instance_id}/rebuild" + instance_id = str(uuid4()) + rebuild_data = { + 'distro': 'Ubuntu', + 'version': '14.04', + 'os_type': 'Linux', + 'rebuild_date': 'A_BAD_DATE' + } + response = self.almanachHelper.put(url=update_instance_rebuild_query, data=rebuild_data, + instance_id=instance_id) + assert_that(response.status_code, equal_to(400)) + assert_that(response.json(), has_entry( + 'error', + 'The provided date has an invalid format. Format should be of yyyy-mm-ddThh:mm:ss.msZ, ' + 'ex: 2015-01-31T18:24:34.1523Z' + )) + + def test_instance_rebuild_missing_param(self): + update_instance_rebuild_query = "{url}/instance/{instance_id}/rebuild" + instance_id = str(uuid4()) + rebuild_data = { + 'distro': 'Ubuntu', + 'os_type': 'Linux', + 'rebuild_date': 'A_BAD_DATE' + } + + response = self.almanachHelper.put(url=update_instance_rebuild_query, data=rebuild_data, + instance_id=instance_id) + assert_that(response.status_code, equal_to(400)) + assert_that(response.json(), has_entry( + "error", + "The 'version' param is mandatory for the request you have made." + )) diff --git a/integration_tests/test_api_instance_resize.py b/integration_tests/test_api_instance_resize.py new file mode 100644 index 0000000..0473673 --- /dev/null +++ b/integration_tests/test_api_instance_resize.py @@ -0,0 +1,89 @@ +# Copyright 2016 Internap. +# +# 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 uuid import uuid4 +from hamcrest import assert_that, equal_to, has_item, has_entry + +from base_api_testcase import BaseApiTestCase + + +class ApiInstanceDelete(BaseApiTestCase): + + def test_instance_resize(self): + instance_create_query = "{url}/project/{project}/instance" + project_id = "my_test_project_id" + instance_id = str(uuid4()) + create_data = {'id': instance_id, + 'created_at': '2016-01-01T18:30:00Z', + 'name': 'integration_test_instance_FlavorA', + 'flavor': 'FlavorA', + 'os_type': 'Linux', + 'os_distro': 'Ubuntu', + 'os_version': '14.04'} + + response = self.almanachHelper.post(url=instance_create_query, data=create_data, project=project_id) + assert_that(response.status_code, equal_to(201)) + + instance_resize_query = "{url}/instance/{instance_id}/resize" + resize_data = {'date': '2016-01-01T18:40:00Z', + 'flavor': 'FlavorC'} + + response = self.almanachHelper.put(url=instance_resize_query, data=resize_data, instance_id=instance_id) + assert_that(response.status_code, equal_to(200)) + + list_query = "{url}/project/{project}/instances?start={start}&end={end}" + response = self.almanachHelper.get(url=list_query, + project=project_id, + start="2016-01-01 18:39:00.000", + end="2016-01-01 18:41:00.000") + + assert_that(response.status_code, equal_to(200)) + assert_that(response.json(), has_item({'entity_id': instance_id, + 'end': None, + 'entity_type': 'instance', + 'flavor': resize_data['flavor'], + 'last_event': '2016-01-01 18:40:00+00:00', + 'name': create_data['name'], + 'os': { + 'distro': create_data['os_distro'], + 'os_type': create_data['os_type'], + 'version': create_data['os_version'] + }, + 'project_id': project_id, + 'start': '2016-01-01 18:40:00+00:00', + 'metadata': {}})) + + def test_instance_resize_bad_date_format(self): + instance_resize_query = "{url}/instance/{instance_id}/resize" + resize_data = {'date': 'A_BAD_DATE', + 'flavor': 'FlavorC'} + + response = self.almanachHelper.put(url=instance_resize_query, data=resize_data, instance_id="my_instance_id") + assert_that(response.status_code, equal_to(400)) + assert_that(response.json(), has_entry( + 'error', + 'The provided date has an invalid format. Format should be of yyyy-mm-ddThh:mm:ss.msZ, ' + 'ex: 2015-01-31T18:24:34.1523Z' + )) + + def test_instance_resize_missing_param(self): + instance_resize_query = "{url}/instance/{instance_id}/resize" + resize_data = {'flavor': 'FlavorC'} + + response = self.almanachHelper.put(url=instance_resize_query, data=resize_data, instance_id="my_instance_id") + assert_that(response.status_code, equal_to(400)) + assert_that(response.json(), has_entry( + "error", + "The 'date' param is mandatory for the request you have made." + )) diff --git a/integration_tests/test_api_volume.py b/integration_tests/test_api_volume.py deleted file mode 100644 index 8bbc442..0000000 --- a/integration_tests/test_api_volume.py +++ /dev/null @@ -1,411 +0,0 @@ -# Copyright 2016 Internap. -# -# 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 uuid import uuid4 -from hamcrest import equal_to, assert_that, has_entry, has_item -from retry import retry - -from builders import messages -from base_api_testcase import BaseApiTestCase -from helpers.mongo_helper import MongoHelper - - -class ApiVolumeTest(BaseApiTestCase): - - @classmethod - def setUpClass(cls): - cls.setup_volume_type() - - @classmethod - def tearDownClass(cls): - MongoHelper().drop_database() - - @classmethod - def setup_volume_type(cls): - cls.rabbitMqHelper.push( - message=messages.get_volume_type_create_sample(volume_type_id=messages.DEFAULT_VOLUME_TYPE, - volume_type_name=messages.DEFAULT_VOLUME_TYPE), - ) - cls._wait_until_volume_type_is_created() - - def test_volume_create(self): - volume_create_query = "{url}/project/{project}/volume" - project_id = "my_test_project_id" - volume_id = str(uuid4()) - data = {'volume_id': volume_id, - 'attached_to': [], - 'volume_name': messages.DEFAULT_VOLUME_NAME, - 'volume_type': messages.DEFAULT_VOLUME_TYPE, - 'start': '2016-01-01T18:30:00Z', - 'size': 100} - - response = self.almanachHelper.post(url=volume_create_query, data=data, project=project_id) - assert_that(response.status_code, equal_to(201)) - - list_query = "{url}/project/{project}/volumes?start={start}&end={end}" - response = self.almanachHelper.get(url=list_query, - project=project_id, - start="2016-01-01 18:29:00.000", end="2016-01-01 18:31:00.000") - - assert_that(response.status_code, equal_to(200)) - assert_that(response.json(), has_item({'entity_id': volume_id, - 'attached_to': data['attached_to'], - 'end': None, - 'name': data['volume_name'], - 'entity_type': 'volume', - 'last_event': '2016-01-01 18:30:00+00:00', - 'volume_type': messages.DEFAULT_VOLUME_TYPE, - 'start': '2016-01-01 18:30:00+00:00', - 'project_id': project_id, - 'size': data['size']})) - - def test_volume_create_bad_date_format(self): - volume_create_query = "{url}/project/{project}/volume" - project_id = "my_test_project_id" - volume_id = str(uuid4()) - data = {'volume_id': volume_id, - 'attached_to': [], - 'volume_name': messages.DEFAULT_VOLUME_NAME, - 'volume_type': messages.DEFAULT_VOLUME_TYPE, - 'start': 'BAD_DATE_FORMAT', - 'size': 100} - - response = self.almanachHelper.post(url=volume_create_query, data=data, project=project_id) - - assert_that(response.status_code, equal_to(400)) - assert_that(response.json(), has_entry( - 'error', - 'The provided date has an invalid format. Format should be of yyyy-mm-ddThh:mm:ss.msZ, ' - 'ex: 2015-01-31T18:24:34.1523Z' - )) - - def test_volume_create_missing_param(self): - volume_create_query = "{url}/project/{project}/volume" - project_id = "my_test_project_id" - volume_id = str(uuid4()) - data = {'volume_id': volume_id, - 'attached_to': [], - 'volume_name': messages.DEFAULT_VOLUME_NAME, - 'volume_type': messages.DEFAULT_VOLUME_TYPE, - 'size': 100} - - response = self.almanachHelper.post(url=volume_create_query, data=data, project=project_id) - - assert_that(response.status_code, equal_to(400)) - assert_that(response.json(), has_entry( - "error", - "The 'start' param is mandatory for the request you have made." - )) - - def test_volume_delete(self): - volume_create_query = "{url}/project/{project}/volume" - project_id = "my_test_project_id" - volume_id = str(uuid4()) - create_data = {'volume_id': volume_id, - 'attached_to': [], - 'volume_name': messages.DEFAULT_VOLUME_NAME, - 'volume_type': messages.DEFAULT_VOLUME_TYPE, - 'start': '2016-01-01T18:30:00Z', - 'size': 100} - - response = self.almanachHelper.post(url=volume_create_query, data=create_data, project=project_id) - assert_that(response.status_code, equal_to(201)) - - volume_delete_query = "{url}/volume/{volume_id}" - delete_data = {'date': '2016-01-01T18:50:00Z'} - response = self.almanachHelper.delete(url=volume_delete_query, data=delete_data, volume_id=volume_id) - assert_that(response.status_code, equal_to(202)) - - list_query = "{url}/project/{project}/volumes?start={start}&end={end}" - response = self.almanachHelper.get(url=list_query, project=project_id, - start="2016-01-01 18:49:00.000", end="2016-01-01 18:51:00.000") - - assert_that(response.status_code, equal_to(200)) - assert_that(response.json(), has_item({'entity_id': volume_id, - 'attached_to': create_data['attached_to'], - 'end': '2016-01-01 18:50:00+00:00', - 'name': create_data['volume_name'], - 'entity_type': 'volume', - 'last_event': '2016-01-01 18:50:00+00:00', - 'volume_type': messages.DEFAULT_VOLUME_TYPE, - 'start': '2016-01-01 18:30:00+00:00', - 'project_id': project_id, - 'size': create_data['size']})) - - def test_volume_delete_bad_date_format(self): - volume_delete_query = "{url}/volume/{volume_id}" - delete_data = {'date': 'A_BAD_DATE'} - - response = self.almanachHelper.delete(url=volume_delete_query, data=delete_data, volume_id="my_test_volume_id") - assert_that(response.status_code, equal_to(400)) - assert_that(response.json(), has_entry( - 'error', - 'The provided date has an invalid format. Format should be of yyyy-mm-ddThh:mm:ss.msZ, ' - 'ex: 2015-01-31T18:24:34.1523Z' - )) - - def test_volume_delete_missing_param(self): - instance_delete_query = "{url}/volume/{volume_id}" - - response = self.almanachHelper.delete(url=instance_delete_query, data=dict(), volume_id="my_test_volume_id") - assert_that(response.status_code, equal_to(400)) - assert_that(response.json(), has_entry( - "error", - "The 'date' param is mandatory for the request you have made." - )) - - def test_volume_resize(self): - volume_create_query = "{url}/project/{project}/volume" - project_id = "my_test_project_id" - volume_id = str(uuid4()) - create_data = {'volume_id': volume_id, - 'attached_to': [], - 'volume_name': messages.DEFAULT_VOLUME_NAME, - 'volume_type': messages.DEFAULT_VOLUME_TYPE, - 'start': '2016-01-01T18:30:00Z', - 'size': 100} - - response = self.almanachHelper.post(url=volume_create_query, data=create_data, project=project_id) - assert_that(response.status_code, equal_to(201)) - - resize_data = {'date': '2016-01-01T18:40:00Z', - 'size': '150'} - - volume_resize_query = "{url}/volume/{volume_id}/resize" - response = self.almanachHelper.put(url=volume_resize_query, data=resize_data, volume_id=volume_id) - assert_that(response.status_code, equal_to(200)) - - list_query = "{url}/project/{project}/volumes?start={start}&end={end}" - response = self.almanachHelper.get(url=list_query, - project=project_id, - start="2016-01-01 18:39:00.000", - end="2016-01-01 18:41:00.000") - - assert_that(response.status_code, equal_to(200)) - assert_that(response.json(), has_item({'entity_id': volume_id, - 'attached_to': create_data['attached_to'], - 'end': None, - 'name': create_data['volume_name'], - 'entity_type': 'volume', - 'last_event': '2016-01-01 18:40:00+00:00', - 'volume_type': messages.DEFAULT_VOLUME_TYPE, - 'start': '2016-01-01 18:40:00+00:00', - 'project_id': project_id, - 'size': resize_data['size']})) - - def test_volume_resize_bad_date_format(self): - volume_resize_query = "{url}/volume/my_test_volume_id/resize" - resize_data = {'date': 'A_BAD_DATE', - 'size': '150'} - - response = self.almanachHelper.put(url=volume_resize_query, data=resize_data) - assert_that(response.status_code, equal_to(400)) - assert_that(response.json(), has_entry( - 'error', - 'The provided date has an invalid format. Format should be of yyyy-mm-ddThh:mm:ss.msZ, ' - 'ex: 2015-01-31T18:24:34.1523Z' - )) - - def test_volume_resize_missing_param(self): - volume_resize_query = "{url}/volume/my_test_volume_id/resize" - resize_data = {'size': '250'} - - response = self.almanachHelper.put(url=volume_resize_query, data=resize_data, instance_id="my_instance_id") - assert_that(response.status_code, equal_to(400)) - assert_that(response.json(), has_entry( - "error", - "The 'date' param is mandatory for the request you have made." - )) - - def test_volume_attach(self): - instance_create_query = "{url}/project/{project}/instance" - project_id = "my_test_project_id" - instance_id = str(uuid4()) - instance_data = {'id': instance_id, - 'created_at': '2016-01-01T18:30:00Z', - 'name': 'integration_test_instance_FlavorA', - 'flavor': 'FlavorA', - 'os_type': 'Linux', - 'os_distro': 'Ubuntu', - 'os_version': '14.04'} - - response = self.almanachHelper.post(url=instance_create_query, data=instance_data, project=project_id) - assert_that(response.status_code, equal_to(201)) - - volume_create_query = "{url}/project/{project}/volume" - volume_id = str(uuid4()) - volume_data = {'volume_id': volume_id, - 'attached_to': [], - 'volume_name': messages.DEFAULT_VOLUME_NAME, - 'volume_type': messages.DEFAULT_VOLUME_TYPE, - 'start': '2016-01-01T18:30:30Z', - 'size': 100} - - response = self.almanachHelper.post(url=volume_create_query, data=volume_data, project=project_id) - assert_that(response.status_code, equal_to(201)) - - attach_data = {'date': '2016-01-01T18:40:00Z', 'attachments': [instance_id]} - - volume_attach_query = "{url}/volume/{volume_id}/attach" - response = self.almanachHelper.put(url=volume_attach_query, data=attach_data, volume_id=volume_id) - assert_that(response.status_code, equal_to(200)) - - list_query = "{url}/project/{project}/volumes?start={start}&end={end}" - response = self.almanachHelper.get(url=list_query, - project=project_id, - start="2016-01-01 18:39:00.000", - end="2016-01-01 18:41:00.000") - - assert_that(response.status_code, equal_to(200)) - assert_that(response.json(), has_item({'entity_id': volume_id, - 'attached_to': [instance_id], - 'end': None, - 'name': volume_data['volume_name'], - 'entity_type': 'volume', - 'last_event': '2016-01-01 18:40:00+00:00', - 'volume_type': messages.DEFAULT_VOLUME_TYPE, - 'start': '2016-01-01 18:40:00+00:00', - 'project_id': project_id, - 'size': volume_data['size']})) - - def test_volume_attach_bad_date_format(self): - volume_attach_query = "{url}/volume/my_test_volume_id/attach" - attach_data = {'date': 'A_BAD_DATE', - 'attachments': ['AN_INSTANCE']} - - response = self.almanachHelper.put(url=volume_attach_query, data=attach_data) - assert_that(response.status_code, equal_to(400)) - assert_that(response.json(), has_entry( - 'error', - 'The provided date has an invalid format. Format should be of yyyy-mm-ddThh:mm:ss.msZ, ' - 'ex: 2015-01-31T18:24:34.1523Z' - )) - - def test_volume_attach_missing_param(self): - volume_attach_query = "{url}/volume/my_test_volume_id/attach" - attach_data = {'attachments': ['AN_INSTANCE']} - - response = self.almanachHelper.put(url=volume_attach_query, data=attach_data) - assert_that(response.status_code, equal_to(400)) - assert_that(response.json(), has_entry( - "error", - "The 'date' param is mandatory for the request you have made." - )) - - def test_volume_detach(self): - instance_create_query = "{url}/project/{project}/instance" - project_id = "my_test_project_id" - instance_id = str(uuid4()) - instance_data = {'id': instance_id, - 'created_at': '2016-01-01T18:30:00Z', - 'name': 'integration_test_instance_FlavorA', - 'flavor': 'FlavorA', - 'os_type': 'Linux', - 'os_distro': 'Ubuntu', - 'os_version': '14.04'} - - response = self.almanachHelper.post(url=instance_create_query, data=instance_data, project=project_id) - assert_that(response.status_code, equal_to(201)) - - volume_create_query = "{url}/project/{project}/volume" - project_id = "my_test_project_id" - volume_id = str(uuid4()) - volume_data = {'volume_id': volume_id, - 'attached_to': [instance_id], - 'volume_name': messages.DEFAULT_VOLUME_NAME, - 'volume_type': messages.DEFAULT_VOLUME_TYPE, - 'start': '2016-01-01T18:30:30Z', - 'size': 100} - - response = self.almanachHelper.post(url=volume_create_query, data=volume_data, project=project_id) - assert_that(response.status_code, equal_to(201)) - - detach_data = {'date': '2016-01-01T18:40:00Z', - 'attachments': []} - - volume_detach_query = "{url}/volume/{volume_id}/detach" - response = self.almanachHelper.put(url=volume_detach_query, data=detach_data, volume_id=volume_id) - assert_that(response.status_code, equal_to(200)) - - list_query = "{url}/project/{project}/volumes?start={start}&end={end}" - response = self.almanachHelper.get(url=list_query, - project=project_id, - start="2016-01-01 18:39:00.000", - end="2016-01-01 18:41:00.000") - - assert_that(response.status_code, equal_to(200)) - assert_that(response.json(), has_item({'entity_id': volume_id, - 'attached_to': detach_data['attachments'], - 'end': None, - 'name': volume_data['volume_name'], - 'entity_type': 'volume', - 'last_event': '2016-01-01 18:40:00+00:00', - 'volume_type': messages.DEFAULT_VOLUME_TYPE, - 'start': '2016-01-01 18:40:00+00:00', - 'project_id': project_id, - 'size': volume_data['size']})) - - def test_volume_detach_bad_date_format(self): - volume_detach_query = "{url}/volume/my_test_volume_id/detach" - attach_data = {'date': 'A_BAD_DATE', - 'attachments': ['AN_INSTANCE']} - - response = self.almanachHelper.put(url=volume_detach_query, data=attach_data) - assert_that(response.status_code, equal_to(400)) - assert_that(response.json(), has_entry( - 'error', - 'The provided date has an invalid format. Format should be of yyyy-mm-ddThh:mm:ss.msZ, ' - 'ex: 2015-01-31T18:24:34.1523Z' - )) - - def test_volume_detach_missing_param(self): - volume_detach_query = "{url}/volume/my_test_volume_id/detach" - attach_data = {'attachments': ['AN_INSTANCE']} - - response = self.almanachHelper.put(url=volume_detach_query, data=attach_data) - assert_that(response.status_code, equal_to(400)) - assert_that(response.json(), has_entry( - "error", - "The 'date' param is mandatory for the request you have made." - )) - - def test_volume_type_create(self): - volume_type_query = "{url}/volume_type" - volume_type_id = str(uuid4()) - data = dict( - type_id=volume_type_id, - type_name=messages.DEFAULT_VOLUME_NAME - ) - - response = self.almanachHelper.post(url=volume_type_query, data=data) - assert_that(response.status_code, equal_to(201)) - - volume_type_get_query = "{url}/volume_type/{volume_type_id}" - - response = self.almanachHelper.get(url=volume_type_get_query, volume_type_id=volume_type_id) - assert_that(response.status_code, equal_to(200)) - assert_that(response.json(), equal_to({'volume_type_id': data['type_id'], - 'volume_type_name': data['type_name']})) - - @classmethod - @retry(exceptions=AssertionError, delay=10, max_delay=300) - def _wait_until_volume_type_is_created(cls): - assert_that(cls._get_volume_types(messages.DEFAULT_VOLUME_TYPE), - has_entry("volume_type_id", messages.DEFAULT_VOLUME_TYPE)) - - @classmethod - def _get_volume_types(cls, type_id): - query = "{url}/volume_type/{type_id}" - response = cls.almanachHelper.get(url=query, type_id=type_id) - return response.json() diff --git a/integration_tests/test_api_volume_attach.py b/integration_tests/test_api_volume_attach.py new file mode 100644 index 0000000..bbc4285 --- /dev/null +++ b/integration_tests/test_api_volume_attach.py @@ -0,0 +1,97 @@ +# Copyright 2016 Internap. +# +# 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 uuid import uuid4 +from hamcrest import equal_to, assert_that, has_entry, has_item + +from base_api_volume_testcase import BaseApiVolumeTestCase +from builders import messages + + +class ApiVolumeTest(BaseApiVolumeTestCase): + + def test_volume_attach(self): + instance_create_query = "{url}/project/{project}/instance" + project_id = "my_test_project_id" + instance_id = str(uuid4()) + instance_data = {'id': instance_id, + 'created_at': '2016-01-01T18:30:00Z', + 'name': 'integration_test_instance_FlavorA', + 'flavor': 'FlavorA', + 'os_type': 'Linux', + 'os_distro': 'Ubuntu', + 'os_version': '14.04'} + + response = self.almanachHelper.post(url=instance_create_query, data=instance_data, project=project_id) + assert_that(response.status_code, equal_to(201)) + + volume_create_query = "{url}/project/{project}/volume" + volume_id = str(uuid4()) + volume_data = {'volume_id': volume_id, + 'attached_to': [], + 'volume_name': messages.DEFAULT_VOLUME_NAME, + 'volume_type': messages.DEFAULT_VOLUME_TYPE, + 'start': '2016-01-01T18:30:30Z', + 'size': 100} + + response = self.almanachHelper.post(url=volume_create_query, data=volume_data, project=project_id) + assert_that(response.status_code, equal_to(201)) + + attach_data = {'date': '2016-01-01T18:40:00Z', 'attachments': [instance_id]} + + volume_attach_query = "{url}/volume/{volume_id}/attach" + response = self.almanachHelper.put(url=volume_attach_query, data=attach_data, volume_id=volume_id) + assert_that(response.status_code, equal_to(200)) + + list_query = "{url}/project/{project}/volumes?start={start}&end={end}" + response = self.almanachHelper.get(url=list_query, + project=project_id, + start="2016-01-01 18:39:00.000", + end="2016-01-01 18:41:00.000") + + assert_that(response.status_code, equal_to(200)) + assert_that(response.json(), has_item({'entity_id': volume_id, + 'attached_to': [instance_id], + 'end': None, + 'name': volume_data['volume_name'], + 'entity_type': 'volume', + 'last_event': '2016-01-01 18:40:00+00:00', + 'volume_type': messages.DEFAULT_VOLUME_TYPE, + 'start': '2016-01-01 18:40:00+00:00', + 'project_id': project_id, + 'size': volume_data['size']})) + + def test_volume_attach_bad_date_format(self): + volume_attach_query = "{url}/volume/my_test_volume_id/attach" + attach_data = {'date': 'A_BAD_DATE', + 'attachments': ['AN_INSTANCE']} + + response = self.almanachHelper.put(url=volume_attach_query, data=attach_data) + assert_that(response.status_code, equal_to(400)) + assert_that(response.json(), has_entry( + 'error', + 'The provided date has an invalid format. Format should be of yyyy-mm-ddThh:mm:ss.msZ, ' + 'ex: 2015-01-31T18:24:34.1523Z' + )) + + def test_volume_attach_missing_param(self): + volume_attach_query = "{url}/volume/my_test_volume_id/attach" + attach_data = {'attachments': ['AN_INSTANCE']} + + response = self.almanachHelper.put(url=volume_attach_query, data=attach_data) + assert_that(response.status_code, equal_to(400)) + assert_that(response.json(), has_entry( + "error", + "The 'date' param is mandatory for the request you have made." + )) diff --git a/integration_tests/test_api_volume_create.py b/integration_tests/test_api_volume_create.py new file mode 100644 index 0000000..74b5211 --- /dev/null +++ b/integration_tests/test_api_volume_create.py @@ -0,0 +1,91 @@ +# Copyright 2016 Internap. +# +# 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 uuid import uuid4 +from hamcrest import equal_to, assert_that, has_entry, has_item + +from base_api_volume_testcase import BaseApiVolumeTestCase +from builders import messages + + +class ApiVolumeTest(BaseApiVolumeTestCase): + + def test_volume_create(self): + volume_create_query = "{url}/project/{project}/volume" + project_id = "my_test_project_id" + volume_id = str(uuid4()) + data = {'volume_id': volume_id, + 'attached_to': [], + 'volume_name': messages.DEFAULT_VOLUME_NAME, + 'volume_type': messages.DEFAULT_VOLUME_TYPE, + 'start': '2016-01-01T18:30:00Z', + 'size': 100} + + response = self.almanachHelper.post(url=volume_create_query, data=data, project=project_id) + assert_that(response.status_code, equal_to(201)) + + list_query = "{url}/project/{project}/volumes?start={start}&end={end}" + response = self.almanachHelper.get(url=list_query, + project=project_id, + start="2016-01-01 18:29:00.000", end="2016-01-01 18:31:00.000") + + assert_that(response.status_code, equal_to(200)) + assert_that(response.json(), has_item({'entity_id': volume_id, + 'attached_to': data['attached_to'], + 'end': None, + 'name': data['volume_name'], + 'entity_type': 'volume', + 'last_event': '2016-01-01 18:30:00+00:00', + 'volume_type': messages.DEFAULT_VOLUME_TYPE, + 'start': '2016-01-01 18:30:00+00:00', + 'project_id': project_id, + 'size': data['size']})) + + def test_volume_create_bad_date_format(self): + volume_create_query = "{url}/project/{project}/volume" + project_id = "my_test_project_id" + volume_id = str(uuid4()) + data = {'volume_id': volume_id, + 'attached_to': [], + 'volume_name': messages.DEFAULT_VOLUME_NAME, + 'volume_type': messages.DEFAULT_VOLUME_TYPE, + 'start': 'BAD_DATE_FORMAT', + 'size': 100} + + response = self.almanachHelper.post(url=volume_create_query, data=data, project=project_id) + + assert_that(response.status_code, equal_to(400)) + assert_that(response.json(), has_entry( + 'error', + 'The provided date has an invalid format. Format should be of yyyy-mm-ddThh:mm:ss.msZ, ' + 'ex: 2015-01-31T18:24:34.1523Z' + )) + + def test_volume_create_missing_param(self): + volume_create_query = "{url}/project/{project}/volume" + project_id = "my_test_project_id" + volume_id = str(uuid4()) + data = {'volume_id': volume_id, + 'attached_to': [], + 'volume_name': messages.DEFAULT_VOLUME_NAME, + 'volume_type': messages.DEFAULT_VOLUME_TYPE, + 'size': 100} + + response = self.almanachHelper.post(url=volume_create_query, data=data, project=project_id) + + assert_that(response.status_code, equal_to(400)) + assert_that(response.json(), has_entry( + "error", + "The 'start' param is mandatory for the request you have made." + )) diff --git a/integration_tests/test_api_volume_delete.py b/integration_tests/test_api_volume_delete.py new file mode 100644 index 0000000..344ba2d --- /dev/null +++ b/integration_tests/test_api_volume_delete.py @@ -0,0 +1,79 @@ +# Copyright 2016 Internap. +# +# 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 uuid import uuid4 +from hamcrest import equal_to, assert_that, has_entry, has_item + +from base_api_volume_testcase import BaseApiVolumeTestCase +from builders import messages + + +class ApiVolumeTest(BaseApiVolumeTestCase): + + def test_volume_delete(self): + volume_create_query = "{url}/project/{project}/volume" + project_id = "my_test_project_id" + volume_id = str(uuid4()) + create_data = {'volume_id': volume_id, + 'attached_to': [], + 'volume_name': messages.DEFAULT_VOLUME_NAME, + 'volume_type': messages.DEFAULT_VOLUME_TYPE, + 'start': '2016-01-01T18:30:00Z', + 'size': 100} + + response = self.almanachHelper.post(url=volume_create_query, data=create_data, project=project_id) + assert_that(response.status_code, equal_to(201)) + + volume_delete_query = "{url}/volume/{volume_id}" + delete_data = {'date': '2016-01-01T18:50:00Z'} + response = self.almanachHelper.delete(url=volume_delete_query, data=delete_data, volume_id=volume_id) + assert_that(response.status_code, equal_to(202)) + + list_query = "{url}/project/{project}/volumes?start={start}&end={end}" + response = self.almanachHelper.get(url=list_query, project=project_id, + start="2016-01-01 18:49:00.000", end="2016-01-01 18:51:00.000") + + assert_that(response.status_code, equal_to(200)) + assert_that(response.json(), has_item({'entity_id': volume_id, + 'attached_to': create_data['attached_to'], + 'end': '2016-01-01 18:50:00+00:00', + 'name': create_data['volume_name'], + 'entity_type': 'volume', + 'last_event': '2016-01-01 18:50:00+00:00', + 'volume_type': messages.DEFAULT_VOLUME_TYPE, + 'start': '2016-01-01 18:30:00+00:00', + 'project_id': project_id, + 'size': create_data['size']})) + + def test_volume_delete_bad_date_format(self): + volume_delete_query = "{url}/volume/{volume_id}" + delete_data = {'date': 'A_BAD_DATE'} + + response = self.almanachHelper.delete(url=volume_delete_query, data=delete_data, volume_id="my_test_volume_id") + assert_that(response.status_code, equal_to(400)) + assert_that(response.json(), has_entry( + 'error', + 'The provided date has an invalid format. Format should be of yyyy-mm-ddThh:mm:ss.msZ, ' + 'ex: 2015-01-31T18:24:34.1523Z' + )) + + def test_volume_delete_missing_param(self): + instance_delete_query = "{url}/volume/{volume_id}" + + response = self.almanachHelper.delete(url=instance_delete_query, data=dict(), volume_id="my_test_volume_id") + assert_that(response.status_code, equal_to(400)) + assert_that(response.json(), has_entry( + "error", + "The 'date' param is mandatory for the request you have made." + )) diff --git a/integration_tests/test_api_volume_detach.py b/integration_tests/test_api_volume_detach.py new file mode 100644 index 0000000..9b43e83 --- /dev/null +++ b/integration_tests/test_api_volume_detach.py @@ -0,0 +1,99 @@ +# Copyright 2016 Internap. +# +# 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 uuid import uuid4 +from hamcrest import equal_to, assert_that, has_entry, has_item + +from base_api_volume_testcase import BaseApiVolumeTestCase +from builders import messages + + +class ApiVolumeTest(BaseApiVolumeTestCase): + + def test_volume_detach(self): + instance_create_query = "{url}/project/{project}/instance" + project_id = "my_test_project_id" + instance_id = str(uuid4()) + instance_data = {'id': instance_id, + 'created_at': '2016-01-01T18:30:00Z', + 'name': 'integration_test_instance_FlavorA', + 'flavor': 'FlavorA', + 'os_type': 'Linux', + 'os_distro': 'Ubuntu', + 'os_version': '14.04'} + + response = self.almanachHelper.post(url=instance_create_query, data=instance_data, project=project_id) + assert_that(response.status_code, equal_to(201)) + + volume_create_query = "{url}/project/{project}/volume" + project_id = "my_test_project_id" + volume_id = str(uuid4()) + volume_data = {'volume_id': volume_id, + 'attached_to': [instance_id], + 'volume_name': messages.DEFAULT_VOLUME_NAME, + 'volume_type': messages.DEFAULT_VOLUME_TYPE, + 'start': '2016-01-01T18:30:30Z', + 'size': 100} + + response = self.almanachHelper.post(url=volume_create_query, data=volume_data, project=project_id) + assert_that(response.status_code, equal_to(201)) + + detach_data = {'date': '2016-01-01T18:40:00Z', + 'attachments': []} + + volume_detach_query = "{url}/volume/{volume_id}/detach" + response = self.almanachHelper.put(url=volume_detach_query, data=detach_data, volume_id=volume_id) + assert_that(response.status_code, equal_to(200)) + + list_query = "{url}/project/{project}/volumes?start={start}&end={end}" + response = self.almanachHelper.get(url=list_query, + project=project_id, + start="2016-01-01 18:39:00.000", + end="2016-01-01 18:41:00.000") + + assert_that(response.status_code, equal_to(200)) + assert_that(response.json(), has_item({'entity_id': volume_id, + 'attached_to': detach_data['attachments'], + 'end': None, + 'name': volume_data['volume_name'], + 'entity_type': 'volume', + 'last_event': '2016-01-01 18:40:00+00:00', + 'volume_type': messages.DEFAULT_VOLUME_TYPE, + 'start': '2016-01-01 18:40:00+00:00', + 'project_id': project_id, + 'size': volume_data['size']})) + + def test_volume_detach_bad_date_format(self): + volume_detach_query = "{url}/volume/my_test_volume_id/detach" + attach_data = {'date': 'A_BAD_DATE', + 'attachments': ['AN_INSTANCE']} + + response = self.almanachHelper.put(url=volume_detach_query, data=attach_data) + assert_that(response.status_code, equal_to(400)) + assert_that(response.json(), has_entry( + 'error', + 'The provided date has an invalid format. Format should be of yyyy-mm-ddThh:mm:ss.msZ, ' + 'ex: 2015-01-31T18:24:34.1523Z' + )) + + def test_volume_detach_missing_param(self): + volume_detach_query = "{url}/volume/my_test_volume_id/detach" + attach_data = {'attachments': ['AN_INSTANCE']} + + response = self.almanachHelper.put(url=volume_detach_query, data=attach_data) + assert_that(response.status_code, equal_to(400)) + assert_that(response.json(), has_entry( + "error", + "The 'date' param is mandatory for the request you have made." + )) diff --git a/integration_tests/test_api_volume_resize.py b/integration_tests/test_api_volume_resize.py new file mode 100644 index 0000000..85a316a --- /dev/null +++ b/integration_tests/test_api_volume_resize.py @@ -0,0 +1,116 @@ +# Copyright 2016 Internap. +# +# 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 uuid import uuid4 +from hamcrest import equal_to, assert_that, has_entry, has_item + +from base_api_volume_testcase import BaseApiVolumeTestCase +from builders import messages + + +class ApiVolumeTest(BaseApiVolumeTestCase): + + def test_volume_create(self): + volume_create_query = "{url}/project/{project}/volume" + project_id = "my_test_project_id" + volume_id = str(uuid4()) + data = {'volume_id': volume_id, + 'attached_to': [], + 'volume_name': messages.DEFAULT_VOLUME_NAME, + 'volume_type': messages.DEFAULT_VOLUME_TYPE, + 'start': '2016-01-01T18:30:00Z', + 'size': 100} + + response = self.almanachHelper.post(url=volume_create_query, data=data, project=project_id) + assert_that(response.status_code, equal_to(201)) + + list_query = "{url}/project/{project}/volumes?start={start}&end={end}" + response = self.almanachHelper.get(url=list_query, + project=project_id, + start="2016-01-01 18:29:00.000", end="2016-01-01 18:31:00.000") + + assert_that(response.status_code, equal_to(200)) + assert_that(response.json(), has_item({'entity_id': volume_id, + 'attached_to': data['attached_to'], + 'end': None, + 'name': data['volume_name'], + 'entity_type': 'volume', + 'last_event': '2016-01-01 18:30:00+00:00', + 'volume_type': messages.DEFAULT_VOLUME_TYPE, + 'start': '2016-01-01 18:30:00+00:00', + 'project_id': project_id, + 'size': data['size']})) + + def test_volume_resize(self): + volume_create_query = "{url}/project/{project}/volume" + project_id = "my_test_project_id" + volume_id = str(uuid4()) + create_data = {'volume_id': volume_id, + 'attached_to': [], + 'volume_name': messages.DEFAULT_VOLUME_NAME, + 'volume_type': messages.DEFAULT_VOLUME_TYPE, + 'start': '2016-01-01T18:30:00Z', + 'size': 100} + + response = self.almanachHelper.post(url=volume_create_query, data=create_data, project=project_id) + assert_that(response.status_code, equal_to(201)) + + resize_data = {'date': '2016-01-01T18:40:00Z', + 'size': '150'} + + volume_resize_query = "{url}/volume/{volume_id}/resize" + response = self.almanachHelper.put(url=volume_resize_query, data=resize_data, volume_id=volume_id) + assert_that(response.status_code, equal_to(200)) + + list_query = "{url}/project/{project}/volumes?start={start}&end={end}" + response = self.almanachHelper.get(url=list_query, + project=project_id, + start="2016-01-01 18:39:00.000", + end="2016-01-01 18:41:00.000") + + assert_that(response.status_code, equal_to(200)) + assert_that(response.json(), has_item({'entity_id': volume_id, + 'attached_to': create_data['attached_to'], + 'end': None, + 'name': create_data['volume_name'], + 'entity_type': 'volume', + 'last_event': '2016-01-01 18:40:00+00:00', + 'volume_type': messages.DEFAULT_VOLUME_TYPE, + 'start': '2016-01-01 18:40:00+00:00', + 'project_id': project_id, + 'size': resize_data['size']})) + + def test_volume_resize_bad_date_format(self): + volume_resize_query = "{url}/volume/my_test_volume_id/resize" + resize_data = {'date': 'A_BAD_DATE', + 'size': '150'} + + response = self.almanachHelper.put(url=volume_resize_query, data=resize_data) + assert_that(response.status_code, equal_to(400)) + assert_that(response.json(), has_entry( + 'error', + 'The provided date has an invalid format. Format should be of yyyy-mm-ddThh:mm:ss.msZ, ' + 'ex: 2015-01-31T18:24:34.1523Z' + )) + + def test_volume_resize_missing_param(self): + volume_resize_query = "{url}/volume/my_test_volume_id/resize" + resize_data = {'size': '250'} + + response = self.almanachHelper.put(url=volume_resize_query, data=resize_data, instance_id="my_instance_id") + assert_that(response.status_code, equal_to(400)) + assert_that(response.json(), has_entry( + "error", + "The 'date' param is mandatory for the request you have made." + )) diff --git a/integration_tests/test_api_volume_type.py b/integration_tests/test_api_volume_type.py new file mode 100644 index 0000000..574c3b5 --- /dev/null +++ b/integration_tests/test_api_volume_type.py @@ -0,0 +1,49 @@ +# Copyright 2016 Internap. +# +# 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 uuid import uuid4 +from hamcrest import assert_that, equal_to + +from builders import messages +from base_api_testcase import BaseApiTestCase +from helpers.mongo_helper import MongoHelper + + +class ApiVolumeTypeTest(BaseApiTestCase): + + @classmethod + def setUpClass(cls): + MongoHelper().drop_database() + + @classmethod + def tearDownClass(cls): + MongoHelper().drop_database() + + def test_volume_type_create(self): + volume_type_query = "{url}/volume_type" + volume_type_id = str(uuid4()) + data = dict( + type_id=volume_type_id, + type_name=messages.DEFAULT_VOLUME_NAME + ) + + response = self.almanachHelper.post(url=volume_type_query, data=data) + assert_that(response.status_code, equal_to(201)) + + volume_type_get_query = "{url}/volume_type/{volume_type_id}" + + response = self.almanachHelper.get(url=volume_type_get_query, volume_type_id=volume_type_id) + assert_that(response.status_code, equal_to(200)) + assert_that(response.json(), equal_to({'volume_type_id': data['type_id'], + 'volume_type_name': data['type_name']})) diff --git a/integration_tests/test_collector_event_order.py b/integration_tests/test_collector_event_order.py new file mode 100644 index 0000000..2d2719e --- /dev/null +++ b/integration_tests/test_collector_event_order.py @@ -0,0 +1,55 @@ +# Copyright 2016 Internap. +# +# 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 pytz +import unittest +import uuid +from datetime import datetime +from hamcrest import has_entry, is_not, assert_that +from retry import retry + +from builders.messages import get_instance_delete_end_sample, get_instance_create_end_sample +from helpers.almanach_helper import AlmanachHelper +from helpers.rabbit_mq_helper import RabbitMqHelper + + +class CollectorEventOrderTest(unittest.TestCase): + def setUp(self): + self.almanachHelper = AlmanachHelper() + self.rabbitMqHelper = RabbitMqHelper() + + def test_when_instance_delete_received_before_create_instance(self): + tenant_id = str(uuid.uuid4()) + instance_id = str(uuid.uuid4()) + + self.rabbitMqHelper.push( + get_instance_delete_end_sample( + instance_id=instance_id, + tenant_id=tenant_id, + deletion_timestamp=datetime(2016, 2, 1, 10, 0, 0, tzinfo=pytz.utc) + )) + + self.rabbitMqHelper.push( + get_instance_create_end_sample( + instance_id=instance_id, + tenant_id=tenant_id, + creation_timestamp=datetime(2016, 2, 1, 9, 0, 0, tzinfo=pytz.utc) + )) + + self.assert_instance_delete_received_before_instance_create(tenant_id) + + @retry(exceptions=AssertionError, delay=10, max_delay=300) + def assert_instance_delete_received_before_instance_create(self, tenant_id): + assert_that(self.almanachHelper.get_entities(tenant_id, "2016-01-01 00:00:00.000"), + is_not(has_entry("end", None))) diff --git a/integration_tests/test_collector_instance_create.py b/integration_tests/test_collector_instance_create.py index 318676b..68bf953 100644 --- a/integration_tests/test_collector_instance_create.py +++ b/integration_tests/test_collector_instance_create.py @@ -12,44 +12,37 @@ # See the License for the specific language governing permissions and # limitations under the License. -import pytz -import unittest -import uuid +from uuid import uuid4 from datetime import datetime -from hamcrest import has_entry, is_not, assert_that -from retry import retry +from retry.api import retry_call -from builders.messages import get_instance_delete_end_sample, get_instance_create_end_sample -from helpers.almanach_helper import AlmanachHelper -from helpers.rabbit_mq_helper import RabbitMqHelper +import pytz +from hamcrest import assert_that, equal_to, has_entry + +from base_api_testcase import BaseApiTestCase +from builders.messages import get_instance_create_end_sample -class CollectorTestInstance(unittest.TestCase): - def setUp(self): - self.almanachHelper = AlmanachHelper() - self.rabbitMqHelper = RabbitMqHelper() - - def test_when_instance_delete_received_before_create_instance(self): - tenant_id = str(uuid.uuid4()) - instance_id = str(uuid.uuid4()) +class CollectorInstanceCreateTest(BaseApiTestCase): + def test_instance_creation(self): + instance_id = str(uuid4()) + tenant_id = str(uuid4()) self.rabbitMqHelper.push( - get_instance_delete_end_sample( - instance_id=instance_id, - tenant_id=tenant_id, - deletion_timestamp=datetime(2016, 2, 1, 10, 0, 0, tzinfo=pytz.utc) - )) + get_instance_create_end_sample( + instance_id=instance_id, + tenant_id=tenant_id, + creation_timestamp=datetime(2016, 2, 1, 9, 0, 0, tzinfo=pytz.utc) + )) - self.rabbitMqHelper.push( - get_instance_create_end_sample( - instance_id=instance_id, - tenant_id=tenant_id, - creation_timestamp=datetime(2016, 2, 1, 9, 0, 0, tzinfo=pytz.utc) - )) + retry_call(self._wait_until_instance_is_created, fargs=[instance_id, tenant_id], delay=10, max_delay=300, + exceptions=AssertionError) - self.assert_instance_delete_received_before_instance_create(tenant_id) + def _wait_until_instance_is_created(self, instance_id, tenant_id): + list_query = "{url}/project/{project}/instances?start={start}" + response = self.almanachHelper.get(url=list_query, project=tenant_id, start="2016-01-01 18:29:00.000") + entities = [entity for entity in response.json() if entity['entity_id'] == instance_id] - @retry(exceptions=AssertionError, delay=10, max_delay=300) - def assert_instance_delete_received_before_instance_create(self, tenant_id): - assert_that(self.almanachHelper.get_entities(tenant_id, "2016-01-01 00:00:00.000"), - is_not(has_entry("end", None))) + assert_that(response.status_code, equal_to(200)) + assert_that(len(entities), equal_to(1)) + assert_that(entities[0], has_entry("entity_id", instance_id)) diff --git a/integration_tests/test_collector_volume_type.py b/integration_tests/test_collector_volume_type.py new file mode 100644 index 0000000..4dc5be4 --- /dev/null +++ b/integration_tests/test_collector_volume_type.py @@ -0,0 +1,47 @@ +# Copyright 2016 Internap. +# +# 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 uuid import uuid4 +from hamcrest import assert_that, equal_to + +from builders import messages +from base_api_testcase import BaseApiTestCase +from helpers.mongo_helper import MongoHelper + + +class ApiVolumeTypeTest(BaseApiTestCase): + + @classmethod + def setUpClass(cls): + MongoHelper().drop_database() + + @classmethod + def tearDownClass(cls): + MongoHelper().drop_database() + + def test_volume_type_create(self): + volume_type_id = str(uuid4()) + volume_type_name = str(uuid4()) + + self.rabbitMqHelper.push(message=messages.get_volume_type_create_sample( + volume_type_id=volume_type_id, volume_type_name=volume_type_name) + ) + + self._wait_until_volume_type_is_created(volume_type_id=volume_type_id) + + volume_type_get_query = "{url}/volume_type/{volume_type_id}" + response = self.almanachHelper.get(url=volume_type_get_query, volume_type_id=volume_type_id) + assert_that(response.status_code, equal_to(200)) + assert_that(response.json(), equal_to({'volume_type_id': volume_type_id, + 'volume_type_name': volume_type_name})) diff --git a/tox-integration.ini b/tox-integration.ini index 2e8ffd3..032d3cb 100644 --- a/tox-integration.ini +++ b/tox-integration.ini @@ -5,4 +5,4 @@ skipsdist = True [testenv:integration-tests] passenv = * deps = -r{toxinidir}/integration-test-requirements.txt -commands = nosetests -s --tests integration_tests +commands = nosetests --nocapture --verbosity 2 --tests integration_tests