diff --git a/daemon/core/nodes/docker.py b/daemon/core/nodes/docker.py index be150275..7c17973c 100644 --- a/daemon/core/nodes/docker.py +++ b/daemon/core/nodes/docker.py @@ -115,12 +115,11 @@ def create_cmd(self, args: str, shell: bool = False) -> str: """ if shell: args = f"{BASH} -c {shlex.quote(args)}" - return f"nsenter -t {self.pid} -m -u -i -p -n -- {args}" + return f"{DOCKER} exec {self.name} {args}" def cmd(self, args: str, wait: bool = True, shell: bool = False) -> str: """ - Runs a command that is used to configure and setup the network within a - node. + Runs a command within the context of the Docker node. :param args: command to run :param wait: True to wait for status, False otherwise @@ -134,6 +133,25 @@ def cmd(self, args: str, wait: bool = True, shell: bool = False) -> str: else: return self.server.remote_cmd(args, wait=wait, env=self.env) + def cmd_perf(self, args: str, wait: bool = True, shell: bool = False) -> str: + """ + Runs a command within the Docker node using nsenter to avoid + client/server overhead. + + :param args: command to run + :param wait: True to wait for status, False otherwise + :param shell: True to use shell, False otherwise + :return: combined stdout and stderr + :raises CoreCommandError: when a non-zero exit status occurs + """ + if shell: + args = f"{BASH} -c {shlex.quote(args)}" + args = f"nsenter -t {self.pid} -m -u -i -p -n -- {args}" + if self.server is None: + return utils.cmd(args, wait=wait, shell=shell, env=self.env) + else: + return self.server.remote_cmd(args, wait=wait, env=self.env) + def create_net_cmd(self, args: str, shell: bool = False) -> str: """ Create command used to run network commands within the context of a node.