Mauro S. M. Rodrigues | e86ed04 | 2013-12-12 18:56:00 +0000 | [diff] [blame^] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2013 IBM Corp. |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
| 18 | |
| 19 | from tempest.common.utils.data_utils import rand_name |
| 20 | from tempest.openstack.common import log as logging |
| 21 | from tempest.scenario import manager |
| 22 | from tempest.test import services |
| 23 | |
| 24 | LOG = logging.getLogger(__name__) |
| 25 | |
| 26 | |
| 27 | class TestSwiftBasicOps(manager.OfficialClientTest): |
| 28 | """ |
| 29 | Test swift with the follow operations: |
| 30 | * get swift stat. |
| 31 | * create container. |
| 32 | * upload a file to the created container. |
| 33 | * list container's objects and assure that the uploaded file is present. |
| 34 | * delete object from container. |
| 35 | * list container's objects and assure that the deleted file is gone. |
| 36 | * delete a container. |
| 37 | * list containers and assure that the deleted container is gone. |
| 38 | """ |
| 39 | |
| 40 | @classmethod |
| 41 | def setUpClass(cls): |
| 42 | super(TestSwiftBasicOps, cls).setUpClass() |
| 43 | if not cls.config.service_available.swift: |
| 44 | skip_msg = ("%s skipped as swift is not available" % |
| 45 | cls.__name__) |
| 46 | raise cls.skipException(skip_msg) |
| 47 | |
| 48 | def _get_swift_stat(self): |
| 49 | """get swift status for our user account.""" |
| 50 | self.object_storage_client.get_account() |
| 51 | LOG.debug('Swift status information obtained successfully') |
| 52 | |
| 53 | def _create_container(self, container_name=None): |
| 54 | name = container_name or rand_name('swift-scenario-container') |
| 55 | self.object_storage_client.put_container(name) |
| 56 | # look for the container to assure it is created |
| 57 | self._list_and_check_container_objects(name) |
| 58 | LOG.debug('Container %s created' % (name)) |
| 59 | return name |
| 60 | |
| 61 | def _delete_container(self, container_name): |
| 62 | self.object_storage_client.delete_container(container_name) |
| 63 | LOG.debug('Container %s deleted' % (container_name)) |
| 64 | |
| 65 | def _upload_object_to_container(self, container_name, obj_name=None): |
| 66 | obj_name = obj_name or rand_name('swift-scenario-object') |
| 67 | self.object_storage_client.put_object(container_name, obj_name, |
| 68 | rand_name('obj_data'), |
| 69 | content_type='text/plain') |
| 70 | return obj_name |
| 71 | |
| 72 | def _delete_object(self, container_name, filename): |
| 73 | self.object_storage_client.delete_object(container_name, filename) |
| 74 | self._list_and_check_container_objects(container_name, |
| 75 | not_present_obj=[filename]) |
| 76 | |
| 77 | def _list_and_check_container_objects(self, container_name, present_obj=[], |
| 78 | not_present_obj=[]): |
| 79 | """ |
| 80 | List objects for a given container and assert which are present and |
| 81 | which are not. |
| 82 | """ |
| 83 | meta, response = self.object_storage_client.get_container( |
| 84 | container_name) |
| 85 | # create a list with file name only |
| 86 | object_list = [obj['name'] for obj in response] |
| 87 | if present_obj: |
| 88 | for obj in present_obj: |
| 89 | self.assertIn(obj, object_list) |
| 90 | if not_present_obj: |
| 91 | for obj in not_present_obj: |
| 92 | self.assertNotIn(obj, object_list) |
| 93 | |
| 94 | @services('object') |
| 95 | def test_swift_basic_ops(self): |
| 96 | self._get_swift_stat() |
| 97 | container_name = self._create_container() |
| 98 | obj_name = self._upload_object_to_container(container_name) |
| 99 | self._list_and_check_container_objects(container_name, [obj_name]) |
| 100 | self._delete_object(container_name, obj_name) |
| 101 | self._delete_container(container_name) |