Merge pull request #21 from fguillot/collector-tests
Added collector tests for volume entities
This commit is contained in:
commit
cbb2d69371
@ -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,
|
||||
|
@ -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"
|
||||
|
@ -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())
|
||||
|
@ -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))
|
||||
|
50
integration_tests/test_collector_instance_delete.py
Normal file
50
integration_tests/test_collector_instance_delete.py
Normal file
@ -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)))
|
@ -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)))
|
@ -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)
|
43
integration_tests/test_collector_volume_attach.py
Normal file
43
integration_tests/test_collector_volume_attach.py
Normal file
@ -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]))
|
39
integration_tests/test_collector_volume_create.py
Normal file
39
integration_tests/test_collector_volume_create.py
Normal file
@ -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", []))
|
51
integration_tests/test_collector_volume_delete.py
Normal file
51
integration_tests/test_collector_volume_delete.py
Normal file
@ -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)))
|
46
integration_tests/test_collector_volume_detach.py
Normal file
46
integration_tests/test_collector_volume_detach.py
Normal file
@ -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", []))
|
44
integration_tests/test_collector_volume_multi_attach.py
Normal file
44
integration_tests/test_collector_volume_multi_attach.py
Normal file
@ -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]))
|
47
integration_tests/test_collector_volume_multi_detach.py
Normal file
47
integration_tests/test_collector_volume_multi_detach.py
Normal file
@ -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]))
|
56
integration_tests/test_collector_volume_resize.py
Normal file
56
integration_tests/test_collector_volume_resize.py
Normal file
@ -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))
|
@ -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())
|
||||
|
Loading…
x
Reference in New Issue
Block a user