Skip to content

Commit

Permalink
fix #659
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Lvov committed Jan 30, 2017
1 parent e9ce451 commit 3abf72d
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tempesta_fw/t/functional/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
__author__ = 'Tempesta Technologies Inc.'
__copyright__ = 'Copyright (C) 2016-2017 Tempesta Technologies Inc.'

__license__ = 'GPL2'

__all__ = [ "bomber", "fragmented_requests", "test_frang", "test_cache",
"test_parser" ]
"test_parser", "test_sched" ]


31 changes: 31 additions & 0 deletions tempesta_fw/t/functional/tests/helpers/apache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

import subprocess

def link_vhost(name):
p = subprocess.Popen(["ln", "-s", "/etc/apache2/sites-available/"
+ name, "/etc/apache2/sites-enabled"], stdout=subprocess.PIPE)


def is_apache():
try:
dist = get_dist()
Expand Down Expand Up @@ -34,6 +39,17 @@ def get_dist():
if out.find("ID=\"centos\"") > 0:
return "centos"

def stop():
distr = get_dist()
if is_apache():
if distr == "debian":
subprocess.call("service apache2 stop", shell = True)
elif distr == "centos":
subprocess.call("service httpd stop", shell = True)

else:
print("apache is not installed\n")

def start():
distr = get_dist()
if is_apache():
Expand All @@ -44,3 +60,18 @@ def start():

else:
print("apache is not installed\n")
p = subprocess.Popen(["ab", "http://127.0.0.1:8081/"], stdout=subprocess.PIPE)
out = p.stdout.read()
if len(out) > 0:
for s in out.split('\n'):
print(s)

def run_ab():
p = subprocess.Popen(["ab", "-n 10", "http://127.0.0.1:8081/"],
stdout=subprocess.PIPE)
out = p.stdout.read()
for line in out.split('\n'):
print(line)



30 changes: 30 additions & 0 deletions tempesta_fw/t/functional/tests/helpers/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def get_beport():
global be_port
if be_port == 0:
be_port = 8080

return be_port

class Config:
Expand Down Expand Up @@ -115,4 +116,33 @@ def add_vhost(self, name):

return self.curr_port

def __init__(self):
Config.__init__(self, '/etc/apache2/apache2.conf', new=False)

def add_vhost(self, name):
self.curr_port += 1
if apache.get_dist() == 'debian':
hconf = Config('/etc/apache2/sites-available/' + name +
'.conf',new=True)
hconf.add_string("<VirtualHost *:" +
str(self.curr_port)+ ">")
hconf.add_string("\tDocumentRoot /var/www/sched/html")
hconf.add_string("\tHeader set Vhost: \"" + name + "\"")
hconf.add_string("</VirtualHost>")
ports = Config('/etc/apache2/ports.conf', new=False)
ports.del_option(str(self.curr_port))
ports.add_string('\tListen ' + str(self.curr_port))
apache.link_vhost(name + '.conf')
else:
self.add_string("<VirtualHost *:" +
str(self.curr_port)+ ">")
self.add_string("\tDocumentRoot /var/www/sched/html")
self.add_string("\tHeader set Vhost: \"" + name + "\"")
self.add_string("</VirtualHost>")
self.add_string('Listen ' + str(self.curr_port))

return self.curr_port




65 changes: 65 additions & 0 deletions tempesta_fw/t/functional/tests/test_sched.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python

__author__ = 'Tempesta Technologies Inc.'
__copyright__ = 'Copyright (C) 2016-2017 Tempesta Technologies.'
__license__ = 'GPL2'

# #659 A functional test of schedulers of the Tempesta.

import apache
import conf
import tfw
class Test:
vh_curr = 1
sg_curr = 1
def __init__(self):
self.cfg = conf.TFWConfig()
self.apache_cfg = conf.ApacheConfig()
self.cfg.add_option('listen', '8081')

def add_sg(self, h_num, sched='round-robin'):
""" The function adds a srv_group section with h_num servers
to a Tempesta configuration. The Servers are virtual hosts of
the Apache configuration.
"""
self.cfg.add_string("")
self.cfg.add_section('srv_group ' + 'group' +
str(self.sg_curr) + ' sched=' + sched)
for x in range(0, h_num):
h_name = 'sched_' + str(self.vh_curr) + '.org'
port = self.apache_cfg.add_vhost(h_name)
self.cfg.add_option('server', '127.0.0.1:' + str(port))
self.vh_curr += 1
self.cfg.add_end_of_section()
self.cfg.add_string("")

self.sg_curr += 1

def add_rules(self,host='sched'):
self.cfg.add_string("")
self.cfg.add_section('sched_http_rules')
for x in range(1, self.sg_curr):
if x == 1:
self.cfg.add_option('match ' + 'group' +
str(x), ' * * *')
self.cfg.add_option('match ' + 'group' +
str(x),' host eq '+
host + str(x))
self.cfg.add_end_of_section()

def run(self):
"""The function adds 100 server groups with 2 servers for group.
Then it adds rules for the groups, starts the Tempesta, then
runs the ab(Apache Benchmark), prints its output.
"""
for x in range(1, 100):
self.add_sg(2)
self.add_rules('sched')
apache.stop()
apache.start()
tfw.start()
print("tfw started")
apache.run_ab()

def get_name(self):
return 'test schedulers'

0 comments on commit 3abf72d

Please sign in to comment.