Commit b773795c authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Make cyclades functional test code pretier

parent ff79a423
......@@ -320,12 +320,9 @@ class SilentEvent(Thread):
class Client(object):
MAX_THREADS = 7
DATE_FORMATS = [
'%a %b %d %H:%M:%S %Y',
'%A, %d-%b-%y %H:%M:%S GMT',
'%a, %d %b %Y %H:%M:%S GMT']
DATE_FORMATS = ['%a %b %d %H:%M:%S %Y', ]
LOG_TOKEN = False
LOG_DATA = False
LOG_DATA = True
CONNECTION_RETRY_LIMIT = 0
def __init__(self, base_url, token):
......
......@@ -160,13 +160,13 @@ class Cyclades(livetest.Generic):
def _has_status(self, servid, status):
r = self.client.get_server_details(servid)
#print 'MY STATUS IS ', r['status']
#print 'MY ', servid, ' STATUS IS ', r['status']
return r['status'] == status
def _wait_for_status(self, servid, status):
(wait_bar, wait_cb) = self._safe_progress_bar(
'Server %s in %s' % (servid, status))
self.client.wait_server(servid, status, wait_cb=wait_cb)
self.client.wait_server(servid, status, wait_cb=wait_cb, delay=5)
self._safe_progress_bar_finish(wait_bar)
def test_parallel_creation(self):
......@@ -174,61 +174,18 @@ class Cyclades(livetest.Generic):
Do not use this in regular livetest
"""
from kamaki.clients import SilentEvent
c1 = SilentEvent(
self._create_server,
self.servname1,
self.flavorid,
self.img)
c2 = SilentEvent(
self._create_server,
self.servname2,
self.flavorid,
self.img)
c3 = SilentEvent(
self._create_server,
self.servname1,
self.flavorid,
self.img)
c4 = SilentEvent(
self._create_server,
self.servname2,
self.flavorid,
self.img)
c5 = SilentEvent(
self._create_server,
self.servname1,
self.flavorid,
self.img)
c6 = SilentEvent(
self._create_server,
self.servname2,
self.flavorid,
self.img)
c7 = SilentEvent(
self._create_server,
self.servname1,
self.flavorid,
self.img)
c8 = SilentEvent(
self._create_server,
self.servname2,
self.flavorid,
self.img)
c1.start()
c2.start()
c3.start()
c4.start()
c5.start()
c6.start()
c7.start()
c8.start()
c = []
for i in range(8):
sname = '%s_%s' % (self.servname1, i)
c.append(SilentEvent(
self._create_server, sname, self.flavorid, self.img))
for i in range(8):
c[i].start()
def test_create_server(self):
"""Test create_server"""
self.server1 = self._create_server(
self.servname1,
self.flavorid,
self.img)
self.servname1, self.flavorid, self.img)
self._wait_for_status(self.server1['id'], 'BUILD')
self._test_0010_create_server()
......@@ -241,13 +198,9 @@ class Cyclades(livetest.Generic):
def test_list_servers(self):
"""Test list servers"""
self.server1 = self._create_server(
self.servname1,
self.flavorid,
self.img)
self.servname1, self.flavorid, self.img)
self.server2 = self._create_server(
self.servname2,
self.flavorid,
self.img)
self.servname2, self.flavorid, self.img)
self._test_0020_list_servers()
def _test_0020_list_servers(self):
......@@ -256,17 +209,12 @@ class Cyclades(livetest.Generic):
"""detailed and simple are same size"""
self.assertEqual(len(dservers), len(servers))
for i in range(len(servers)):
for field in (
'created',
'flavor',
'hostId',
'image',
'progress',
'status',
'updated'):
self.assertFalse(field in servers[i])
self.assertTrue(field in dservers[i])
fields = set([
'created', 'flavor', 'hostId', 'image', 'progress', 'status',
'updated'])
for i, srv in enumerate(servers):
self.assertTrue(fields.isdisjoint(srv))
self.assertTrue(fields.issubset(dservers[i]))
"""detailed and simple contain same names"""
names = sorted(map(lambda x: x["name"], servers))
......@@ -282,9 +230,7 @@ class Cyclades(livetest.Generic):
def test_get_server_details(self):
"""Test get_server_details"""
self.server1 = self._create_server(
self.servname1,
self.flavorid,
self.img)
self.servname1, self.flavorid, self.img)
self._wait_for_status(self.server1['id'], 'BUILD')
self._test_0040_get_server_details()
......@@ -298,17 +244,14 @@ class Cyclades(livetest.Generic):
def test_update_server_name(self):
"""Test update_server_name"""
self.server1 = self._create_server(
self.servname1,
self.flavorid,
self.img)
self.servname1, self.flavorid, self.img)
self._test_0050_update_server_name()
def _test_0050_update_server_name(self):
new_name = self.servname1 + '_new_name'
self.client.update_server_name(self.server1['id'], new_name)
r = self.client.get_server_details(
self.server1['id'],
success=(200, 400))
self.server1['id'], success=(200, 400))
self.assertEqual(r['name'], new_name)
changed = self.servers.pop(self.servname1)
changed['name'] = new_name
......@@ -317,14 +260,10 @@ class Cyclades(livetest.Generic):
def test_reboot_server(self):
"""Test reboot server"""
self.server1 = self._create_server(
self.servname1,
self.flavorid,
self.img)
self.servname1, self.flavorid, self.img)
self._wait_for_status(self.server1['id'], 'BUILD')
self.server2 = self._create_server(
self.servname2,
self.flavorid + 1,
self.img)
self.servname2, self.flavorid + 2, self.img)
self._wait_for_status(self.server2['id'], 'BUILD')
self._test_0060_reboot_server()
self._wait_for_status(self.server1['id'], 'REBOOT')
......@@ -345,10 +284,10 @@ class Cyclades(livetest.Generic):
self.server1 = self._create_server(
self.servname1, self.flavorid, self.img)
def test_0065_resize_server(self):
self.client.resize_server(self.servname1, self.flavorid + 1, self.img)
def _test_0065_resize_server(self):
self.client.resize_server(self.servname1, self.flavorid + 2)
srv = self.client.get_flavor_details(self.server1['id'])
self.assertEqual(srv['flavor']['id'], self.flavorid + 1)
self.assertEqual(srv['flavor']['id'], self.flavorid + 2)
def _test_0070_wait_test_servers_to_reboot(self):
"""Pseudo-test to wait for VMs to load"""
......@@ -359,16 +298,12 @@ class Cyclades(livetest.Generic):
def test_create_server_metadata(self):
"""Test create_server_metadata"""
self.server1 = self._create_server(
self.servname1,
self.flavorid,
self.img)
self.servname1, self.flavorid, self.img)
self._test_0080_create_server_metadata()
def _test_0080_create_server_metadata(self):
r1 = self.client.create_server_metadata(
self.server1['id'],
'mymeta',
'mymeta val')
self.server1['id'], 'mymeta', 'mymeta val')
self.assertTrue('mymeta' in r1)
r2 = self.client.get_server_metadata(self.server1['id'], 'mymeta')
self.assert_dicts_are_equal(r1, r2)
......@@ -376,9 +311,7 @@ class Cyclades(livetest.Generic):
def test_get_server_metadata(self):
"""Test get server_metadata"""
self.server1 = self._create_server(
self.servname1,
self.flavorid,
self.img)
self.servname1, self.flavorid, self.img)
self._test_0090_get_server_metadata()
def _test_0090_get_server_metadata(self):
......@@ -390,9 +323,7 @@ class Cyclades(livetest.Generic):
def test_update_server_metadata(self):
"""Test update_server_metadata"""
self.server1 = self._create_server(
self.servname1,
self.flavorid,
self.img)
self.servname1, self.flavorid, self.img)
self._test_0100_update_server_metadata()
def _test_0100_update_server_metadata(self):
......@@ -474,9 +405,7 @@ class Cyclades(livetest.Generic):
def test_shutdown_server(self):
"""Test shutdown_server"""
self.server1 = self._create_server(
self.servname1,
self.flavorid,
self.img)
self.servname1, self.flavorid, self.img)
self._wait_for_status(self.server1['id'], 'BUILD')
self._test_0170_shutdown_server()
......@@ -489,9 +418,7 @@ class Cyclades(livetest.Generic):
def test_start_server(self):
"""Test start_server"""
self.server1 = self._create_server(
self.servname1,
self.flavorid,
self.img)
self.servname1, self.flavorid, self.img)
self._wait_for_status(self.server1['id'], 'BUILD')
self.client.shutdown_server(self.server1['id'])
self._wait_for_status(self.server1['id'], 'ACTIVE')
......@@ -506,9 +433,7 @@ class Cyclades(livetest.Generic):
def test_get_server_console(self):
"""Test get_server_console"""
self.server2 = self._create_server(
self.servname2,
self.flavorid,
self.img)
self.servname2, self.flavorid, self.img)
self._wait_for_status(self.server2['id'], 'BUILD')
self._test_0190_get_server_console()
......@@ -522,9 +447,7 @@ class Cyclades(livetest.Generic):
def test_get_firewall_profile(self):
"""Test get_firewall_profile"""
self.server1 = self._create_server(
self.servname1,
self.flavorid,
self.img)
self.servname1, self.flavorid, self.img)
self._test_0200_get_firewall_profile()
def _test_0200_get_firewall_profile(self):
......@@ -535,9 +458,7 @@ class Cyclades(livetest.Generic):
def test_set_firewall_profile(self):
"""Test set_firewall_profile"""
self.server1 = self._create_server(
self.servname1,
self.flavorid,
self.img)
self.servname1, self.flavorid, self.img)
self._test_0210_set_firewall_profile()
def _test_0210_set_firewall_profile(self):
......@@ -573,9 +494,7 @@ class Cyclades(livetest.Generic):
def test_get_server_stats(self):
self.server1 = self._create_server(
self.servname1,
self.flavorid,
self.img)
self.servname1, self.flavorid, self.img)
self._test_0220_get_server_stats()
def _test_0220_get_server_stats(self):
......@@ -625,9 +544,7 @@ class Cyclades(livetest.Generic):
def test_connect_server(self):
"""Test connect_server"""
self.server1 = self._create_server(
self.servname1,
self.flavorid,
self.img)
self.servname1, self.flavorid, self.img)
self.network1 = self._create_network(self.netname1)
self._wait_for_status(self.server1['id'], 'BUILD')
self._wait_for_network(self.network1['id'], 'ACTIVE')
......@@ -635,9 +552,8 @@ class Cyclades(livetest.Generic):
def _test_0250_connect_server(self):
self.client.connect_server(self.server1['id'], self.network1['id'])
self.assertTrue(self._wait_for_nic(
self.network1['id'],
self.server1['id']))
self.assertTrue(
self._wait_for_nic(self.network1['id'], self.server1['id']))
def test_disconnect_server(self):
"""Test disconnect_server"""
......@@ -647,9 +563,7 @@ class Cyclades(livetest.Generic):
def _test_0250_disconnect_server(self):
self.client.disconnect_server(self.server1['id'], self.network1['id'])
self.assertTrue(self._wait_for_nic(
self.network1['id'],
self.server1['id'],
in_creation=False))
self.network1['id'], self.server1['id'], in_creation=False))
def _test_0260_wait_for_second_network(self):
self.network2 = self._create_network(self.netname2)
......@@ -658,9 +572,7 @@ class Cyclades(livetest.Generic):
def test_list_server_nics(self):
"""Test list_server_nics"""
self.server1 = self._create_server(
self.servname1,
self.flavorid,
self.img)
self.servname1, self.flavorid, self.img)
self.network2 = self._create_network(self.netname2)
self._wait_for_status(self.server1['id'], 'BUILD')
self._wait_for_network(self.network2['id'], 'ACTIVE')
......@@ -670,9 +582,8 @@ class Cyclades(livetest.Generic):
r = self.client.list_server_nics(self.server1['id'])
len0 = len(r)
self.client.connect_server(self.server1['id'], self.network2['id'])
self.assertTrue(self._wait_for_nic(
self.network2['id'],
self.server1['id']))
self.assertTrue(
self._wait_for_nic(self.network2['id'], self.server1['id']))
r = self.client.list_server_nics(self.server1['id'])
self.assertTrue(len(r) > len0)
......@@ -704,9 +615,7 @@ class Cyclades(livetest.Generic):
def test_list_network_nics(self):
"""Test list_server_nics"""
self.server1 = self._create_server(
self.servname1,
self.flavorid,
self.img)
self.servname1, self.flavorid, self.img)
self.network1 = self._create_network(self.netname1)
self.network2 = self._create_network(self.netname2)
self._wait_for_status(self.server1['id'], 'BUILD')
......@@ -719,8 +628,7 @@ class Cyclades(livetest.Generic):
self._test_0293_list_network_nics()
def _test_0293_list_network_nics(self):
netid1 = self.network1['id']
netid2 = self.network2['id']
netid1, netid2 = self.network1['id'], self.network2['id']
r = self.client.list_network_nics(netid1)
expected = ['nic-%s-1' % self.server1['id']]
self.assertEqual(r, expected)
......
......@@ -1111,6 +1111,7 @@ class Pithos(livetest.Generic):
def _test_0130_object_post(self):
self.client.container = self.c2
obj = 'test2'
"""create a filesystem file"""
self.files.append(NamedTemporaryFile())
newf = self.files[-1]
......@@ -1118,6 +1119,7 @@ class Pithos(livetest.Generic):
'ello!\n',
'This is a test line\n',
'inside a test file\n'])
"""create a file on container"""
r = self.client.object_put(
obj,
......@@ -1182,15 +1184,13 @@ class Pithos(livetest.Generic):
"""Check if_etag_(not)match"""
etag = r['etag']
"""
r = self.client.object_post(
obj,
update=True,
public=True,
if_etag_not_match=etag,
success=(412, 202, 204))
self.assertEqual(r.status_code, 412)
"""
#self.assertEqual(r.status_code, 412)
r = self.client.object_post(
obj,
......
......@@ -157,7 +157,7 @@ class PithosRestClient(StorageClient):
self._assert_account()
self.set_param('update', iff=update)
self.set_param('update', '', iff=update)
if groups:
for group, usernames in groups.items():
......@@ -354,7 +354,7 @@ class PithosRestClient(StorageClient):
"""
self._assert_container()
self.set_param('update', iff=update)
self.set_param('update', '', iff=update)
self.set_param('format', format, iff=format)
self.set_header('X-Container-Policy-Quota', quota)
......@@ -769,15 +769,10 @@ class PithosRestClient(StorageClient):
self.set_header('Content-Type', content_type)
self.set_header('Content-Encoding', content_encoding)
self.set_header('Content-Disposition', content_disposition)
if permissions:
perms = ''
for perm_type, perm_list in permissions.items():
if not perms:
perms = '' # Remove permissions
if perm_list:
perms += ';' if perms else ''
perms += '%s=%s' % (perm_type, ','.join(perm_list))
self.set_header('X-Object-Sharing', perms)
perms = ';'.join(
['%s=%s' % (k, ','.join(v)) for k, v in permissions.items() if (
v)]) if (permissions) else ''
self.set_header('X-Object-Sharing', perms, iff=permissions)
self.set_header('X-Object-Public', public, public is not None)
if metadata:
for key, val in metadata.items():
......@@ -864,14 +859,12 @@ class PithosRestClient(StorageClient):
self._assert_container()
self.set_param('format', format, iff=format)
self.set_param('update', iff=update)
self.set_param('update', '', iff=update)
self.set_header('If-Match', if_etag_match)
self.set_header('If-None-Match', if_etag_not_match)
self.set_header(
'Content-Length',
content_length,
iff=not transfer_encoding)
'Content-Length', content_length, iff=not transfer_encoding)
self.set_header('Content-Type', content_type)
self.set_header('Content-Range', content_range)
self.set_header('Transfer-Encoding', transfer_encoding)
......@@ -882,15 +875,10 @@ class PithosRestClient(StorageClient):
self.set_header('X-Source-Version', source_version)
self.set_header('X-Object-Bytes', object_bytes)
self.set_header('X-Object-Manifest', manifest)
if permissions:
perms = ''
for perm_type, perm_list in permissions.items():
if not perms:
perms = '' # Remove permissions
if perm_list:
perms += ';' if perms else ''
perms += '%s=%s' % (perm_type, ','.join(perm_list))
self.set_header('X-Object-Sharing', perms)
perms = ';'.join(
['%s=%s' % (k, ','.join(v)) for k, v in permissions.items() if (
v)]) if (permissions) else ''
self.set_header('X-Object-Sharing', perms, iff=permissions)
self.set_header('X-Object-Public', public, public is not None)
for key, val in metadata.items():
self.set_header('X-Object-Meta-' + key, val)
......
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