Fix rally plugins relative imports

We are not able to use relative imports for plugins that are
outside of rally package.

To fix this we should add to sys.path all directories with Rally
plugins.

This is quite easy fix. But in any case it includes functional test
that checks that this actually works in real life.

+ Fix of Rally gates to copy whole tree not just *.py files from
  rally-jobs/plugins/

Change-Id: Ie53dc2ba5c32a5e83d84d0ea5703e2e04b10ff33
Closes-bug: #1446923
This commit is contained in:
Boris Pavlovic 2015-04-22 04:25:03 +03:00
parent 5ec83a73bd
commit 6bb572e046
6 changed files with 13 additions and 1 deletions

View File

View File

@ -19,6 +19,9 @@ import time
from rally.benchmark.scenarios import base
# This is used to test relative import
from test_relative_import import zzz
class FakePlugin(base.Scenario):
"""Fake plugin with a scenario."""
@ -37,5 +40,6 @@ class FakePlugin(base.Scenario):
:param factor: influences the argument value for a time.sleep() call
"""
zzz.some_very_important_function()
self._test1(factor)
self._test2(factor)

View File

@ -0,0 +1,5 @@
# This module is used just for test that relative imports work well
def some_very_important_function():
return 42

View File

@ -252,6 +252,9 @@ def load_plugins(directory):
to_load.extend((plugin[:-3], root)
for plugin in files if plugin.endswith(".py"))
for plugin, directory in to_load:
if directory not in sys.path:
sys.path.append(directory)
fullpath = os.path.join(directory, plugin)
try:
fp, pathname, descr = imp.find_module(plugin, [directory])

View File

@ -36,7 +36,7 @@ RALLY_PLUGINS_DIR=~/.rally/plugins
mkdir -p $RALLY_PLUGINS_DIR
if [ -d $PLUGINS_DIR ]; then
cp -r $PLUGINS_DIR/*.py $RALLY_PLUGINS_DIR
cp -r $PLUGINS_DIR/ $RALLY_PLUGINS_DIR
fi
if [ -d $EXTRA_DIR ]; then