root / snf-tools / synnefo_tools / burnin / pithos_tests.py @ 5d9987a5
History | View | Annotate | Download (8.7 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 |
|
46 |
|
47 |
# Too many public methods. pylint: disable-msg=R0904
|
48 |
class PithosTestSuite(BurninTests): |
49 |
"""Test Pithos functionality"""
|
50 |
containers = Proper(value=None)
|
51 |
created_container = Proper(value=None)
|
52 |
now_unformated = Proper(value=datetime.utcnow()) |
53 |
|
54 |
def test_005_account_head(self): |
55 |
"""HEAD on pithos account"""
|
56 |
self._set_pithos_account(self._get_uuid()) |
57 |
pithos = self.clients.pithos
|
58 |
r = pithos.account_head() |
59 |
self.assertEqual(r.status_code, 204) |
60 |
self.info('Returns 204') |
61 |
|
62 |
r = pithos.account_head(until='1000000000')
|
63 |
self.assertEqual(r.status_code, 204) |
64 |
datestring = unicode(r.headers['x-account-until-timestamp']) |
65 |
self.assertEqual(u'Sun, 09 Sep 2001 01:46:40 GMT', datestring) |
66 |
self.assertTrue('x-account-policy-quota' in r.headers) |
67 |
self.info('Until and policy quota exist') |
68 |
|
69 |
for format in pithos.DATE_FORMATS: |
70 |
now_formated = self.now_unformated.strftime(format)
|
71 |
r1 = pithos.account_head( |
72 |
if_modified_since=now_formated, success=(204, 304, 412)) |
73 |
r2 = pithos.account_head( |
74 |
if_unmodified_since=now_formated, success=(204, 304, 412)) |
75 |
self.assertNotEqual(r1.status_code, r2.status_code)
|
76 |
self.info('If_(un)modified_since is OK') |
77 |
|
78 |
def test_010_account_get(self): |
79 |
"""Test account_get"""
|
80 |
self.info('Preparation') |
81 |
pithos = self.clients.pithos
|
82 |
for i in range(1, 3): |
83 |
cont_name = "cont%s_%s%s" % (
|
84 |
i, self.run_id, random.randint(1000, 9999)) |
85 |
self._create_pithos_container(cont_name)
|
86 |
pithos.container, obj = cont_name, 'shared_file'
|
87 |
pithos.create_object(obj) |
88 |
pithos.set_object_sharing(obj, read_permission='*')
|
89 |
self.info('Created object /%s/%s' % (cont_name, obj)) |
90 |
|
91 |
r = pithos.list_containers() |
92 |
fullLen = len(r)
|
93 |
self.assertTrue(fullLen > 2) |
94 |
self.info('Normal use is OK') |
95 |
|
96 |
r = pithos.account_get(limit=1)
|
97 |
self.assertEqual(len(r.json), 1) |
98 |
self.info('Limit works') |
99 |
|
100 |
r = pithos.account_get(marker='cont')
|
101 |
cont1, cont3 = r.json[0], r.json[2] |
102 |
self.info('Marker works') |
103 |
|
104 |
r = pithos.account_get(limit=2, marker='cont') |
105 |
conames = [container['name'] for container in r.json if ( |
106 |
container['name'].lower().startswith('cont'))] |
107 |
self.assertTrue(cont1['name'] in conames) |
108 |
self.assertFalse(cont3['name'] in conames) |
109 |
self.info('Marker-limit combination works') |
110 |
|
111 |
r = pithos.account_get(show_only_shared=True)
|
112 |
self.assertTrue(cont_name in [c['name'] for c in r.json]) |
113 |
self.info('Show-only-shared works') |
114 |
|
115 |
r = pithos.account_get(until=1342609206.0)
|
116 |
self.assertTrue(len(r.json) <= fullLen) |
117 |
self.info('Until works') |
118 |
|
119 |
for format in pithos.DATE_FORMATS: |
120 |
now_formated = self.now_unformated.strftime(format)
|
121 |
r1 = pithos.account_get( |
122 |
if_modified_since=now_formated, success=(200, 304, 412)) |
123 |
r2 = pithos.account_get( |
124 |
if_unmodified_since=now_formated, success=(200, 304, 412)) |
125 |
self.assertNotEqual(r1.status_code, r2.status_code)
|
126 |
self.info('If_(un)modified_since is OK') |
127 |
|
128 |
def test_051_list_containers(self): |
129 |
"""Test container list actually returns containers"""
|
130 |
#self.assertTrue(False) # This is a stoper!
|
131 |
self.containers = self._get_list_of_containers() |
132 |
self.assertGreater(len(self.containers), 0) |
133 |
self.lala = 1 |
134 |
|
135 |
def test_052_unique_containers(self): |
136 |
"""Test if containers have unique names"""
|
137 |
names = [n['name'] for n in self.containers] |
138 |
names = sorted(names)
|
139 |
self.assertEqual(sorted(list(set(names))), names) |
140 |
|
141 |
def test_053_create_container(self): |
142 |
"""Test creating a new container"""
|
143 |
names = [n['name'] for n in self.containers] |
144 |
while True: |
145 |
rand_num = random.randint(1000, 9999) |
146 |
rand_name = "%s%s" % (self.run_id, rand_num) |
147 |
self.info("Trying container name %s", rand_name) |
148 |
if rand_name not in names: |
149 |
break
|
150 |
self.info("Container name %s already exists", rand_name) |
151 |
# Create container
|
152 |
self._create_pithos_container(rand_name)
|
153 |
# Verify that container is created
|
154 |
containers = self._get_list_of_containers()
|
155 |
self.info("Verify that container %s is created", rand_name) |
156 |
names = [n['name'] for n in containers] |
157 |
self.assertIn(rand_name, names)
|
158 |
# Keep the name of the container so we can remove it
|
159 |
# at cleanup phase, if something goes wrong.
|
160 |
self.created_container = rand_name
|
161 |
|
162 |
def test_054_upload_file(self): |
163 |
"""Test uploading a txt file to Pithos"""
|
164 |
# Create a tmp file
|
165 |
with tempfile.TemporaryFile(dir=self.temp_directory) as fout: |
166 |
fout.write("This is a temp file")
|
167 |
fout.seek(0, 0) |
168 |
# Upload the file,
|
169 |
# The container is the one choosen during the `create_container'
|
170 |
self.clients.pithos.upload_object("test.txt", fout) |
171 |
# Verify quotas
|
172 |
self._check_quotas(diskspace=+os.fstat(fout.fileno()).st_size)
|
173 |
|
174 |
def test_055_download_file(self): |
175 |
"""Test downloading the file from Pithos"""
|
176 |
# Create a tmp directory to save the file
|
177 |
with tempfile.TemporaryFile(dir=self.temp_directory) as fout: |
178 |
self.clients.pithos.download_object("test.txt", fout) |
179 |
# Now read the file
|
180 |
fout.seek(0, 0) |
181 |
contents = fout.read() |
182 |
# Compare results
|
183 |
self.info("Comparing contents with the uploaded file") |
184 |
self.assertEqual(contents, "This is a temp file") |
185 |
|
186 |
def test_056_remove(self): |
187 |
"""Test removing files and containers from Pithos"""
|
188 |
self.info("Removing the file %s from container %s", |
189 |
"test.txt", self.created_container) |
190 |
# The container is the one choosen during the `create_container'
|
191 |
content_length = \ |
192 |
self.clients.pithos.get_object_info("test.txt")['content-length'] |
193 |
self.clients.pithos.del_object("test.txt") |
194 |
|
195 |
# Verify quotas
|
196 |
self._check_quotas(diskspace=-int(content_length)) |
197 |
|
198 |
self.info("Removing the container %s", self.created_container) |
199 |
self.clients.pithos.purge_container()
|
200 |
|
201 |
# List containers
|
202 |
containers = self._get_list_of_containers()
|
203 |
self.info("Check that the container %s has been deleted", |
204 |
self.created_container)
|
205 |
names = [n['name'] for n in containers] |
206 |
self.assertNotIn(self.created_container, names) |
207 |
# We successfully deleted our container, no need to do it
|
208 |
# in our clean up phase
|
209 |
self.created_container = None |
210 |
|
211 |
@classmethod
|
212 |
def tearDownClass(cls): # noqa |
213 |
"""Clean up"""
|
214 |
if cls.created_container is not None: |
215 |
cls.clients.pithos.del_container(delimiter='/')
|
216 |
cls.clients.pithos.purge_container() |