Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 3 | # Copyright 2012 OpenStack Foundation |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 4 | # 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 Taylor | b2ca5ca | 2013-04-28 18:00:21 -0700 | [diff] [blame] | 18 | import contextlib |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 19 | |
Monty Taylor | b2ca5ca | 2013-04-28 18:00:21 -0700 | [diff] [blame] | 20 | import boto.s3.key |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 21 | |
Matthew Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 22 | from tempest import clients |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 23 | from tempest.common.utils.data_utils import rand_name |
Chris Yeoh | 01cb279 | 2013-02-09 22:25:37 +1030 | [diff] [blame] | 24 | from tempest.test import attr |
Sean Dague | 09761f6 | 2013-05-13 15:20:40 -0400 | [diff] [blame] | 25 | from tempest.thirdparty.boto.test import BotoTestCase |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 26 | |
| 27 | |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 28 | class S3BucketsTest(BotoTestCase): |
| 29 | |
| 30 | @classmethod |
| 31 | def setUpClass(cls): |
| 32 | super(S3BucketsTest, cls).setUpClass() |
Matthew Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 33 | cls.os = clients.Manager() |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 34 | cls.client = cls.os.s3_client |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 35 | |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 36 | @attr(type='smoke') |
| 37 | def test_create_get_delete_object(self): |
Sean Dague | 64ef48d | 2013-01-03 17:54:36 -0500 | [diff] [blame] | 38 | # S3 Create, get and delete object |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 39 | 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 Taylor | b2ca5ca | 2013-04-28 18:00:21 -0700 | [diff] [blame] | 48 | with contextlib.closing(boto.s3.key.Key(bucket)) as key: |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 49 | 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) |