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