root / snf-tools / synnefo_tools / burnin / pithos_tests.py @ 6a6aba0b
History | View | Annotate | Download (10.5 kB)
1 |
# Copyright 2013 GRNET S.A. All rights reserved.
|
---|---|
2 |
#
|
3 |
# Redistribution and use in source and binary forms, with or
|
4 |
# without modification, are permitted provided that the following
|
5 |
# conditions are met:
|
6 |
#
|
7 |
# 1. Redistributions of source code must retain the above
|
8 |
# copyright notice, this list of conditions and the following
|
9 |
# disclaimer.
|
10 |
#
|
11 |
# 2. Redistributions in binary form must reproduce the above
|
12 |
# copyright notice, this list of conditions and the following
|
13 |
# disclaimer in the documentation and/or other materials
|
14 |
# provided with the distribution.
|
15 |
#
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 |
# POSSIBILITY OF SUCH DAMAGE.
|
28 |
#
|
29 |
# The views and conclusions contained in the software and
|
30 |
# documentation are those of the authors and should not be
|
31 |
# interpreted as representing official policies, either expressed
|
32 |
# or implied, of GRNET S.A.
|
33 |
|
34 |
"""
|
35 |
This is the burnin class that tests the Pithos functionality
|
36 |
|
37 |
"""
|
38 |
|
39 |
import os |
40 |
import random |
41 |
import tempfile |
42 |
from datetime import datetime |
43 |
|
44 |
from synnefo_tools.burnin.common import BurninTests, Proper |
45 |
from kamaki.clients import ClientError |
46 |
|
47 |
|
48 |
# Too many public methods. pylint: disable-msg=R0904
|
49 |
class PithosTestSuite(BurninTests): |
50 |
"""Test Pithos functionality"""
|
51 |
containers = Proper(value=None)
|
52 |
created_container = Proper(value=None)
|
53 |
now_unformated = Proper(value=datetime.utcnow()) |
54 |
|
55 |
def test_005_account_head(self): |
56 |
"""HEAD on pithos account"""
|
57 |
self._set_pithos_account(self._get_uuid()) |
58 |
pithos = self.clients.pithos
|
59 |
r = pithos.account_head() |
60 |
self.assertEqual(r.status_code, 204) |
61 |
self.info('Returns 204') |
62 |
|
63 |
r = pithos.account_head(until='1000000000')
|
64 |
self.assertEqual(r.status_code, 204) |
65 |
datestring = unicode(r.headers['x-account-until-timestamp']) |
66 |
self.assertEqual(u'Sun, 09 Sep 2001 01:46:40 GMT', datestring) |
67 |
self.assertTrue('x-account-policy-quota' in r.headers) |
68 |
self.info('Until and policy quota exist') |
69 |
|
70 |
for format in pithos.DATE_FORMATS: |
71 |
now_formated = self.now_unformated.strftime(format)
|
72 |
r1 = pithos.account_head( |
73 |
if_modified_since=now_formated, success=(204, 304, 412)) |
74 |
r2 = pithos.account_head( |
75 |
if_unmodified_since=now_formated, success=(204, 304, 412)) |
76 |
self.assertNotEqual(r1.status_code, r2.status_code)
|
77 |
self.info('If_(un)modified_since is OK') |
78 |
|
79 |
def test_010_account_get(self): |
80 |
"""Test account_get"""
|
81 |
self.info('Preparation') |
82 |
pithos = self.clients.pithos
|
83 |
for i in range(1, 3): |
84 |
cont_name = "cont%s_%s%s" % (
|
85 |
i, self.run_id, random.randint(1000, 9999)) |
86 |
self._create_pithos_container(cont_name)
|
87 |
pithos.container, obj = cont_name, 'shared_file'
|
88 |
pithos.create_object(obj) |
89 |
pithos.set_object_sharing(obj, read_permission='*')
|
90 |
self.info('Created object /%s/%s' % (cont_name, obj)) |
91 |
|
92 |
r = pithos.list_containers() |
93 |
fullLen = len(r)
|
94 |
self.assertTrue(fullLen > 2) |
95 |
self.info('Normal use is OK') |
96 |
|
97 |
r = pithos.account_get(limit=1)
|
98 |
self.assertEqual(len(r.json), 1) |
99 |
self.info('Limit works') |
100 |
|
101 |
r = pithos.account_get(marker='cont')
|
102 |
cont1, cont3 = r.json[0], r.json[2] |
103 |
self.info('Marker works') |
104 |
|
105 |
r = pithos.account_get(limit=2, marker='cont') |
106 |
conames = [container['name'] for container in r.json if ( |
107 |
container['name'].lower().startswith('cont'))] |
108 |
self.assertTrue(cont1['name'] in conames) |
109 |
self.assertFalse(cont3['name'] in conames) |
110 |
self.info('Marker-limit combination works') |
111 |
|
112 |
r = pithos.account_get(show_only_shared=True)
|
113 |
self.assertTrue(cont_name in [c['name'] for c in r.json]) |
114 |
self.info('Show-only-shared works') |
115 |
|
116 |
r = pithos.account_get(until=1342609206.0)
|
117 |
self.assertTrue(len(r.json) <= fullLen) |
118 |
self.info('Until works') |
119 |
|
120 |
for format in pithos.DATE_FORMATS: |
121 |
now_formated = self.now_unformated.strftime(format)
|
122 |
r1 = pithos.account_get( |
123 |
if_modified_since=now_formated, success=(200, 304, 412)) |
124 |
r2 = pithos.account_get( |
125 |
if_unmodified_since=now_formated, success=(200, 304, 412)) |
126 |
self.assertNotEqual(r1.status_code, r2.status_code)
|
127 |
self.info('If_(un)modified_since is OK') |
128 |
|
129 |
def test_015_account_post(self): |
130 |
"""Test account_post"""
|
131 |
pithos = self.clients.pithos
|
132 |
r = pithos.account_post() |
133 |
self.assertEqual(r.status_code, 202) |
134 |
self.info('Status code is OK') |
135 |
|
136 |
rand_num = '%s%s' % (self.run_id or 0, random.randint(1000, 9999)) |
137 |
grpName = 'grp%s' % rand_num
|
138 |
|
139 |
u1, u2 = pithos.account, 'invalid-user-uuid-%s' % rand_num
|
140 |
self.assertRaises(
|
141 |
ClientError, pithos.set_account_group, grpName, [u1, u2]) |
142 |
self.info('Invalid uuid is handled correctly') |
143 |
|
144 |
pithos.set_account_group(grpName, [u1]) |
145 |
r = pithos.get_account_group() |
146 |
self.assertEqual(r['x-account-group-' + grpName], '%s' % u1) |
147 |
self.info('Account group is OK') |
148 |
pithos.del_account_group(grpName) |
149 |
r = pithos.get_account_group() |
150 |
self.assertTrue('x-account-group-' + grpName not in r) |
151 |
self.info('Removed account group') |
152 |
|
153 |
mprefix = 'meta%s' % rand_num
|
154 |
pithos.set_account_meta({ |
155 |
mprefix + '1': 'v1', mprefix + '2': 'v2'}) |
156 |
r = pithos.get_account_meta() |
157 |
self.assertEqual(r['x-account-meta-' + mprefix + '1'], 'v1') |
158 |
self.assertEqual(r['x-account-meta-' + mprefix + '2'], 'v2') |
159 |
self.info('Account meta is OK') |
160 |
|
161 |
pithos.del_account_meta(mprefix + '1')
|
162 |
r = pithos.get_account_meta() |
163 |
self.assertTrue('x-account-meta-' + mprefix + '1' not in r) |
164 |
self.assertTrue('x-account-meta-' + mprefix + '2' in r) |
165 |
self.info('Selective removal of account meta is OK') |
166 |
|
167 |
pithos.del_account_meta(mprefix + '2')
|
168 |
r = pithos.get_account_meta() |
169 |
self.assertTrue('x-account-meta-' + mprefix + '2' not in r) |
170 |
self.info('Temporary account meta are removed') |
171 |
|
172 |
# def test_050_stop_test(self):
|
173 |
# """STOP TESTING ALREADY"""
|
174 |
# self.assertTrue(False)
|
175 |
|
176 |
def test_051_list_containers(self): |
177 |
"""Test container list actually returns containers"""
|
178 |
self.containers = self._get_list_of_containers() |
179 |
self.assertGreater(len(self.containers), 0) |
180 |
self.lala = 1 |
181 |
|
182 |
def test_052_unique_containers(self): |
183 |
"""Test if containers have unique names"""
|
184 |
names = [n['name'] for n in self.containers] |
185 |
names = sorted(names)
|
186 |
self.assertEqual(sorted(list(set(names))), names) |
187 |
|
188 |
def test_053_create_container(self): |
189 |
"""Test creating a new container"""
|
190 |
names = [n['name'] for n in self.containers] |
191 |
while True: |
192 |
rand_num = random.randint(1000, 9999) |
193 |
rand_name = "%s%s" % (self.run_id, rand_num) |
194 |
self.info("Trying container name %s", rand_name) |
195 |
if rand_name not in names: |
196 |
break
|
197 |
self.info("Container name %s already exists", rand_name) |
198 |
# Create container
|
199 |
self._create_pithos_container(rand_name)
|
200 |
# Verify that container is created
|
201 |
containers = self._get_list_of_containers()
|
202 |
self.info("Verify that container %s is created", rand_name) |
203 |
names = [n['name'] for n in containers] |
204 |
self.assertIn(rand_name, names)
|
205 |
# Keep the name of the container so we can remove it
|
206 |
# at cleanup phase, if something goes wrong.
|
207 |
self.created_container = rand_name
|
208 |
|
209 |
def test_054_upload_file(self): |
210 |
"""Test uploading a txt file to Pithos"""
|
211 |
# Create a tmp file
|
212 |
with tempfile.TemporaryFile(dir=self.temp_directory) as fout: |
213 |
fout.write("This is a temp file")
|
214 |
fout.seek(0, 0) |
215 |
# Upload the file,
|
216 |
# The container is the one choosen during the `create_container'
|
217 |
self.clients.pithos.upload_object("test.txt", fout) |
218 |
# Verify quotas
|
219 |
self._check_quotas(diskspace=+os.fstat(fout.fileno()).st_size)
|
220 |
|
221 |
def test_055_download_file(self): |
222 |
"""Test downloading the file from Pithos"""
|
223 |
# Create a tmp directory to save the file
|
224 |
with tempfile.TemporaryFile(dir=self.temp_directory) as fout: |
225 |
self.clients.pithos.download_object("test.txt", fout) |
226 |
# Now read the file
|
227 |
fout.seek(0, 0) |
228 |
contents = fout.read() |
229 |
# Compare results
|
230 |
self.info("Comparing contents with the uploaded file") |
231 |
self.assertEqual(contents, "This is a temp file") |
232 |
|
233 |
def test_056_remove(self): |
234 |
"""Test removing files and containers from Pithos"""
|
235 |
self.info("Removing the file %s from container %s", |
236 |
"test.txt", self.created_container) |
237 |
# The container is the one choosen during the `create_container'
|
238 |
content_length = \ |
239 |
self.clients.pithos.get_object_info("test.txt")['content-length'] |
240 |
self.clients.pithos.del_object("test.txt") |
241 |
|
242 |
# Verify quotas
|
243 |
self._check_quotas(diskspace=-int(content_length)) |
244 |
|
245 |
self.info("Removing the container %s", self.created_container) |
246 |
self.clients.pithos.purge_container()
|
247 |
|
248 |
# List containers
|
249 |
containers = self._get_list_of_containers()
|
250 |
self.info("Check that the container %s has been deleted", |
251 |
self.created_container)
|
252 |
names = [n['name'] for n in containers] |
253 |
self.assertNotIn(self.created_container, names) |
254 |
# We successfully deleted our container, no need to do it
|
255 |
# in our clean up phase
|
256 |
self.created_container = None |
257 |
|
258 |
@classmethod
|
259 |
def tearDownClass(cls): # noqa |
260 |
"""Clean up"""
|
261 |
if cls.created_container is not None: |
262 |
cls.clients.pithos.del_container(delimiter='/')
|
263 |
cls.clients.pithos.purge_container() |