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