diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2014-06-18 16:16:44 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-06-19 08:41:51 +0900 |
commit | c7701728041afc24ae19c2f88d361d4cb86059f9 (patch) | |
tree | f79b76796f3f32b15ad38b08db526fdda2df12c3 | |
parent | 03731ad04cab7746e095c44934fbdee3f1134ea0 (diff) |
app_manager: prevent loading unnecessary RyuApps
don't load RyuApps which is just imported and not defined in the module.
for example, if we run the script "test.py" as shown below by
$ ryu run test.py
the past implementation loads and instantiates not only Test but also RyuApp
and DPSet. this patch fix this wrong behavior
test.py
===
from ryu.base.app_manager import RyuApp
from ryu.controller.dpset import DPSet
class Test(RyuApp):
_CONTEXTS = {'dpset' : DPSet}
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/base/app_manager.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/ryu/base/app_manager.py b/ryu/base/app_manager.py index 695c401e..357d34d6 100644 --- a/ryu/base/app_manager.py +++ b/ryu/base/app_manager.py @@ -27,6 +27,7 @@ import inspect import itertools import logging import sys +import os from ryu import cfg from ryu import utils @@ -338,8 +339,11 @@ class AppManager(object): def load_app(self, name): mod = utils.import_module(name) - clses = inspect.getmembers(mod, lambda cls: (inspect.isclass(cls) and - issubclass(cls, RyuApp))) + clses = inspect.getmembers(mod, + lambda cls: (inspect.isclass(cls) and + issubclass(cls, RyuApp) and + mod.__name__ == + cls.__module__)) if clses: return clses[0][1] return None |