daemon: refactored how to get required commands, added usage of this func for validating distributed servers when added
This commit is contained in:
parent
6d4434bc12
commit
5e2ca0f549
3 changed files with 28 additions and 8 deletions
|
@ -9,7 +9,7 @@ import core.services
|
|||
from core import configservices, utils
|
||||
from core.configservice.manager import ConfigServiceManager
|
||||
from core.emulator.session import Session
|
||||
from core.executables import COMMON_REQUIREMENTS, OVS_REQUIREMENTS, VCMD_REQUIREMENTS
|
||||
from core.executables import get_requirements
|
||||
from core.services.coreservices import ServiceManager
|
||||
|
||||
|
||||
|
@ -79,13 +79,8 @@ class CoreEmu:
|
|||
:return: nothing
|
||||
:raises core.errors.CoreError: when an executable does not exist on path
|
||||
"""
|
||||
requirements = COMMON_REQUIREMENTS
|
||||
use_ovs = self.config.get("ovs") == "1"
|
||||
if use_ovs:
|
||||
requirements += OVS_REQUIREMENTS
|
||||
else:
|
||||
requirements += VCMD_REQUIREMENTS
|
||||
for requirement in requirements:
|
||||
for requirement in get_requirements(use_ovs):
|
||||
utils.which(requirement, required=True)
|
||||
|
||||
def load_services(self) -> None:
|
||||
|
|
|
@ -14,7 +14,8 @@ from fabric import Connection
|
|||
from invoke import UnexpectedExit
|
||||
|
||||
from core import utils
|
||||
from core.errors import CoreCommandError
|
||||
from core.errors import CoreCommandError, CoreError
|
||||
from core.executables import get_requirements
|
||||
from core.nodes.interface import GreTap
|
||||
from core.nodes.network import CoreNetwork, CtrlNet
|
||||
|
||||
|
@ -131,8 +132,17 @@ class DistributedController:
|
|||
:param name: distributed server name
|
||||
:param host: distributed server host address
|
||||
:return: nothing
|
||||
:raises CoreError: when there is an error validating server
|
||||
"""
|
||||
server = DistributedServer(name, host)
|
||||
for requirement in get_requirements(self.session.use_ovs()):
|
||||
try:
|
||||
server.remote_cmd(f"which {requirement}")
|
||||
except CoreCommandError:
|
||||
raise CoreError(
|
||||
f"server({server.name}) failed validation for "
|
||||
f"command({requirement})"
|
||||
)
|
||||
self.servers[name] = server
|
||||
cmd = f"mkdir -p {self.session.session_dir}"
|
||||
server.remote_cmd(cmd)
|
||||
|
|
|
@ -14,3 +14,18 @@ OVS_VSCTL: str = "ovs-vsctl"
|
|||
COMMON_REQUIREMENTS: List[str] = [SYSCTL, IP, ETHTOOL, TC, EBTABLES, MOUNT, UMOUNT]
|
||||
VCMD_REQUIREMENTS: List[str] = [VNODED, VCMD]
|
||||
OVS_REQUIREMENTS: List[str] = [OVS_VSCTL]
|
||||
|
||||
|
||||
def get_requirements(use_ovs: bool) -> List[str]:
|
||||
"""
|
||||
Retrieve executable requirements needed to run CORE.
|
||||
|
||||
:param use_ovs: True if OVS is being used, False otherwise
|
||||
:return: list of executable requirements
|
||||
"""
|
||||
requirements = COMMON_REQUIREMENTS
|
||||
if use_ovs:
|
||||
requirements += OVS_REQUIREMENTS
|
||||
else:
|
||||
requirements += VCMD_REQUIREMENTS
|
||||
return requirements
|
||||
|
|
Loading…
Reference in a new issue