Commit b0be02a6 authored by Arnaud Fontaine's avatar Arnaud Fontaine

Allow to set the source IP address in userInfo.user_tuple.

Using the same IP address may produce unrealistic results, thus allow to set
the source IP address (only meaningful when not using SlapOS). Network alias
interfaces must be set up before running the script.
parent 29dd9cc8
# Specify user login/password used to run the tests
# Specify user login/password used to run the tests. Note that there must be
# the same number of users specified here *and* on the script command-line.
user_tuple = (('zope', 'zope'),)
# A more complex example setting the source IP address as well, assuming the
# users and network alias interfaces (not necessary with SlapOS though) have
# been created beforehand
#user_tuple = tuple((('zope%d' % i, 'zope', '192.168.168.%d' % (i + 1))
# for i in range(30)))
......@@ -34,6 +34,7 @@ import logging
import signal
import sys
import datetime
import socket
from ..testbrowser.browser import Browser
......@@ -48,7 +49,13 @@ class BenchmarkProcess(multiprocessing.Process):
self._nb_users = nb_users
self._user_index = user_index
self._base_url, self._erp5_site_id = argument_namespace.url
self._username, self._password = argument_namespace.user_tuple[user_index]
try:
self._username, self._password, self._source_ip = \
argument_namespace.user_tuple[user_index]
except ValueError:
self._source_ip = None
self._username, self._password = argument_namespace.user_tuple[user_index]
# Initialized when running the test
self._browser = None
......@@ -125,6 +132,20 @@ class BenchmarkProcess(multiprocessing.Process):
self._logger = result_instance.logger
# Set up the source IP address in order to be more realistic (can be given
# as the third element in userInfo.user_tuple) by monkey-patching
# socket.socket() as mechanize doesn't provide a way to call bind after
# creating the new socket and before calling connect()
if self._source_ip:
_socket = socket.socket
def _patched_socket(*args, **kwargs):
new_socket = _socket(*args, **kwargs)
self._logger.debug("source IP: %s" % self._source_ip)
new_socket.bind((self._source_ip, 0))
return new_socket
socket.socket = _patched_socket
# Ensure the data are flushed before exiting, handled by Result class
# __exit__ block
signal.signal(signal.SIGTERM, self.stopGracefully)
......
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