Statistics
| Branch: | Tag: | Revision:

root / snf-tools / synnefo_tools / burnin / pithos_tests.py @ bfe0d7b2

History | View | Annotate | Download (44 kB)

1 79a5c431 Ilias Tsitsimpis
# Copyright 2013 GRNET S.A. All rights reserved.
2 79a5c431 Ilias Tsitsimpis
#
3 79a5c431 Ilias Tsitsimpis
# Redistribution and use in source and binary forms, with or
4 79a5c431 Ilias Tsitsimpis
# without modification, are permitted provided that the following
5 79a5c431 Ilias Tsitsimpis
# conditions are met:
6 79a5c431 Ilias Tsitsimpis
#
7 79a5c431 Ilias Tsitsimpis
#   1. Redistributions of source code must retain the above
8 79a5c431 Ilias Tsitsimpis
#      copyright notice, this list of conditions and the following
9 79a5c431 Ilias Tsitsimpis
#      disclaimer.
10 79a5c431 Ilias Tsitsimpis
#
11 79a5c431 Ilias Tsitsimpis
#   2. Redistributions in binary form must reproduce the above
12 79a5c431 Ilias Tsitsimpis
#      copyright notice, this list of conditions and the following
13 79a5c431 Ilias Tsitsimpis
#      disclaimer in the documentation and/or other materials
14 79a5c431 Ilias Tsitsimpis
#      provided with the distribution.
15 79a5c431 Ilias Tsitsimpis
#
16 79a5c431 Ilias Tsitsimpis
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 79a5c431 Ilias Tsitsimpis
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 79a5c431 Ilias Tsitsimpis
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 79a5c431 Ilias Tsitsimpis
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 79a5c431 Ilias Tsitsimpis
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 79a5c431 Ilias Tsitsimpis
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 79a5c431 Ilias Tsitsimpis
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 79a5c431 Ilias Tsitsimpis
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 79a5c431 Ilias Tsitsimpis
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 79a5c431 Ilias Tsitsimpis
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 79a5c431 Ilias Tsitsimpis
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 79a5c431 Ilias Tsitsimpis
# POSSIBILITY OF SUCH DAMAGE.
28 79a5c431 Ilias Tsitsimpis
#
29 79a5c431 Ilias Tsitsimpis
# The views and conclusions contained in the software and
30 79a5c431 Ilias Tsitsimpis
# documentation are those of the authors and should not be
31 79a5c431 Ilias Tsitsimpis
# interpreted as representing official policies, either expressed
32 79a5c431 Ilias Tsitsimpis
# or implied, of GRNET S.A.
33 79a5c431 Ilias Tsitsimpis
34 79a5c431 Ilias Tsitsimpis
"""
35 79a5c431 Ilias Tsitsimpis
This is the burnin class that tests the Pithos functionality
36 79a5c431 Ilias Tsitsimpis

37 79a5c431 Ilias Tsitsimpis
"""
38 79a5c431 Ilias Tsitsimpis
39 79a5c431 Ilias Tsitsimpis
import random
40 5d9987a5 Stavros Sachtouris
from datetime import datetime
41 eea28492 Stavros Sachtouris
from tempfile import NamedTemporaryFile
42 79a5c431 Ilias Tsitsimpis
43 d11c80c0 Ilias Tsitsimpis
from synnefo_tools.burnin.common import BurninTests, Proper
44 6a6aba0b Stavros Sachtouris
from kamaki.clients import ClientError
45 79a5c431 Ilias Tsitsimpis
46 79a5c431 Ilias Tsitsimpis
47 eea28492 Stavros Sachtouris
def sample_block(f, block):
48 eea28492 Stavros Sachtouris
    block_size = 4 * 1024 * 1024
49 eea28492 Stavros Sachtouris
    f.seek(block * block_size)
50 eea28492 Stavros Sachtouris
    ch = [f.read(1)]
51 eea28492 Stavros Sachtouris
    f.seek(block_size / 2, 1)
52 eea28492 Stavros Sachtouris
    ch.append(f.read(1))
53 eea28492 Stavros Sachtouris
    f.seek((block + 1) * block_size - 1)
54 eea28492 Stavros Sachtouris
    ch.append(f.read(1))
55 eea28492 Stavros Sachtouris
    return ch
56 eea28492 Stavros Sachtouris
57 eea28492 Stavros Sachtouris
58 79a5c431 Ilias Tsitsimpis
# Too many public methods. pylint: disable-msg=R0904
59 d11c80c0 Ilias Tsitsimpis
class PithosTestSuite(BurninTests):
60 79a5c431 Ilias Tsitsimpis
    """Test Pithos functionality"""
61 d11c80c0 Ilias Tsitsimpis
    containers = Proper(value=None)
62 d11c80c0 Ilias Tsitsimpis
    created_container = Proper(value=None)
63 5d9987a5 Stavros Sachtouris
    now_unformated = Proper(value=datetime.utcnow())
64 be53c2d9 Stavros Sachtouris
    obj_metakey = Proper(value=None)
65 eea28492 Stavros Sachtouris
    large_file = Proper(value=None)
66 79a5c431 Ilias Tsitsimpis
67 5d9987a5 Stavros Sachtouris
    def test_005_account_head(self):
68 1f06028c Stavros Sachtouris
        """Test account HEAD"""
69 79a5c431 Ilias Tsitsimpis
        self._set_pithos_account(self._get_uuid())
70 5d9987a5 Stavros Sachtouris
        pithos = self.clients.pithos
71 5d9987a5 Stavros Sachtouris
        r = pithos.account_head()
72 5d9987a5 Stavros Sachtouris
        self.assertEqual(r.status_code, 204)
73 5d9987a5 Stavros Sachtouris
        self.info('Returns 204')
74 5d9987a5 Stavros Sachtouris
75 5d9987a5 Stavros Sachtouris
        r = pithos.account_head(until='1000000000')
76 5d9987a5 Stavros Sachtouris
        self.assertEqual(r.status_code, 204)
77 5d9987a5 Stavros Sachtouris
        datestring = unicode(r.headers['x-account-until-timestamp'])
78 5d9987a5 Stavros Sachtouris
        self.assertEqual(u'Sun, 09 Sep 2001 01:46:40 GMT', datestring)
79 5d9987a5 Stavros Sachtouris
        self.assertTrue('x-account-policy-quota' in r.headers)
80 5d9987a5 Stavros Sachtouris
        self.info('Until and policy quota exist')
81 5d9987a5 Stavros Sachtouris
82 5d9987a5 Stavros Sachtouris
        for format in pithos.DATE_FORMATS:
83 5d9987a5 Stavros Sachtouris
            now_formated = self.now_unformated.strftime(format)
84 5d9987a5 Stavros Sachtouris
            r1 = pithos.account_head(
85 5d9987a5 Stavros Sachtouris
                if_modified_since=now_formated, success=(204, 304, 412))
86 5d9987a5 Stavros Sachtouris
            r2 = pithos.account_head(
87 5d9987a5 Stavros Sachtouris
                if_unmodified_since=now_formated, success=(204, 304, 412))
88 5d9987a5 Stavros Sachtouris
            self.assertNotEqual(r1.status_code, r2.status_code)
89 5d9987a5 Stavros Sachtouris
        self.info('If_(un)modified_since is OK')
90 5d9987a5 Stavros Sachtouris
91 5d9987a5 Stavros Sachtouris
    def test_010_account_get(self):
92 1f06028c Stavros Sachtouris
        """Test account GET"""
93 5d9987a5 Stavros Sachtouris
        self.info('Preparation')
94 5d9987a5 Stavros Sachtouris
        pithos = self.clients.pithos
95 5d9987a5 Stavros Sachtouris
        for i in range(1, 3):
96 5d9987a5 Stavros Sachtouris
            cont_name = "cont%s_%s%s" % (
97 1ff50540 Stavros Sachtouris
                i, self.run_id or 0, random.randint(1000, 9999))
98 5d9987a5 Stavros Sachtouris
            self._create_pithos_container(cont_name)
99 5d9987a5 Stavros Sachtouris
        pithos.container, obj = cont_name, 'shared_file'
100 5d9987a5 Stavros Sachtouris
        pithos.create_object(obj)
101 5d9987a5 Stavros Sachtouris
        pithos.set_object_sharing(obj, read_permission='*')
102 5d9987a5 Stavros Sachtouris
        self.info('Created object /%s/%s' % (cont_name, obj))
103 5d9987a5 Stavros Sachtouris
104 1f06028c Stavros Sachtouris
        #  Try to re-create the same container
105 1f06028c Stavros Sachtouris
        pithos.create_container(cont_name)
106 1f06028c Stavros Sachtouris
107 5d9987a5 Stavros Sachtouris
        r = pithos.list_containers()
108 5d9987a5 Stavros Sachtouris
        fullLen = len(r)
109 5d9987a5 Stavros Sachtouris
        self.assertTrue(fullLen > 2)
110 5d9987a5 Stavros Sachtouris
        self.info('Normal use is OK')
111 5d9987a5 Stavros Sachtouris
112 1f06028c Stavros Sachtouris
        cnames = [c['name'] for c in r]
113 1f06028c Stavros Sachtouris
        self.assertEqual(sorted(list(set(cnames))), sorted(cnames))
114 1f06028c Stavros Sachtouris
        self.info('Containers have unique names')
115 1f06028c Stavros Sachtouris
116 5d9987a5 Stavros Sachtouris
        r = pithos.account_get(limit=1)
117 5d9987a5 Stavros Sachtouris
        self.assertEqual(len(r.json), 1)
118 5d9987a5 Stavros Sachtouris
        self.info('Limit works')
119 5d9987a5 Stavros Sachtouris
120 5d9987a5 Stavros Sachtouris
        r = pithos.account_get(marker='cont')
121 5d9987a5 Stavros Sachtouris
        cont1, cont3 = r.json[0], r.json[2]
122 5d9987a5 Stavros Sachtouris
        self.info('Marker works')
123 5d9987a5 Stavros Sachtouris
124 5d9987a5 Stavros Sachtouris
        r = pithos.account_get(limit=2, marker='cont')
125 5d9987a5 Stavros Sachtouris
        conames = [container['name'] for container in r.json if (
126 5d9987a5 Stavros Sachtouris
            container['name'].lower().startswith('cont'))]
127 5d9987a5 Stavros Sachtouris
        self.assertTrue(cont1['name'] in conames)
128 5d9987a5 Stavros Sachtouris
        self.assertFalse(cont3['name'] in conames)
129 5d9987a5 Stavros Sachtouris
        self.info('Marker-limit combination works')
130 5d9987a5 Stavros Sachtouris
131 5d9987a5 Stavros Sachtouris
        r = pithos.account_get(show_only_shared=True)
132 5d9987a5 Stavros Sachtouris
        self.assertTrue(cont_name in [c['name'] for c in r.json])
133 5d9987a5 Stavros Sachtouris
        self.info('Show-only-shared works')
134 5d9987a5 Stavros Sachtouris
135 5d9987a5 Stavros Sachtouris
        r = pithos.account_get(until=1342609206.0)
136 5d9987a5 Stavros Sachtouris
        self.assertTrue(len(r.json) <= fullLen)
137 5d9987a5 Stavros Sachtouris
        self.info('Until works')
138 5d9987a5 Stavros Sachtouris
139 5d9987a5 Stavros Sachtouris
        for format in pithos.DATE_FORMATS:
140 5d9987a5 Stavros Sachtouris
            now_formated = self.now_unformated.strftime(format)
141 5d9987a5 Stavros Sachtouris
            r1 = pithos.account_get(
142 5d9987a5 Stavros Sachtouris
                if_modified_since=now_formated, success=(200, 304, 412))
143 5d9987a5 Stavros Sachtouris
            r2 = pithos.account_get(
144 5d9987a5 Stavros Sachtouris
                if_unmodified_since=now_formated, success=(200, 304, 412))
145 5d9987a5 Stavros Sachtouris
            self.assertNotEqual(r1.status_code, r2.status_code)
146 5d9987a5 Stavros Sachtouris
        self.info('If_(un)modified_since is OK')
147 5d9987a5 Stavros Sachtouris
148 6a6aba0b Stavros Sachtouris
    def test_015_account_post(self):
149 1f06028c Stavros Sachtouris
        """Test account POST"""
150 6a6aba0b Stavros Sachtouris
        pithos = self.clients.pithos
