blob: 86e0867ac9fbe976db84b628b13a72621ee9b2f5 [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
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090017from tempest.common.utils import data_utils
Matthew Treinish6c072292014-01-29 19:15:52 +000018from tempest import config
Mauro S. M. Rodriguese86ed042013-12-12 18:56:00 +000019from tempest.openstack.common import log as logging
20from tempest.scenario import manager
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090021from tempest import test
Mauro S. M. Rodriguese86ed042013-12-12 18:56:00 +000022
Matthew Treinish6c072292014-01-29 19:15:52 +000023CONF = config.CONF
24
Mauro S. M. Rodriguese86ed042013-12-12 18:56:00 +000025LOG = logging.getLogger(__name__)
26
27
28class TestSwiftBasicOps(manager.OfficialClientTest):
29 """
30 Test swift with the follow operations:
31 * get swift stat.
32 * create container.
33 * upload a file to the created container.
34 * list container's objects and assure that the uploaded file is present.
35 * delete object from container.
36 * list container's objects and assure that the deleted file is gone.
37 * delete a container.
38 * list containers and assure that the deleted container is gone.
39 """
40
41 @classmethod
42 def setUpClass(cls):
Sylvain Afchain92064772014-01-16 02:45:57 +010043 cls.set_network_resources()
Mauro S. M. Rodriguese86ed042013-12-12 18:56:00 +000044 super(TestSwiftBasicOps, cls).setUpClass()
Matthew Treinish6c072292014-01-29 19:15:52 +000045 if not CONF.service_available.swift:
Mauro S. M. Rodriguese86ed042013-12-12 18:56:00 +000046 skip_msg = ("%s skipped as swift is not available" %
47 cls.__name__)
48 raise cls.skipException(skip_msg)
49
50 def _get_swift_stat(self):
51 """get swift status for our user account."""
52 self.object_storage_client.get_account()
53 LOG.debug('Swift status information obtained successfully')
54
55 def _create_container(self, container_name=None):
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090056 name = container_name or data_utils.rand_name(
57 'swift-scenario-container')
Mauro S. M. Rodriguese86ed042013-12-12 18:56:00 +000058 self.object_storage_client.put_container(name)
59 # look for the container to assure it is created
60 self._list_and_check_container_objects(name)
61 LOG.debug('Container %s created' % (name))
62 return name
63
64 def _delete_container(self, container_name):
65 self.object_storage_client.delete_container(container_name)
66 LOG.debug('Container %s deleted' % (container_name))
67
68 def _upload_object_to_container(self, container_name, obj_name=None):
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090069 obj_name = obj_name or data_utils.rand_name('swift-scenario-object')
Mauro S. M. Rodriguese86ed042013-12-12 18:56:00 +000070 self.object_storage_client.put_object(container_name, obj_name,
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090071 data_utils.rand_name('obj_data'),
Mauro S. M. Rodriguese86ed042013-12-12 18:56:00 +000072 content_type='text/plain')
73 return obj_name
74
75 def _delete_object(self, container_name, filename):
76 self.object_storage_client.delete_object(container_name, filename)
77 self._list_and_check_container_objects(container_name,
78 not_present_obj=[filename])
79
80 def _list_and_check_container_objects(self, container_name, present_obj=[],
81 not_present_obj=[]):
82 """
83 List objects for a given container and assert which are present and
84 which are not.
85 """
86 meta, response = self.object_storage_client.get_container(
87 container_name)
88 # create a list with file name only
89 object_list = [obj['name'] for obj in response]
90 if present_obj:
91 for obj in present_obj:
92 self.assertIn(obj, object_list)
93 if not_present_obj:
94 for obj in not_present_obj:
95 self.assertNotIn(obj, object_list)
96
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090097 @test.services('object_storage')
Mauro S. M. Rodriguese86ed042013-12-12 18:56:00 +000098 def test_swift_basic_ops(self):
99 self._get_swift_stat()
100 container_name = self._create_container()
101 obj_name = self._upload_object_to_container(container_name)
102 self._list_and_check_container_objects(container_name, [obj_name])
103 self._delete_object(container_name, obj_name)
104 self._delete_container(container_name)