root / snf-tools / synnefo_tools / burnin / pithos_tests.py @ 24d1788b
History | View | Annotate | Download (5.6 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 |
|
43 |
from synnefo_tools.burnin.common import BurninTests, Proper |
44 |
|
45 |
|
46 |
# Too many public methods. pylint: disable-msg=R0904
|
47 |
class PithosTestSuite(BurninTests): |
48 |
"""Test Pithos functionality"""
|
49 |
containers = Proper(value=None)
|
50 |
created_container = Proper(value=None)
|
51 |
|
52 |
def test_001_list_containers(self): |
53 |
"""Test container list actually returns containers"""
|
54 |
self._set_pithos_account(self._get_uuid()) |
55 |
self.containers = self._get_list_of_containers() |
56 |
self.assertGreater(len(self.containers), 0) |
57 |
|
58 |
def test_002_unique_containers(self): |
59 |
"""Test if containers have unique names"""
|
60 |
names = [n['name'] for n in self.containers] |
61 |
names = sorted(names)
|
62 |
self.assertEqual(sorted(list(set(names))), names) |
63 |
|
64 |
def test_003_create_container(self): |
65 |
"""Test creating a new container"""
|
66 |
names = [n['name'] for n in self.containers] |
67 |
while True: |
68 |
rand_num = random.randint(1000, 9999) |
69 |
rand_name = "%s%s" % (self.run_id, rand_num) |
70 |
self.info("Trying container name %s", rand_name) |
71 |
if rand_name not in names: |
72 |
break
|
73 |
self.info("Container name %s already exists", rand_name) |
74 |
# Create container
|
75 |
self._create_pithos_container(rand_name)
|
76 |
# Verify that container is created
|
77 |
containers = self._get_list_of_containers()
|
78 |
self.info("Verify that container %s is created", rand_name) |
79 |
names = [n['name'] for n in containers] |
80 |
self.assertIn(rand_name, names)
|
81 |
# Keep the name of the container so we can remove it
|
82 |
# at cleanup phase, if something goes wrong.
|
83 |
self.created_container = rand_name
|
84 |
|
85 |
def test_004_upload_file(self): |
86 |
"""Test uploading a txt file to Pithos"""
|
87 |
# Create a tmp file
|
88 |
with tempfile.TemporaryFile(dir=self.temp_directory) as fout: |
89 |
fout.write("This is a temp file")
|
90 |
fout.seek(0, 0) |
91 |
# Upload the file,
|
92 |
# The container is the one choosen during the `create_container'
|
93 |
self.clients.pithos.upload_object("test.txt", fout) |
94 |
# Verify quotas
|
95 |
self._check_quotas(diskspace=+os.fstat(fout.fileno()).st_size)
|
96 |
|
97 |
def test_005_download_file(self): |
98 |
"""Test downloading the file from Pithos"""
|
99 |
# Create a tmp directory to save the file
|
100 |
with tempfile.TemporaryFile(dir=self.temp_directory) as fout: |
101 |
self.clients.pithos.download_object("test.txt", fout) |
102 |
# Now read the file
|
103 |
fout.seek(0, 0) |
104 |
contents = fout.read() |
105 |
# Compare results
|
106 |
self.info("Comparing contents with the uploaded file") |
107 |
self.assertEqual(contents, "This is a temp file") |
108 |
|
109 |
def test_006_remove(self): |
110 |
"""Test removing files and containers from Pithos"""
|
111 |
self.info("Removing the file %s from container %s", |
112 |
"test.txt", self.created_container) |
113 |
# The container is the one choosen during the `create_container'
|
114 |
content_length = \ |
115 |
self.clients.pithos.get_object_info("test.txt")['content-length'] |
116 |
self.clients.pithos.del_object("test.txt") |
117 |
|
118 |
# Verify quotas
|
119 |
self._check_quotas(diskspace=-int(content_length)) |
120 |
|
121 |
self.info("Removing the container %s", self.created_container) |
122 |
self.clients.pithos.purge_container()
|
123 |
|
124 |
# List containers
|
125 |
containers = self._get_list_of_containers()
|
126 |
self.info("Check that the container %s has been deleted", |
127 |
self.created_container)
|
128 |
names = [n['name'] for n in containers] |
129 |
self.assertNotIn(self.created_container, names) |
130 |
# We successfully deleted our container, no need to do it
|
131 |
# in our clean up phase
|
132 |
self.created_container = None |
133 |
|
134 |
@classmethod
|
135 |
def tearDownClass(cls): # noqa |
136 |
"""Clean up"""
|
137 |
if cls.created_container is not None: |
138 |
cls.clients.pithos.del_container(delimiter='/')
|
139 |
cls.clients.pithos.purge_container() |