blob: 188d1dbd0cf0a59889dbc5f14b19d564f04dcf5e [file] [log] [blame]
Attila Fazekasa23f5002012-10-23 19:32:45 +02001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2012 OpenStack Foundation
Attila Fazekasa23f5002012-10-23 19:32:45 +02004# 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
Monty Taylorb2ca5ca2013-04-28 18:00:21 -070018import contextlib
Matthew Treinisha83a16e2012-12-07 13:44:02 -050019
Monty Taylorb2ca5ca2013-04-28 18:00:21 -070020import boto.s3.key
Matthew Treinisha83a16e2012-12-07 13:44:02 -050021
Matthew Treinish481466b2012-12-20 17:16:01 -050022from tempest import clients
Attila Fazekasa23f5002012-10-23 19:32:45 +020023from tempest.common.utils.data_utils import rand_name
Chris Yeoh01cb2792013-02-09 22:25:37 +103024from tempest.test import attr
Sean Dague09761f62013-05-13 15:20:40 -040025from tempest.thirdparty.boto.test import BotoTestCase
Attila Fazekasa23f5002012-10-23 19:32:45 +020026
27
Attila Fazekasa23f5002012-10-23 19:32:45 +020028class S3BucketsTest(BotoTestCase):
29
30 @classmethod
31 def setUpClass(cls):
32 super(S3BucketsTest, cls).setUpClass()
Matthew Treinish481466b2012-12-20 17:16:01 -050033 cls.os = clients.Manager()
Attila Fazekasa23f5002012-10-23 19:32:45 +020034 cls.client = cls.os.s3_client
Attila Fazekasa23f5002012-10-23 19:32:45 +020035
Attila Fazekasa23f5002012-10-23 19:32:45 +020036 @attr(type='smoke')
37 def test_create_get_delete_object(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050038 # S3 Create, get and delete object
Attila Fazekasa23f5002012-10-23 19:32:45 +020039 bucket_name = rand_name("s3bucket-")
40 object_name = rand_name("s3object-")
41 content = 'x' * 42
42 bucket = self.client.create_bucket(bucket_name)
43 self.addResourceCleanUp(self.destroy_bucket,
44 self.client.connection_data,
45 bucket_name)
46
47 self.assertTrue(bucket.name == bucket_name)
Monty Taylorb2ca5ca2013-04-28 18:00:21 -070048 with contextlib.closing(boto.s3.key.Key(bucket)) as key:
Attila Fazekasa23f5002012-10-23 19:32:45 +020049 key.key = object_name
50 key.set_contents_from_string(content)
51 readback = key.get_contents_as_string()
52 self.assertTrue(readback == content)
53 bucket.delete_key(key)
54 self.assertBotoError(self.s3_error_code.client.NoSuchKey,
55 key.get_contents_as_string)