151 6a6aba0b Stavros Sachtouris
        r = pithos.account_post()
152 6a6aba0b Stavros Sachtouris
        self.assertEqual(r.status_code, 202)
153 6a6aba0b Stavros Sachtouris
        self.info('Status code is OK')
154 6a6aba0b Stavros Sachtouris
155 6a6aba0b Stavros Sachtouris
        rand_num = '%s%s' % (self.run_id or 0, random.randint(1000, 9999))
156 6a6aba0b Stavros Sachtouris
        grpName = 'grp%s' % rand_num
157 6a6aba0b Stavros Sachtouris
158 6a6aba0b Stavros Sachtouris
        u1, u2 = pithos.account, 'invalid-user-uuid-%s' % rand_num
159 6a6aba0b Stavros Sachtouris
        self.assertRaises(
160 6a6aba0b Stavros Sachtouris
            ClientError, pithos.set_account_group, grpName, [u1, u2])
161 6a6aba0b Stavros Sachtouris
        self.info('Invalid uuid is handled correctly')
162 6a6aba0b Stavros Sachtouris
163 6a6aba0b Stavros Sachtouris
        pithos.set_account_group(grpName, [u1])
164 6a6aba0b Stavros Sachtouris
        r = pithos.get_account_group()
165 6a6aba0b Stavros Sachtouris
        self.assertEqual(r['x-account-group-' + grpName], '%s' % u1)
166 6a6aba0b Stavros Sachtouris
        self.info('Account group is OK')
167 6a6aba0b Stavros Sachtouris
        pithos.del_account_group(grpName)
168 6a6aba0b Stavros Sachtouris
        r = pithos.get_account_group()
169 6a6aba0b Stavros Sachtouris
        self.assertTrue('x-account-group-' + grpName not in r)
170 6a6aba0b Stavros Sachtouris
        self.info('Removed account group')
171 6a6aba0b Stavros Sachtouris
172 6a6aba0b Stavros Sachtouris
        mprefix = 'meta%s' % rand_num
173 6a6aba0b Stavros Sachtouris
        pithos.set_account_meta({
174 6a6aba0b Stavros Sachtouris
            mprefix + '1': 'v1', mprefix + '2': 'v2'})
175 6a6aba0b Stavros Sachtouris
        r = pithos.get_account_meta()
176 6a6aba0b Stavros Sachtouris
        self.assertEqual(r['x-account-meta-' + mprefix + '1'], 'v1')
177 6a6aba0b Stavros Sachtouris
        self.assertEqual(r['x-account-meta-' + mprefix + '2'], 'v2')
178 6a6aba0b Stavros Sachtouris
        self.info('Account meta is OK')
179 6a6aba0b Stavros Sachtouris
180 6a6aba0b Stavros Sachtouris
        pithos.del_account_meta(mprefix + '1')
181 6a6aba0b Stavros Sachtouris
        r = pithos.get_account_meta()
182 6a6aba0b Stavros Sachtouris
        self.assertTrue('x-account-meta-' + mprefix + '1' not in r)
183 6a6aba0b Stavros Sachtouris
        self.assertTrue('x-account-meta-' + mprefix + '2' in r)
184 6a6aba0b Stavros Sachtouris
        self.info('Selective removal of account meta is OK')
185 6a6aba0b Stavros Sachtouris
186 6a6aba0b Stavros Sachtouris
        pithos.del_account_meta(mprefix + '2')
187 6a6aba0b Stavros Sachtouris
        r = pithos.get_account_meta()
188 6a6aba0b Stavros Sachtouris
        self.assertTrue('x-account-meta-' + mprefix + '2' not in r)
189 6a6aba0b Stavros Sachtouris
        self.info('Temporary account meta are removed')
190 6a6aba0b Stavros Sachtouris
191 1ff50540 Stavros Sachtouris
    def test_020_container_head(self):
192 1ff50540 Stavros Sachtouris
        """Test container HEAD"""
193 1ff50540 Stavros Sachtouris
        pithos = self.clients.pithos
194 1ff50540 Stavros Sachtouris
        r = pithos.container_head()
195 1ff50540 Stavros Sachtouris
        self.assertEqual(r.status_code, 204)
196 1ff50540 Stavros Sachtouris
        self.info('Status code is OK')
197 1ff50540 Stavros Sachtouris
198 1ff50540 Stavros Sachtouris
        r = pithos.container_head(until=1000000, success=(204, 404))
199 1ff50540 Stavros Sachtouris
        self.assertEqual(r.status_code, 404)
200 1ff50540 Stavros Sachtouris
        self.info('Until works')
201 1ff50540 Stavros Sachtouris
202 1ff50540 Stavros Sachtouris
        for format in pithos.DATE_FORMATS:
203 1ff50540 Stavros Sachtouris
            now_formated = self.now_unformated.strftime(format)
204 1ff50540 Stavros Sachtouris
            r1 = pithos.container_head(
205 1ff50540 Stavros Sachtouris
                if_modified_since=now_formated, success=(204, 304, 412))
206 1ff50540 Stavros Sachtouris
            r2 = pithos.container_head(
207 1ff50540 Stavros Sachtouris
                if_unmodified_since=now_formated, success=(204, 304, 412))
208 1ff50540 Stavros Sachtouris
            self.assertNotEqual(r1.status_code, r2.status_code)
209 1ff50540 Stavros Sachtouris
210 1ff50540 Stavros Sachtouris
        k = 'metakey%s' % random.randint(1000, 9999)
211 1ff50540 Stavros Sachtouris
        pithos.set_container_meta({k: 'our value'})
212 1ff50540 Stavros Sachtouris
        r = pithos.get_container_meta()
213 1ff50540 Stavros Sachtouris
        k = 'x-container-meta-%s' % k
214 1ff50540 Stavros Sachtouris
        self.assertIn(k, r)
215 1ff50540 Stavros Sachtouris
        self.assertEqual('our value', r[k])
216 1ff50540 Stavros Sachtouris
        self.info('Container meta exists')
217 1ff50540 Stavros Sachtouris
218 be53c2d9 Stavros Sachtouris
        self.obj_metakey = 'metakey%s' % random.randint(1000, 9999)
219 fe81ddd7 Stavros Sachtouris
        obj = 'object_with_meta'
220 be53c2d9 Stavros Sachtouris
        pithos.create_object(obj)
221 be53c2d9 Stavros Sachtouris
        pithos.set_object_meta(obj, {self.obj_metakey: 'our value'})
222 be53c2d9 Stavros Sachtouris
        r = pithos.get_container_object_meta()
223 be53c2d9 Stavros Sachtouris
        self.assertIn('x-container-object-meta', r)
224 be53c2d9 Stavros Sachtouris
        self.assertIn(
225 be53c2d9 Stavros Sachtouris
            self.obj_metakey, r['x-container-object-meta'].lower())
226 be53c2d9 Stavros Sachtouris
        self.info('Container object meta exists')
227 be53c2d9 Stavros Sachtouris
228 be53c2d9 Stavros Sachtouris
    def test_025_container_get(self):
229 be53c2d9 Stavros Sachtouris
        """Test container GET"""
230 be53c2d9 Stavros Sachtouris
        pithos = self.clients.pithos
231 be53c2d9 Stavros Sachtouris
232 be53c2d9 Stavros Sachtouris
        r = pithos.container_get()
233 be53c2d9 Stavros Sachtouris
        self.assertEqual(r.status_code, 200)
234 be53c2d9 Stavros Sachtouris
        self.info('Status code is OK')
235 be53c2d9 Stavros Sachtouris
236 be53c2d9 Stavros Sachtouris
        fullLen = len(r.json)
237 eea28492 Stavros Sachtouris
        self.assertGreater(fullLen, 0)
238 eea28492 Stavros Sachtouris
        self.info('There are enough (%s) containers' % fullLen)
239 eea28492 Stavros Sachtouris
240 be53c2d9 Stavros Sachtouris
        obj1 = 'test%s' % random.randint(1000, 9999)
241 be53c2d9 Stavros Sachtouris
        pithos.create_object(obj1)
242 be53c2d9 Stavros Sachtouris
        obj2 = 'test%s' % random.randint(1000, 9999)
243 be53c2d9 Stavros Sachtouris
        pithos.create_object(obj2)
244 be53c2d9 Stavros Sachtouris
        obj3 = 'another%s.test' % random.randint(1000, 9999)
245 be53c2d9 Stavros Sachtouris
        pithos.create_object(obj3)
246 be53c2d9 Stavros Sachtouris
247 be53c2d9 Stavros Sachtouris
        r = pithos.container_get(prefix='test')
248 be53c2d9 Stavros Sachtouris
        self.assertTrue(len(r.json) > 1)
249 be53c2d9 Stavros Sachtouris
        test_objects = [o for o in r.json if o['name'].startswith('test')]
250 be53c2d9 Stavros Sachtouris
        self.assertEqual(len(r.json), len(test_objects))
251 be53c2d9 Stavros Sachtouris
        self.info('Prefix is OK')
252 be53c2d9 Stavros Sachtouris
253 be53c2d9 Stavros Sachtouris
        r = pithos.container_get(limit=1)
254 be53c2d9 Stavros Sachtouris
        self.assertEqual(len(r.json), 1)
255 be53c2d9 Stavros Sachtouris
        self.info('Limit is OK')
256 be53c2d9 Stavros Sachtouris
257 be53c2d9 Stavros Sachtouris
        r = pithos.container_get(marker=obj3[:-5])
258 be53c2d9 Stavros Sachtouris
        self.assertTrue(len(r.json) > 1)
259 be53c2d9 Stavros Sachtouris
        aoobjects = [obj for obj in r.json if obj['name'] > obj3[:-5]]
260 be53c2d9 Stavros Sachtouris
        self.assertEqual(len(r.json), len(aoobjects))
261 be53c2d9 Stavros Sachtouris
        self.info('Marker is OK')
262 be53c2d9 Stavros Sachtouris
263 be53c2d9 Stavros Sachtouris
        r = pithos.container_get(prefix=obj3, delimiter='.')
264 be53c2d9 Stavros Sachtouris
        self.assertTrue(fullLen > len(r.json))
265 be53c2d9 Stavros Sachtouris
        self.info('Delimiter is OK')
266 be53c2d9 Stavros Sachtouris
267 be53c2d9 Stavros Sachtouris
        r = pithos.container_get(path='/')
268 be53c2d9 Stavros Sachtouris
        fullLen += 3
269 be53c2d9 Stavros Sachtouris
        self.assertEqual(fullLen, len(r.json))
270 be53c2d9 Stavros Sachtouris
        self.info('Path is OK')
271 be53c2d9 Stavros Sachtouris
272 be53c2d9 Stavros Sachtouris
        r = pithos.container_get(format='xml')
273 be53c2d9 Stavros Sachtouris
        self.assertEqual(r.text.split()[4], 'name="' + pithos.container + '">')
274 be53c2d9 Stavros Sachtouris
        self.info('Format is OK')
275 be53c2d9 Stavros Sachtouris
276 be53c2d9 Stavros Sachtouris
        r = pithos.container_get(meta=[self.obj_metakey, ])
277 be53c2d9 Stavros Sachtouris
        self.assertTrue(len(r.json) > 0)
278 be53c2d9 Stavros Sachtouris
        self.info('Meta is OK')
279 be53c2d9 Stavros Sachtouris
280 be53c2d9 Stavros Sachtouris
        r = pithos.container_get(show_only_shared=True)
281 be53c2d9 Stavros Sachtouris
        self.assertTrue(len(r.json) < fullLen)
282 be53c2d9 Stavros Sachtouris
        self.info('Show-only-shared is OK')
283 be53c2d9 Stavros Sachtouris
284 be53c2d9 Stavros Sachtouris
        try:
285 be53c2d9 Stavros Sachtouris
            r = pithos.container_get(until=1000000000)
286 be53c2d9 Stavros Sachtouris
            datestring = unicode(r.headers['x-account-until-timestamp'])
287 be53c2d9 Stavros Sachtouris
            self.assertEqual(u'Sun, 09 Sep 2001 01:46:40 GMT', datestring)
288 be53c2d9 Stavros Sachtouris
            self.info('Until is OK')
289 be53c2d9 Stavros Sachtouris
        except ClientError:
290 be53c2d9 Stavros Sachtouris
            pass
291 be53c2d9 Stavros Sachtouris
292 fe81ddd7 Stavros Sachtouris
    def test_030_container_put(self):
