Commit befc1d2c authored by Ilias Tsitsimpis's avatar Ilias Tsitsimpis
Browse files

burnin: Use descriptors as test attributes

Since each instance of the TestCase will only be used to run a single
test method (a new fixture is created for each test) the attributes can
not be saved in the class instances. Instead we use descriptors.
parent b597c849
...@@ -38,18 +38,11 @@ Common utils for burnin tests ...@@ -38,18 +38,11 @@ Common utils for burnin tests
import os import os
import re import re
import sys
import shutil import shutil
import unittest
import datetime import datetime
import tempfile import tempfile
import traceback import traceback
# Use backported unittest functionality if Python < 2.7
try:
import unittest2 as unittest
except ImportError:
if sys.version_info < (2, 7):
raise Exception("The unittest2 package is required for Python < 2.7")
import unittest
from kamaki.clients.astakos import AstakosClient from kamaki.clients.astakos import AstakosClient
from kamaki.clients.compute import ComputeClient from kamaki.clients.compute import ComputeClient
...@@ -152,17 +145,6 @@ class BurninTests(unittest.TestCase): ...@@ -152,17 +145,6 @@ class BurninTests(unittest.TestCase):
# Set test parameters # Set test parameters
cls.longMessage = True cls.longMessage = True
def _setattr(self, attr, value):
"""Used by tests to set an attribute to TestCase
Since each instance of the TestCase will only be used to run a single
test method (a new fixture is created for each test) the attributes can
not be saved in the class instance. Instead the class itself should be
used.
"""
setattr(self.__class__, attr, value)
def test_000_clients_setup(self): def test_000_clients_setup(self):
"""Initializing astakos/cyclades/pithos clients""" """Initializing astakos/cyclades/pithos clients"""
# Update class attributes # Update class attributes
...@@ -494,3 +476,21 @@ def parse_typed_option(value): ...@@ -494,3 +476,21 @@ def parse_typed_option(value):
return type_, val return type_, val
except ValueError: except ValueError:
return None return None
class Proper(object):
"""A descriptor used by tests implementing the TestCase class
Since each instance of the TestCase will only be used to run a single
test method (a new fixture is created for each test) the attributes can
not be saved in the class instances. Instead we use descriptors.
"""
def __init__(self, value=None):
self.val = value
def __get__(self, obj, objtype=None):
return self.val
def __set__(self, obj, value):
self.val = value
...@@ -36,34 +36,32 @@ This is the burnin class that tests the Cyclades functionality ...@@ -36,34 +36,32 @@ This is the burnin class that tests the Cyclades functionality
""" """
from synnefo_tools.burnin import common from synnefo_tools.burnin.common import BurninTests, Proper
# Too many public methods. pylint: disable-msg=R0904 # Too many public methods. pylint: disable-msg=R0904
class FlavorsTestSuite(common.BurninTests): class FlavorsTestSuite(BurninTests):
"""Test flavor lists for consistency""" """Test flavor lists for consistency"""
simple_flavors = None simple_flavors = Proper(value=None)
detailed_flavors = None detailed_flavors = Proper(value=None)
simple_names = None simple_names = Proper(value=None)
def test_001_simple_flavors(self): def test_001_simple_flavors(self):
"""Test flavor list actually returns flavors""" """Test flavor list actually returns flavors"""
simple_flavors = self._get_list_of_flavors(detail=False) self.simple_flavors = self._get_list_of_flavors(detail=False)
self._setattr("simple_flavors", simple_flavors)
self.assertGreater(len(self.simple_flavors), 0) self.assertGreater(len(self.simple_flavors), 0)
def test_002_get_detailed_flavors(self): def test_002_get_detailed_flavors(self):
"""Test detailed flavor list is the same length as list""" """Test detailed flavor list is the same length as list"""
detailed_flavors = self._get_list_of_flavors(detail=True) self.detailed_flavors = self._get_list_of_flavors(detail=True)
self._setattr("detailed_flavors", detailed_flavors)
self.assertEquals(len(self.simple_flavors), len(self.detailed_flavors)) self.assertEquals(len(self.simple_flavors), len(self.detailed_flavors))
def test_003_same_flavor_names(self): def test_003_same_flavor_names(self):
"""Test detailed and simple flavor list contain same names""" """Test detailed and simple flavor list contain same names"""
simple_names = sorted([flv['name'] for flv in self.simple_flavors]) names = sorted([flv['name'] for flv in self.simple_flavors])
self._setattr("simple_names", simple_names) self.simple_names = names
detailed_names = sorted([flv['name'] for flv in self.detailed_flavors]) detailed_names = sorted([flv['name'] for flv in self.detailed_flavors])
self.assertEqual(simple_names, detailed_names) self.assertEqual(self.simple_names, detailed_names)
def test_004_unique_flavor_names(self): def test_004_unique_flavor_names(self):
"""Test flavors have unique names""" """Test flavors have unique names"""
......
...@@ -42,34 +42,32 @@ import shutil ...@@ -42,34 +42,32 @@ import shutil
from kamaki.clients import ClientError from kamaki.clients import ClientError
from synnefo_tools.burnin import common from synnefo_tools.burnin.common import BurninTests, Proper
# Too many public methods. pylint: disable-msg=R0904 # Too many public methods. pylint: disable-msg=R0904
class FlavorsTestSuite(common.BurninTests): class FlavorsTestSuite(BurninTests):
"""Test flavor lists for consistency""" """Test flavor lists for consistency"""
simple_flavors = None simple_flavors = Proper(value=None)
detailed_flavors = None detailed_flavors = Proper(value=None)
simple_names = None simple_names = Proper(value=None)
def test_001_simple_flavors(self): def test_001_simple_flavors(self):
"""Test flavor list actually returns flavors""" """Test flavor list actually returns flavors"""
simple_flavors = self._get_list_of_flavors(detail=False) self.simple_flavors = self._get_list_of_flavors(detail=False)
self._setattr("simple_flavors", simple_flavors)
self.assertGreater(len(self.simple_flavors), 0) self.assertGreater(len(self.simple_flavors), 0)
def test_002_get_detailed_flavors(self): def test_002_get_detailed_flavors(self):
"""Test detailed flavor list is the same length as list""" """Test detailed flavor list is the same length as list"""
detailed_flavors = self._get_list_of_flavors(detail=True) self.detailed_flavors = self._get_list_of_flavors(detail=True)
self._setattr("detailed_flavors", detailed_flavors)
self.assertEquals(len(self.simple_flavors), len(self.detailed_flavors)) self.assertEquals(len(self.simple_flavors), len(self.detailed_flavors))
def test_003_same_flavor_names(self): def test_003_same_flavor_names(self):
"""Test detailed and simple flavor list contain same names""" """Test detailed and simple flavor list contain same names"""
simple_names = sorted([flv['name'] for flv in self.simple_flavors]) names = sorted([flv['name'] for flv in self.simple_flavors])
self._setattr("simple_names", simple_names) self.simple_names = names
detailed_names = sorted([flv['name'] for flv in self.detailed_flavors]) detailed_names = sorted([flv['name'] for flv in self.detailed_flavors])
self.assertEqual(simple_names, detailed_names) self.assertEqual(self.simple_names, detailed_names)
def test_004_unique_flavor_names(self): def test_004_unique_flavor_names(self):
"""Test flavors have unique names""" """Test flavors have unique names"""
...@@ -92,26 +90,24 @@ class FlavorsTestSuite(common.BurninTests): ...@@ -92,26 +90,24 @@ class FlavorsTestSuite(common.BurninTests):
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Too many public methods. pylint: disable-msg=R0904 # Too many public methods. pylint: disable-msg=R0904
class ImagesTestSuite(common.BurninTests): class ImagesTestSuite(BurninTests):
"""Test image lists for consistency""" """Test image lists for consistency"""
simple_images = None simple_images = Proper(value=None)
detailed_images = None detailed_images = Proper(value=None)
system_images = None system_images = Proper(value=None)
temp_dir = None temp_dir = Proper(value=None)
temp_image_name = None temp_image_name = Proper(value=None)
temp_image_file = None temp_image_file = Proper(value=None)
def test_001_list_images(self): def test_001_list_images(self):
"""Test simple image list actually returns images""" """Test simple image list actually returns images"""
images = self._get_list_of_images(detail=False) self.simple_images = self._get_list_of_images(detail=False)
self._setattr("simple_images", images) self.assertGreater(len(self.simple_images), 0)
self.assertGreater(len(images), 0)
def test_002_list_images_detailed(self): def test_002_list_images_detailed(self):
"""Test detailed image list is the same length as simple list""" """Test detailed image list is the same length as simple list"""
images = self._get_list_of_images(detail=True) self.detailed_images = self._get_list_of_images(detail=True)
self._setattr("detailed_images", images) self.assertEqual(len(self.simple_images), len(self.detailed_images))
self.assertEqual(len(self.simple_images), len(images))
def test_003_same_image_names(self): def test_003_same_image_names(self):
"""Test detailed and simple image list contain the same names""" """Test detailed and simple image list contain the same names"""
...@@ -122,7 +118,7 @@ class ImagesTestSuite(common.BurninTests): ...@@ -122,7 +118,7 @@ class ImagesTestSuite(common.BurninTests):
def test_004_system_images(self): def test_004_system_images(self):
"""Test that there are system images registered""" """Test that there are system images registered"""
images = self._get_list_of_sys_images(images=self.detailed_images) images = self._get_list_of_sys_images(images=self.detailed_images)
self._setattr("system_images", images) self.system_images = images
self.assertGreater(len(images), 0) self.assertGreater(len(images), 0)
def test_005_unique_image_names(self): def test_005_unique_image_names(self):
...@@ -149,16 +145,15 @@ class ImagesTestSuite(common.BurninTests): ...@@ -149,16 +145,15 @@ class ImagesTestSuite(common.BurninTests):
self.info("Image's container is %s", image_container) self.info("Image's container is %s", image_container)
image_name = image_location[3] image_name = image_location[3]
self.info("Image's name is %s", image_name) self.info("Image's name is %s", image_name)
self._setattr("temp_image_name", image_name) self.temp_image_name = image_name
self._set_pithos_account(image_owner) self._set_pithos_account(image_owner)
self._set_pithos_container(image_container) self._set_pithos_container(image_container)
# Create temp directory # Create temp directory
temp_dir = self._create_tmp_directory() self.temp_dir = self._create_tmp_directory()
self._setattr("temp_dir", temp_dir) self.temp_image_file = \
self._setattr("temp_image_file", os.path.join(self.temp_dir, self.temp_image_name)
os.path.join(self.temp_dir, self.temp_image_name))
# Write to file # Write to file
self.info("Download image to %s", self.temp_image_file) self.info("Download image to %s", self.temp_image_file)
...@@ -195,11 +190,11 @@ class ImagesTestSuite(common.BurninTests): ...@@ -195,11 +190,11 @@ class ImagesTestSuite(common.BurninTests):
# Remove uploaded image # Remove uploaded image
self.info("Deleting uploaded image %s", self.temp_image_name) self.info("Deleting uploaded image %s", self.temp_image_name)
self.clients.pithos.del_object(self.temp_image_name) self.clients.pithos.del_object(self.temp_image_name)
self._setattr("temp_image_name", None) self.temp_image_name = None
# Remove temp directory # Remove temp directory
self.info("Deleting temp directory %s", self.temp_dir) self.info("Deleting temp directory %s", self.temp_dir)
self._remove_tmp_directory(self.temp_dir) self._remove_tmp_directory(self.temp_dir)
self._setattr("temp_dir", None) self.temp_dir = None
@classmethod @classmethod
def tearDownClass(cls): # noqa def tearDownClass(cls): # noqa
......
...@@ -39,20 +39,19 @@ This is the burnin class that tests the Pithos functionality ...@@ -39,20 +39,19 @@ This is the burnin class that tests the Pithos functionality
import random import random
import tempfile import tempfile
from synnefo_tools.burnin import common from synnefo_tools.burnin.common import BurninTests, Proper
# Too many public methods. pylint: disable-msg=R0904 # Too many public methods. pylint: disable-msg=R0904
class PithosTestSuite(common.BurninTests): class PithosTestSuite(BurninTests):
"""Test Pithos functionality""" """Test Pithos functionality"""
containers = None containers = Proper(value=None)
created_container = None created_container = Proper(value=None)
def test_001_list_containers(self): def test_001_list_containers(self):
"""Test container list actually returns containers""" """Test container list actually returns containers"""
self._set_pithos_account(self._get_uuid()) self._set_pithos_account(self._get_uuid())
containers = self._get_list_of_containers() self.containers = self._get_list_of_containers()
self._setattr("containers", containers)
self.assertGreater(len(self.containers), 0) self.assertGreater(len(self.containers), 0)
def test_002_unique_containers(self): def test_002_unique_containers(self):
...@@ -80,7 +79,7 @@ class PithosTestSuite(common.BurninTests): ...@@ -80,7 +79,7 @@ class PithosTestSuite(common.BurninTests):
self.assertIn(rand_name, names) self.assertIn(rand_name, names)
# Keep the name of the container so we can remove it # Keep the name of the container so we can remove it
# at cleanup phase, if something goes wrong. # at cleanup phase, if something goes wrong.
self._setattr("created_container", rand_name) self.created_container = rand_name
def test_004_upload_file(self): def test_004_upload_file(self):
"""Test uploading a txt file to Pithos""" """Test uploading a txt file to Pithos"""
...@@ -122,7 +121,7 @@ class PithosTestSuite(common.BurninTests): ...@@ -122,7 +121,7 @@ class PithosTestSuite(common.BurninTests):
self.assertNotIn(self.created_container, names) self.assertNotIn(self.created_container, names)
# We successfully deleted our container, no need to do it # We successfully deleted our container, no need to do it
# in our clean up phase # in our clean up phase
self._setattr("created_container", None) self.created_container = None
@classmethod @classmethod
def tearDownClass(cls): # noqa def tearDownClass(cls): # noqa
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment