ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 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 | |
Monty Taylor | b2ca5ca | 2013-04-28 18:00:21 -0700 | [diff] [blame] | 16 | import contextlib |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 17 | |
Monty Taylor | b2ca5ca | 2013-04-28 18:00:21 -0700 | [diff] [blame] | 18 | import boto.s3.key |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 19 | |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 20 | from tempest.common.utils import data_utils |
Masayuki Igawa | 224a827 | 2014-02-17 15:07:43 +0900 | [diff] [blame] | 21 | from tempest.thirdparty.boto import test as boto_test |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 22 | |
| 23 | |
Masayuki Igawa | 224a827 | 2014-02-17 15:07:43 +0900 | [diff] [blame] | 24 | class S3BucketsTest(boto_test.BotoTestCase): |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 25 | |
| 26 | @classmethod |
Andrea Frittoli | 29fea35 | 2014-09-15 13:31:14 +0100 | [diff] [blame] | 27 | def resource_setup(cls): |
| 28 | super(S3BucketsTest, cls).resource_setup() |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 29 | cls.client = cls.os.s3_client |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 30 | |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 31 | def test_create_get_delete_object(self): |
Sean Dague | 64ef48d | 2013-01-03 17:54:36 -0500 | [diff] [blame] | 32 | # S3 Create, get and delete object |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 33 | bucket_name = data_utils.rand_name("s3bucket-") |
| 34 | object_name = data_utils.rand_name("s3object-") |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 35 | 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 Taylor | b2ca5ca | 2013-04-28 18:00:21 -0700 | [diff] [blame] | 42 | with contextlib.closing(boto.s3.key.Key(bucket)) as key: |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 43 | 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) |