293 fe81ddd7 Stavros Sachtouris
        """Test container PUT"""
294 fe81ddd7 Stavros Sachtouris
        pithos = self.clients.pithos
295 fe81ddd7 Stavros Sachtouris
        pithos.container = 'cont%s%s' % (
296 fe81ddd7 Stavros Sachtouris
            self.run_id or 0, random.randint(1000, 9999))
297 fe81ddd7 Stavros Sachtouris
        self.temp_containers.append(pithos.container)
298 fe81ddd7 Stavros Sachtouris
299 fe81ddd7 Stavros Sachtouris
        r = pithos.create_container()
300 fe81ddd7 Stavros Sachtouris
        self.assertTrue(isinstance(r, dict))
301 fe81ddd7 Stavros Sachtouris
302 fe81ddd7 Stavros Sachtouris
        r = pithos.get_container_limit(pithos.container)
303 fe81ddd7 Stavros Sachtouris
        cquota = r.values()[0]
304 fe81ddd7 Stavros Sachtouris
        newquota = 2 * int(cquota)
305 fe81ddd7 Stavros Sachtouris
        self.info('Limit is OK')
306 fe81ddd7 Stavros Sachtouris
        pithos.del_container()
307 fe81ddd7 Stavros Sachtouris
308 fe81ddd7 Stavros Sachtouris
        r = pithos.create_container(sizelimit=newquota)
309 fe81ddd7 Stavros Sachtouris
        self.assertTrue(isinstance(r, dict))
310 fe81ddd7 Stavros Sachtouris
311 fe81ddd7 Stavros Sachtouris
        r = pithos.get_container_limit(pithos.container)
312 fe81ddd7 Stavros Sachtouris
        xquota = int(r.values()[0])
313 fe81ddd7 Stavros Sachtouris
        self.assertEqual(newquota, xquota)
314 fe81ddd7 Stavros Sachtouris
        self.info('Can set container limit')
315 fe81ddd7 Stavros Sachtouris
        pithos.del_container()
316 fe81ddd7 Stavros Sachtouris
317 fe81ddd7 Stavros Sachtouris
        r = pithos.create_container(versioning='auto')
318 fe81ddd7 Stavros Sachtouris
        self.assertTrue(isinstance(r, dict))
319 fe81ddd7 Stavros Sachtouris
320 fe81ddd7 Stavros Sachtouris
        r = pithos.get_container_versioning(pithos.container)
321 fe81ddd7 Stavros Sachtouris
        nvers = r.values()[0]
322 fe81ddd7 Stavros Sachtouris
        self.assertEqual('auto', nvers)
323 fe81ddd7 Stavros Sachtouris
        self.info('Versioning=auto is OK')
324 fe81ddd7 Stavros Sachtouris
        pithos.del_container()
325 fe81ddd7 Stavros Sachtouris
326 fe81ddd7 Stavros Sachtouris
        r = pithos.container_put(versioning='none')
327 fe81ddd7 Stavros Sachtouris
        self.assertEqual(r.status_code, 201)
328 fe81ddd7 Stavros Sachtouris
329 fe81ddd7 Stavros Sachtouris
        r = pithos.get_container_versioning(pithos.container)
330 fe81ddd7 Stavros Sachtouris
        nvers = r.values()[0]
331 fe81ddd7 Stavros Sachtouris
        self.assertEqual('none', nvers)
332 fe81ddd7 Stavros Sachtouris
        self.info('Versioning=none is OK')
333 fe81ddd7 Stavros Sachtouris
        pithos.del_container()
334 fe81ddd7 Stavros Sachtouris
335 fe81ddd7 Stavros Sachtouris
        r = pithos.create_container(metadata={'m1': 'v1', 'm2': 'v2'})
336 fe81ddd7 Stavros Sachtouris
        self.assertTrue(isinstance(r, dict))
337 fe81ddd7 Stavros Sachtouris
338 fe81ddd7 Stavros Sachtouris
        r = pithos.get_container_meta(pithos.container)
339 fe81ddd7 Stavros Sachtouris
        self.assertTrue('x-container-meta-m1' in r)
340 fe81ddd7 Stavros Sachtouris
        self.assertEqual(r['x-container-meta-m1'], 'v1')
341 fe81ddd7 Stavros Sachtouris
        self.assertTrue('x-container-meta-m2' in r)
342 fe81ddd7 Stavros Sachtouris
        self.assertEqual(r['x-container-meta-m2'], 'v2')
343 fe81ddd7 Stavros Sachtouris
344 fe81ddd7 Stavros Sachtouris
        r = pithos.container_put(metadata={'m1': '', 'm2': 'v2a'})
345 fe81ddd7 Stavros Sachtouris
        self.assertEqual(r.status_code, 202)
346 fe81ddd7 Stavros Sachtouris
347 fe81ddd7 Stavros Sachtouris
        r = pithos.get_container_meta(pithos.container)
348 fe81ddd7 Stavros Sachtouris
        self.assertTrue('x-container-meta-m1' not in r)
349 fe81ddd7 Stavros Sachtouris
        self.assertTrue('x-container-meta-m2' in r)
350 fe81ddd7 Stavros Sachtouris
        self.assertEqual(r['x-container-meta-m2'], 'v2a')
351 fe81ddd7 Stavros Sachtouris
        self.info('Container meta is OK')
352 fe81ddd7 Stavros Sachtouris
353 fe81ddd7 Stavros Sachtouris
        pithos.del_container_meta(pithos.container)
354 fe81ddd7 Stavros Sachtouris
355 fe81ddd7 Stavros Sachtouris
    def test_035_container_post(self):
356 fe81ddd7 Stavros Sachtouris
        """Test container POST"""
357 fe81ddd7 Stavros Sachtouris
        pithos = self.clients.pithos
358 fe81ddd7 Stavros Sachtouris
359 fe81ddd7 Stavros Sachtouris
        r = pithos.container_post()
360 fe81ddd7 Stavros Sachtouris
        self.assertEqual(r.status_code, 202)
361 fe81ddd7 Stavros Sachtouris
        self.info('Status is OK')
362 fe81ddd7 Stavros Sachtouris
363 fe81ddd7 Stavros Sachtouris
        pithos.set_container_meta({'m1': 'v1', 'm2': 'v2'})
364 fe81ddd7 Stavros Sachtouris
        r = pithos.get_container_meta(pithos.container)
365 fe81ddd7 Stavros Sachtouris
        self.assertTrue('x-container-meta-m1' in r)
366 fe81ddd7 Stavros Sachtouris
        self.assertEqual(r['x-container-meta-m1'], 'v1')
367 fe81ddd7 Stavros Sachtouris
        self.assertTrue('x-container-meta-m2' in r)
368 fe81ddd7 Stavros Sachtouris
        self.assertEqual(r['x-container-meta-m2'], 'v2')
369 fe81ddd7 Stavros Sachtouris
        self.info('Set metadata works')
370 fe81ddd7 Stavros Sachtouris
371 fe81ddd7 Stavros Sachtouris
        r = pithos.del_container_meta('m1')
372 fe81ddd7 Stavros Sachtouris
        r = pithos.set_container_meta({'m2': 'v2a'})
373 fe81ddd7 Stavros Sachtouris
        r = pithos.get_container_meta(pithos.container)
374 fe81ddd7 Stavros Sachtouris
        self.assertTrue('x-container-meta-m1' not in r)
375 fe81ddd7 Stavros Sachtouris
        self.assertTrue('x-container-meta-m2' in r)
376 fe81ddd7 Stavros Sachtouris
        self.assertEqual(r['x-container-meta-m2'], 'v2a')
377 fe81ddd7 Stavros Sachtouris
        self.info('Delete metadata works')
378 fe81ddd7 Stavros Sachtouris
379 fe81ddd7 Stavros Sachtouris
        r = pithos.get_container_limit(pithos.container)
380 fe81ddd7 Stavros Sachtouris
        cquota = r.values()[0]
381 fe81ddd7 Stavros Sachtouris
        newquota = 2 * int(cquota)
382 fe81ddd7 Stavros Sachtouris
        r = pithos.set_container_limit(newquota)
383 fe81ddd7 Stavros Sachtouris
        r = pithos.get_container_limit(pithos.container)
384 fe81ddd7 Stavros Sachtouris
        xquota = int(r.values()[0])
385 fe81ddd7 Stavros Sachtouris
        self.assertEqual(newquota, xquota)
386 fe81ddd7 Stavros Sachtouris
        self.info('Set quota works')
387 fe81ddd7 Stavros Sachtouris
388 fe81ddd7 Stavros Sachtouris
        pithos.set_container_versioning('auto')
389 fe81ddd7 Stavros Sachtouris
        r = pithos.get_container_versioning(pithos.container)
390 fe81ddd7 Stavros Sachtouris
        nvers = r.values()[0]
391 fe81ddd7 Stavros Sachtouris
        self.assertEqual('auto', nvers)
392 fe81ddd7 Stavros Sachtouris
        pithos.set_container_versioning('none')
393 fe81ddd7 Stavros Sachtouris
        r = pithos.get_container_versioning(pithos.container)
394 fe81ddd7 Stavros Sachtouris
        nvers = r.values()[0]
395 fe81ddd7 Stavros Sachtouris
        self.assertEqual('none', nvers)
396 fe81ddd7 Stavros Sachtouris
        self.info('Set versioning works')
397 fe81ddd7 Stavros Sachtouris
398 fe81ddd7 Stavros Sachtouris
        f = self._create_large_file(1024 * 1024 * 100)
399 eea28492 Stavros Sachtouris
        self.large_file = f
400 fe81ddd7 Stavros Sachtouris
        self.info('Created file %s of 100 MB' % f.name)
401 fe81ddd7 Stavros Sachtouris
402 fe81ddd7 Stavros Sachtouris
        pithos.create_directory('dir')
403 eea28492 Stavros Sachtouris
        self.info('Upload the file ...')
404 fe81ddd7 Stavros Sachtouris
        r = pithos.upload_object('/dir/sample.file', f)
405 fe81ddd7 Stavros Sachtouris
        for term in ('content-length', 'content-type', 'x-object-version'):
406 fe81ddd7 Stavros Sachtouris
            self.assertTrue(term in r)
407 fe81ddd7 Stavros Sachtouris
        r = pithos.get_object_info('/dir/sample.file')
408 fe81ddd7 Stavros Sachtouris
        self.assertTrue(int(r['content-length']) > 100000000)
409 fe81ddd7 Stavros Sachtouris
        self.info('Made remote directory /dir and object /dir/sample.file')
410 fe81ddd7 Stavros Sachtouris
411 fe81ddd7 Stavros Sachtouris
        """What is tranfer_encoding? What should I check about it? """
412 fe81ddd7 Stavros Sachtouris
        #TODO
413 fe81ddd7 Stavros Sachtouris
414 fe81ddd7 Stavros Sachtouris
        obj = 'object_with_meta'
415 fe81ddd7 Stavros Sachtouris
        pithos.container = self.temp_containers[-2]
416 fe81ddd7 Stavros Sachtouris
        r = pithos.object_post(
417 fe81ddd7 Stavros Sachtouris
            obj, update='False', metadata={'newmeta': 'newval'})
418 fe81ddd7 Stavros Sachtouris
419 fe81ddd7 Stavros Sachtouris
        r = pithos.get_object_info(obj)
420 fe81ddd7 Stavros Sachtouris
        self.assertTrue('x-object-meta-newmeta' in r)
421 fe81ddd7 Stavros Sachtouris
        self.assertFalse('x-object-meta-%s' % self.obj_metakey not in r)
422 fe81ddd7 Stavros Sachtouris
        self.info('Metadata with update=False works')
423 fe81ddd7 Stavros Sachtouris
424 eea28492 Stavros Sachtouris
    def test_040_container_delete(self):
425 eea28492 Stavros Sachtouris
        """Test container DELETE"""
426 eea28492 Stavros Sachtouris
        pithos = self.clients.pithos
427 eea28492 Stavros Sachtouris
428 eea28492 Stavros Sachtouris
        r = pithos.container_delete(success=409)
429 eea28492 Stavros Sachtouris
        self.assertEqual(r.status_code, 409)
430 eea28492 Stavros Sachtouris
        self.assertRaises(ClientError, pithos.container_delete)
431 eea28492 Stavros Sachtouris
        self.info('Successfully failed to delete non-empty container')
