daemon: moved executable check to CoreEmu and separated them into their own module core.executables

This commit is contained in:
Blake Harnden 2020-06-23 09:11:37 -07:00
parent c43dd60a42
commit e0c9f9c832
13 changed files with 75 additions and 44 deletions

View file

@ -13,10 +13,9 @@ import time
from typing import TYPE_CHECKING, Dict, Iterable, List, Optional, Set, Tuple, Type
from core import utils
from core.constants import which
from core.emulator.data import FileData
from core.emulator.enumerations import ExceptionLevels, MessageFlags, RegisterTlvs
from core.errors import CoreCommandError
from core.errors import CoreCommandError, CoreError
from core.nodes.base import CoreNode
if TYPE_CHECKING:
@ -262,7 +261,10 @@ class ServiceManager:
# validate dependent executables are present
for executable in service.executables:
which(executable, required=True)
try:
utils.which(executable, required=True)
except CoreError as e:
raise CoreError(f"service({name}): {e}")
# validate service on load succeeds
try:
@ -300,7 +302,7 @@ class ServiceManager:
try:
cls.add(service)
except ValueError as e:
except (CoreError, ValueError) as e:
service_errors.append(service.name)
logging.debug("not loading service(%s): %s", service.name, e)
return service_errors

View file

@ -5,8 +5,9 @@ from typing import Optional, Tuple
import netaddr
from core import constants, utils
from core import utils
from core.errors import CoreCommandError
from core.executables import SYSCTL_BIN
from core.nodes.base import CoreNode
from core.services.coreservices import CoreService, ServiceMode
@ -47,19 +48,13 @@ class IPForwardService(UtilService):
%(sysctl)s -w net.ipv4.conf.all.rp_filter=0
%(sysctl)s -w net.ipv4.conf.default.rp_filter=0
""" % {
"sysctl": constants.SYSCTL_BIN
"sysctl": SYSCTL_BIN
}
for iface in node.get_ifaces():
name = utils.sysctl_devname(iface.name)
cfg += "%s -w net.ipv4.conf.%s.forwarding=1\n" % (
constants.SYSCTL_BIN,
name,
)
cfg += "%s -w net.ipv4.conf.%s.send_redirects=0\n" % (
constants.SYSCTL_BIN,
name,
)
cfg += "%s -w net.ipv4.conf.%s.rp_filter=0\n" % (constants.SYSCTL_BIN, name)
cfg += "%s -w net.ipv4.conf.%s.forwarding=1\n" % (SYSCTL_BIN, name)
cfg += "%s -w net.ipv4.conf.%s.send_redirects=0\n" % (SYSCTL_BIN, name)
cfg += "%s -w net.ipv4.conf.%s.rp_filter=0\n" % (SYSCTL_BIN, name)
return cfg