renamed utils.check_cmd to utils.cmd, updated host_cmd to allow for shell commands for output redirection
This commit is contained in:
parent
16b7e70c33
commit
78f981463d
15 changed files with 34 additions and 31 deletions
|
@ -79,7 +79,7 @@ class NodeBase(object):
|
|||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def host_cmd(self, args, env=None, cwd=None, wait=True):
|
||||
def host_cmd(self, args, env=None, cwd=None, wait=True, shell=False):
|
||||
"""
|
||||
Runs a command on the host system or distributed server.
|
||||
|
||||
|
@ -87,12 +87,13 @@ class NodeBase(object):
|
|||
:param dict env: environment to run command with
|
||||
:param str cwd: directory to run command in
|
||||
:param bool wait: True to wait for status, False otherwise
|
||||
:param bool shell: True to use shell, False otherwise
|
||||
:return: combined stdout and stderr
|
||||
:rtype: str
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
if self.server is None:
|
||||
return utils.check_cmd(args, env, cwd, wait)
|
||||
return utils.cmd(args, env, cwd, wait, shell)
|
||||
else:
|
||||
return self.server.remote_cmd(args, env, cwd, wait)
|
||||
|
||||
|
|
|
@ -65,4 +65,4 @@ class VnodeClient(object):
|
|||
"""
|
||||
self._verify_connection()
|
||||
args = self.create_cmd(args)
|
||||
return utils.check_cmd(args, wait=wait)
|
||||
return utils.cmd(args, wait=wait)
|
||||
|
|
|
@ -45,14 +45,14 @@ class DockerClient(object):
|
|||
|
||||
def check_cmd(self, cmd):
|
||||
logging.info("docker cmd output: %s", cmd)
|
||||
return utils.check_cmd(f"docker exec {self.name} {cmd}")
|
||||
return utils.cmd(f"docker exec {self.name} {cmd}")
|
||||
|
||||
def create_ns_cmd(self, cmd):
|
||||
return f"nsenter -t {self.pid} -u -i -p -n {cmd}"
|
||||
|
||||
def ns_cmd(self, cmd, wait):
|
||||
args = f"nsenter -t {self.pid} -u -i -p -n {cmd}"
|
||||
return utils.check_cmd(args, wait=wait)
|
||||
return utils.cmd(args, wait=wait)
|
||||
|
||||
def get_pid(self):
|
||||
args = f"docker inspect -f '{{{{.State.Pid}}}}' {self.name}"
|
||||
|
@ -153,7 +153,7 @@ class DockerNode(CoreNode):
|
|||
def nsenter_cmd(self, args, wait=True):
|
||||
if self.server is None:
|
||||
args = self.client.create_ns_cmd(args)
|
||||
return utils.check_cmd(args, wait=wait)
|
||||
return utils.cmd(args, wait=wait)
|
||||
else:
|
||||
args = self.client.create_ns_cmd(args)
|
||||
return self.server.remote_cmd(args, wait=wait)
|
||||
|
|
|
@ -48,7 +48,7 @@ class CoreInterface(object):
|
|||
use_ovs = session.options.get_config("ovs") == "True"
|
||||
self.net_client = get_net_client(use_ovs, self.host_cmd)
|
||||
|
||||
def host_cmd(self, args, env=None, cwd=None, wait=True):
|
||||
def host_cmd(self, args, env=None, cwd=None, wait=True, shell=False):
|
||||
"""
|
||||
Runs a command on the host system or distributed server.
|
||||
|
||||
|
@ -56,12 +56,13 @@ class CoreInterface(object):
|
|||
:param dict env: environment to run command with
|
||||
:param str cwd: directory to run command in
|
||||
:param bool wait: True to wait for status, False otherwise
|
||||
:param bool shell: True to use shell, False otherwise
|
||||
:return: combined stdout and stderr
|
||||
:rtype: str
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
if self.server is None:
|
||||
return utils.check_cmd(args, env, cwd, wait)
|
||||
return utils.cmd(args, env, cwd, wait, shell)
|
||||
else:
|
||||
return self.server.remote_cmd(args, env, cwd, wait)
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ class LxdClient(object):
|
|||
|
||||
def check_cmd(self, cmd, wait=True):
|
||||
args = self.create_cmd(cmd)
|
||||
return utils.check_cmd(args, wait=wait)
|
||||
return utils.cmd(args, wait=wait)
|
||||
|
||||
def copy_file(self, source, destination):
|
||||
if destination[0] != "/":
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
Clients for dealing with bridge/interface commands.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from core.constants import BRCTL_BIN, ETHTOOL_BIN, IP_BIN, OVS_BIN, TC_BIN
|
||||
|
||||
|
||||
|
@ -236,10 +234,10 @@ class LinuxNetClient(object):
|
|||
self.device_up(name)
|
||||
|
||||
# turn off multicast snooping so forwarding occurs w/o IGMP joins
|
||||
snoop = f"/sys/devices/virtual/net/{name}/bridge/multicast_snooping"
|
||||
if os.path.exists(snoop):
|
||||
with open(snoop, "w") as f:
|
||||
f.write("0")
|
||||
snoop_file = "multicast_snooping"
|
||||
snoop = f"/sys/devices/virtual/net/{name}/bridge/{snoop_file}"
|
||||
self.run(f"echo 0 > /tmp/{snoop_file}", shell=True)
|
||||
self.run(f"cp /tmp/{snoop_file} {snoop}")
|
||||
|
||||
def delete_bridge(self, name):
|
||||
"""
|
||||
|
|
|
@ -270,7 +270,7 @@ class CoreNetwork(CoreNetworkBase):
|
|||
self.startup()
|
||||
ebq.startupdateloop(self)
|
||||
|
||||
def host_cmd(self, args, env=None, cwd=None, wait=True):
|
||||
def host_cmd(self, args, env=None, cwd=None, wait=True, shell=False):
|
||||
"""
|
||||
Runs a command that is used to configure and setup the network on the host
|
||||
system and all configured distributed servers.
|
||||
|
@ -279,12 +279,13 @@ class CoreNetwork(CoreNetworkBase):
|
|||
:param dict env: environment to run command with
|
||||
:param str cwd: directory to run command in
|
||||
:param bool wait: True to wait for status, False otherwise
|
||||
:param bool shell: True to use shell, False otherwise
|
||||
:return: combined stdout and stderr
|
||||
:rtype: str
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
logging.info("network node(%s) cmd", self.name)
|
||||
output = utils.check_cmd(args, env, cwd, wait)
|
||||
output = utils.cmd(args, env, cwd, wait, shell)
|
||||
self.session.distributed.execute(lambda x: x.remote_cmd(args, env, cwd, wait))
|
||||
return output
|
||||
|
||||
|
@ -765,7 +766,7 @@ class CtrlNet(CoreNetwork):
|
|||
"""
|
||||
use_ovs = self.session.options.get_config("ovs") == "True"
|
||||
current = f"{address}/{self.prefix.prefixlen}"
|
||||
net_client = get_net_client(use_ovs, utils.check_cmd)
|
||||
net_client = get_net_client(use_ovs, utils.cmd)
|
||||
net_client.create_address(self.brname, current)
|
||||
servers = self.session.distributed.servers
|
||||
for name in servers:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue