Fix loading plugins from path with relative imports
Also: - fixes `tox -e self` job. It was designed to ensure that relative imports are working, but ignored the error. - changed `rally task sla-check` to return not zero code in case of finding non of workloads had been executed. Change-Id: I723f81abdfbe7c71e9ec36aaf6f0936a42eac425
This commit is contained in:
parent
12404b8402
commit
e9264de713
@ -31,7 +31,13 @@ Changed
|
||||
|
||||
* *path_or_url* plugin follows redirects while validating urls now.
|
||||
|
||||
* Move *rally.common.sshutils* to *rally.utils.sshutils*
|
||||
* *rally task sla-check` fails if there is no data.
|
||||
|
||||
Deprecated
|
||||
~~~~~~~~~~
|
||||
|
||||
* Module *rally.common.sshutils* is deprecated. Use *rally.utils.sshutils*
|
||||
instead.
|
||||
|
||||
Removed
|
||||
~~~~~~~
|
||||
|
@ -915,6 +915,8 @@ class TaskCommands(object):
|
||||
else:
|
||||
cliutils.print_list(data, ("benchmark", "pos", "criterion",
|
||||
"status", "detail"))
|
||||
if not data:
|
||||
return 2
|
||||
return failed_criteria
|
||||
|
||||
@cliutils.args("--uuid", type=str, dest="task_id",
|
||||
|
@ -132,6 +132,10 @@ def load_plugins(dir_or_file, depth=0):
|
||||
LOG.info("Loading plugins from directories %s/*" %
|
||||
directory.rstrip("/"))
|
||||
for root, _dirs, files in os.walk(directory, followlinks=True):
|
||||
if root not in sys.path:
|
||||
# this hack is required to support relative imports
|
||||
sys.path.append(root)
|
||||
|
||||
for plugin in files:
|
||||
load_plugins(os.path.join(root, plugin), depth=1)
|
||||
|
||||
@ -141,9 +145,10 @@ def load_plugins(dir_or_file, depth=0):
|
||||
if depth:
|
||||
msg = "\t" + msg
|
||||
LOG.info(msg)
|
||||
module_name = os.path.splitext(plugin_file.split("/")[-1])[0]
|
||||
try:
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
plugin_file, plugin_file)
|
||||
module_name, plugin_file)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
|
||||
@ -155,5 +160,4 @@ def load_plugins(dir_or_file, depth=0):
|
||||
LOG.warning("%(msg)s: %(e)s" % {"msg": msg, "e": e})
|
||||
return
|
||||
_loaded_modules.append(module)
|
||||
LOG.info("\t Loaded module with plugins: %s" %
|
||||
os.path.splitext(plugin_file.split("/")[-1])[0])
|
||||
LOG.info("\t Loaded module with plugins: %s" % module_name)
|
||||
|
@ -2,7 +2,7 @@
|
||||
vars:
|
||||
results_dir: "{{ zuul.project.src_dir }}/.test_results/"
|
||||
html_report: "{{ tox_env }}_report.html"
|
||||
json_report: "{{ tox_env }}_report.html"
|
||||
json_report: "{{ tox_env }}_report.json"
|
||||
tasks:
|
||||
- shell: "ls {{ results_dir }}"
|
||||
register: results_dir_stat
|
||||
|
@ -13,7 +13,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""Simple app based on rally api for testing porpuses"""
|
||||
"""Simple app based on rally api for testing purpose"""
|
||||
|
||||
import sys
|
||||
|
||||
|
@ -25,10 +25,15 @@ TMP_RALLY_DB="/tmp/self-rally-$RND.sqlite"
|
||||
DBCONNSTRING="sqlite:///$TMP_RALLY_DB"
|
||||
RALLY="rally --config-file $TMP_RALLY_CONF"
|
||||
|
||||
# Create temp db
|
||||
# Create temp cfg
|
||||
cp etc/rally/rally.conf.sample $TMP_RALLY_CONF
|
||||
sed -i.bak "s|#connection =.*|connection = \"$DBCONNSTRING\"|" $TMP_RALLY_CONF
|
||||
rally --config-file $TMP_RALLY_CONF db create
|
||||
|
||||
# ensure plugins loading
|
||||
$RALLY --debug --plugin-paths=$PLUGIN_PATHS plugin show --name FakePlugin.testplugin
|
||||
|
||||
# Create db
|
||||
$RALLY db create
|
||||
|
||||
# Create self deployment
|
||||
$RALLY -d env create --name=self
|
||||
@ -44,10 +49,5 @@ set -e
|
||||
$RALLY task report --html-static --out $HTML_REPORT
|
||||
$RALLY task report --json --out $JSON_REPORT
|
||||
|
||||
if [ -n "$ZUUL_PROJECT" ]; then
|
||||
gzip -9 -f $HTML_REPORT
|
||||
gzip -9 -f $JSON_REPORT
|
||||
fi
|
||||
|
||||
# Check sla (this may fail the job)
|
||||
$RALLY task sla-check
|
||||
|
@ -95,7 +95,7 @@ class LoadExtraModulesTestCase(test.TestCase):
|
||||
test_path = "/somewhere"
|
||||
discover.load_plugins(test_path)
|
||||
expected = [
|
||||
mock.call(p, p)
|
||||
mock.call(p.rsplit("/", 1)[1][:-3], p)
|
||||
for p in ("/somewhere/plugin1.py", "/somewhere/subdir/plugin2.py",
|
||||
"/somewhere/subdir/subsubdir/plugin3.py")
|
||||
]
|
||||
@ -111,7 +111,7 @@ class LoadExtraModulesTestCase(test.TestCase):
|
||||
path = "/somewhere/plugin.py"
|
||||
discover.load_plugins(path)
|
||||
|
||||
mock_spec_from_file_location.assert_called_once_with(path, path)
|
||||
mock_spec_from_file_location.assert_called_once_with("plugin", path)
|
||||
mock_module_from_spec.assert_called_once_with(
|
||||
mock_spec_from_file_location.return_value)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user