blob: c42d85c4a4215ec0f7e294993bde7099c90447f2 [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
Fei Long Wangd39431f2015-05-14 11:30:48 +120020from tempest.common.utils import data_utils
Chris Hoge7579c1a2015-02-26 14:12:15 -080021from tempest import test
Masayuki Igawa224a8272014-02-17 15:07:43 +090022from tempest.thirdparty.boto import test as boto_test
Attila Fazekasa23f5002012-10-23 19:32:45 +020023
24
Masayuki Igawa224a8272014-02-17 15:07:43 +090025class S3BucketsTest(boto_test.BotoTestCase):
Attila Fazekasa23f5002012-10-23 19:32:45 +020026
27 @classmethod
Emily Hugenbruche252a4a2015-02-27 15:43:12 +000028 def setup_clients(cls):
29 super(S3BucketsTest, cls).setup_clients()
Attila Fazekasa23f5002012-10-23 19:32:45 +020030 cls.client = cls.os.s3_client
Attila Fazekasa23f5002012-10-23 19:32:45 +020031
Chris Hoge7579c1a2015-02-26 14:12:15 -080032 @test.idempotent_id('4eea567a-b46a-405b-a475-6097e1faebde')
Attila Fazekasa23f5002012-10-23 19:32:45 +020033 def test_create_get_delete_object(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050034 # S3 Create, get and delete object
Ken'ichi Ohmichia498b1d2015-03-23 01:56:52 +000035 bucket_name = data_utils.rand_name("s3bucket")
36 object_name = data_utils.rand_name("s3object")
Attila Fazekasa23f5002012-10-23 19:32:45 +020037 content = 'x' * 42
38 bucket = self.client.create_bucket(bucket_name)
39 self.addResourceCleanUp(self.destroy_bucket,
40 self.client.connection_data,
41 bucket_name)
42
43 self.assertTrue(bucket.name == bucket_name)
Monty Taylorb2ca5ca2013-04-28 18:00:21 -070044 with contextlib.closing(boto.s3.key.Key(bucket)) as key:
Attila Fazekasa23f5002012-10-23 19:32:45 +020045 key.key = object_name
46 key.set_contents_from_string(content)
47 readback = key.get_contents_as_string()
48 self.assertTrue(readback == content)
49 bucket.delete_key(key)
50 self.assertBotoError(self.s3_error_code.client.NoSuchKey,
51 key.get_contents_as_string)