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
|
# ignore package files
|
||||||
*.rpm
|
*.rpm
|
||||||
*.deb
|
*.deb
|
||||||
|
|
||||||
|
# pytest cache files
|
||||||
|
.cache
|
||||||
|
|
|
@ -118,7 +118,11 @@ class ServiceManager(object):
|
||||||
:return: list of core services
|
:return: list of core services
|
||||||
:rtype: list
|
: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)
|
logger.info("getting custom services from: %s", path)
|
||||||
parent_path = os.path.dirname(path)
|
parent_path = os.path.dirname(path)
|
||||||
if parent_path not in sys.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
|
# dict of tuple of service objects, key is node number
|
||||||
self.customservices = {}
|
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
|
# TODO: remove need for cyclic import
|
||||||
from core.services import startup
|
from core.services import startup
|
||||||
self.is_startup_service = startup.Startup.is_startup_service
|
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):
|
def reset(self):
|
||||||
"""
|
"""
|
||||||
Called when config message with reset flag is received
|
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 import nodeutils
|
||||||
from core.misc.utils import closeonexec
|
from core.misc.utils import closeonexec
|
||||||
from core.misc.utils import daemonize
|
from core.misc.utils import daemonize
|
||||||
|
from core.service import ServiceManager
|
||||||
|
|
||||||
DEFAULT_MAXFD = 1024
|
DEFAULT_MAXFD = 1024
|
||||||
|
|
||||||
|
@ -313,6 +314,14 @@ def main():
|
||||||
for a in args:
|
for a in args:
|
||||||
logger.error("ignoring command line argument: %s", a)
|
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":
|
if cfg["daemonize"] == "True":
|
||||||
daemonize(rootdir=None, umask=0, close_fds=False,
|
daemonize(rootdir=None, umask=0, close_fds=False,
|
||||||
stdin=os.devnull,
|
stdin=os.devnull,
|
||||||
|
|
|
@ -8,12 +8,11 @@ import pytest
|
||||||
|
|
||||||
from mock.mock import MagicMock
|
from mock.mock import MagicMock
|
||||||
|
|
||||||
|
from core import services
|
||||||
from core.coreserver import CoreServer
|
from core.coreserver import CoreServer
|
||||||
from core.misc import nodemaps
|
from core.misc import nodemaps
|
||||||
from core.misc import nodeutils
|
from core.misc import nodeutils
|
||||||
from core.netns import nodes
|
from core.netns import nodes
|
||||||
from core.services import quagga
|
|
||||||
from core.services import utility
|
|
||||||
from core.session import Session
|
from core.session import Session
|
||||||
from core.api.coreapi import CoreConfMessage
|
from core.api.coreapi import CoreConfMessage
|
||||||
from core.api.coreapi import CoreEventMessage
|
from core.api.coreapi import CoreEventMessage
|
||||||
|
@ -244,14 +243,6 @@ class Core(object):
|
||||||
|
|
||||||
class CoreServerTest(object):
|
class CoreServerTest(object):
|
||||||
def __init__(self):
|
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)
|
address = ("localhost", CORE_API_PORT)
|
||||||
self.server = CoreServer(address, CoreRequestHandler, {
|
self.server = CoreServer(address, CoreRequestHandler, {
|
||||||
"numthreads": 1,
|
"numthreads": 1,
|
||||||
|
@ -320,19 +311,14 @@ class CoreServerTest(object):
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def session():
|
def session():
|
||||||
# configure default nodes
|
# load default services
|
||||||
node_map = nodemaps.NODES
|
services.load()
|
||||||
nodeutils.set_node_map(node_map)
|
|
||||||
|
|
||||||
# create and return session
|
# create and return session
|
||||||
session_fixture = Session(1, persistent=True)
|
session_fixture = Session(1, persistent=True)
|
||||||
session_fixture.master = True
|
session_fixture.master = True
|
||||||
assert os.path.exists(session_fixture.session_dir)
|
assert os.path.exists(session_fixture.session_dir)
|
||||||
|
|
||||||
# load emane services
|
|
||||||
quagga.load_services()
|
|
||||||
utility.load_services()
|
|
||||||
|
|
||||||
# set location
|
# set location
|
||||||
# session_fixture.master = True
|
# session_fixture.master = True
|
||||||
session_fixture.location.setrefgeo(47.57917, -122.13232, 2.00000)
|
session_fixture.location.setrefgeo(47.57917, -122.13232, 2.00000)
|
||||||
|
@ -362,6 +348,9 @@ def core(session, ip_prefix):
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def cored():
|
def cored():
|
||||||
|
# load default services
|
||||||
|
services.load()
|
||||||
|
|
||||||
# create and return server
|
# create and return server
|
||||||
server = CoreServerTest()
|
server = CoreServerTest()
|
||||||
yield server
|
yield server
|
||||||
|
|
|
@ -36,7 +36,7 @@ class TestCore:
|
||||||
|
|
||||||
:param conftest.Core core: core fixture to test with
|
: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("MyService")
|
||||||
assert ServiceManager.get("MyService2")
|
assert ServiceManager.get("MyService2")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue