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

burnin: Test name2uuid

parent fa663bc1
......@@ -41,13 +41,13 @@ import optparse
from synnefo_tools import version
from synnefo_tools.burnin import common
from synnefo_tools.burnin.astakos_tests import AstakosTestCase, AstakosFoo
from synnefo_tools.burnin.astakos_tests import AstakosTestSuite
# --------------------------------------------------------------------
# Define our TestSuites
TESTSUITES = [
AstakosTestCase, AstakosFoo
AstakosTestSuite
]
TSUITES_NAMES = [tsuite.__name__ for tsuite in TESTSUITES]
......
......@@ -43,11 +43,12 @@ from synnefo_tools.burnin import common
# Too many public methods (47/20). pylint: disable-msg=R0904
class AstakosTestCase(common.BurninTests):
class AstakosTestSuite(common.BurninTests):
"""Test Astakos functionality"""
def test_unauthorized_access(self):
"""Test access without a valid token fails"""
"""Test that access without a valid token fails"""
false_token = "12345"
self.info("Will use token %s", false_token)
client = ComputeClient(self.clients.compute_url, false_token)
client.CONNECTION_RETRY_LIMIT = self.clients.retry
......@@ -55,9 +56,17 @@ class AstakosTestCase(common.BurninTests):
client.list_servers()
self.assertEqual(cl_error.exception.status, 401)
def test_name2uuid(self):
"""Test that usernames2uuids and uuids2usernames are complementary"""
our_uuid = self._get_uuid()
class AstakosFoo(common.BurninTests):
"""Just Fail"""
def test_just_foo(self):
"""A test that just fails"""
self.fail("just fail")
given_name = self.clients.astakos.uuids2usernames([our_uuid])
self.info("uuids2usernames returned %s", given_name)
self.assertIn(our_uuid, given_name)
given_uuid = \
self.clients.astakos.usernames2uuids([given_name[our_uuid]])
self.info("usernames2uuids returned %s", given_uuid)
self.assertIn(given_name[our_uuid], given_uuid)
self.assertEqual(given_uuid[given_name[our_uuid]], our_uuid)
......@@ -37,6 +37,7 @@ Common utils for burnin tests
"""
import sys
import datetime
import traceback
# Use backported unittest functionality if Python < 2.7
try:
......@@ -79,8 +80,10 @@ class BurninTestResult(unittest.TestResult):
def _test_failed(self, test, err):
"""Test failed"""
# Access to a protected member. pylint: disable-msg=W0212
err_msg = test._testMethodDoc + "... failed."
logger.error(test.__class__.__name__, err_msg)
err_msg = test._testMethodDoc + "... failed (%s)."
timestamp = datetime.datetime.strftime(
datetime.datetime.now(), "%a %b %d %Y %H:%M:%S")
logger.error(test.__class__.__name__, err_msg, timestamp)
(err_type, err_value, err_trace) = err
trcback = traceback.format_exception(err_type, err_value, err_trace)
logger.info(test.__class__.__name__, trcback)
......@@ -116,6 +119,7 @@ class BurninTests(unittest.TestCase):
"""Common class that all burnin tests should implement"""
clients = Clients()
opts = None
run_id = None
@classmethod
def setUpClass(cls): # noqa
......@@ -141,6 +145,8 @@ class BurninTests(unittest.TestCase):
self.clients.compute_url, self.clients.token)
self.clients.compute.CONNECTION_RETRY_LIMIT = self.clients.retry
# ----------------------------------
# Loggers helper functions
def log(self, msg, *args):
"""Pass the section value to logger"""
logger.log(self.suite_name, msg, *args)
......@@ -161,6 +167,22 @@ class BurninTests(unittest.TestCase):
"""Pass the section value to logger"""
logger.error(self.suite_name, msg, *args)
# ----------------------------------
# Helper functions that every testsuite may need
def _get_uuid(self):
"""Get our uuid"""
authenticate = self.clients.astakos.authenticate()
uuid = authenticate['access']['user']['id']
self.info("User's uuid is %s", uuid)
return uuid
def _get_username(self):
"""Get our User Name"""
authenticate = self.clients.astakos.authenticate()
username = authenticate['access']['user']['name']
self.info("User's name is %s", username)
return username
# --------------------------------------------------------------------
# Initialize Burnin
......@@ -182,6 +204,8 @@ def initialize(opts, testsuites):
# Pass the rest options to BurninTests
BurninTests.opts = opts
BurninTests.run_id = datetime.datetime.strftime(
datetime.datetime.now(), "%Y%m%d%H%M%S")
# Choose tests to run
if opts.tests != "all":
......
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