root / snf-tools / synnefo_tools / burnin / images_tests.py @ c2f037ff
History | View | Annotate | Download (9 kB)
1 |
|
---|---|
2 |
# Copyright 2013 GRNET S.A. All rights reserved.
|
3 |
#
|
4 |
# Redistribution and use in source and binary forms, with or
|
5 |
# without modification, are permitted provided that the following
|
6 |
# conditions are met:
|
7 |
#
|
8 |
# 1. Redistributions of source code must retain the above
|
9 |
# copyright notice, this list of conditions and the following
|
10 |
# disclaimer.
|
11 |
#
|
12 |
# 2. Redistributions in binary form must reproduce the above
|
13 |
# copyright notice, this list of conditions and the following
|
14 |
# disclaimer in the documentation and/or other materials
|
15 |
# provided with the distribution.
|
16 |
#
|
17 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 |
# POSSIBILITY OF SUCH DAMAGE.
|
29 |
#
|
30 |
# The views and conclusions contained in the software and
|
31 |
# documentation are those of the authors and should not be
|
32 |
# interpreted as representing official policies, either expressed
|
33 |
# or implied, of GRNET S.A.
|
34 |
|
35 |
"""
|
36 |
This is the burnin class that tests the Flavors/Images functionality
|
37 |
|
38 |
"""
|
39 |
|
40 |
import os |
41 |
import shutil |
42 |
|
43 |
from kamaki.clients import ClientError |
44 |
|
45 |
from synnefo_tools.burnin.common import BurninTests, Proper, \ |
46 |
QPITHOS, QADD, QREMOVE |
47 |
|
48 |
|
49 |
# pylint: disable=too-many-public-methods
|
50 |
class FlavorsTestSuite(BurninTests): |
51 |
"""Test flavor lists for consistency"""
|
52 |
simple_flavors = Proper(value=None)
|
53 |
detailed_flavors = Proper(value=None)
|
54 |
simple_names = Proper(value=None)
|
55 |
|
56 |
def test_001_simple_flavors(self): |
57 |
"""Test flavor list actually returns flavors"""
|
58 |
self.simple_flavors = self._get_list_of_flavors(detail=False) |
59 |
self.assertGreater(len(self.simple_flavors), 0) |
60 |
|
61 |
def test_002_get_detailed_flavors(self): |
62 |
"""Test detailed flavor list is the same length as list"""
|
63 |
self.detailed_flavors = self._get_list_of_flavors(detail=True) |
64 |
self.assertEquals(len(self.simple_flavors), len(self.detailed_flavors)) |
65 |
|
66 |
def test_003_same_flavor_names(self): |
67 |
"""Test detailed and simple flavor list contain same names"""
|
68 |
names = sorted([flv['name'] for flv in self.simple_flavors]) |
69 |
self.simple_names = names
|
70 |
detailed_names = sorted([flv['name'] for flv in self.detailed_flavors]) |
71 |
self.assertEqual(self.simple_names, detailed_names) |
72 |
|
73 |
def test_004_unique_flavor_names(self): |
74 |
"""Test flavors have unique names"""
|
75 |
self.assertEqual(sorted(list(set(self.simple_names))), |
76 |
self.simple_names)
|
77 |
|
78 |
def test_005_well_formed_names(self): |
79 |
"""Test flavors have well formed names
|
80 |
|
81 |
Test flavors have names of the form CxxRyyDzz, where xx is vCPU count,
|
82 |
yy is RAM in MiB, zz is Disk in GiB
|
83 |
|
84 |
"""
|
85 |
for flv in self.detailed_flavors: |
86 |
flavor = (flv['vcpus'], flv['ram'], flv['disk'], |
87 |
flv['SNF:disk_template'])
|
88 |
self.assertEqual("C%dR%dD%d%s" % flavor, flv['name'], |
89 |
"Flavor %s doesn't match its specs" % flv['name']) |
90 |
|
91 |
|
92 |
# --------------------------------------------------------------------
|
93 |
# pylint: disable=too-many-public-methods
|
94 |
class ImagesTestSuite(BurninTests): |
95 |
"""Test image lists for consistency"""
|
96 |
simple_images = Proper(value=None)
|
97 |
detailed_images = Proper(value=None)
|
98 |
system_images = Proper(value=None)
|
99 |
temp_dir = Proper(value=None)
|
100 |
temp_image_name = Proper(value=None)
|
101 |
temp_image_file = Proper(value=None)
|
102 |
|
103 |
def test_001_list_images(self): |
104 |
"""Test simple image list actually returns images"""
|
105 |
self.simple_images = self._get_list_of_images(detail=False) |
106 |
self.assertGreater(len(self.simple_images), 0) |
107 |
|
108 |
def test_002_list_images_detailed(self): |
109 |
"""Test detailed image list is the same length as simple list"""
|
110 |
self.detailed_images = self._get_list_of_images(detail=True) |
111 |
self.assertEqual(len(self.simple_images), len(self.detailed_images)) |
112 |
|
113 |
def test_003_same_image_names(self): |
114 |
"""Test detailed and simple image list contain the same names"""
|
115 |
snames = sorted([i['name'] for i in self.simple_images]) |
116 |
dnames = sorted([i['name'] for i in self.detailed_images]) |
117 |
self.assertEqual(snames, dnames)
|
118 |
|
119 |
def test_004_system_images(self): |
120 |
"""Test that there are system images registered"""
|
121 |
images = self._get_list_of_sys_images(images=self.detailed_images) |
122 |
self.system_images = images
|
123 |
self.assertGreater(len(images), 0) |
124 |
|
125 |
def test_005_unique_image_names(self): |
126 |
"""Test system images have unique names"""
|
127 |
names = sorted([i['name'] for i in self.system_images]) |
128 |
self.assertEqual(sorted(list(set(names))), names) |
129 |
|
130 |
def test_006_image_metadata(self): |
131 |
"""Test every system image has specific metadata defined"""
|
132 |
keys = frozenset(["osfamily", "root_partition"]) |
133 |
for i in self.system_images: |
134 |
self.assertTrue(keys.issubset(i['properties'].keys())) |
135 |
|
136 |
def test_007_download_image(self): |
137 |
"""Download image from Pithos"""
|
138 |
# Find the 'Debian Base' image
|
139 |
images = self._find_images(["name:^Debian Base$"], |
140 |
images=self.system_images)
|
141 |
image = images[0]
|
142 |
self.info("Will use %s with id %s", image['name'], image['id']) |
143 |
image_location = \ |
144 |
image['location'].replace("://", " ").replace("/", " ").split() |
145 |
image_owner = image_location[1]
|
146 |
self.info("Image's owner is %s", image_owner) |
147 |
image_container = image_location[2]
|
148 |
self.info("Image's container is %s", image_container) |
149 |
image_name = image_location[3]
|
150 |
self.info("Image's name is %s", image_name) |
151 |
self.temp_image_name = image_name
|
152 |
|
153 |
self._set_pithos_account(image_owner)
|
154 |
self._set_pithos_container(image_container)
|
155 |
|
156 |
# Create temp directory
|
157 |
self.temp_dir = self._create_tmp_directory() |
158 |
self.temp_image_file = \
|
159 |
os.path.join(self.temp_dir, self.temp_image_name) |
160 |
|
161 |
# Write to file
|
162 |
self.info("Downloading image to %s", self.temp_image_file) |
163 |
with open(self.temp_image_file, "w+b") as fout: |
164 |
self.clients.pithos.download_object(image_name, fout)
|
165 |
|
166 |
def test_008_upload_image(self): |
167 |
"""Upload the image to Pithos"""
|
168 |
self._set_pithos_account(self._get_uuid()) |
169 |
self._create_pithos_container("burnin-images") |
170 |
file_size = os.path.getsize(self.temp_image_file)
|
171 |
with open(self.temp_image_file, "r+b") as fin: |
172 |
self.clients.pithos.upload_object(self.temp_image_name, fin) |
173 |
|
174 |
# Verify quotas
|
175 |
changes = \ |
176 |
{self._get_uuid(): [(QPITHOS, QADD, file_size, None)]} |
177 |
self._check_quotas(changes)
|
178 |
|
179 |
def test_009_register_image(self): |
180 |
"""Register image to Plankton"""
|
181 |
location = "pithos://" + self._get_uuid() + \ |
182 |
"/burnin-images/" + self.temp_image_name |
183 |
self.info("Registering image %s", location) |
184 |
|
185 |
params = {'is_public': False} |
186 |
properties = {'OSFAMILY': "linux", 'ROOT_PARTITION': 1} |
187 |
self.clients.image.register(self.temp_image_name, location, |
188 |
params, properties) |
189 |
|
190 |
# Check that image is registered
|
191 |
self.info("Checking that image has been registered") |
192 |
images = self._get_list_of_images(detail=True) |
193 |
images = [i for i in images if i['location'] == location] |
194 |
self.assertEqual(len(images), 1) |
195 |
self.info("Image registered with id %s", images[0]['id']) |
196 |
|
197 |
def test_010_cleanup_image(self): |
198 |
"""Remove uploaded image from Pithos"""
|
199 |
# Remove uploaded image
|
200 |
self.info("Deleting uploaded image %s", self.temp_image_name) |
201 |
self.clients.pithos.del_object(self.temp_image_name) |
202 |
# Verify quotas
|
203 |
file_size = os.path.getsize(self.temp_image_file)
|
204 |
changes = \ |
205 |
{self._get_uuid(): [(QPITHOS, QREMOVE, file_size, None)]} |
206 |
self._check_quotas(changes)
|
207 |
self.temp_image_name = None |
208 |
# Remove temp directory
|
209 |
self.info("Deleting temp directory %s", self.temp_dir) |
210 |
self._remove_tmp_directory(self.temp_dir) |
211 |
self.temp_dir = None |
212 |
|
213 |
@classmethod
|
214 |
def tearDownClass(cls): # noqa |
215 |
"""Clean up"""
|
216 |
if cls.temp_image_name is not None: |
217 |
try:
|
218 |
cls.clients.pithos.del_object(cls.temp_image_name) |
219 |
except ClientError:
|
220 |
pass
|
221 |
|
222 |
if cls.temp_dir is not None: |
223 |
try:
|
224 |
shutil.rmtree(cls.temp_dir) |
225 |
except OSError: |
226 |
pass
|