From 5e2ca0f5497b2b5ed43e104d29860a5a1297af1b Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Sat, 18 Jul 2020 11:56:48 -0700 Subject: [PATCH] daemon: refactored how to get required commands, added usage of this func for validating distributed servers when added --- daemon/core/emulator/coreemu.py | 9 ++------- daemon/core/emulator/distributed.py | 12 +++++++++++- daemon/core/executables.py | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/daemon/core/emulator/coreemu.py b/daemon/core/emulator/coreemu.py index 016f2e5b..c07d8c95 100644 --- a/daemon/core/emulator/coreemu.py +++ b/daemon/core/emulator/coreemu.py @@ -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: diff --git a/daemon/core/emulator/distributed.py b/daemon/core/emulator/distributed.py index 381eb019..a5e1009f 100644 --- a/daemon/core/emulator/distributed.py +++ b/daemon/core/emulator/distributed.py @@ -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) diff --git a/daemon/core/executables.py b/daemon/core/executables.py index 17aecc1d..6eb0214a 100644 --- a/daemon/core/executables.py +++ b/daemon/core/executables.py @@ -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