Revision 9d5c8826
b/snf-tools/synnefo_tools/burnin/__init__.py | ||
---|---|---|
43 | 43 |
from synnefo_tools.burnin import common |
44 | 44 |
from synnefo_tools.burnin.astakos_tests import AstakosTestSuite |
45 | 45 |
from synnefo_tools.burnin.cyclades_tests import FlavorsTestSuite |
46 |
from synnefo_tools.burnin.pithos_tests import PithosTestSuite |
|
46 | 47 |
|
47 | 48 |
|
48 | 49 |
# -------------------------------------------------------------------- |
49 | 50 |
# Define our TestSuites |
50 | 51 |
TESTSUITES = [ |
51 | 52 |
AstakosTestSuite, |
52 |
FlavorsTestSuite |
|
53 |
FlavorsTestSuite, |
|
54 |
PithosTestSuite, |
|
53 | 55 |
] |
54 | 56 |
|
55 | 57 |
TSUITES_NAMES = [tsuite.__name__ for tsuite in TESTSUITES] |
b/snf-tools/synnefo_tools/burnin/common.py | ||
---|---|---|
49 | 49 |
|
50 | 50 |
from kamaki.clients.astakos import AstakosClient |
51 | 51 |
from kamaki.clients.compute import ComputeClient |
52 |
from kamaki.clients.pithos import PithosClient |
|
52 | 53 |
|
53 | 54 |
from synnefo_tools.burnin.logger import Log |
54 | 55 |
|
... | ... | |
78 | 79 |
# Method could be a function. pylint: disable-msg=R0201 |
79 | 80 |
def _test_failed(self, test, err): |
80 | 81 |
"""Test failed""" |
82 |
# Get class name |
|
83 |
if test.__class__.__name__ == "_ErrorHolder": |
|
84 |
class_name = test.id().split('.')[-1].rstrip(')') |
|
85 |
else: |
|
86 |
class_name = test.__class__.__name__ |
|
81 | 87 |
err_msg = str(test) + "... failed (%s)." |
82 | 88 |
timestamp = datetime.datetime.strftime( |
83 | 89 |
datetime.datetime.now(), "%a %b %d %Y %H:%M:%S") |
84 |
logger.error(test.__class__.__name__, err_msg, timestamp)
|
|
90 |
logger.error(class_name, err_msg, timestamp)
|
|
85 | 91 |
(err_type, err_value, err_trace) = err |
86 | 92 |
trcback = traceback.format_exception(err_type, err_value, err_trace) |
87 |
logger.info(test.__class__.__name__, trcback)
|
|
93 |
logger.info(class_name, trcback)
|
|
88 | 94 |
|
89 | 95 |
def addError(self, test, err): # noqa |
90 | 96 |
"""Called when the test case test raises an unexpected exception""" |
... | ... | |
104 | 110 |
"""Our kamaki clients""" |
105 | 111 |
auth_url = None |
106 | 112 |
token = None |
107 |
|
|
113 |
# Astakos |
|
108 | 114 |
astakos = None |
109 | 115 |
retry = CONNECTION_RETRY_LIMIT |
110 |
|
|
116 |
# Compute |
|
111 | 117 |
compute = None |
112 | 118 |
compute_url = None |
119 |
# Cyclades |
|
120 |
cyclades = None |
|
121 |
# Pithos |
|
122 |
pithos = None |
|
123 |
pithos_url = None |
|
113 | 124 |
|
114 | 125 |
|
115 | 126 |
# Too many public methods (45/20). pylint: disable-msg=R0904 |
116 | 127 |
class BurninTests(unittest.TestCase): |
117 | 128 |
"""Common class that all burnin tests should implement""" |
118 | 129 |
clients = Clients() |
119 |
opts = None |
|
120 | 130 |
run_id = None |
131 |
use_ipv6 = None |
|
132 |
action_timeout = None |
|
133 |
action_warning = None |
|
134 |
query_interval = None |
|
121 | 135 |
|
122 | 136 |
@classmethod |
123 | 137 |
def setUpClass(cls): # noqa |
... | ... | |
154 | 168 |
self.clients.compute_url, self.clients.token) |
155 | 169 |
self.clients.compute.CONNECTION_RETRY_LIMIT = self.clients.retry |
156 | 170 |
|
171 |
self.clients.pithos_url = self.clients.astakos.\ |
|
172 |
get_service_endpoints('object-store')['publicURL'] |
|
173 |
self.info("Pithos url is %s", self.clients.pithos_url) |
|
174 |
self.clients.pithos = PithosClient( |
|
175 |
self.clients.pithos_url, self.clients.token) |
|
176 |
self.clients.pithos.CONNECTION_RETRY_LIMIT = self.clients.retry |
|
177 |
|
|
157 | 178 |
# ---------------------------------- |
158 | 179 |
# Loggers helper functions |
159 | 180 |
def log(self, msg, *args): |
... | ... | |
201 | 222 |
flavors = self.clients.compute.list_flavors(detail=detail) |
202 | 223 |
return flavors |
203 | 224 |
|
225 |
def _set_pithos_account(self, account): |
|
226 |
"""Set the pithos account""" |
|
227 |
assert account, "No pithos account was given" |
|
228 |
|
|
229 |
self.info("Setting pithos account to %s", account) |
|
230 |
self.clients.pithos.account = account |
|
231 |
|
|
232 |
def _get_list_of_containers(self, account=None): |
|
233 |
"""Get list of containers""" |
|
234 |
if account is not None: |
|
235 |
self._set_pithos_account(account) |
|
236 |
self.info("Getting list of containers") |
|
237 |
return self.clients.pithos.list_containers() |
|
238 |
|
|
239 |
def _create_pithos_container(self, container): |
|
240 |
"""Create a pithos container |
|
241 |
|
|
242 |
If the container exists, nothing will happen |
|
243 |
|
|
244 |
""" |
|
245 |
assert container, "No pithos container was given" |
|
246 |
|
|
247 |
self.info("Creating pithos container %s", container) |
|
248 |
self.clients.pithos.container = container |
|
249 |
self.clients.pithos.container_put() |
|
250 |
|
|
204 | 251 |
|
205 | 252 |
# -------------------------------------------------------------------- |
206 | 253 |
# Initialize Burnin |
... | ... | |
221 | 268 |
Clients.token = opts.token |
222 | 269 |
|
223 | 270 |
# Pass the rest options to BurninTests |
224 |
BurninTests.opts = opts |
|
225 |
BurninTests.run_id = datetime.datetime.strftime( |
|
226 |
datetime.datetime.now(), "%Y%m%d%H%M%S") |
|
271 |
BurninTests.use_ipv6 = opts.use_ipv6 |
|
272 |
BurninTests.action_timeout = opts.action_timeout |
|
273 |
BurninTests.action_warning = opts.action_warning |
|
274 |
BurninTests.query_interval = opts.query_interval |
|
275 |
BurninTests.run_id = SNF_TEST_PREFIX + \ |
|
276 |
datetime.datetime.strftime(datetime.datetime.now(), "%Y%m%d%H%M%S") |
|
227 | 277 |
|
228 | 278 |
# Choose tests to run |
229 | 279 |
if opts.tests != "all": |
b/snf-tools/synnefo_tools/burnin/pithos_tests.py | ||
---|---|---|
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 random |
|
40 |
import tempfile |
|
41 |
|
|
42 |
from synnefo_tools.burnin import common |
|
43 |
|
|
44 |
|
|
45 |
# Too many public methods. pylint: disable-msg=R0904 |
|
46 |
class PithosTestSuite(common.BurninTests): |
|
47 |
"""Test Pithos functionality""" |
|
48 |
containers = None |
|
49 |
created_container = None |
|
50 |
|
|
51 |
def test_001_list_containers(self): |
|
52 |
"""Test container list actually returns containers""" |
|
53 |
self._set_pithos_account(self._get_uuid()) |
|
54 |
containers = self._get_list_of_containers() |
|
55 |
self._setattr("containers", 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._setattr("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() 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 |
|
|
95 |
def test_005_download_file(self): |
|
96 |
"""Test downloading the file from Pithos""" |
|
97 |
# Create a tmp directory to save the file |
|
98 |
with tempfile.TemporaryFile() as fout: |
|
99 |
self.clients.pithos.download_object("test.txt", fout) |
|
100 |
# Now read the file |
|
101 |
fout.seek(0, 0) |
|
102 |
contents = fout.read() |
|
103 |
# Compare results |
|
104 |
self.info("Comparing contents with the uploaded file") |
|
105 |
self.assertEqual(contents, "This is a temp file") |
|
106 |
|
|
107 |
def test_006_remove(self): |
|
108 |
"""Test removing files and containers from Pithos""" |
|
109 |
self.info("Removing the file %s from container %s", |
|
110 |
"test.txt", self.created_container) |
|
111 |
# The container is the one choosen during the `create_container' |
|
112 |
self.clients.pithos.del_object("test.txt") |
|
113 |
|
|
114 |
self.info("Removing the container %s", self.created_container) |
|
115 |
self.clients.pithos.purge_container() |
|
116 |
|
|
117 |
# List containers |
|
118 |
containers = self._get_list_of_containers() |
|
119 |
self.info("Check that the container %s has been deleted", |
|
120 |
self.created_container) |
|
121 |
names = [n['name'] for n in containers] |
|
122 |
self.assertNotIn(self.created_container, names) |
|
123 |
# We successfully deleted our container, no need to do it |
|
124 |
# in our clean up phase |
|
125 |
self._setattr("created_container", None) |
|
126 |
|
|
127 |
@classmethod |
|
128 |
def tearDownClass(cls): # noqa |
|
129 |
"""Clean up""" |
|
130 |
if cls.created_container is not None: |
|
131 |
cls.clients.pithos.del_container(delimiter='/') |
|
132 |
cls.clients.pithos.purge_container() |
Also available in: Unified diff