Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2011 OpenStack, LLC |
| 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 | |
| 18 | """Functional test case for OpenStack Swift """ |
| 19 | |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 20 | import httplib2 |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 21 | import os |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 22 | |
| 23 | from pprint import pprint |
| 24 | |
Soren Hansen | ec3f709 | 2011-09-08 13:03:42 +0200 | [diff] [blame] | 25 | from kong import tests |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 26 | |
| 27 | SMALL_OBJ = "include/swift_objects/swift_small" |
| 28 | MED_OBJ = "include/swift_objects/swift_medium" |
| 29 | LRG_OBJ = "include/swift_objects/swift_large" |
| 30 | |
| 31 | |
| 32 | class TestSwift(tests.FunctionalTest): |
| 33 | def test_000_auth(self): |
| 34 | if self.swift['auth_ssl'] == "False": |
| 35 | prot = "http://" |
| 36 | else: |
| 37 | prot = "https://" |
| 38 | |
| 39 | path = "%s%s:%s%s%s" % (prot, self.swift['auth_host'], |
| 40 | self.swift['auth_port'], |
| 41 | self.swift['auth_prefix'], |
| 42 | self.swift['ver']) |
| 43 | |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 44 | http = httplib2.Http(disable_ssl_certificate_validation=True) |
| 45 | self.swift['auth_user'] = '%s:%s' % (self.swift['account'], |
| 46 | self.swift['username']) |
| 47 | headers = {'X-Auth-User': '%s' % (self.swift['auth_user']), |
| 48 | 'X-Auth-Key': '%s' % (self.swift['password'])} |
| 49 | response, content = http.request(path, 'GET', headers=headers) |
Justin Shepherd | 74a95b6 | 2011-08-18 11:52:02 -0500 | [diff] [blame] | 50 | self.assertEqual(response.status, 200) |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 51 | self.assertIsNotNone(response['x-auth-token']) |
| 52 | self.assertIsNotNone(response['x-storage-token']) |
| 53 | self.assertIsNotNone(response['x-storage-url']) |
| 54 | |
Justin Shepherd | 74a95b6 | 2011-08-18 11:52:02 -0500 | [diff] [blame] | 55 | # TODO: there has got to be a better way to do this (jshepher) |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 56 | for k, v in response.items(): |
| 57 | if (k == 'x-auth-token'): |
| 58 | self.swift['x-auth-token'] = v |
| 59 | if (k == 'x-storage-token'): |
| 60 | self.swift['x-storage-token'] = v |
| 61 | |
| 62 | # Since we don't have DNS this is a bit of a hack, but works |
| 63 | url = response['x-storage-url'].split('/') |
| 64 | self.swift['storage_url'] = "%s//%s:%s/%s/%s" % (url[0], |
| 65 | self.swift['auth_host'], |
| 66 | self.swift['auth_port'], |
| 67 | url[3], |
| 68 | url[4]) |
| 69 | test_000_auth.tags = ['swift'] |
| 70 | |
| 71 | def test_001_create_container(self): |
| 72 | path = "%s/%s/" % (self.swift['storage_url'], "test_container") |
| 73 | http = httplib2.Http(disable_ssl_certificate_validation=True) |
Soren Hansen | 826d5df | 2011-08-29 11:30:40 +0200 | [diff] [blame] | 74 | headers = {'X-Storage-Token': '%s' % (self.swift['x-storage-token'])} |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 75 | response, content = http.request(path, 'PUT', headers=headers) |
Justin Shepherd | 74a95b6 | 2011-08-18 11:52:02 -0500 | [diff] [blame] | 76 | self.assertEqual(response.status, 201) |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 77 | test_001_create_container.tags = ['swift'] |
| 78 | |
| 79 | def test_002_list_containers(self): |
| 80 | http = httplib2.Http(disable_ssl_certificate_validation=True) |
| 81 | headers = {'X-Auth-Token': '%s' % (self.swift['x-auth-token'])} |
| 82 | response, content = http.request(self.swift['storage_url'], 'GET', |
| 83 | headers=headers) |
Justin Shepherd | 74a95b6 | 2011-08-18 11:52:02 -0500 | [diff] [blame] | 84 | self.assertEqual(response.status, 200) |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 85 | self.assertLessEqual('1', response['x-account-container-count']) |
| 86 | test_002_list_containers.tags = ['swift'] |
| 87 | |
| 88 | def test_010_create_small_object(self): |
| 89 | md5 = self._md5sum_file(SMALL_OBJ) |
| 90 | path = "%s/%s/%s" % (self.swift['storage_url'], |
| 91 | "test_container", |
| 92 | "swift_small") |
| 93 | http = httplib2.Http(disable_ssl_certificate_validation=True) |
| 94 | headers = {'X-Auth-User': '%s:%s' % (self.swift['account'], |
| 95 | self.swift['username']), |
| 96 | 'X-Storage-Token': '%s' % (self.swift['x-storage-token']), |
| 97 | 'ETag': '%s' % (md5), |
| 98 | 'Content-Length': '%d' % os.path.getsize(SMALL_OBJ), |
| 99 | 'Content-Type': 'application/octet-stream'} |
| 100 | upload = open(SMALL_OBJ, "rb") |
| 101 | response, content = http.request(path, 'PUT', |
| 102 | headers=headers, |
| 103 | body=upload) |
Justin Shepherd | 74a95b6 | 2011-08-18 11:52:02 -0500 | [diff] [blame] | 104 | self.assertEqual(response.status, 201) |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 105 | test_010_create_small_object.tags = ['swift'] |
| 106 | |
| 107 | def test_011_create_medium_object(self): |
| 108 | md5 = self._md5sum_file(MED_OBJ) |
| 109 | path = "%s/%s/%s" % (self.swift['storage_url'], |
| 110 | "test_container", |
| 111 | "swift_medium") |
| 112 | http = httplib2.Http(disable_ssl_certificate_validation=True) |
| 113 | headers = {'X-Auth-User': '%s:%s' % (self.swift['account'], |
| 114 | self.swift['username']), |
| 115 | 'X-Storage-Token': '%s' % (self.swift['x-storage-token']), |
| 116 | 'ETag': '%s' % (md5), |
| 117 | 'Content-Length': '%d' % (os.path.getsize(MED_OBJ)), |
| 118 | 'Content-Type': 'application/octet-stream', |
| 119 | 'Content-Encoding': 'gzip'} |
| 120 | upload = "" |
| 121 | for chunk in self._read_in_chunks(MED_OBJ): |
| 122 | upload += chunk |
| 123 | response, content = http.request(path, 'PUT', |
| 124 | headers=headers, |
| 125 | body=upload) |
Justin Shepherd | 74a95b6 | 2011-08-18 11:52:02 -0500 | [diff] [blame] | 126 | self.assertEqual(response.status, 201) |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 127 | test_011_create_medium_object.tags = ['swift'] |
| 128 | |
| 129 | def test_013_get_small_object(self): |
| 130 | path = "%s/%s/%s" % (self.swift['storage_url'], |
| 131 | "test_container", |
| 132 | "swift_small") |
| 133 | http = httplib2.Http(disable_ssl_certificate_validation=True) |
| 134 | headers = {'X-Auth-User': '%s:%s' % (self.swift['account'], |
| 135 | self.swift['username']), |
| 136 | 'X-Storage-Token': '%s' % (self.swift['x-storage-token'])} |
| 137 | response, content = http.request(path, 'GET', |
| 138 | headers=headers) |
Justin Shepherd | 74a95b6 | 2011-08-18 11:52:02 -0500 | [diff] [blame] | 139 | self.assertEqual(response.status, 200) |
| 140 | self.assertEqual(response['etag'], self._md5sum_file(SMALL_OBJ)) |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 141 | test_013_get_small_object.tags = ['swift'] |
| 142 | |
| 143 | def test_017_delete_small_object(self): |
| 144 | path = "%s/%s/%s" % (self.swift['storage_url'], "test_container", |
| 145 | "swift_small") |
| 146 | http = httplib2.Http(disable_ssl_certificate_validation=True) |
| 147 | headers = {'X-Auth-User': '%s:%s' % (self.swift['account'], |
| 148 | self.swift['username']), |
| 149 | 'X-Storage-Token': '%s' % ( |
| 150 | self.swift['x-storage-token'])} |
| 151 | response, content = http.request(path, 'DELETE', headers=headers) |
Justin Shepherd | 74a95b6 | 2011-08-18 11:52:02 -0500 | [diff] [blame] | 152 | self.assertEqual(response.status, 204) |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 153 | test_017_delete_small_object.tags = ['swift'] |
| 154 | |
| 155 | def test_018_delete_medium_object(self): |
| 156 | path = "%s/%s/%s" % (self.swift['storage_url'], "test_container", |
| 157 | "swift_medium") |
| 158 | http = httplib2.Http(disable_ssl_certificate_validation=True) |
| 159 | headers = {'X-Auth-User': '%s:%s' % (self.swift['account'], |
| 160 | self.swift['username']), |
| 161 | 'X-Storage-Token': '%s' % ( |
| 162 | self.swift['x-storage-token'])} |
| 163 | response, content = http.request(path, 'DELETE', headers=headers) |
Justin Shepherd | 74a95b6 | 2011-08-18 11:52:02 -0500 | [diff] [blame] | 164 | self.assertEqual(response.status, 204) |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 165 | test_018_delete_medium_object.tags = ['swift'] |
| 166 | |
| 167 | def test_030_check_container_metadata(self): |
| 168 | path = "%s/%s" % (self.swift['storage_url'], "test_container") |
| 169 | http = httplib2.Http(disable_ssl_certificate_validation=True) |
| 170 | headers = {'X-Auth-User': '%s:%s' % (self.swift['account'], |
| 171 | self.swift['username']), |
| 172 | 'X-Storage-Token': '%s' % (self.swift['x-storage-token'])} |
| 173 | response, content = http.request(path, 'HEAD', headers=headers) |
Justin Shepherd | 74a95b6 | 2011-08-18 11:52:02 -0500 | [diff] [blame] | 174 | self.assertEqual(response.status, 204) |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 175 | test_030_check_container_metadata.tags = ['swift'] |
| 176 | |
| 177 | def test_050_delete_container(self): |
| 178 | path = "%s/%s" % (self.swift['storage_url'], "test_container") |
| 179 | http = httplib2.Http(disable_ssl_certificate_validation=True) |
| 180 | headers = {'X-Auth-User': '%s:%s' % (self.swift['account'], |
| 181 | self.swift['username']), |
| 182 | 'X-Storage-Token': '%s' % (self.swift['x-storage-token'])} |
| 183 | response, content = http.request(path, 'DELETE', headers=headers) |
Justin Shepherd | 74a95b6 | 2011-08-18 11:52:02 -0500 | [diff] [blame] | 184 | self.assertEqual(response.status, 204) |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 185 | test_050_delete_container.tags = ['swift'] |