blob: 43774c219fee9ff52161776bf8b8d3eecf47bd5f [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Attila Fazekasa23f5002012-10-23 19:32:45 +02002# 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
Monty Taylorb2ca5ca2013-04-28 18:00:21 -070016import contextlib
Matthew Treinisha83a16e2012-12-07 13:44:02 -050017
Monty Taylorb2ca5ca2013-04-28 18:00:21 -070018import boto.s3.key
Matthew Treinisha83a16e2012-12-07 13:44:02 -050019
Masayuki Igawa259c1132013-10-31 17:48:44 +090020from tempest.common.utils import data_utils
Masayuki Igawa224a8272014-02-17 15:07:43 +090021from tempest.thirdparty.boto import test as boto_test
Attila Fazekasa23f5002012-10-23 19:32:45 +020022
23
Masayuki Igawa224a8272014-02-17 15:07:43 +090024class S3BucketsTest(boto_test.BotoTestCase):
Attila Fazekasa23f5002012-10-23 19:32:45 +020025
26 @classmethod
Andrea Frittoli29fea352014-09-15 13:31:14 +010027 def resource_setup(cls):
28 super(S3BucketsTest, cls).resource_setup()
Attila Fazekasa23f5002012-10-23 19:32:45 +020029 cls.client = cls.os.s3_client
Attila Fazekasa23f5002012-10-23 19:32:45 +020030
Attila Fazekasa23f5002012-10-23 19:32:45 +020031 def test_create_get_delete_object(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050032 # S3 Create, get and delete object
Masayuki Igawa259c1132013-10-31 17:48:44 +090033 bucket_name = data_utils.rand_name("s3bucket-")
34 object_name = data_utils.rand_name("s3object-")
Attila Fazekasa23f5002012-10-23 19:32:45 +020035 content = 'x' * 42
36 bucket = self.client.create_bucket(bucket_name)
37 self.addResourceCleanUp(self.destroy_bucket,
38 self.client.connection_data,
39 bucket_name)
40
41 self.assertTrue(bucket.name == bucket_name)
Monty Taylorb2ca5ca2013-04-28 18:00:21 -070042 with contextlib.closing(boto.s3.key.Key(bucket)) as key:
Attila Fazekasa23f5002012-10-23 19:32:45 +020043 key.key = object_name
44 key.set_contents_from_string(content)
45 readback = key.get_contents_as_string()
46 self.assertTrue(readback == content)
47 bucket.delete_key(key)
48 self.assertBotoError(self.s3_error_code.client.NoSuchKey,
49 key.get_contents_as_string)