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