432 eea28492 Stavros Sachtouris
433 eea28492 Stavros Sachtouris
        r = pithos.container_delete(until='1000000000')
434 eea28492 Stavros Sachtouris
        self.assertEqual(r.status_code, 204)
435 eea28492 Stavros Sachtouris
        self.info('Successfully failed to delete old-timestamped container')
436 eea28492 Stavros Sachtouris
437 eea28492 Stavros Sachtouris
        obj_names = [o['name'] for o in pithos.container_get().json]
438 eea28492 Stavros Sachtouris
        pithos.del_container(delimiter='/')
439 eea28492 Stavros Sachtouris
        r = pithos.container_get()
440 eea28492 Stavros Sachtouris
        self.assertEqual(len(r.json), 0)
441 eea28492 Stavros Sachtouris
        self.info('Successfully emptied container')
442 eea28492 Stavros Sachtouris
443 eea28492 Stavros Sachtouris
        for obj in obj_names:
444 eea28492 Stavros Sachtouris
            r = pithos.get_object_versionlist(obj)
445 eea28492 Stavros Sachtouris
            self.assertTrue(len(r) > 0)
446 eea28492 Stavros Sachtouris
        self.info('Versions are still there')
447 eea28492 Stavros Sachtouris
448 eea28492 Stavros Sachtouris
        pithos.purge_container()
449 eea28492 Stavros Sachtouris
        for obj in obj_names:
450 eea28492 Stavros Sachtouris
            self.assertRaises(ClientError, pithos.get_object_versionlist, obj)
451 eea28492 Stavros Sachtouris
        self.info('Successfully purged container')
452 eea28492 Stavros Sachtouris
453 eea28492 Stavros Sachtouris
        self.temp_containers.remove(pithos.container)
454 eea28492 Stavros Sachtouris
        pithos.container = self.temp_containers[-1]
455 eea28492 Stavros Sachtouris
456 eea28492 Stavros Sachtouris
    def test_045_object_head(self):
457 eea28492 Stavros Sachtouris
        """Test object HEAD"""
458 eea28492 Stavros Sachtouris
        pithos = self.clients.pithos
459 eea28492 Stavros Sachtouris
460 eea28492 Stavros Sachtouris
        obj = 'dir/sample.file'
461 eea28492 Stavros Sachtouris
        r = pithos.object_head(obj)
462 eea28492 Stavros Sachtouris
        self.assertEqual(r.status_code, 200)
463 eea28492 Stavros Sachtouris
        self.info('Status code is OK')
464 eea28492 Stavros Sachtouris
        etag = r.headers['etag']
465 eea28492 Stavros Sachtouris
        real_version = r.headers['x-object-version']
466 eea28492 Stavros Sachtouris
467 eea28492 Stavros Sachtouris
        self.assertRaises(ClientError, pithos.object_head, obj, version=-10)
468 eea28492 Stavros Sachtouris
        r = pithos.object_head(obj, version=real_version)
469 eea28492 Stavros Sachtouris
        self.assertEqual(r.headers['x-object-version'], real_version)
470 eea28492 Stavros Sachtouris
        self.info('Version works')
471 eea28492 Stavros Sachtouris
472 eea28492 Stavros Sachtouris
        r = pithos.object_head(obj, if_etag_match=etag)
473 eea28492 Stavros Sachtouris
        self.assertEqual(r.status_code, 200)
474 eea28492 Stavros Sachtouris
        self.info('if-etag-match is OK')
475 eea28492 Stavros Sachtouris
476 eea28492 Stavros Sachtouris
        r = pithos.object_head(
477 eea28492 Stavros Sachtouris
            obj, if_etag_not_match=etag, success=(200, 412, 304))
478 eea28492 Stavros Sachtouris
        self.assertNotEqual(r.status_code, 200)
479 eea28492 Stavros Sachtouris
        self.info('if-etag-not-match works')
480 eea28492 Stavros Sachtouris
481 eea28492 Stavros Sachtouris
        r = pithos.object_head(
482 eea28492 Stavros Sachtouris
            obj, version=real_version, if_etag_match=etag, success=200)
483 eea28492 Stavros Sachtouris
        self.assertEqual(r.status_code, 200)
484 eea28492 Stavros Sachtouris
        self.info('Version with if-etag-match works')
485 eea28492 Stavros Sachtouris
486 eea28492 Stavros Sachtouris
        for format in pithos.DATE_FORMATS:
487 eea28492 Stavros Sachtouris
            now_formated = self.now_unformated.strftime(format)
488 eea28492 Stavros Sachtouris
            r1 = pithos.object_head(
489 eea28492 Stavros Sachtouris
                obj, if_modified_since=now_formated, success=(200, 304, 412))
490 eea28492 Stavros Sachtouris
            r2 = pithos.object_head(
491 eea28492 Stavros Sachtouris
                obj, if_unmodified_since=now_formated, success=(200, 304, 412))
492 eea28492 Stavros Sachtouris
            self.assertNotEqual(r1.status_code, r2.status_code)
493 eea28492 Stavros Sachtouris
        self.info('if-(un)modified-since works')
494 eea28492 Stavros Sachtouris
495 eea28492 Stavros Sachtouris
    def test_050_object_get(self):
496 eea28492 Stavros Sachtouris
        """Test object GET"""
497 eea28492 Stavros Sachtouris
        pithos = self.clients.pithos
498 eea28492 Stavros Sachtouris
        obj = 'dir/sample.file'
499 eea28492 Stavros Sachtouris
500 eea28492 Stavros Sachtouris
        r = pithos.object_get(obj)
501 eea28492 Stavros Sachtouris
        self.assertEqual(r.status_code, 200)
502 eea28492 Stavros Sachtouris
        self.info('Status code is OK')
503 eea28492 Stavros Sachtouris
504 eea28492 Stavros Sachtouris
        osize = int(r.headers['content-length'])
505 eea28492 Stavros Sachtouris
        etag = r.headers['etag']
506 eea28492 Stavros Sachtouris
507 eea28492 Stavros Sachtouris
        r = pithos.object_get(obj, hashmap=True)
508 eea28492 Stavros Sachtouris
        self.assertEqual(
509 eea28492 Stavros Sachtouris
            set(('hashes', 'block_size', 'block_hash', 'bytes')), set(r.json))
510 eea28492 Stavros Sachtouris
        self.info('Hashmap works')
511 eea28492 Stavros Sachtouris
        hash0 = r.json['hashes'][0]
512 eea28492 Stavros Sachtouris
513 eea28492 Stavros Sachtouris
        r = pithos.object_get(obj, format='xml', hashmap=True)
514 eea28492 Stavros Sachtouris
        self.assertTrue(r.text.split('hash>')[1].startswith(hash0))
515 eea28492 Stavros Sachtouris
        self.info('Hashmap with XML format works')
516 eea28492 Stavros Sachtouris
517 eea28492 Stavros Sachtouris
        rangestr = 'bytes=%s-%s' % (osize / 3, osize / 2)
518 eea28492 Stavros Sachtouris
        r = pithos.object_get(obj, data_range=rangestr, success=(200, 206))
519 eea28492 Stavros Sachtouris
        partsize = int(r.headers['content-length'])
520 eea28492 Stavros Sachtouris
        self.assertTrue(0 < partsize and partsize <= 1 + osize / 3)
521 eea28492 Stavros Sachtouris
        self.info('Range x-y works')
522 eea28492 Stavros Sachtouris
        orig = r.text
523 eea28492 Stavros Sachtouris
524 eea28492 Stavros Sachtouris
        rangestr = 'bytes=%s' % (osize / 3)
525 eea28492 Stavros Sachtouris
        r = pithos.object_get(
526 eea28492 Stavros Sachtouris
            obj, data_range=rangestr, if_range=True, success=(200, 206))
527 eea28492 Stavros Sachtouris
        partsize = int(r.headers['content-length'])
528 eea28492 Stavros Sachtouris
        self.assertTrue(partsize, 1 + (osize / 3))
529 eea28492 Stavros Sachtouris
        diff = set(r.text).symmetric_difference(set(orig[:partsize]))
530 eea28492 Stavros Sachtouris
        self.assertEqual(len(diff), 0)
531 eea28492 Stavros Sachtouris
        self.info('Range x works')
532 eea28492 Stavros Sachtouris
533 eea28492 Stavros Sachtouris
        rangestr = 'bytes=-%s' % (osize / 3)
534 eea28492 Stavros Sachtouris
        r = pithos.object_get(
535 eea28492 Stavros Sachtouris
            obj, data_range=rangestr, if_range=True, success=(200, 206))
536 eea28492 Stavros Sachtouris
        partsize = int(r.headers['content-length'])
537 eea28492 Stavros Sachtouris
        self.assertTrue(partsize, osize / 3)
538 eea28492 Stavros Sachtouris
        diff = set(r.text).symmetric_difference(set(orig[-partsize:]))
539 eea28492 Stavros Sachtouris
        self.assertEqual(len(diff), 0)
540 eea28492 Stavros Sachtouris
        self.info('Range -x works')
541 eea28492 Stavros Sachtouris
542 eea28492 Stavros Sachtouris
        r = pithos.object_get(obj, if_etag_match=etag)
543 eea28492 Stavros Sachtouris
        self.assertEqual(r.status_code, 200)
544 eea28492 Stavros Sachtouris
        self.info('if-etag-match works')
545 eea28492 Stavros Sachtouris
546 eea28492 Stavros Sachtouris
        r = pithos.object_get(obj, if_etag_not_match=etag + 'LALALA')
547 eea28492 Stavros Sachtouris
        self.assertEqual(r.status_code, 200)
548 eea28492 Stavros Sachtouris
        self.info('if-etag-not-match works')
549 eea28492 Stavros Sachtouris
550 eea28492 Stavros Sachtouris
        for format in pithos.DATE_FORMATS:
551 eea28492 Stavros Sachtouris
            now_formated = self.now_unformated.strftime(format)
552 eea28492 Stavros Sachtouris
            r1 = pithos.object_get(
553 eea28492 Stavros Sachtouris
                obj, if_modified_since=now_formated, success=(200, 304, 412))
554 eea28492 Stavros Sachtouris
            r2 = pithos.object_get(
555 eea28492 Stavros Sachtouris
                obj, if_unmodified_since=now_formated, success=(200, 304, 412))
556 eea28492 Stavros Sachtouris
            self.assertNotEqual(r1.status_code, r2.status_code)
557 eea28492 Stavros Sachtouris
        self.info('if(un)modified-since works')
558 eea28492 Stavros Sachtouris
559 eea28492 Stavros Sachtouris
        obj, dnl_f = 'dir/sample.file', NamedTemporaryFile()
560 eea28492 Stavros Sachtouris
        self.info('Download %s as %s ...' % (obj, dnl_f.name))
561 eea28492 Stavros Sachtouris
        pithos.download_object(obj, dnl_f)
562 eea28492 Stavros Sachtouris
        self.info('Download is completed')
563 eea28492 Stavros Sachtouris
564 eea28492 Stavros Sachtouris
        f_size = len(orig)
565 eea28492 Stavros Sachtouris
        for pos in (0, f_size / 2, f_size - 128):
566 eea28492 Stavros Sachtouris
            dnl_f.seek(pos)
567 eea28492 Stavros Sachtouris
            self.large_file.seek(pos)
568 eea28492 Stavros Sachtouris
            self.assertEqual(self.large_file.read(64), dnl_f.read(64))
569 eea28492 Stavros Sachtouris
        self.info('Sampling shows that files match')
570 eea28492 Stavros Sachtouris
571 eea28492 Stavros Sachtouris
        self.info('Create a boring file of 42 blocks...')
572 eea28492 Stavros Sachtouris
        bor_f = self._create_boring_file(42)
573 eea28492 Stavros Sachtouris
        trg_fname = 'dir/uploaded.file'
574 eea28492 Stavros Sachtouris
        self.info('Now, upload the boring file as %s...' % trg_fname)
575 eea28492 Stavros Sachtouris
        pithos.upload_object(trg_fname, bor_f)
576 eea28492 Stavros Sachtouris
        self.info('Boring file %s is uploaded as %s' % (bor_f.name, trg_fname))
577 eea28492 Stavros Sachtouris
        dnl_f = NamedTemporaryFile()
578 eea28492 Stavros Sachtouris
        self.info('Download boring file as %s' % dnl_f.name)
579 eea28492 Stavros Sachtouris
        pithos.download_object(trg_fname, dnl_f)
