Fix stepping cache bug with uri ammo

Change plugins loading slightly
This commit is contained in:
Andrey Pohilko 2012-10-05 20:46:59 +04:00
parent 01817d23ab
commit d244f5fc6e
4 changed files with 33 additions and 15 deletions

View File

@ -9,10 +9,10 @@ import fnmatch
import logging
import os
import sys
import tankcore
import tempfile
import time
import traceback
import tankcore
# FIXME: 1 remove lock in case of config format error
# TODO: 2 add system resources busy check

View File

@ -35,6 +35,7 @@ class MonitoringPlugin(AbstractPlugin):
if self.config == 'none':
self.monitoring = None
# TODO: 2 check for config file existence here
if self.config == 'auto':
self.config = os.path.dirname(__file__) + '/monitoring_default_config.xml'

View File

@ -358,7 +358,7 @@ class PhantomPlugin(AbstractPlugin):
if self.use_caching:
sep = "|"
hasher = hashlib.md5()
hashed_str = os.path.realpath(self.ammo_file) + sep + self.instances_schedule + sep + str(self.loop_limit)
hashed_str = self.instances_schedule + sep + str(self.loop_limit)
hashed_str += sep + str(self.ammo_limit) + sep + ';'.join(self.rps_schedule) + sep + self.autocases
hashed_str += sep + ";".join(self.uris) + sep + ";".join(self.headers)
@ -366,6 +366,7 @@ class PhantomPlugin(AbstractPlugin):
if not os.path.exists(self.ammo_file):
raise RuntimeError("Ammo file not found: %s", self.ammo_file)
hashed_str += sep + os.path.realpath(self.ammo_file)
stat = os.stat(self.ammo_file)
cnt = 0
for stat_option in stat:
@ -373,13 +374,13 @@ class PhantomPlugin(AbstractPlugin):
continue
cnt += 1
hashed_str += ";" + str(stat_option)
self.log.debug("stpd-hash source: %s", hashed_str)
hasher.update(hashed_str)
else:
if not self.uris:
raise RuntimeError("Neither phantom.ammofile nor phantom.uris specified")
hasher.update(';'.join(self.uris) + ';'.join(self.headers))
hashed_str += sep + ';'.join(self.uris) + sep + ';'.join(self.headers)
self.log.debug("stpd-hash source: %s", hashed_str)
hasher.update(hashed_str)
if not os.path.exists(self.cache_dir):
os.makedirs(self.cache_dir)
@ -619,7 +620,11 @@ class PhantomReader(AbstractReader):
'''
Read phantom results
'''
phout = self.phout.readlines()
if self.phout:
phout = self.phout.readlines()
else:
phout = []
self.log.debug("About to process %s phout lines", len(phout))
for line in phout:
line = self.partial_buffer + line

View File

@ -189,20 +189,25 @@ class TankCore:
Tells core to take plugin options and instantiate plugin classes
'''
self.log.info("Loading plugins...")
self.log.debug("sys.path: %s", sys.path)
self.artifacts_base_dir = os.path.expanduser(self.get_option(self.SECTION, "artifacts_base_dir", self.artifacts_base_dir))
self.artifacts_dir = self.get_option(self.SECTION, "artifacts_dir", "")
if self.artifacts_dir:
self.artifacts_dir = os.path.expanduser(self.artifacts_dir)
for (plugin_name, plugin_path) in self.config.get_options(self.SECTION, self.PLUGIN_PREFIX):
options = self.config.get_options(self.SECTION, self.PLUGIN_PREFIX)
#old_count = len(self.plugins)
#while old_count
for (plugin_name, plugin_path) in options:
if not plugin_path:
self.log.debug("Seems the plugin '%s' was disabled", plugin_name)
continue
instance = self.__load_plugin(plugin_name, plugin_path)
self.plugins[instance.get_key()] = instance
self.plugins_order.append(instance.get_key())
key = os.path.realpath(instance.get_key())
self.plugins[key] = instance
self.plugins_order.append(key)
self.log.debug("Plugin instances: %s", self.plugins)
self.log.debug("Plugins order: %s", self.plugins_order)
@ -212,12 +217,18 @@ class TankCore:
'''
self.log.debug("Loading plugin %s from %s", name, path)
for basedir in [''] + sys.path:
new_dir = basedir + '/' + path
if os.path.exists(basedir + '/' + path):
self.log.debug('Append to path basedir of: %s', new_dir)
sys.path.append(os.path.dirname(new_dir))
if basedir:
new_dir = basedir + '/' + path
else:
new_dir = path
if os.path.exists(new_dir):
new_dir = os.path.dirname(new_dir)
if new_dir not in sys.path:
self.log.debug('Append to path: %s', new_dir)
sys.path.append(new_dir)
res = None
classname = os.path.basename(path)[:-3]
self.log.debug("sys.path: %s", sys.path)
exec ("import " + classname)
script = "res=" + classname + "." + classname + "Plugin(self)"
self.log.debug("Exec: " + script)
@ -303,6 +314,7 @@ class TankCore:
def __collect_artifacts(self):
self.log.debug("Collecting artifacts")
if not self.artifacts_dir:
date_str = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S.")
self.artifacts_dir = tempfile.mkdtemp("", date_str, self.artifacts_base_dir)
@ -367,7 +379,7 @@ class TankCore:
Retrieve a plugin of desired class, KeyError raised otherwise
'''
self.log.debug("Searching for plugin: %s", needle)
key = needle.get_key()
key = os.path.realpath(needle.get_key())
return self.__get_plugin_by_key(key)