blob: 0864d52d29ddbd7028ea25c0146eb6443a2bf4c5 [file] [log] [blame]
import logging, os, socket, time
from autotest_lib.client.bin import utils
from autotest_lib.client.common_lib import error
def run_softlockup(test, params, env):
soft lockup/drift test with stress.
1) Boot up a VM.
2) Build stress on host and guest.
3) run heartbeat with the given options on server and host.
3) Run for a relatively long time length. ex: 12, 18 or 24 hours.
4) Output the test result and observe drift.
@param test: KVM test object.
@param params: Dictionary with the test parameters.
@param env: Dictionary with test environment.
stress_setup_cmd = params.get("stress_setup_cmd")
stress_cmd = params.get("stress_cmd")
server_setup_cmd = params.get("server_setup_cmd")
drift_cmd = params.get("drift_cmd")
kill_stress_cmd = params.get("kill_stress_cmd")
kill_monitor_cmd = params.get("kill_monitor_cmd")
threshold = int(params.get("stress_threshold"))
monitor_log_file_server = params.get("monitor_log_file_server")
monitor_log_file_client = params.get("monitor_log_file_client")
test_length = int(3600 * float(params.get("test_length")))
monitor_port = int(params.get("monitor_port"))
vm = env.get_vm(params["main_vm"])
login_timeout = int(params.get("login_timeout", 360))
stress_dir = os.path.join(os.environ['AUTODIR'], "tests/stress")
monitor_dir = os.path.join(test.bindir, 'deps')
def _kill_guest_programs(session, kill_stress_cmd, kill_monitor_cmd):"Kill stress and monitor on guest")
def _kill_host_programs(kill_stress_cmd, kill_monitor_cmd):"Kill stress and monitor on host"), ignore_status=True), ignore_status=True)
def host():"Setup monitor server on host")
# Kill previous instances of the host load programs, if any
_kill_host_programs(kill_stress_cmd, kill_monitor_cmd)
# Cleanup previous log instances
if os.path.isfile(monitor_log_file_server):
# Opening firewall ports on host"iptables -F", ignore_status=True)
# Run heartbeat on host % (monitor_dir, threshold,
monitor_log_file_server, monitor_port))"Build stress on host")
# Uncompress and build stress on host % stress_dir)"Run stress on host")
# stress_threads = 2 * n_cpus
threads_host = 2 * utils.count_cpus()
# Run stress test on host % (stress_dir, threads_host))
def guest():
host_ip = socket.gethostbyname(socket.gethostname())
except socket.error:
# Hackish, but works well on stand alone (laptop) setups
# with access to the internet. If this fails, well, then
# not much else can be done...
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("", 80))
host_ip = s.getsockname()[0]
except socket.error, (value, e):
raise error.TestError("Could not determine host IP: %d %s" %
(value, e))
# Now, starting the guest
session = vm.wait_for_login(timeout=login_timeout)
# Kill previous instances of the load programs, if any
_kill_guest_programs(session, kill_stress_cmd, kill_monitor_cmd)
# Clean up previous log instances
session.cmd("rm -f %s" % monitor_log_file_client)
# Opening firewall ports on guest
session.cmd("iptables -F")
# Get required files and copy them from host to guest
monitor_path = os.path.join(test.bindir, 'deps', '')
stress_path = os.path.join(os.environ['AUTODIR'], "tests", "stress",
vm.copy_files_to(monitor_path, "/tmp")
vm.copy_files_to(stress_path, "/tmp")"Setup monitor client on guest")
# Start heartbeat on guest
session.cmd(params.get("client_setup_cmd") %
("/tmp", host_ip, monitor_log_file_client, monitor_port))"Build stress on guest")
# Uncompress and build stress on guest
session.cmd(stress_setup_cmd % "/tmp", timeout=200)"Run stress on guest")
# stress_threads = 2 * n_vcpus
threads_guest = 2 * int(params.get("smp", 1))
# Run stress test on guest
session.cmd(stress_cmd % ("/tmp", threads_guest))
# Wait and report
logging.debug("Wait for %d s", test_length)
# Kill instances of the load programs on both guest and host
_kill_guest_programs(session, kill_stress_cmd, kill_monitor_cmd)
_kill_host_programs(kill_stress_cmd, kill_monitor_cmd)
# Collect drift
drift = utils.system_output(drift_cmd % monitor_log_file_server)"Drift noticed: %s", drift)