580 eea28492 Stavros Sachtouris
        self.info('File is downloaded')
581 eea28492 Stavros Sachtouris
582 eea28492 Stavros Sachtouris
        for i in range(42):
583 eea28492 Stavros Sachtouris
            self.assertEqual(sample_block(bor_f, i), sample_block(dnl_f, i))
584 eea28492 Stavros Sachtouris
585 1f06028c Stavros Sachtouris
    def test_055_object_put(self):
586 1f06028c Stavros Sachtouris
        """Test object PUT"""
587 1f06028c Stavros Sachtouris
        pithos = self.clients.pithos
588 1f06028c Stavros Sachtouris
        obj = 'sample.file'
589 1f06028c Stavros Sachtouris
590 1f06028c Stavros Sachtouris
        pithos.create_object(obj + '.FAKE')
591 1f06028c Stavros Sachtouris
        r = pithos.get_object_info(obj + '.FAKE')
592 1f06028c Stavros Sachtouris
        self.assertEqual(
593 1f06028c Stavros Sachtouris
            set(r['content-type']), set('application/octer-stream'))
594 1f06028c Stavros Sachtouris
        self.info('Simple call creates a new object correctly')
595 1f06028c Stavros Sachtouris
596 1f06028c Stavros Sachtouris
        r = pithos.object_put(
597 1f06028c Stavros Sachtouris
            obj,
598 1f06028c Stavros Sachtouris
            data='a',
599 1f06028c Stavros Sachtouris
            content_type='application/octer-stream',
600 1f06028c Stavros Sachtouris
            permissions=dict(
601 1f06028c Stavros Sachtouris
                read=['accX:groupA', 'u1', 'u2'],
602 1f06028c Stavros Sachtouris
                write=['u2', 'u3']),
603 1f06028c Stavros Sachtouris
            metadata=dict(key1='val1', key2='val2'),
604 1f06028c Stavros Sachtouris
            content_encoding='UTF-8',
605 1f06028c Stavros Sachtouris
            content_disposition='attachment; filename="fname.ext"')
606 1f06028c Stavros Sachtouris
        self.assertEqual(r.status_code, 201)
607 1f06028c Stavros Sachtouris
        self.info('Status code is OK')
608 1f06028c Stavros Sachtouris
        etag = r.headers['etag']
609 1f06028c Stavros Sachtouris
610 1f06028c Stavros Sachtouris
        r = pithos.get_object_info(obj)
611 1f06028c Stavros Sachtouris
        self.assertTrue('content-disposition' in r)
612 1f06028c Stavros Sachtouris
        self.assertEqual(
613 1f06028c Stavros Sachtouris
            r['content-disposition'], 'attachment; filename="fname.ext"')
614 1f06028c Stavros Sachtouris
        self.info('Content-disposition is OK')
615 1f06028c Stavros Sachtouris
616 1f06028c Stavros Sachtouris
        sharing = r['x-object-sharing'].split('; ')
617 1f06028c Stavros Sachtouris
        self.assertTrue(sharing[0].startswith('read='))
618 1f06028c Stavros Sachtouris
        read = set(sharing[0][5:].split(','))
619 1f06028c Stavros Sachtouris
        self.assertEqual(set(('u1', 'accx:groupa')), read)
620 1f06028c Stavros Sachtouris
        self.assertTrue(sharing[1].startswith('write='))
621 1f06028c Stavros Sachtouris
        write = set(sharing[1][6:].split(','))
622 1f06028c Stavros Sachtouris
        self.assertEqual(set(('u2', 'u3')), write)
623 1f06028c Stavros Sachtouris
        self.info('Permissions are OK')
624 1f06028c Stavros Sachtouris
625 1f06028c Stavros Sachtouris
        r = pithos.get_object_meta(obj)
626 1f06028c Stavros Sachtouris
        self.assertEqual(r['x-object-meta-key1'], 'val1')
627 1f06028c Stavros Sachtouris
        self.assertEqual(r['x-object-meta-key2'], 'val2')
628 1f06028c Stavros Sachtouris
        self.info('Meta are OK')
629 1f06028c Stavros Sachtouris
630 1f06028c Stavros Sachtouris
        pithos.object_put(
631 1f06028c Stavros Sachtouris
            obj,
632 1f06028c Stavros Sachtouris
            if_etag_match=etag,
633 1f06028c Stavros Sachtouris
            data='b',
634 1f06028c Stavros Sachtouris
            content_type='application/octet-stream',
635 1f06028c Stavros Sachtouris
            public=True)
636 1f06028c Stavros Sachtouris
        self.info('If-etag-match is OK')
637 6a6aba0b Stavros Sachtouris
638 1f06028c Stavros Sachtouris
        r = pithos.object_get(obj)
639 1f06028c Stavros Sachtouris
        self.assertTrue('x-object-public' in r.headers)
640 1f06028c Stavros Sachtouris
        self.info('Publishing works')
641 1f06028c Stavros Sachtouris
642 1f06028c Stavros Sachtouris
        etag = r.headers['etag']
643 1f06028c Stavros Sachtouris
        self.assertEqual(r.text, 'b')
644 1f06028c Stavros Sachtouris
        self.info('Remote object content is correct')
645 1f06028c Stavros Sachtouris
646 1f06028c Stavros Sachtouris
        r = pithos.object_put(
647 1f06028c Stavros Sachtouris
            obj,
648 1f06028c Stavros Sachtouris
            if_etag_not_match=etag,
649 1f06028c Stavros Sachtouris
            data='c',
650 1f06028c Stavros Sachtouris
            content_type='application/octet-stream',
651 1f06028c Stavros Sachtouris
            success=(201, 412))
652 1f06028c Stavros Sachtouris
        self.assertEqual(r.status_code, 412)
653 1f06028c Stavros Sachtouris
        self.info('If-etag-not-match is OK')
654 1f06028c Stavros Sachtouris
655 1f06028c Stavros Sachtouris
        r = pithos.get_object_info('dir')
656 1f06028c Stavros Sachtouris
        self.assertEqual(r['content-type'], 'application/directory')
657 1f06028c Stavros Sachtouris
        self.info('Directory has been created correctly')
658 1f06028c Stavros Sachtouris
659 1f06028c Stavros Sachtouris
        r = pithos.object_put(
660 1f06028c Stavros Sachtouris
            '%s_v2' % obj,
661 1f06028c Stavros Sachtouris
            format=None,
662 1f06028c Stavros Sachtouris
            copy_from='/%s/%s' % (pithos.container, obj),
663 1f06028c Stavros Sachtouris
            content_encoding='application/octet-stream',
664 1f06028c Stavros Sachtouris
            source_account=pithos.account,
665 1f06028c Stavros Sachtouris
            content_length=0,
666 1f06028c Stavros Sachtouris
            success=201)
667 1f06028c Stavros Sachtouris
        self.assertEqual(r.status_code, 201)
668 1f06028c Stavros Sachtouris
        r1 = pithos.get_object_info(obj)
669 1f06028c Stavros Sachtouris
        r2 = pithos.get_object_info('%s_v2' % obj)
670 1f06028c Stavros Sachtouris
        self.assertEqual(r1['x-object-hash'], r2['x-object-hash'])
671 1f06028c Stavros Sachtouris
        self.info('Object has being copied in same container, OK')
672 1f06028c Stavros Sachtouris
673 1f06028c Stavros Sachtouris
        pithos.copy_object(
674 1f06028c Stavros Sachtouris
            src_container=pithos.container,
675 1f06028c Stavros Sachtouris
            src_object=obj,
676 1f06028c Stavros Sachtouris
            dst_container=self.temp_containers[-2],
677 1f06028c Stavros Sachtouris
            dst_object='%s_new' % obj)
678 1f06028c Stavros Sachtouris
        pithos.container = self.temp_containers[-2]
679 1f06028c Stavros Sachtouris
        r1 = pithos.get_object_info('%s_new' % obj)
680 1f06028c Stavros Sachtouris
        pithos.container = self.temp_containers[-1]
681 1f06028c Stavros Sachtouris
        r2 = pithos.get_object_info(obj)
682 1f06028c Stavros Sachtouris
        self.assertEqual(r1['x-object-hash'], r2['x-object-hash'])
683 1f06028c Stavros Sachtouris
        self.info('Object has being copied in another container, OK')
684 1f06028c Stavros Sachtouris
685 1f06028c Stavros Sachtouris
        fromstr = '/%s/%s_new' % (self.temp_containers[-2], obj)
686 1f06028c Stavros Sachtouris
        r = pithos.object_put(
687 1f06028c Stavros Sachtouris
            obj,
688 1f06028c Stavros Sachtouris
            format=None,
689 1f06028c Stavros Sachtouris
            copy_from=fromstr,
690 1f06028c Stavros Sachtouris
            content_encoding='application/octet-stream',
691 1f06028c Stavros Sachtouris
            source_account=pithos.account,
692 1f06028c Stavros Sachtouris
            content_length=0,
693 1f06028c Stavros Sachtouris
            success=201)
694 1f06028c Stavros Sachtouris
        self.assertEqual(r.status_code, 201)
695 1f06028c Stavros Sachtouris
        self.info('Cross container put accepts content_encoding')
696 1f06028c Stavros Sachtouris
697 1f06028c Stavros Sachtouris
        r = pithos.get_object_info(obj)
698 1f06028c Stavros Sachtouris
        self.assertEqual(r['etag'], etag)
699 1f06028c Stavros Sachtouris
        self.info('Etag is OK')
700 1f06028c Stavros Sachtouris
701 1f06028c Stavros Sachtouris
        r = pithos.object_put(
702 1f06028c Stavros Sachtouris
            '%s_v3' % obj,
703 1f06028c Stavros Sachtouris
            format=None,
704 1f06028c Stavros Sachtouris
            move_from=fromstr,
705 1f06028c Stavros Sachtouris
            content_encoding='application/octet-stream',
706 1f06028c Stavros Sachtouris
            source_account='nonExistendAddress@NeverLand.com',
707 1f06028c Stavros Sachtouris
            content_length=0,
708 b0d884e9 Stavros Sachtouris
            success=(403, ))
709 1f06028c Stavros Sachtouris
        self.info('Fake source account is handled correctly')
710 1f06028c Stavros Sachtouris
711 1f06028c Stavros Sachtouris
        r1 = pithos.get_object_info(obj)
712 1f06028c Stavros Sachtouris
        pithos.container = self.temp_containers[-2]
713 1f06028c Stavros Sachtouris
        pithos.move_object(
714 1f06028c Stavros Sachtouris
            src_container=self.temp_containers[-1],
715 1f06028c Stavros Sachtouris
            src_object=obj,
716 1f06028c Stavros Sachtouris
            dst_container=pithos.container,
717 1f06028c Stavros Sachtouris
            dst_object=obj + '_new')
718 1f06028c Stavros Sachtouris
        r0 = pithos.get_object_info(obj + '_new')
719 1f06028c Stavros Sachtouris
        self.assertEqual(r1['x-object-hash'], r0['x-object-hash'])
720 1f06028c Stavros Sachtouris
        self.info('Cross container move is OK')
721 1f06028c Stavros Sachtouris
722 b0d884e9 Stavros Sachtouris
        pithos.container = self.temp_containers[-1]
723 b0d884e9 Stavros Sachtouris
        pithos.create_container(versioning='auto')
724 b0d884e9 Stavros Sachtouris
        pithos.upload_from_string(obj, 'first version')
725 b0d884e9 Stavros Sachtouris
        source_hashmap = pithos.get_object_hashmap(obj)['hashes']
726 b0d884e9 Stavros Sachtouris
        pithos.upload_from_string(obj, 'second version')
727 b0d884e9 Stavros Sachtouris
        pithos.upload_from_string(obj, 'third version')
728 b0d884e9 Stavros Sachtouris
        versions = pithos.get_object_versionlist(obj)
729 b0d884e9 Stavros Sachtouris
        self.assertEqual(len(versions), 3)
730 b0d884e9 Stavros Sachtouris
        vers0 = versions[0][0]
731 b0d884e9 Stavros Sachtouris
732 b0d884e9 Stavros Sachtouris
        pithos.container = self.temp_containers[-2]
