diff --git a/daemon/core/nodes/base.py b/daemon/core/nodes/base.py index 147989d7..d2d49fb4 100644 --- a/daemon/core/nodes/base.py +++ b/daemon/core/nodes/base.py @@ -421,17 +421,6 @@ class CoreNodeBase(NodeBase): """ raise NotImplementedError - def cmd(self, args, wait=True): - """ - Runs shell command on node, with option to not wait for a result. - - :param list[str]|str args: command to run - :param bool wait: wait for command to exit, defaults to True - :return: exit status for command - :rtype: int - """ - raise NotImplementedError - def cmd_output(self, args): """ Runs shell command on node and get exit status and output. @@ -609,17 +598,6 @@ class CoreNode(CoreNodeBase): finally: self.rmnodedir() - def cmd(self, args, wait=True): - """ - Runs shell command on node, with option to not wait for a result. - - :param list[str]|str args: command to run - :param bool wait: wait for command to exit, defaults to True - :return: exit status for command - :rtype: int - """ - return self.client.cmd(args, wait) - def cmd_output(self, args): """ Runs shell command on node and get exit status and output. diff --git a/daemon/core/nodes/docker.py b/daemon/core/nodes/docker.py index ad7deff2..69bf376f 100644 --- a/daemon/core/nodes/docker.py +++ b/daemon/core/nodes/docker.py @@ -47,15 +47,6 @@ class DockerClient(object): name=self.name )) - def cmd(self, cmd, wait=True): - if isinstance(cmd, list): - cmd = " ".join(cmd) - logging.info("docker cmd wait(%s): %s", wait, cmd) - return utils.cmd("docker exec {name} {cmd}".format( - name=self.name, - cmd=cmd - ), wait) - def cmd_output(self, cmd): if isinstance(cmd, list): cmd = " ".join(cmd) @@ -155,17 +146,6 @@ class DockerNode(CoreNode): self.client.stop_container() self.up = False - def cmd(self, args, wait=True): - """ - Runs shell command on node, with option to not wait for a result. - - :param list[str]|str args: command to run - :param bool wait: wait for command to exit, defaults to True - :return: exit status for command - :rtype: int - """ - return self.client.cmd(args, wait) - def cmd_output(self, args): """ Runs shell command on node and get exit status and output. diff --git a/daemon/core/nodes/lxd.py b/daemon/core/nodes/lxd.py index 86ca192e..54a66182 100644 --- a/daemon/core/nodes/lxd.py +++ b/daemon/core/nodes/lxd.py @@ -55,13 +55,6 @@ class LxdClient(object): logging.info("lxc cmd output: %s", args) return utils.cmd_output(args) - def cmd(self, cmd, wait=True): - if isinstance(cmd, list): - cmd = " ".join(cmd) - args = self._cmd_args(cmd) - logging.info("lxc cmd: %s", args) - return utils.cmd(args, wait) - def _ns_args(self, cmd): return "nsenter -t {pid} -m -u -i -p -n {cmd}".format(pid=self.pid, cmd=cmd) @@ -72,13 +65,6 @@ class LxdClient(object): logging.info("ns cmd: %s", args) return utils.cmd_output(args) - def ns_cmd(self, cmd, wait=True): - if isinstance(cmd, list): - cmd = " ".join(cmd) - args = self._ns_args(cmd) - logging.info("ns cmd: %s", args) - return utils.cmd(args, wait) - def copy_file(self, source, destination): if destination[0] != "/": destination = os.path.join("/root/", destination) @@ -158,17 +144,6 @@ class LxcNode(CoreNode): self.client.stop_container() self.up = False - def cmd(self, args, wait=True): - """ - Runs shell command on node, with option to not wait for a result. - - :param list[str]|str args: command to run - :param bool wait: wait for command to exit, defaults to True - :return: exit status for command - :rtype: int - """ - return self.client.cmd(args, wait) - def cmd_output(self, args): """ Runs shell command on node and get exit status and output. diff --git a/daemon/core/nodes/physical.py b/daemon/core/nodes/physical.py index 48bd5a5a..159c746d 100644 --- a/daemon/core/nodes/physical.py +++ b/daemon/core/nodes/physical.py @@ -52,19 +52,6 @@ class PhysicalNode(CoreNodeBase): """ return sh - def cmd(self, args, wait=True): - """ - Runs shell command on node, with option to not wait for a result. - - :param list[str]|str args: command to run - :param bool wait: wait for command to exit, defaults to True - :return: exit status for command - :rtype: int - """ - os.chdir(self.nodedir) - status = utils.cmd(args, wait) - return status - def cmd_output(self, args): """ Runs shell command on node and get exit status and output. diff --git a/daemon/core/utils.py b/daemon/core/utils.py index 8e59a050..83a18c6a 100644 --- a/daemon/core/utils.py +++ b/daemon/core/utils.py @@ -207,26 +207,6 @@ def mute_detach(args, **kwargs): return subprocess.Popen(args, **kwargs).pid -def cmd(args, wait=True): - """ - Runs a command on and returns the exit status. - - :param list[str]|str args: command arguments - :param bool wait: wait for command to end or not - :return: command status - :rtype: int - """ - args = split_args(args) - logging.debug("command: %s", args) - try: - p = subprocess.Popen(args) - if not wait: - return 0 - return p.wait() - except OSError: - raise CoreCommandError(-1, args) - - def cmd_output(args): """ Execute a command on the host and return a tuple containing the exit status and diff --git a/daemon/tests/emane/test_emane.py b/daemon/tests/emane/test_emane.py index d9001065..3d9b9eb2 100644 --- a/daemon/tests/emane/test_emane.py +++ b/daemon/tests/emane/test_emane.py @@ -12,7 +12,7 @@ from core.emane.ieee80211abg import EmaneIeee80211abgModel from core.emane.rfpipe import EmaneRfPipeModel from core.emane.tdma import EmaneTdmaModel from core.emulator.emudata import NodeOptions -from core.errors import CoreError +from core.errors import CoreCommandError, CoreError _EMANE_MODELS = [ EmaneIeee80211abgModel, @@ -26,7 +26,12 @@ _DIR = os.path.dirname(os.path.abspath(__file__)) def ping(from_node, to_node, ip_prefixes, count=3): address = ip_prefixes.ip4_address(to_node) - return from_node.node_net_cmd(["ping", "-c", str(count), address]) + try: + from_node.node_net_cmd(["ping", "-c", str(count), address]) + status = 0 + except CoreCommandError as e: + status = e.returncode + return status class TestEmane: diff --git a/daemon/tests/test_core.py b/daemon/tests/test_core.py index 7d64ae69..9a59b4ce 100644 --- a/daemon/tests/test_core.py +++ b/daemon/tests/test_core.py @@ -10,6 +10,7 @@ import pytest from core.emulator.emudata import NodeOptions from core.emulator.enumerations import MessageFlags, NodeTypes +from core.errors import CoreCommandError from core.location.mobility import BasicRangeModel, Ns2ScriptedMobility from core.nodes.client import VnodeClient @@ -38,7 +39,12 @@ def createclients(sessiondir, clientcls=VnodeClient, cmdchnlfilterfunc=None): def ping(from_node, to_node, ip_prefixes): address = ip_prefixes.ip4_address(to_node) - return from_node.node_net_cmd(["ping", "-c", "3", address]) + try: + from_node.node_net_cmd(["ping", "-c", "3", address]) + status = 0 + except CoreCommandError as e: + status = e.returncode + return status class TestCore: