Skip to content

Commit

Permalink
tests: raise better framework errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vankoven committed Feb 27, 2017
1 parent 2a3499d commit e29f344
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion tempesta_fw/t/functional/helpers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__all__ = ['be', 'cli', 'tfw', 'tfw_test', 'tf_cfg',
'nginx', 'tempesta', 'siege']
'nginx', 'tempesta', 'siege', 'framework']
9 changes: 5 additions & 4 deletions tempesta_fw/t/functional/helpers/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import abc
import re
import multiprocessing.dummy as multiprocessing
from . import tf_cfg, remote, nginx, tempesta, siege
from . import tf_cfg, remote, framework, nginx, tempesta, siege

__author__ = 'Tempesta Technologies, Inc.'
__copyright__ = 'Copyright (C) 2017 Tempesta Technologies, Inc.'
Expand Down Expand Up @@ -195,9 +195,9 @@ def set_user_agent(self, ua):

def client_run_blocking(client):
tf_cfg.dbg(3, '\tRunning HTTP client on %s' % remote.client.host)
assert client.prepare()
framework.assertTrue(client.prepare())
stdout, stderr = remote.client.run_cmd(client.cmd)
assert client.parse_out(stdout, stderr)
framework.assertTrue(client.parse_out(stdout, stderr))
client.cleanup()

def __clients_prepare(client):
Expand Down Expand Up @@ -226,7 +226,8 @@ def clients_run_parallel(clients):

pool = multiprocessing.Pool(len(clients))
results = pool.map(__clients_prepare, clients)
assert all(results), 'Some HTTP clients failed on prepare stage!'
framework.assertTrue(all(results),
'Some HTTP clients failed on prepare stage!')

results = pool.map(__clients_run, clients)

Expand Down
4 changes: 2 additions & 2 deletions tempesta_fw/t/functional/helpers/nginx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import print_function
import re
from . import tf_cfg
from . import tf_cfg, framework

__author__ = 'Tempesta Technologies, Inc.'
__copyright__ = 'Copyright (C) 2017 Tempesta Technologies, Inc.'
Expand Down Expand Up @@ -81,7 +81,7 @@ def set_port(self, port):
' '.join(['listen', str(port), ';']))

def set_workdir(self, workdir):
assert workdir
framework.assertTrue(workdir)
self.__replace(r'pid[ ]+([\w._/]+);',
''.join(['pid ', workdir, self.pidfile_name, ' ;']))

Expand Down
16 changes: 8 additions & 8 deletions tempesta_fw/t/functional/helpers/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import abc
import paramiko
import subprocess32 as subprocess
from . import tf_cfg
from . import tf_cfg, framework

__author__ = 'Tempesta Technologies, Inc.'
__copyright__ = 'Copyright (C) 2017 Tempesta Technologies, Inc.'
Expand Down Expand Up @@ -57,7 +57,7 @@ def run_cmd(self, cmd, timeout=10, ignore_stderr=False, err_msg=''):
if not err_msg:
err_msg = ("Error running command '%s' on %s: %s" %
(cmd, self.host, e))
assert False, err_msg
framework.bug(err_msg)
return stdout, stderr

def mkdir(self, path):
Expand Down Expand Up @@ -104,7 +104,7 @@ def connect(self):
self.ssh.connect(hostname=self.host, username=self.user,
port=self.port, timeout=5)
except Exception as e:
assert False, ("Error connecting %s: %s" % (self.host, e))
framework.bug("Error connecting %s: %s" % (self.host, e))

def close(self):
""" Release SSH connection without waitning for GC. """
Expand All @@ -124,7 +124,7 @@ def run_cmd(self, cmd, timeout=10, ignore_stderr=False, err_msg=''):
if not err_msg:
err_msg = ("Error running command '%s' on %s: %s" %
(cmd, self.host, e))
assert False, err_msg
framework.bug(err_msg)
return stdout, stderr

def mkdir(self, path):
Expand All @@ -144,8 +144,8 @@ def copy_file(self, filename, content, path=None):
sfile.flush()
sftp.close()
except Exception as e:
assert False, ("Error copying file %s to %s: %s" %
(filename, self.host, e))
framework.bug(("Error copying file %s to %s: %s" %
(filename, self.host, e)))

def remove_file(self, filename):
if DEBUG_FILES:
Expand All @@ -155,8 +155,8 @@ def remove_file(self, filename):
sftp.unlink(filename)
sftp.close()
except Exception as e:
assert False, ("Error removing file %s on %s: %s" %
(filename, self.host, e))
framework.bug(("Error removing file %s on %s: %s" %
(filename, self.host, e)))



Expand Down
7 changes: 4 additions & 3 deletions tempesta_fw/t/functional/helpers/tempesta.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from . import framework

__author__ = 'Tempesta Technologies, Inc.'
__copyright__ = 'Copyright (C) 2017 Tempesta Technologies, Inc.'
Expand Down Expand Up @@ -121,8 +122,8 @@ def __init__(self, name, sched='round-robin'):
self.servers = []

def add_server(self, ip, port, conns=server_conns_default()):
assert conns < server_conns_max()
assert len(self.servers) < servers_in_group()
framework.assertTrue(conns < server_conns_max())
framework.assertTrue(len(self.servers) < servers_in_group())
conns_str = (' conns_n=%d' % conns if (conns != server_conns_default())
else '')
self.servers.append('server %s:%d%s;' % (ip, port, conns_str))
Expand All @@ -145,7 +146,7 @@ def __init__(self):

def add_sg(self, new_sg):
for sg in self.server_groups:
assert(sg.name != new_sg.name)
framework.assertTrue(sg.name != new_sg.name)
self.server_groups.append(new_sg)

def get_config(self):
Expand Down

0 comments on commit e29f344

Please sign in to comment.