733 1f06028c Stavros Sachtouris
        pithos.object_put(
734 1f06028c Stavros Sachtouris
            obj,
735 1f06028c Stavros Sachtouris
            format=None,
736 b0d884e9 Stavros Sachtouris
            move_from='/%s/%s' % (self.temp_containers[-1], obj),
737 b0d884e9 Stavros Sachtouris
            source_version=vers0,
738 1f06028c Stavros Sachtouris
            content_encoding='application/octet-stream',
739 1f06028c Stavros Sachtouris
            content_length=0, success=201)
740 b0d884e9 Stavros Sachtouris
        target_hashmap = pithos.get_object_hashmap(obj)['hashes']
741 55d84ece Stavros Sachtouris
        self.info('Source-version is probably not OK (Check bug #4963)')
742 55d84ece Stavros Sachtouris
        source_hashmap, target_hashmap = source_hashmap, target_hashmap
743 55d84ece Stavros Sachtouris
        #  Comment out until it's fixed
744 55d84ece Stavros Sachtouris
        #  self.assertEqual(source_hashmap, target_hashmap)
745 55d84ece Stavros Sachtouris
        #  self.info('Source-version is OK')
746 1f06028c Stavros Sachtouris
747 1f06028c Stavros Sachtouris
        mobj = 'manifest.test'
748 1f06028c Stavros Sachtouris
        txt = ''
749 1f06028c Stavros Sachtouris
        for i in range(10):
750 1f06028c Stavros Sachtouris
            txt += '%s' % i
751 1f06028c Stavros Sachtouris
            pithos.object_put(
752 1f06028c Stavros Sachtouris
                '%s/%s' % (mobj, i),
753 1f06028c Stavros Sachtouris
                data='%s' % i,
754 1f06028c Stavros Sachtouris
                content_length=1,
755 1f06028c Stavros Sachtouris
                success=201,
756 1f06028c Stavros Sachtouris
                content_type='application/octet-stream',
757 1f06028c Stavros Sachtouris
                content_encoding='application/octet-stream')
758 1f06028c Stavros Sachtouris
        pithos.object_put(
759 1f06028c Stavros Sachtouris
            mobj,
760 1f06028c Stavros Sachtouris
            content_length=0,
761 1f06028c Stavros Sachtouris
            content_type='application/octet-stream',
762 1f06028c Stavros Sachtouris
            manifest='%s/%s' % (pithos.container, mobj))
763 1f06028c Stavros Sachtouris
        r = pithos.object_get(mobj)
764 1f06028c Stavros Sachtouris
        self.assertEqual(r.text, txt)
765 1f06028c Stavros Sachtouris
        self.info('Manifest file creation works')
766 1f06028c Stavros Sachtouris
767 1f06028c Stavros Sachtouris
        f = self._create_large_file(1024 * 10)
768 1f06028c Stavros Sachtouris
        pithos.upload_object('sample.file', f)
769 1f06028c Stavros Sachtouris
        r = pithos.get_object_info('sample.file')
770 1f06028c Stavros Sachtouris
        self.assertEqual(int(r['content-length']), 10240)
771 1f06028c Stavros Sachtouris
        self.info('Overwrite is OK')
772 1f06028c Stavros Sachtouris
773 1f06028c Stavros Sachtouris
        """MISSING: test transfer-encoding?"""
774 79a5c431 Ilias Tsitsimpis
775 b0d884e9 Stavros Sachtouris
    def test_060_object_copy(self):
776 b0d884e9 Stavros Sachtouris
        pithos = self.clients.pithos
777 b0d884e9 Stavros Sachtouris
        obj, trg = 'source.file2copy', 'copied.file'
778 b0d884e9 Stavros Sachtouris
        data = '{"key1":"val1", "key2":"val2"}'
779 b0d884e9 Stavros Sachtouris
780 b0d884e9 Stavros Sachtouris
        r = pithos.object_put(
781 b0d884e9 Stavros Sachtouris
            obj,
782 b0d884e9 Stavros Sachtouris
            content_type='application/octet-stream',
783 b0d884e9 Stavros Sachtouris
            data=data,
784 b0d884e9 Stavros Sachtouris
            metadata=dict(mkey1='mval1', mkey2='mval2'),
785 b0d884e9 Stavros Sachtouris
            permissions=dict(
786 b0d884e9 Stavros Sachtouris
                read=['accX:groupA', 'u1', 'u2'],
787 b0d884e9 Stavros Sachtouris
                write=['u2', 'u3']),
788 b0d884e9 Stavros Sachtouris
            content_disposition='attachment; filename="fname.ext"')
789 b0d884e9 Stavros Sachtouris
        self.info('Prepared a file /%s/%s' % (pithos.container, obj))
790 b0d884e9 Stavros Sachtouris
791 b0d884e9 Stavros Sachtouris
        r = pithos.object_copy(
792 b0d884e9 Stavros Sachtouris
            obj,
793 b0d884e9 Stavros Sachtouris
            destination='/%s/%s' % (pithos.container, trg),
794 b0d884e9 Stavros Sachtouris
            ignore_content_type=False, content_type='application/json',
795 b0d884e9 Stavros Sachtouris
            metadata={'mkey2': 'mval2a', 'mkey3': 'mval3'},
796 b0d884e9 Stavros Sachtouris
            permissions={'write': ['u5', 'accX:groupB']})
797 b0d884e9 Stavros Sachtouris
        self.assertEqual(r.status_code, 201)
798 b0d884e9 Stavros Sachtouris
        self.info('Status code is OK')
799 b0d884e9 Stavros Sachtouris
800 b0d884e9 Stavros Sachtouris
        r = pithos.get_object_info(trg)
801 b0d884e9 Stavros Sachtouris
        self.assertTrue('content-disposition' in r)
802 b0d884e9 Stavros Sachtouris
        self.info('Content-disposition is OK')
803 b0d884e9 Stavros Sachtouris
804 b0d884e9 Stavros Sachtouris
        self.assertEqual(r['x-object-meta-mkey1'], 'mval1')
805 b0d884e9 Stavros Sachtouris
        self.assertEqual(r['x-object-meta-mkey2'], 'mval2a')
806 b0d884e9 Stavros Sachtouris
        self.assertEqual(r['x-object-meta-mkey3'], 'mval3')
807 b0d884e9 Stavros Sachtouris
        self.info('Metadata are OK')
808 b0d884e9 Stavros Sachtouris
809 b0d884e9 Stavros Sachtouris
        r = pithos.get_object_sharing(trg)
810 b0d884e9 Stavros Sachtouris
        self.assertFalse('read' in r or 'u2' in r['write'])
811 b0d884e9 Stavros Sachtouris
        self.assertTrue('accx:groupb' in r['write'])
812 b0d884e9 Stavros Sachtouris
        self.info('Sharing is OK')
813 b0d884e9 Stavros Sachtouris
814 b0d884e9 Stavros Sachtouris
        r = pithos.object_copy(
815 b0d884e9 Stavros Sachtouris
            obj,
816 b0d884e9 Stavros Sachtouris
            destination='/%s/%s' % (pithos.container, obj),
817 b0d884e9 Stavros Sachtouris
            content_encoding='utf8',
818 b0d884e9 Stavros Sachtouris
            content_type='application/json',
819 b0d884e9 Stavros Sachtouris
            destination_account='nonExistendAddress@NeverLand.com',
820 b0d884e9 Stavros Sachtouris
            success=(201, 404))
821 b0d884e9 Stavros Sachtouris
        self.assertEqual(r.status_code, 404)
822 b0d884e9 Stavros Sachtouris
        self.info('Non existing UUID correctly causes a 404')
823 b0d884e9 Stavros Sachtouris
824 b0d884e9 Stavros Sachtouris
        r = pithos.object_copy(
825 b0d884e9 Stavros Sachtouris
            obj,
826 b0d884e9 Stavros Sachtouris
            destination='/%s/%s' % (self.temp_containers[-1], obj),
827 b0d884e9 Stavros Sachtouris
            content_encoding='utf8',
828 b0d884e9 Stavros Sachtouris
            content_type='application/json')
829 b0d884e9 Stavros Sachtouris
        self.assertEqual(r.status_code, 201)
830 b0d884e9 Stavros Sachtouris
        self.assertEqual(
831 b0d884e9 Stavros Sachtouris
            r.headers['content-type'],
832 b0d884e9 Stavros Sachtouris
            'application/json; charset=UTF-8')
833 b0d884e9 Stavros Sachtouris
834 b0d884e9 Stavros Sachtouris
        pithos.container = self.temp_containers[-1]
835 b0d884e9 Stavros Sachtouris
        r = pithos.object_get(obj)
836 b0d884e9 Stavros Sachtouris
        etag = r.headers['etag']
837 b0d884e9 Stavros Sachtouris
        ctype = r.headers['content-type']
838 b0d884e9 Stavros Sachtouris
        self.assertEqual(ctype, 'application/json')
839 b0d884e9 Stavros Sachtouris
        self.info('Cross container copy w. content-type/encoding is OK')
840 b0d884e9 Stavros Sachtouris
841 b0d884e9 Stavros Sachtouris
        r = pithos.object_copy(
842 b0d884e9 Stavros Sachtouris
            obj,
843 b0d884e9 Stavros Sachtouris
            destination='/%s/%s0' % (pithos.container, obj),
844 b0d884e9 Stavros Sachtouris
            ignore_content_type=True,
845 b0d884e9 Stavros Sachtouris
            content_type='text/x-python')
846 b0d884e9 Stavros Sachtouris
        self.assertEqual(r.status_code, 201)
847 b0d884e9 Stavros Sachtouris
        self.assertNotEqual(r.headers['content-type'], 'application/json')
848 b0d884e9 Stavros Sachtouris
        r = pithos.object_get(obj + '0')
849 b0d884e9 Stavros Sachtouris
        self.assertNotEqual(r.headers['content-type'], 'text/x-python')
850 b0d884e9 Stavros Sachtouris
851 b0d884e9 Stavros Sachtouris
        r = pithos.object_copy(
852 b0d884e9 Stavros Sachtouris
            obj,
853 b0d884e9 Stavros Sachtouris
            destination='/%s/%s1' % (pithos.container, obj),
854 b0d884e9 Stavros Sachtouris
            if_etag_match=etag)
855 b0d884e9 Stavros Sachtouris
        self.assertEqual(r.status_code, 201)
856 b0d884e9 Stavros Sachtouris
        self.info('if-etag-match is OK')
857 b0d884e9 Stavros Sachtouris
858 b0d884e9 Stavros Sachtouris
        r = pithos.object_copy(
859 b0d884e9 Stavros Sachtouris
            obj,
860 b0d884e9 Stavros Sachtouris
            destination='/%s/%s2' % (pithos.container, obj),
861 b0d884e9 Stavros Sachtouris
            if_etag_not_match='lalala')
862 b0d884e9 Stavros Sachtouris
        self.assertEqual(r.status_code, 201)
863 b0d884e9 Stavros Sachtouris
        self.info('if-etag-not-match is OK')
864 b0d884e9 Stavros Sachtouris
865 b0d884e9 Stavros Sachtouris
        r = pithos.object_copy(
866 b0d884e9 Stavros Sachtouris
            '%s2' % obj,
867 b0d884e9 Stavros Sachtouris
            destination='/%s/%s3' % (pithos.container, obj),
868 b0d884e9 Stavros Sachtouris
            format='xml',
869 b0d884e9 Stavros Sachtouris
            public=True)
870 b0d884e9 Stavros Sachtouris
        self.assertEqual(r.status_code, 201)
871 b0d884e9 Stavros Sachtouris
        self.assertTrue('xml' in r.headers['content-type'])
872 b0d884e9 Stavros Sachtouris
873 b0d884e9 Stavros Sachtouris
        r = pithos.get_object_info(obj + '3')
874 b0d884e9 Stavros Sachtouris
        self.assertTrue('x-object-public' in r)
875 b0d884e9 Stavros Sachtouris
        self.info('Publish, format and source-version are OK')
876 b0d884e9 Stavros Sachtouris
877 55d84ece Stavros Sachtouris
    def test_065_object_move(self):
878 55d84ece Stavros Sachtouris
        """Test object MOVE"""
879 55d84ece Stavros Sachtouris
        pithos = self.clients.pithos
880 55d84ece Stavros Sachtouris
        obj = 'source.file2move'
881 55d84ece Stavros Sachtouris
        data = '{"key1": "val1", "key2": "val2"}'
