updated test cases to fix old broken code
This commit is contained in:
parent
77be7f5c30
commit
3ce416b610
5 changed files with 24 additions and 42 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -33,3 +33,6 @@ coverage.xml
|
|||
# ignore package files
|
||||
*.rpm
|
||||
*.deb
|
||||
|
||||
# pytest cache files
|
||||
.cache
|
||||
|
|
|
@ -118,7 +118,11 @@ class ServiceManager(object):
|
|||
:return: list of core services
|
||||
:rtype: list
|
||||
"""
|
||||
# validate path exists for importing
|
||||
# validate path exists
|
||||
logger.info("attempting to add services from path: %s", path)
|
||||
if not os.path.isdir(path):
|
||||
logger.warn("invalid custom service directory specified" ": %s" % path)
|
||||
# check if path is in sys.path
|
||||
logger.info("getting custom services from: %s", path)
|
||||
parent_path = os.path.dirname(path)
|
||||
if parent_path not in sys.path:
|
||||
|
@ -175,33 +179,10 @@ class CoreServices(ConfigurableManager):
|
|||
# dict of tuple of service objects, key is node number
|
||||
self.customservices = {}
|
||||
|
||||
paths = self.session.get_config_item('custom_services_dir')
|
||||
if paths:
|
||||
for path in paths.split(','):
|
||||
path = path.strip()
|
||||
self.importcustom(path)
|
||||
|
||||
# TODO: remove need for cyclic import
|
||||
from core.services import startup
|
||||
self.is_startup_service = startup.Startup.is_startup_service
|
||||
|
||||
def importcustom(self, path):
|
||||
"""
|
||||
Import services from a myservices directory.
|
||||
|
||||
:param str path: path to import custom services from
|
||||
:return: nothing
|
||||
"""
|
||||
|
||||
if not path or len(path) == 0:
|
||||
return
|
||||
|
||||
if not os.path.isdir(path):
|
||||
logger.warn("invalid custom service directory specified" ": %s" % path)
|
||||
return
|
||||
|
||||
ServiceManager.add_services(path)
|
||||
|
||||
def reset(self):
|
||||
"""
|
||||
Called when config message with reset flag is received
|
||||
|
|
|
@ -39,6 +39,7 @@ from core.misc import nodemaps
|
|||
from core.misc import nodeutils
|
||||
from core.misc.utils import closeonexec
|
||||
from core.misc.utils import daemonize
|
||||
from core.service import ServiceManager
|
||||
|
||||
DEFAULT_MAXFD = 1024
|
||||
|
||||
|
@ -313,6 +314,14 @@ def main():
|
|||
for a in args:
|
||||
logger.error("ignoring command line argument: %s", a)
|
||||
|
||||
# attempt load custom services
|
||||
service_paths = cfg.get("custom_services_dir")
|
||||
logger.debug("custom service paths: %s", service_paths)
|
||||
if service_paths:
|
||||
for service_path in service_paths.split(','):
|
||||
service_path = service_path.strip()
|
||||
ServiceManager.add_services(service_path)
|
||||
|
||||
if cfg["daemonize"] == "True":
|
||||
daemonize(rootdir=None, umask=0, close_fds=False,
|
||||
stdin=os.devnull,
|
||||
|
|
|
@ -8,12 +8,11 @@ import pytest
|
|||
|
||||
from mock.mock import MagicMock
|
||||
|
||||
from core import services
|
||||
from core.coreserver import CoreServer
|
||||
from core.misc import nodemaps
|
||||
from core.misc import nodeutils
|
||||
from core.netns import nodes
|
||||
from core.services import quagga
|
||||
from core.services import utility
|
||||
from core.session import Session
|
||||
from core.api.coreapi import CoreConfMessage
|
||||
from core.api.coreapi import CoreEventMessage
|
||||
|
@ -244,14 +243,6 @@ class Core(object):
|
|||
|
||||
class CoreServerTest(object):
|
||||
def __init__(self):
|
||||
# setup nodes
|
||||
node_map = nodemaps.NODES
|
||||
nodeutils.set_node_map(node_map)
|
||||
|
||||
# load emane services
|
||||
quagga.load_services()
|
||||
utility.load_services()
|
||||
|
||||
address = ("localhost", CORE_API_PORT)
|
||||
self.server = CoreServer(address, CoreRequestHandler, {
|
||||
"numthreads": 1,
|
||||
|
@ -320,19 +311,14 @@ class CoreServerTest(object):
|
|||
|
||||
@pytest.fixture()
|
||||
def session():
|
||||
# configure default nodes
|
||||
node_map = nodemaps.NODES
|
||||
nodeutils.set_node_map(node_map)
|
||||
# load default services
|
||||
services.load()
|
||||
|
||||
# create and return session
|
||||
session_fixture = Session(1, persistent=True)
|
||||
session_fixture.master = True
|
||||
assert os.path.exists(session_fixture.session_dir)
|
||||
|
||||
# load emane services
|
||||
quagga.load_services()
|
||||
utility.load_services()
|
||||
|
||||
# set location
|
||||
# session_fixture.master = True
|
||||
session_fixture.location.setrefgeo(47.57917, -122.13232, 2.00000)
|
||||
|
@ -362,6 +348,9 @@ def core(session, ip_prefix):
|
|||
|
||||
@pytest.fixture()
|
||||
def cored():
|
||||
# load default services
|
||||
services.load()
|
||||
|
||||
# create and return server
|
||||
server = CoreServerTest()
|
||||
yield server
|
||||
|
|
|
@ -36,7 +36,7 @@ class TestCore:
|
|||
|
||||
:param conftest.Core core: core fixture to test with
|
||||
"""
|
||||
core.session.services.importcustom(_SERVICES_PATH)
|
||||
ServiceManager.add_services(_SERVICES_PATH)
|
||||
assert ServiceManager.get("MyService")
|
||||
assert ServiceManager.get("MyService2")
|
||||
|
||||
|
|
Loading…
Reference in a new issue