"""Script run before tests start.

This script is run with some additional globals set:

- project_name: The name of this project (dir)
- cmd_opts: Commandline args from stress-run invocation
  Includes the stresstest-project directory.
- cfg_opts: options as set in local config.cfg.

Context Python is normally the version used when running bootstrap on
the waeup.stress package.
"""
import waeup.stress

instance=cfg_opts['instance']
mode = cfg_opts['instance_mode']

print "PRE-RUN.PY: using instance: waeup.%s" % instance

## removes any existing ZODB (for a clean ZODB at start)
waeup.stress.remove_zodb(instance)

## installs a University named 'stress_app' in root folder
waeup.stress.install_app(instance)

## starts an instance as daemon
waeup.stress.start_instance(instance, mode=mode)
## wait for instance to come up
waeup.stress.wait_for_startup(cfg_opts['host'], int(cfg_opts['baseport']))

## we need a running instance, so leave this commented out.
#waeup.stress.stop_instance(instance)