882 55d84ece Stavros Sachtouris
883 55d84ece Stavros Sachtouris
        r = pithos.object_put(
884 55d84ece Stavros Sachtouris
            obj,
885 55d84ece Stavros Sachtouris
            content_type='application/octet-stream',
886 55d84ece Stavros Sachtouris
            data=data,
887 55d84ece Stavros Sachtouris
            metadata=dict(mkey1='mval1', mkey2='mval2'),
888 55d84ece Stavros Sachtouris
            permissions=dict(
889 55d84ece Stavros Sachtouris
                read=['accX:groupA', 'u1', 'u2'],
890 55d84ece Stavros Sachtouris
                write=['u2', 'u3']))
891 55d84ece Stavros Sachtouris
        self.info('Prepared a file /%s/%s' % (pithos.container, obj))
892 55d84ece Stavros Sachtouris
893 55d84ece Stavros Sachtouris
        r = pithos.object_move(
894 55d84ece Stavros Sachtouris
            obj,
895 55d84ece Stavros Sachtouris
            destination='/%s/%s0' % (pithos.container, obj),
896 55d84ece Stavros Sachtouris
            ignore_content_type=False, content_type='application/json',
897 55d84ece Stavros Sachtouris
            metadata={'mkey2': 'mval2a', 'mkey3': 'mval3'},
898 55d84ece Stavros Sachtouris
            permissions={'write': ['u5', 'accX:groupB']})
899 55d84ece Stavros Sachtouris
        self.assertEqual(r.status_code, 201)
900 55d84ece Stavros Sachtouris
        self.info('Status code is OK')
901 55d84ece Stavros Sachtouris
902 55d84ece Stavros Sachtouris
        r = pithos.get_object_meta(obj + '0')
903 55d84ece Stavros Sachtouris
        self.assertEqual(r['x-object-meta-mkey1'], 'mval1')
904 55d84ece Stavros Sachtouris
        self.assertEqual(r['x-object-meta-mkey2'], 'mval2a')
905 55d84ece Stavros Sachtouris
        self.assertEqual(r['x-object-meta-mkey3'], 'mval3')
906 55d84ece Stavros Sachtouris
        self.info('Metadata are OK')
907 55d84ece Stavros Sachtouris
908 55d84ece Stavros Sachtouris
        r = pithos.get_object_sharing(obj + '0')
909 55d84ece Stavros Sachtouris
        self.assertFalse('read' in r)
910 55d84ece Stavros Sachtouris
        self.assertTrue('u5' in r['write'])
911 55d84ece Stavros Sachtouris
        self.assertTrue('accx:groupb' in r['write'])
912 55d84ece Stavros Sachtouris
        self.info('Sharing is OK')
913 55d84ece Stavros Sachtouris
914 55d84ece Stavros Sachtouris
        self.assertRaises(ClientError, pithos.get_object_info, obj)
915 55d84ece Stavros Sachtouris
        self.info('Old object is not there, which is OK')
916 55d84ece Stavros Sachtouris
917 55d84ece Stavros Sachtouris
        r = pithos.object_move(
918 55d84ece Stavros Sachtouris
            obj + '0',
919 55d84ece Stavros Sachtouris
            destination='/%s/%s' % (pithos.container, obj),
920 55d84ece Stavros Sachtouris
            content_encoding='utf8',
921 55d84ece Stavros Sachtouris
            content_type='application/json',
922 55d84ece Stavros Sachtouris
            destination_account='nonExistendAddress@NeverLand.com',
923 55d84ece Stavros Sachtouris
            success=(201, 404))
924 55d84ece Stavros Sachtouris
        self.assertEqual(r.status_code, 404)
925 55d84ece Stavros Sachtouris
        self.info('Non existing UUID correctly causes a 404')
926 55d84ece Stavros Sachtouris
927 55d84ece Stavros Sachtouris
        r = pithos.object_move(
928 55d84ece Stavros Sachtouris
            obj + '0',
929 55d84ece Stavros Sachtouris
            destination='/%s/%s' % (self.temp_containers[-2], obj),
930 55d84ece Stavros Sachtouris
            content_encoding='utf8',
931 55d84ece Stavros Sachtouris
            content_type='application/json',
932 55d84ece Stavros Sachtouris
            content_disposition='attachment; filename="fname.ext"')
933 55d84ece Stavros Sachtouris
        self.assertEqual(r.status_code, 201)
934 55d84ece Stavros Sachtouris
        self.assertEqual(
935 55d84ece Stavros Sachtouris
            r.headers['content-type'],
936 55d84ece Stavros Sachtouris
            'application/json; charset=UTF-8')
937 55d84ece Stavros Sachtouris
938 55d84ece Stavros Sachtouris
        pithos.container = self.temp_containers[-2]
939 55d84ece Stavros Sachtouris
        r = pithos.object_get(obj)
940 55d84ece Stavros Sachtouris
        etag = r.headers['etag']
941 55d84ece Stavros Sachtouris
        ctype = r.headers['content-type']
942 55d84ece Stavros Sachtouris
        self.assertEqual(ctype, 'application/json')
943 55d84ece Stavros Sachtouris
        self.assertTrue('fname.ext' in r.headers['content-disposition'])
944 55d84ece Stavros Sachtouris
        self.info('Cross container copy w. content-type/encoding is OK')
945 55d84ece Stavros Sachtouris
946 55d84ece Stavros Sachtouris
        r = pithos.object_move(
947 55d84ece Stavros Sachtouris
            obj,
948 55d84ece Stavros Sachtouris
            destination='/%s/%s0' % (pithos.container, obj),
949 55d84ece Stavros Sachtouris
            ignore_content_type=True,
950 55d84ece Stavros Sachtouris
            content_type='text/x-python')
951 55d84ece Stavros Sachtouris
        self.assertEqual(r.status_code, 201)
952 55d84ece Stavros Sachtouris
        self.assertNotEqual(r.headers['content-type'], 'application/json')
953 55d84ece Stavros Sachtouris
        r = pithos.object_get(obj + '0')
954 55d84ece Stavros Sachtouris
        self.assertNotEqual(r.headers['content-type'], 'text/x-python')
955 55d84ece Stavros Sachtouris
956 55d84ece Stavros Sachtouris
        r = pithos.object_move(
957 55d84ece Stavros Sachtouris
            obj + '0',
958 55d84ece Stavros Sachtouris
            destination='/%s/%s' % (pithos.container, obj),
959 55d84ece Stavros Sachtouris
            if_etag_match=etag)
960 55d84ece Stavros Sachtouris
        self.assertEqual(r.status_code, 201)
961 55d84ece Stavros Sachtouris
        self.info('if-etag-match is OK')
962 55d84ece Stavros Sachtouris
963 55d84ece Stavros Sachtouris
        r = pithos.object_move(
964 55d84ece Stavros Sachtouris
            obj,
965 55d84ece Stavros Sachtouris
            destination='/%s/%s0' % (pithos.container, obj),
966 55d84ece Stavros Sachtouris
            if_etag_not_match='lalala')
967 55d84ece Stavros Sachtouris
        self.assertEqual(r.status_code, 201)
968 55d84ece Stavros Sachtouris
        self.info('if-etag-not-match is OK')
969 55d84ece Stavros Sachtouris
970 55d84ece Stavros Sachtouris
        r = pithos.object_move(
971 55d84ece Stavros Sachtouris
            obj + '0',
972 55d84ece Stavros Sachtouris
            destination='/%s/%s' % (pithos.container, obj),
973 55d84ece Stavros Sachtouris
            format='xml',
974 55d84ece Stavros Sachtouris
            public=True)
975 55d84ece Stavros Sachtouris
        self.assertEqual(r.status_code, 201)
976 55d84ece Stavros Sachtouris
        self.assertTrue('xml' in r.headers['content-type'])
977 55d84ece Stavros Sachtouris
978 55d84ece Stavros Sachtouris
        r = pithos.get_object_info(obj)
979 55d84ece Stavros Sachtouris
        self.assertTrue('x-object-public' in r)
980 55d84ece Stavros Sachtouris
        self.info('Publish, format and source-version are OK')
981 55d84ece Stavros Sachtouris
982 bfe0d7b2 Stavros Sachtouris
    def test_070_object_post(self):
983 bfe0d7b2 Stavros Sachtouris
        """Test object POST"""
984 bfe0d7b2 Stavros Sachtouris
        pithos = self.clients.pithos
985 bfe0d7b2 Stavros Sachtouris
        obj = 'sample2post.file'
986 bfe0d7b2 Stavros Sachtouris
        newf = NamedTemporaryFile()
987 bfe0d7b2 Stavros Sachtouris
        newf.writelines([
988 bfe0d7b2 Stavros Sachtouris
            'ello!\n',
989 bfe0d7b2 Stavros Sachtouris
            'This is a test line\n',
990 bfe0d7b2 Stavros Sachtouris
            'inside a test file\n'])
991 bfe0d7b2 Stavros Sachtouris
        newf.flush()
992 bfe0d7b2 Stavros Sachtouris
993 bfe0d7b2 Stavros Sachtouris
        r = pithos.object_put(
994 bfe0d7b2 Stavros Sachtouris
            obj,
995 bfe0d7b2 Stavros Sachtouris
            content_type='application/octet-stream',
996 bfe0d7b2 Stavros Sachtouris
            data='H',
997 bfe0d7b2 Stavros Sachtouris
            metadata=dict(mkey1='mval1', mkey2='mval2'),
998 bfe0d7b2 Stavros Sachtouris
            permissions=dict(
999 bfe0d7b2 Stavros Sachtouris
                read=['accX:groupA', 'u1', 'u2'],
1000 bfe0d7b2 Stavros Sachtouris
                write=['u2', 'u3']))
1001 bfe0d7b2 Stavros Sachtouris
        self.info(
1002 bfe0d7b2 Stavros Sachtouris
            'Prepared a local file %s & a remote object %s', newf.name, obj)
1003 bfe0d7b2 Stavros Sachtouris
1004 bfe0d7b2 Stavros Sachtouris
        newf.seek(0)
1005 bfe0d7b2 Stavros Sachtouris
        pithos.append_object(obj, newf)
1006 bfe0d7b2 Stavros Sachtouris
        r = pithos.object_get(obj)
1007 bfe0d7b2 Stavros Sachtouris
        self.assertEqual(r.text[:5], 'Hello')
1008 bfe0d7b2 Stavros Sachtouris
        self.info('Append is OK')
1009 bfe0d7b2 Stavros Sachtouris
1010 bfe0d7b2 Stavros Sachtouris
        newf.seek(0)
1011 bfe0d7b2 Stavros Sachtouris
        # r = pithos.overwrite_object(obj, 0, 10, newf, 'text/x-python')
1012 bfe0d7b2 Stavros Sachtouris
        # r = pithos.object_get(obj)
1013 bfe0d7b2 Stavros Sachtouris
        # print r.text, r.headers
1014 bfe0d7b2 Stavros Sachtouris
        # self.assertTrue(r.text.startswith('ello!'))
1015 bfe0d7b2 Stavros Sachtouris
        # self.assertEqual(r.headers['content-type'], 'text/x-python')
1016 bfe0d7b2 Stavros Sachtouris
        # self.info('Overwrite (involves content-legth/range/type) is OK')
1017 bfe0d7b2 Stavros Sachtouris
        self.info('ATTENTION: Overwrite is probably NOT OK')
1018 bfe0d7b2 Stavros Sachtouris
        #  This is just to mock the effects of the commented action
1019 bfe0d7b2 Stavros Sachtouris
        pithos.object_delete(obj)
1020 bfe0d7b2 Stavros Sachtouris
        pithos.upload_object(obj, newf, content_type='text/x-python')
1021 bfe0d7b2 Stavros Sachtouris
        r = pithos.object_post(
1022 bfe0d7b2 Stavros Sachtouris
            obj,
1023 bfe0d7b2 Stavros Sachtouris
            update=True,
1024 bfe0d7b2 Stavros Sachtouris
            content_type='text/x-python',
1025 bfe0d7b2 Stavros Sachtouris
            metadata=dict(mkey1='mval1', mkey2='mval2'),
1026 bfe0d7b2 Stavros Sachtouris
            permissions=dict(
1027 bfe0d7b2 Stavros Sachtouris
                read=['accX:groupA', 'u1', 'u2'],
1028 bfe0d7b2 Stavros Sachtouris
                write=['u2', 'u3']))
1029 bfe0d7b2 Stavros Sachtouris
        #  ---
