Add Tempest scenario for API
Change-Id: If1c38b1a2004295675a7c66722d79ce80dec8dcf
This commit is contained in:
parent
51f1fa1d3d
commit
0d5ba59482
@ -31,6 +31,14 @@ class AlmanachClient(rest_client.RestClient):
|
||||
resp, response_body = self.get('info')
|
||||
return resp, response_body
|
||||
|
||||
def create_server(self, tenant_id, body):
|
||||
resp, response_body = self.post('/project/{}/instance'.format(tenant_id), body=body)
|
||||
return resp, response_body
|
||||
|
||||
def delete_server(self, instance_id, body):
|
||||
resp, response_body = self.delete('/instance/{}'.format(instance_id), body=body)
|
||||
return resp, response_body
|
||||
|
||||
def get_volume_type(self, volume_type_id):
|
||||
resp, response_body = self.get('volume_type/{}'.format(volume_type_id))
|
||||
return resp, response_body
|
||||
@ -39,3 +47,18 @@ class AlmanachClient(rest_client.RestClient):
|
||||
url = 'project/{}/entities?start=2016-01-01%2000:00:00.000'.format(tenant_id)
|
||||
resp, response_body = self.get(url)
|
||||
return resp, response_body
|
||||
|
||||
def update_server(self, instance_id, body):
|
||||
url = '/entity/instance/{}'.format(instance_id)
|
||||
resp, response_body = self.put(url, body)
|
||||
return resp, response_body
|
||||
|
||||
def rebuild(self, instance_id, body):
|
||||
update_instance_rebuild_query = "/instance/{}/rebuild".format(instance_id)
|
||||
resp, response_body = self.put(update_instance_rebuild_query, body)
|
||||
return resp, response_body
|
||||
|
||||
def resize(self, instance_id, body):
|
||||
url = "/instance/{}/resize".format(instance_id)
|
||||
resp, response_body = self.put(url, body)
|
||||
return resp, response_body
|
||||
|
@ -11,7 +11,9 @@
|
||||
# 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 oslo_serialization import jsonutils as json
|
||||
from tempest import config
|
||||
import tempest.test
|
||||
|
||||
@ -21,7 +23,6 @@ CONF = config.CONF
|
||||
|
||||
|
||||
class BaseAlmanachTest(tempest.test.BaseTestCase):
|
||||
|
||||
@classmethod
|
||||
def skip_checks(cls):
|
||||
super(BaseAlmanachTest, cls).skip_checks()
|
||||
@ -38,3 +39,19 @@ class BaseAlmanachTest(tempest.test.BaseTestCase):
|
||||
credentials = cred_provider.get_creds_by_roles(['admin']).credentials
|
||||
cls.os = clients.Manager(credentials=credentials)
|
||||
cls.almanach_client = cls.os.almanach_client
|
||||
|
||||
@classmethod
|
||||
def create_server_through_api(cls, tenant_id, server):
|
||||
resp, _ = cls.almanach_client.create_server(tenant_id, json.dumps(server))
|
||||
return resp
|
||||
|
||||
@staticmethod
|
||||
def get_server_creation_payload():
|
||||
server = {'id': str(uuid4()),
|
||||
'created_at': '2016-01-01T18:30:00Z',
|
||||
'name': 'api_test_instance_create',
|
||||
'flavor': 'api_flavor',
|
||||
'os_type': 'linux',
|
||||
'os_distro': 'ubuntu',
|
||||
'os_version': '14.04'}
|
||||
return server
|
||||
|
59
almanach/tests/tempest/tests/api/test_server_creation.py
Normal file
59
almanach/tests/tempest/tests/api/test_server_creation.py
Normal file
@ -0,0 +1,59 @@
|
||||
# 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 almanach.tests.tempest.tests.api import base
|
||||
from oslo_serialization import jsonutils as json
|
||||
from tempest.lib import exceptions
|
||||
|
||||
|
||||
class TestServerCreation(base.BaseAlmanachTest):
|
||||
tenant_id = ''
|
||||
|
||||
def setUp(self):
|
||||
super(base.BaseAlmanachTest, self).setUp()
|
||||
self.tenant_id = str(uuid4())
|
||||
|
||||
@classmethod
|
||||
def resource_setup(cls):
|
||||
super(TestServerCreation, cls).resource_setup()
|
||||
|
||||
def test_instance_create(self):
|
||||
server = self.get_server_creation_payload()
|
||||
|
||||
resp = self.create_server_through_api(self.tenant_id, server)
|
||||
self.assertEqual(resp.status, 201)
|
||||
|
||||
_, response_body = self.almanach_client.get_tenant_entities(self.tenant_id)
|
||||
|
||||
response_body = json.loads(response_body)
|
||||
self.assertIsInstance(response_body, list)
|
||||
self.assertEqual(1, len(response_body))
|
||||
|
||||
self.assertEqual(server['id'], response_body[0]['entity_id'])
|
||||
self.assertIsNone(response_body[0]['end'])
|
||||
|
||||
def test_instance_create_bad_date_format(self):
|
||||
server = self.get_server_creation_payload()
|
||||
server['created_at'] = 'not_a_real_date'
|
||||
exception = None
|
||||
try:
|
||||
self.create_server_through_api(self.tenant_id, server)
|
||||
except exceptions.BadRequest as bad_request:
|
||||
exception = bad_request
|
||||
|
||||
self.assertIsNotNone(exception)
|
||||
self.assertEqual('400', exception.resp['status'])
|
||||
self.assertIn('The provided date has an invalid format. Format should be of yyyy-mm-ddThh:mm:ss.msZ',
|
||||
exception.resp_body['error'])
|
42
almanach/tests/tempest/tests/api/test_server_deletion.py
Normal file
42
almanach/tests/tempest/tests/api/test_server_deletion.py
Normal file
@ -0,0 +1,42 @@
|
||||
# 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 almanach.tests.tempest.tests.api import base
|
||||
from oslo_serialization import jsonutils as json
|
||||
|
||||
|
||||
class TestServerDeletion(base.BaseAlmanachTest):
|
||||
def setUp(self):
|
||||
super(base.BaseAlmanachTest, self).setUp()
|
||||
|
||||
@classmethod
|
||||
def resource_setup(cls):
|
||||
super(TestServerDeletion, cls).resource_setup()
|
||||
|
||||
def test_instance_delete(self):
|
||||
tenant_id = str(uuid4())
|
||||
server = self.get_server_creation_payload()
|
||||
self.create_server_through_api(tenant_id, server)
|
||||
|
||||
self.almanach_client.delete_server(server['id'],
|
||||
json.dumps({'date': '2016-01-01T19:50:00Z'}))
|
||||
_, response_body = self.almanach_client.get_tenant_entities(tenant_id)
|
||||
|
||||
response_body = json.loads(response_body)
|
||||
self.assertIsInstance(response_body, list)
|
||||
self.assertEqual(1, len(response_body))
|
||||
|
||||
self.assertEqual(server['id'], response_body[0]['entity_id'])
|
||||
self.assertIsNotNone(response_body[0]['end'])
|
56
almanach/tests/tempest/tests/api/test_server_rebuild.py
Normal file
56
almanach/tests/tempest/tests/api/test_server_rebuild.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.
|
||||
from uuid import uuid4
|
||||
|
||||
from almanach.tests.tempest.tests.api import base
|
||||
from oslo_serialization import jsonutils as json
|
||||
|
||||
|
||||
class TestServerRebuild(base.BaseAlmanachTest):
|
||||
def setUp(self):
|
||||
super(base.BaseAlmanachTest, self).setUp()
|
||||
|
||||
@classmethod
|
||||
def resource_setup(cls):
|
||||
super(TestServerRebuild, cls).resource_setup()
|
||||
|
||||
def test_server_rebuild(self):
|
||||
tenant_id = str(uuid4())
|
||||
server = self.get_server_creation_payload()
|
||||
self.create_server_through_api(tenant_id, server)
|
||||
|
||||
rebuild_data = {
|
||||
'distro': 'Ubuntu',
|
||||
'version': '14.04',
|
||||
'os_type': 'Linux',
|
||||
'rebuild_date': '2016-01-01T18:50:00Z'
|
||||
}
|
||||
data = json.dumps(rebuild_data)
|
||||
|
||||
self.almanach_client.rebuild(server['id'], data)
|
||||
|
||||
resp, response_body = self.almanach_client.get_tenant_entities(tenant_id)
|
||||
|
||||
entities = json.loads(response_body)
|
||||
self.assertIsInstance(entities, list)
|
||||
self.assertEqual(2, len(entities))
|
||||
|
||||
rebuilded_server, initial_server = sorted(entities, key=lambda k: k['end'] if k['end'] is not None else '')
|
||||
|
||||
self.assertEqual(server['id'], initial_server['entity_id'])
|
||||
self.assertEqual(server['os_version'], initial_server['os']['version'])
|
||||
self.assertIsNotNone(initial_server['end'])
|
||||
self.assertEqual(server['id'], rebuilded_server['entity_id'])
|
||||
self.assertEqual(rebuild_data['version'], rebuilded_server['os']['version'])
|
||||
self.assertIsNone(rebuilded_server['end'])
|
51
almanach/tests/tempest/tests/api/test_server_resize.py
Normal file
51
almanach/tests/tempest/tests/api/test_server_resize.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.
|
||||
from uuid import uuid4
|
||||
|
||||
from almanach.tests.tempest.tests.api import base
|
||||
from oslo_serialization import jsonutils as json
|
||||
|
||||
|
||||
class TestServerResize(base.BaseAlmanachTest):
|
||||
def setUp(self):
|
||||
super(base.BaseAlmanachTest, self).setUp()
|
||||
|
||||
@classmethod
|
||||
def resource_setup(cls):
|
||||
super(TestServerResize, cls).resource_setup()
|
||||
|
||||
def test_instance_resize(self):
|
||||
tenant_id = str(uuid4())
|
||||
server = self.get_server_creation_payload()
|
||||
self.create_server_through_api(tenant_id, server)
|
||||
|
||||
resize_data = {'date': '2016-01-01T18:40:00Z',
|
||||
'flavor': 'resized_flavor'}
|
||||
serialized_data = json.dumps(resize_data)
|
||||
|
||||
self.almanach_client.resize(server['id'], serialized_data)
|
||||
|
||||
resp, response_body = self.almanach_client.get_tenant_entities(tenant_id)
|
||||
|
||||
entities = json.loads(response_body)
|
||||
self.assertIsInstance(entities, list)
|
||||
self.assertEqual(2, len(entities))
|
||||
|
||||
initial_server, resized_server = sorted(entities,
|
||||
key=lambda k: k['flavor'] if k['flavor'] == 'resized_flavor' else '')
|
||||
|
||||
self.assertEqual(server['id'], initial_server['entity_id'])
|
||||
self.assertEqual(server['flavor'], initial_server['flavor'])
|
||||
self.assertEqual(server['id'], resized_server['entity_id'])
|
||||
self.assertEqual(resize_data['flavor'], resized_server['flavor'])
|
40
almanach/tests/tempest/tests/api/test_server_update.py
Normal file
40
almanach/tests/tempest/tests/api/test_server_update.py
Normal file
@ -0,0 +1,40 @@
|
||||
# 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 almanach.tests.tempest.tests.api import base
|
||||
from oslo_serialization import jsonutils as json
|
||||
|
||||
|
||||
class TestServerUpdate(base.BaseAlmanachTest):
|
||||
def setUp(self):
|
||||
super(base.BaseAlmanachTest, self).setUp()
|
||||
|
||||
@classmethod
|
||||
def resource_setup(cls):
|
||||
super(TestServerUpdate, cls).resource_setup()
|
||||
|
||||
def test_instance_update(self):
|
||||
server = self.get_server_creation_payload()
|
||||
self.create_server_through_api(str(uuid4()), server)
|
||||
|
||||
update_field = json.dumps({'start_date': '2016-04-14T18:30:00.00Z',
|
||||
'flavor': 'NewFlavor'})
|
||||
resp, response_body = self.almanach_client.update_server(server['id'], update_field)
|
||||
|
||||
updated_server = json.loads(response_body)
|
||||
|
||||
self.assertEqual(server['id'], updated_server['entity_id'])
|
||||
self.assertEqual('2016-04-14 18:30:00+00:00', updated_server['start'])
|
||||
self.assertEqual('NewFlavor', updated_server['flavor'])
|
Loading…
x
Reference in New Issue
Block a user