From c7701728041afc24ae19c2f88d361d4cb86059f9 Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Wed, 18 Jun 2014 16:16:44 +0900 Subject: 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 Signed-off-by: FUJITA Tomonori --- ryu/base/app_manager.py | 8 ++++++-- 1 file 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 -- cgit v1.2.3