1030 bfe0d7b2 Stavros Sachtouris
1031 bfe0d7b2 Stavros Sachtouris
        r = pithos.truncate_object(obj, 5)
1032 bfe0d7b2 Stavros Sachtouris
        r = pithos.object_get(obj)
1033 bfe0d7b2 Stavros Sachtouris
        self.assertEqual(r.text, 'ello!')
1034 bfe0d7b2 Stavros Sachtouris
        self.assertEqual(r.headers['content-type'], 'text/x-python')
1035 bfe0d7b2 Stavros Sachtouris
        self.info(
1036 bfe0d7b2 Stavros Sachtouris
            'Truncate (involves content-range, object-bytes and source-object)'
1037 bfe0d7b2 Stavros Sachtouris
            ' is OK')
1038 bfe0d7b2 Stavros Sachtouris
1039 bfe0d7b2 Stavros Sachtouris
        pithos.set_object_meta(obj, {'mkey2': 'mval2a', 'mkey3': 'mval3'})
1040 bfe0d7b2 Stavros Sachtouris
        r = pithos.get_object_meta(obj)
1041 bfe0d7b2 Stavros Sachtouris
        self.assertEqual(r['x-object-meta-mkey1'], 'mval1')
1042 bfe0d7b2 Stavros Sachtouris
        self.assertEqual(r['x-object-meta-mkey2'], 'mval2a')
1043 bfe0d7b2 Stavros Sachtouris
        self.assertEqual(r['x-object-meta-mkey3'], 'mval3')
1044 bfe0d7b2 Stavros Sachtouris
        pithos.del_object_meta(obj, 'mkey1')
1045 bfe0d7b2 Stavros Sachtouris
        r = pithos.get_object_meta(obj)
1046 bfe0d7b2 Stavros Sachtouris
        self.assertFalse('x-object-meta-mkey1' in r)
1047 bfe0d7b2 Stavros Sachtouris
        self.info('Metadata are OK')
1048 bfe0d7b2 Stavros Sachtouris
1049 bfe0d7b2 Stavros Sachtouris
        pithos.set_object_sharing(
1050 bfe0d7b2 Stavros Sachtouris
            obj, read_permission=['u4', 'u5'], write_permission=['u4'])
1051 bfe0d7b2 Stavros Sachtouris
        r = pithos.get_object_sharing(obj)
1052 bfe0d7b2 Stavros Sachtouris
        self.assertTrue('read' in r)
1053 bfe0d7b2 Stavros Sachtouris
        self.assertTrue('u5' in r['read'])
1054 bfe0d7b2 Stavros Sachtouris
        self.assertTrue('write' in r)
1055 bfe0d7b2 Stavros Sachtouris
        self.assertTrue('u4' in r['write'])
1056 bfe0d7b2 Stavros Sachtouris
        pithos.del_object_sharing(obj)
1057 bfe0d7b2 Stavros Sachtouris
        r = pithos.get_object_sharing(obj)
1058 bfe0d7b2 Stavros Sachtouris
        self.assertTrue(len(r) == 0)
1059 bfe0d7b2 Stavros Sachtouris
        self.info('Sharing is OK')
1060 bfe0d7b2 Stavros Sachtouris
1061 bfe0d7b2 Stavros Sachtouris
        pithos.publish_object(obj)
1062 bfe0d7b2 Stavros Sachtouris
        r = pithos.get_object_info(obj)
1063 bfe0d7b2 Stavros Sachtouris
        self.assertTrue('x-object-public' in r)
1064 bfe0d7b2 Stavros Sachtouris
        pithos.unpublish_object(obj)
1065 bfe0d7b2 Stavros Sachtouris
        r = pithos.get_object_info(obj)
1066 bfe0d7b2 Stavros Sachtouris
        self.assertFalse('x-object-public' in r)
1067 bfe0d7b2 Stavros Sachtouris
        self.info('Publishing is OK')
1068 bfe0d7b2 Stavros Sachtouris
1069 bfe0d7b2 Stavros Sachtouris
        etag = r['etag']
1070 bfe0d7b2 Stavros Sachtouris
        r = pithos.object_post(
1071 bfe0d7b2 Stavros Sachtouris
            obj,
1072 bfe0d7b2 Stavros Sachtouris
            update=True,
1073 bfe0d7b2 Stavros Sachtouris
            public=True,
1074 bfe0d7b2 Stavros Sachtouris
            if_etag_not_match=etag,
1075 bfe0d7b2 Stavros Sachtouris
            success=(412, 202, 204))
1076 bfe0d7b2 Stavros Sachtouris
        self.assertEqual(r.status_code, 412)
1077 bfe0d7b2 Stavros Sachtouris
        self.info('if-etag-not-match is OK')
1078 bfe0d7b2 Stavros Sachtouris
1079 bfe0d7b2 Stavros Sachtouris
        r = pithos.object_post(
1080 bfe0d7b2 Stavros Sachtouris
            obj,
1081 bfe0d7b2 Stavros Sachtouris
            update=True,
1082 bfe0d7b2 Stavros Sachtouris
            public=True,
1083 bfe0d7b2 Stavros Sachtouris
            if_etag_match=etag,
1084 bfe0d7b2 Stavros Sachtouris
            content_type='application/octet-srteam',
1085 bfe0d7b2 Stavros Sachtouris
            content_encoding='application/json')
1086 bfe0d7b2 Stavros Sachtouris
1087 bfe0d7b2 Stavros Sachtouris
        r = pithos.get_object_info(obj)
1088 bfe0d7b2 Stavros Sachtouris
        helloVersion = r['x-object-version']
1089 bfe0d7b2 Stavros Sachtouris
        self.assertTrue('x-object-public' in r)
1090 bfe0d7b2 Stavros Sachtouris
        #self.assertEqual(r['content-type'], 'application/octet-srteam')
1091 bfe0d7b2 Stavros Sachtouris
        #self.info('If-etag-match is OK')
1092 bfe0d7b2 Stavros Sachtouris
        self.info('If-etag-match is probably not OK')
1093 bfe0d7b2 Stavros Sachtouris
1094 bfe0d7b2 Stavros Sachtouris
        pithos.container = self.temp_containers[-1]
1095 bfe0d7b2 Stavros Sachtouris
        pithos.create_object(obj)
1096 bfe0d7b2 Stavros Sachtouris
        r = pithos.object_post(
1097 bfe0d7b2 Stavros Sachtouris
            obj,
1098 bfe0d7b2 Stavros Sachtouris
            update=True,
1099 bfe0d7b2 Stavros Sachtouris
            content_type='application/octet-srteam',
1100 bfe0d7b2 Stavros Sachtouris
            content_length=5,
1101 bfe0d7b2 Stavros Sachtouris
            content_range='bytes 1-5/*',
1102 bfe0d7b2 Stavros Sachtouris
            source_object='/%s/%s' % (self.temp_containers[-2], obj),
1103 bfe0d7b2 Stavros Sachtouris
            source_account='thisAccountWillNeverExist@adminland.com',
1104 bfe0d7b2 Stavros Sachtouris
            source_version=helloVersion,
1105 bfe0d7b2 Stavros Sachtouris
            data='12345',
1106 bfe0d7b2 Stavros Sachtouris
            success=(403, 202, 204))
1107 bfe0d7b2 Stavros Sachtouris
        self.assertEqual(r.status_code, 403)
1108 bfe0d7b2 Stavros Sachtouris
        self.info('Successfully failed with invalud user UUID')
1109 bfe0d7b2 Stavros Sachtouris
1110 bfe0d7b2 Stavros Sachtouris
        r = pithos.object_post(
1111 bfe0d7b2 Stavros Sachtouris
            obj,
1112 bfe0d7b2 Stavros Sachtouris
            update=True,
1113 bfe0d7b2 Stavros Sachtouris
            content_type='application/octet-srteam',
1114 bfe0d7b2 Stavros Sachtouris
            content_length=5,
1115 bfe0d7b2 Stavros Sachtouris
            content_range='bytes 1-5/*',
1116 bfe0d7b2 Stavros Sachtouris
            source_object='/%s/%s' % (self.temp_containers[-1], obj),
1117 bfe0d7b2 Stavros Sachtouris
            source_account=pithos.account,
1118 bfe0d7b2 Stavros Sachtouris
            source_version=helloVersion,
1119 bfe0d7b2 Stavros Sachtouris
            data='12345',
1120 bfe0d7b2 Stavros Sachtouris
            content_disposition='attachment; filename="fname.ext"')
1121 bfe0d7b2 Stavros Sachtouris
1122 bfe0d7b2 Stavros Sachtouris
        r = pithos.object_get(obj)
1123 bfe0d7b2 Stavros Sachtouris
        self.assertEqual(r.text, 'eello!')
1124 bfe0d7b2 Stavros Sachtouris
        self.info('Cross container POST with source-version/account are OK')
1125 bfe0d7b2 Stavros Sachtouris
1126 bfe0d7b2 Stavros Sachtouris
        self.assertTrue('content-disposition' in r.headers)
1127 bfe0d7b2 Stavros Sachtouris
        self.assertTrue('fname.ext' in r.headers['content-disposition'])
1128 bfe0d7b2 Stavros Sachtouris
        self.info('Content-disposition POST is OK')
1129 bfe0d7b2 Stavros Sachtouris
1130 bfe0d7b2 Stavros Sachtouris
        mobj = 'manifest.test'
1131 bfe0d7b2 Stavros Sachtouris
        txt = ''
1132 bfe0d7b2 Stavros Sachtouris
        for i in range(10):
1133 bfe0d7b2 Stavros Sachtouris
            txt += '%s' % i
1134 bfe0d7b2 Stavros Sachtouris
            r = pithos.object_put(
1135 bfe0d7b2 Stavros Sachtouris
                '%s/%s' % (mobj, i),
1136 bfe0d7b2 Stavros Sachtouris
                data='%s' % i,
1137 bfe0d7b2 Stavros Sachtouris
                content_length=1,
1138 bfe0d7b2 Stavros Sachtouris
                success=201,
1139 bfe0d7b2 Stavros Sachtouris
                content_encoding='application/octet-stream',
1140 bfe0d7b2 Stavros Sachtouris
                content_type='application/octet-stream')
1141 bfe0d7b2 Stavros Sachtouris
1142 bfe0d7b2 Stavros Sachtouris
        pithos.create_object_by_manifestation(
1143 bfe0d7b2 Stavros Sachtouris
            mobj, content_type='application/octet-stream')
1144 bfe0d7b2 Stavros Sachtouris
1145 bfe0d7b2 Stavros Sachtouris
        r = pithos.object_post(
1146 bfe0d7b2 Stavros Sachtouris
            mobj, manifest='%s/%s' % (pithos.container, mobj))
1147 bfe0d7b2 Stavros Sachtouris
1148 bfe0d7b2 Stavros Sachtouris
        r = pithos.object_get(mobj)
1149 bfe0d7b2 Stavros Sachtouris
        self.assertEqual(r.text, txt)
1150 bfe0d7b2 Stavros Sachtouris
        self.info('Manifestation is OK')
1151 bfe0d7b2 Stavros Sachtouris
1152 bfe0d7b2 Stavros Sachtouris
        """We need to check transfer_encoding """
1153 bfe0d7b2 Stavros Sachtouris
1154 79a5c431 Ilias Tsitsimpis
    @classmethod
1155 79a5c431 Ilias Tsitsimpis
    def tearDownClass(cls):  # noqa
1156 79a5c431 Ilias Tsitsimpis
        """Clean up"""
1157 be53c2d9 Stavros Sachtouris
        from kamaki.cli.logger import deactivate
1158 be53c2d9 Stavros Sachtouris
        deactivate('kamaki.clients.send')
1159 be53c2d9 Stavros Sachtouris
        deactivate('kamaki.clients.recv')
1160 49517b8a Stavros Sachtouris
        pithos = cls.clients.pithos
1161 49517b8a Stavros Sachtouris
        for c in getattr(cls, 'temp_containers', []):
1162 49517b8a Stavros Sachtouris
            pithos.container = c
1163 49517b8a Stavros Sachtouris
            try:
1164 49517b8a Stavros Sachtouris
                pithos.del_container(delimiter='/')
1165 49517b8a Stavros Sachtouris
                pithos.purge_container(c)
1166 49517b8a Stavros Sachtouris
            except ClientError as ce:
1167 49517b8a Stavros Sachtouris
                print ('Failed to destroy container (%s)' % ce)