From 3a970d7d655875dd6ee59080691dacd9eecc6608 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Tue, 31 May 2016 14:41:05 -0400 Subject: [PATCH] Added collector tests for volume entities --- integration_tests/builders/messages.py | 48 +++++--- integration_tests/test_api_volume_resize.py | 31 ----- integration_tests/test_api_volume_type.py | 14 +-- .../test_collector_instance_create.py | 16 +-- .../test_collector_instance_delete.py | 50 ++++++++ ...ollector_instance_delete_before_create.py} | 12 +- .../test_collector_multi_attach.py | 110 ------------------ .../test_collector_volume_attach.py | 43 +++++++ .../test_collector_volume_create.py | 39 +++++++ .../test_collector_volume_delete.py | 51 ++++++++ .../test_collector_volume_detach.py | 46 ++++++++ .../test_collector_volume_multi_attach.py | 44 +++++++ .../test_collector_volume_multi_detach.py | 47 ++++++++ .../test_collector_volume_resize.py | 56 +++++++++ .../test_collector_volume_type.py | 14 +-- 15 files changed, 421 insertions(+), 200 deletions(-) create mode 100644 integration_tests/test_collector_instance_delete.py rename integration_tests/{test_collector_event_order.py => test_collector_instance_delete_before_create.py} (84%) delete mode 100644 integration_tests/test_collector_multi_attach.py create mode 100644 integration_tests/test_collector_volume_attach.py create mode 100644 integration_tests/test_collector_volume_create.py create mode 100644 integration_tests/test_collector_volume_delete.py create mode 100644 integration_tests/test_collector_volume_detach.py create mode 100644 integration_tests/test_collector_volume_multi_attach.py create mode 100644 integration_tests/test_collector_volume_multi_detach.py create mode 100644 integration_tests/test_collector_volume_resize.py diff --git a/integration_tests/builders/messages.py b/integration_tests/builders/messages.py index 6ce1261..870ea20 100644 --- a/integration_tests/builders/messages.py +++ b/integration_tests/builders/messages.py @@ -150,6 +150,21 @@ def get_volume_detach_kilo_end_sample(volume_id=None, tenant_id=None, volume_typ return _get_volume_kilo_payload("volume.detach.end", **kwargs) +def get_volume_resize_end_sample(volume_id=None, tenant_id=None, volume_type=None, volume_size=None, + timestamp=None, name=None, attached_to=None): + kwargs = { + "volume_id": volume_id or "64a0ca7f-5f5a-4dc5-a1e1-e04e89eb95ed", + "tenant_id": tenant_id or "46eeb8e44298460899cf4b3554bfe11f", + "display_name": name or "mytenant-0001-myvolume", + "volume_type": volume_type or DEFAULT_VOLUME_TYPE, + "volume_size": volume_size or 50, + "attached_to": attached_to, + "timestamp": timestamp + timedelta(seconds=1) if timestamp else datetime(2014, 2, 14, 17, 18, 40, + tzinfo=pytz.utc), + } + return _get_volume_kilo_payload("volume.resize.end", **kwargs) + + def get_volume_detach_end_sample(volume_id=None, tenant_id=None, volume_type=None, volume_size=None, creation_timestamp=None, deletion_timestamp=None, name=None): kwargs = { @@ -344,22 +359,23 @@ def _get_volume_kilo_payload(event_type, volume_id=None, tenant_id=None, display if not isinstance(timestamp, datetime): timestamp = dateutil.parser.parse(timestamp) - for instance_id in attached_to: - volume_attachment.append({ - "instance_uuid": instance_id, - "attach_time": _format_date(timestamp - timedelta(seconds=10)), - "deleted": False, - "attach_mode": "ro", - "created_at": _format_date(timestamp - timedelta(seconds=10)), - "attached_host": "", - "updated_at": _format_date(timestamp - timedelta(seconds=10)), - "attach_status": 'available', - "detach_time": "", - "volume_id": volume_id, - "mountpoint": "/dev/vdd", - "deleted_at": "", - "id": "228345ee-0520-4d45-86fa-1e4c9f8d057d" - }) + if attached_to: + for instance_id in attached_to: + volume_attachment.append({ + "instance_uuid": instance_id, + "attach_time": _format_date(timestamp - timedelta(seconds=10)), + "deleted": False, + "attach_mode": "ro", + "created_at": _format_date(timestamp - timedelta(seconds=10)), + "attached_host": "", + "updated_at": _format_date(timestamp - timedelta(seconds=10)), + "attach_status": 'available', + "detach_time": "", + "volume_id": volume_id, + "mountpoint": "/dev/vdd", + "deleted_at": "", + "id": "228345ee-0520-4d45-86fa-1e4c9f8d057d" + }) return { "event_type": event_type, diff --git a/integration_tests/test_api_volume_resize.py b/integration_tests/test_api_volume_resize.py index 85a316a..779bb25 100644 --- a/integration_tests/test_api_volume_resize.py +++ b/integration_tests/test_api_volume_resize.py @@ -21,37 +21,6 @@ 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" diff --git a/integration_tests/test_api_volume_type.py b/integration_tests/test_api_volume_type.py index 574c3b5..f682bab 100644 --- a/integration_tests/test_api_volume_type.py +++ b/integration_tests/test_api_volume_type.py @@ -15,21 +15,11 @@ from uuid import uuid4 from hamcrest import assert_that, equal_to +from base_api_volume_testcase import BaseApiVolumeTestCase 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() - +class ApiVolumeTypeTest(BaseApiVolumeTestCase): def test_volume_type_create(self): volume_type_query = "{url}/volume_type" volume_type_id = str(uuid4()) diff --git a/integration_tests/test_collector_instance_create.py b/integration_tests/test_collector_instance_create.py index 68bf953..9128dc6 100644 --- a/integration_tests/test_collector_instance_create.py +++ b/integration_tests/test_collector_instance_create.py @@ -14,7 +14,7 @@ from uuid import uuid4 from datetime import datetime -from retry.api import retry_call +from retry import retry import pytz from hamcrest import assert_that, equal_to, has_entry @@ -24,7 +24,7 @@ from builders.messages import get_instance_create_end_sample class CollectorInstanceCreateTest(BaseApiTestCase): - def test_instance_creation(self): + def test_instance_create(self): instance_id = str(uuid4()) tenant_id = str(uuid4()) @@ -35,14 +35,10 @@ class CollectorInstanceCreateTest(BaseApiTestCase): 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_that_instance_entity_is_created(instance_id, 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] - - assert_that(response.status_code, equal_to(200)) + @retry(exceptions=AssertionError, delay=1, max_delay=300) + def assert_that_instance_entity_is_created(self, instance_id, tenant_id): + entities = self.almanachHelper.get_entities(tenant_id, "2016-01-01 00:00:00.000") assert_that(len(entities), equal_to(1)) assert_that(entities[0], has_entry("entity_id", instance_id)) diff --git a/integration_tests/test_collector_instance_delete.py b/integration_tests/test_collector_instance_delete.py new file mode 100644 index 0000000..d970e8a --- /dev/null +++ b/integration_tests/test_collector_instance_delete.py @@ -0,0 +1,50 @@ +# 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 uuid +from datetime import datetime +from hamcrest import has_entry, is_not, assert_that, equal_to +from retry import retry + +from base_api_testcase import BaseApiTestCase +from builders.messages import get_instance_delete_end_sample, get_instance_create_end_sample + + +class CollectorInstanceDeleteTest(BaseApiTestCase): + def test_instance_delete(self): + tenant_id = str(uuid.uuid4()) + instance_id = str(uuid.uuid4()) + + 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.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.assert_instance_entity_is_closed(tenant_id) + + @retry(exceptions=AssertionError, delay=1, max_delay=300) + def assert_instance_entity_is_closed(self, tenant_id): + entities = self.almanachHelper.get_entities(tenant_id, "2016-01-01 00:00:00.000") + assert_that(len(entities), equal_to(1)) + assert_that(entities[0], is_not(has_entry("end", None))) diff --git a/integration_tests/test_collector_event_order.py b/integration_tests/test_collector_instance_delete_before_create.py similarity index 84% rename from integration_tests/test_collector_event_order.py rename to integration_tests/test_collector_instance_delete_before_create.py index 2d2719e..f4128ac 100644 --- a/integration_tests/test_collector_event_order.py +++ b/integration_tests/test_collector_instance_delete_before_create.py @@ -13,22 +13,16 @@ # 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 base_api_testcase import BaseApiTestCase 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() - +class CollectorInstanceDeleteBeforeCreateTest(BaseApiTestCase): def test_when_instance_delete_received_before_create_instance(self): tenant_id = str(uuid.uuid4()) instance_id = str(uuid.uuid4()) @@ -49,7 +43,7 @@ class CollectorEventOrderTest(unittest.TestCase): self.assert_instance_delete_received_before_instance_create(tenant_id) - @retry(exceptions=AssertionError, delay=10, max_delay=300) + @retry(exceptions=AssertionError, delay=1, 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_multi_attach.py b/integration_tests/test_collector_multi_attach.py deleted file mode 100644 index fd265ab..0000000 --- a/integration_tests/test_collector_multi_attach.py +++ /dev/null @@ -1,110 +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. - -import json -import time -import uuid -import pytz - -from datetime import datetime -from hamcrest import assert_that, equal_to -from builders import messages -from helpers.rabbit_mq_helper import RabbitMqHelper -from helpers.almanach_helper import AlmanachHelper -from helpers.mongo_helper import MongoHelper -from base_api_testcase import BaseApiTestCase - - -class CollectorMultiAttachTest(BaseApiTestCase): - tenant_id = None - rabbitMqHelper = None - - @classmethod - def setUpClass(cls): - cls.almanachHelper = AlmanachHelper() - cls.rabbitMqHelper = RabbitMqHelper() - cls.prepare_dataset() - - @classmethod - def prepare_dataset(cls): - MongoHelper().drop_database() - cls.tenant_id = "my-tenant-" + str(uuid.uuid4()) - cls.setup_volume_type() - cls.setup_attached_kilo_volume(cls.tenant_id) - cls.setup_detached_kilo_volume(cls.tenant_id) - time.sleep(5) # todo replace me with @retry - - @classmethod - def tearDownClass(cls): - MongoHelper().drop_database() - - def test_kilo_volume_attach(self): - entities = self.query_almanach() - - matches = [x for x in entities if x.get('entity_id') == 'attached-volume-kilo'] - assert_that(len(matches), equal_to(1)) - assert_that(len(matches[0].get('attached_to')), equal_to(2)) - - def test_kilo_volume_detach(self): - entities = self.query_almanach() - - detached_matches = [x for x in entities if - x.get('entity_id') == 'detached-volume-kilo' and x.get('attached_to') == []] - assert_that(len(detached_matches), equal_to(2)) - - unattached_matches = [x for x in entities if - x.get('entity_id') == 'detached-volume-kilo' and x.get('attached_to') == ["my_vm"]] - assert_that(len(unattached_matches), equal_to(1)) - - def query_almanach(self): - response = self.almanachHelper.get(url="{url}/project/{project}/entities?start={start}", - project=self.tenant_id, - start="2010-01-01 18:50:00.000") - - return json.loads(response.text) - - @classmethod - def setup_attached_kilo_volume(cls, tenant_id): - cls.push(message=messages.get_volume_create_end_sample( - volume_id="attached-volume-kilo", tenant_id=tenant_id, volume_type=messages.DEFAULT_VOLUME_TYPE) - ) - - cls.push(message=messages.get_volume_attach_kilo_end_sample( - volume_id="attached-volume-kilo", tenant_id=tenant_id, attached_to=["vm1"])) - - cls.push(message=messages.get_volume_attach_kilo_end_sample( - volume_id="attached-volume-kilo", tenant_id=tenant_id, attached_to=["vm1", "vm2"])) - - @classmethod - def setup_detached_kilo_volume(cls, tenant_id): - cls.push(message=messages.get_volume_create_end_sample( - volume_id="detached-volume-kilo", tenant_id=tenant_id, volume_type=messages.DEFAULT_VOLUME_TYPE) - ) - - cls.push(message=messages.get_volume_attach_kilo_end_sample( - volume_id="detached-volume-kilo", tenant_id=tenant_id, attached_to=["my_vm"], - timestamp=datetime(2015, 7, 29, 8, 1, 59, tzinfo=pytz.utc))) - - cls.push(message=messages.get_volume_detach_kilo_end_sample( - volume_id="detached-volume-kilo", tenant_id=tenant_id, attached_to=[], - timestamp=datetime(2015, 7, 30, 8, 1, 59, tzinfo=pytz.utc))) - - @classmethod - def setup_volume_type(cls): - cls.push(message=messages.get_volume_type_create_sample( - volume_type_id=messages.DEFAULT_VOLUME_TYPE, volume_type_name=messages.DEFAULT_VOLUME_TYPE)) - - @classmethod - def push(cls, message): - cls.rabbitMqHelper.push(message) diff --git a/integration_tests/test_collector_volume_attach.py b/integration_tests/test_collector_volume_attach.py new file mode 100644 index 0000000..e13323a --- /dev/null +++ b/integration_tests/test_collector_volume_attach.py @@ -0,0 +1,43 @@ +# 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 uuid + +from hamcrest import has_entry, assert_that, equal_to +from retry import retry + +from base_api_volume_testcase import BaseApiVolumeTestCase +from builders import messages + + +class CollectorVolumeAttachTest(BaseApiVolumeTestCase): + def test_attach_volume(self): + tenant_id = str(uuid.uuid4()) + instance_id = str(uuid.uuid4()) + volume_id = str(uuid.uuid4()) + + self.rabbitMqHelper.push(message=messages.get_volume_create_end_sample( + volume_id=volume_id, tenant_id=tenant_id, volume_type=messages.DEFAULT_VOLUME_TYPE)) + + self.rabbitMqHelper.push(message=messages.get_volume_attach_kilo_end_sample( + volume_id=volume_id, tenant_id=tenant_id, attached_to=[instance_id])) + + self.assert_that_volume_entity_has_instance_attached(tenant_id, instance_id) + + @retry(exceptions=AssertionError, delay=1, max_delay=300) + def assert_that_volume_entity_has_instance_attached(self, tenant_id, instance_id): + entities = self.almanachHelper.get_entities(tenant_id, "2016-01-01 00:00:00.000") + assert_that(len(entities), equal_to(1)) + assert_that(entities[0], has_entry("end", None)) + assert_that(entities[0], has_entry("attached_to", [instance_id])) diff --git a/integration_tests/test_collector_volume_create.py b/integration_tests/test_collector_volume_create.py new file mode 100644 index 0000000..36e389d --- /dev/null +++ b/integration_tests/test_collector_volume_create.py @@ -0,0 +1,39 @@ +# 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 uuid + +from hamcrest import has_entry, assert_that, equal_to +from retry import retry + +from base_api_volume_testcase import BaseApiVolumeTestCase +from builders import messages + + +class CollectorVolumeCreateTest(BaseApiVolumeTestCase): + def test_create_volume(self): + tenant_id = str(uuid.uuid4()) + volume_id = str(uuid.uuid4()) + + self.rabbitMqHelper.push(message=messages.get_volume_create_end_sample( + volume_id=volume_id, tenant_id=tenant_id, volume_type=messages.DEFAULT_VOLUME_TYPE)) + + self.assert_that_volume_entity_is_created(tenant_id) + + @retry(exceptions=AssertionError, delay=1, max_delay=300) + def assert_that_volume_entity_is_created(self, tenant_id): + entities = self.almanachHelper.get_entities(tenant_id, "2016-01-01 00:00:00.000") + assert_that(len(entities), equal_to(1)) + assert_that(entities[0], has_entry("end", None)) + assert_that(entities[0], has_entry("attached_to", [])) diff --git a/integration_tests/test_collector_volume_delete.py b/integration_tests/test_collector_volume_delete.py new file mode 100644 index 0000000..30d5331 --- /dev/null +++ b/integration_tests/test_collector_volume_delete.py @@ -0,0 +1,51 @@ +# 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 uuid + +import pytz +from datetime import datetime +from hamcrest import has_entry, assert_that, equal_to, is_not +from retry import retry + +from base_api_volume_testcase import BaseApiVolumeTestCase +from builders import messages + + +class CollectorVolumeDeleteTest(BaseApiVolumeTestCase): + def test_delete_volume(self): + tenant_id = str(uuid.uuid4()) + volume_id = str(uuid.uuid4()) + + self.rabbitMqHelper.push(message=messages.get_volume_create_end_sample( + volume_id=volume_id, + tenant_id=tenant_id, + volume_type=messages.DEFAULT_VOLUME_TYPE, + creation_timestamp=datetime(2016, 1, 2, 15, 1, 1, tzinfo=pytz.utc) + )) + + self.rabbitMqHelper.push(message=messages.get_volume_delete_end_sample( + volume_id=volume_id, + tenant_id=tenant_id, + volume_type=messages.DEFAULT_VOLUME_TYPE, + deletion_timestamp=datetime(2016, 1, 3, 15, 1, 1, tzinfo=pytz.utc) + )) + + self.assert_that_volume_entity_is_closed(tenant_id) + + @retry(exceptions=AssertionError, delay=1, max_delay=300) + def assert_that_volume_entity_is_closed(self, tenant_id): + entities = self.almanachHelper.get_entities(tenant_id, "2016-01-01 00:00:00.000") + assert_that(len(entities), equal_to(1)) + assert_that(entities[0], is_not(has_entry("end", None))) diff --git a/integration_tests/test_collector_volume_detach.py b/integration_tests/test_collector_volume_detach.py new file mode 100644 index 0000000..59763f7 --- /dev/null +++ b/integration_tests/test_collector_volume_detach.py @@ -0,0 +1,46 @@ +# 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 uuid + +from hamcrest import has_entry, assert_that, equal_to +from retry import retry + +from base_api_volume_testcase import BaseApiVolumeTestCase +from builders import messages + + +class CollectorVolumeDetachTest(BaseApiVolumeTestCase): + def test_detach_volume(self): + tenant_id = str(uuid.uuid4()) + instance_id = str(uuid.uuid4()) + volume_id = str(uuid.uuid4()) + + self.rabbitMqHelper.push(message=messages.get_volume_create_end_sample( + volume_id=volume_id, tenant_id=tenant_id, volume_type=messages.DEFAULT_VOLUME_TYPE)) + + self.rabbitMqHelper.push(message=messages.get_volume_attach_kilo_end_sample( + volume_id=volume_id, tenant_id=tenant_id, attached_to=[instance_id])) + + self.rabbitMqHelper.push(message=messages.get_volume_detach_kilo_end_sample( + volume_id=volume_id, tenant_id=tenant_id, attached_to=[instance_id])) + + self.assert_that_volume_entity_has_instance_detached(tenant_id) + + @retry(exceptions=AssertionError, delay=1, max_delay=300) + def assert_that_volume_entity_has_instance_detached(self, tenant_id): + entities = self.almanachHelper.get_entities(tenant_id, "2016-01-01 00:00:00.000") + assert_that(len(entities), equal_to(1)) + assert_that(entities[0], has_entry("end", None)) + assert_that(entities[0], has_entry("attached_to", [])) diff --git a/integration_tests/test_collector_volume_multi_attach.py b/integration_tests/test_collector_volume_multi_attach.py new file mode 100644 index 0000000..21b3add --- /dev/null +++ b/integration_tests/test_collector_volume_multi_attach.py @@ -0,0 +1,44 @@ +# 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 uuid + +from hamcrest import has_entry, assert_that, equal_to +from retry import retry + +from base_api_volume_testcase import BaseApiVolumeTestCase +from builders import messages + + +class CollectorVolumeMultiAttachTest(BaseApiVolumeTestCase): + def test_multi_attach_volume(self): + tenant_id = str(uuid.uuid4()) + instance_id1 = str(uuid.uuid4()) + instance_id2 = str(uuid.uuid4()) + volume_id = str(uuid.uuid4()) + + self.rabbitMqHelper.push(message=messages.get_volume_create_end_sample( + volume_id=volume_id, tenant_id=tenant_id, volume_type=messages.DEFAULT_VOLUME_TYPE)) + + self.rabbitMqHelper.push(message=messages.get_volume_attach_kilo_end_sample( + volume_id=volume_id, tenant_id=tenant_id, attached_to=[instance_id1, instance_id2])) + + self.assert_that_volume_entity_has_multiple_instances_attached(tenant_id, instance_id1, instance_id2) + + @retry(exceptions=AssertionError, delay=1, max_delay=300) + def assert_that_volume_entity_has_multiple_instances_attached(self, tenant_id, instance_id1, instance_id2): + entities = self.almanachHelper.get_entities(tenant_id, "2016-01-01 00:00:00.000") + assert_that(len(entities), equal_to(1)) + assert_that(entities[0], has_entry("end", None)) + assert_that(entities[0], has_entry("attached_to", [instance_id1, instance_id2])) diff --git a/integration_tests/test_collector_volume_multi_detach.py b/integration_tests/test_collector_volume_multi_detach.py new file mode 100644 index 0000000..dd9a76b --- /dev/null +++ b/integration_tests/test_collector_volume_multi_detach.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. + +import uuid + +from hamcrest import has_entry, assert_that, equal_to +from retry import retry + +from base_api_volume_testcase import BaseApiVolumeTestCase +from builders import messages + + +class CollectorVolumeMultiDetachTest(BaseApiVolumeTestCase): + def test_multi_detach_volume(self): + tenant_id = str(uuid.uuid4()) + instance_id1 = str(uuid.uuid4()) + instance_id2 = str(uuid.uuid4()) + volume_id = str(uuid.uuid4()) + + self.rabbitMqHelper.push(message=messages.get_volume_create_end_sample( + volume_id=volume_id, tenant_id=tenant_id, volume_type=messages.DEFAULT_VOLUME_TYPE)) + + self.rabbitMqHelper.push(message=messages.get_volume_attach_kilo_end_sample( + volume_id=volume_id, tenant_id=tenant_id, attached_to=[instance_id1, instance_id2])) + + self.rabbitMqHelper.push(message=messages.get_volume_attach_kilo_end_sample( + volume_id=volume_id, tenant_id=tenant_id, attached_to=[instance_id2])) + + self.assert_that_volume_entity_has_only_one_instance_attached(tenant_id, instance_id2) + + @retry(exceptions=AssertionError, delay=1, max_delay=300) + def assert_that_volume_entity_has_only_one_instance_attached(self, tenant_id, instance_id2): + entities = self.almanachHelper.get_entities(tenant_id, "2016-01-01 00:00:00.000") + assert_that(len(entities), equal_to(1)) + assert_that(entities[0], has_entry("end", None)) + assert_that(entities[0], has_entry("attached_to", [instance_id2])) diff --git a/integration_tests/test_collector_volume_resize.py b/integration_tests/test_collector_volume_resize.py new file mode 100644 index 0000000..3006ea2 --- /dev/null +++ b/integration_tests/test_collector_volume_resize.py @@ -0,0 +1,56 @@ +# 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 uuid + +import pytz +from datetime import datetime +from hamcrest import has_entry, assert_that, equal_to, is_not +from retry import retry + +from base_api_volume_testcase import BaseApiVolumeTestCase +from builders import messages + + +class CollectorVolumeResizeTest(BaseApiVolumeTestCase): + def test_resize_volume(self): + tenant_id = str(uuid.uuid4()) + volume_id = str(uuid.uuid4()) + + self.rabbitMqHelper.push(message=messages.get_volume_create_end_sample( + volume_id=volume_id, + tenant_id=tenant_id, + volume_type=messages.DEFAULT_VOLUME_TYPE, + volume_size=10, + creation_timestamp=datetime(2016, 1, 2, 15, 1, 1, tzinfo=pytz.utc) + )) + + self.rabbitMqHelper.push(message=messages.get_volume_resize_end_sample( + volume_id=volume_id, + tenant_id=tenant_id, + volume_type=messages.DEFAULT_VOLUME_TYPE, + volume_size=100, + timestamp=datetime(2016, 1, 3, 15, 1, 1, tzinfo=pytz.utc) + )) + + self.assert_that_volume_entity_is_created(tenant_id) + + @retry(exceptions=AssertionError, delay=1, max_delay=300) + def assert_that_volume_entity_is_created(self, tenant_id): + entities = self.almanachHelper.get_entities(tenant_id, "2016-01-01 00:00:00.000") + assert_that(len(entities), equal_to(2)) + assert_that(entities[0], is_not(has_entry("end", None))) + assert_that(entities[0], has_entry("size", 10)) + assert_that(entities[1], has_entry("end", None)) + assert_that(entities[1], has_entry("size", 100)) diff --git a/integration_tests/test_collector_volume_type.py b/integration_tests/test_collector_volume_type.py index 4dc5be4..38ba72b 100644 --- a/integration_tests/test_collector_volume_type.py +++ b/integration_tests/test_collector_volume_type.py @@ -15,21 +15,11 @@ from uuid import uuid4 from hamcrest import assert_that, equal_to +from base_api_volume_testcase import BaseApiVolumeTestCase 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() - +class ApiVolumeTypeTest(BaseApiVolumeTestCase): def test_volume_type_create(self): volume_type_id = str(uuid4()) volume_type_name = str(uuid4())