removed node based check_cmd, updated to use appropriate function
This commit is contained in:
parent
4a6d69bb09
commit
d326f246a7
11 changed files with 51 additions and 113 deletions
|
@ -152,8 +152,13 @@ class EmaneManager(ModelManager):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# check for emane
|
# check for emane
|
||||||
emane_version = utils.check_cmd(["emane", "--version"])
|
args = ["emane", "--version"]
|
||||||
|
emane_version = utils.check_cmd(args)
|
||||||
logging.info("using EMANE: %s", emane_version)
|
logging.info("using EMANE: %s", emane_version)
|
||||||
|
args = " ".join(args)
|
||||||
|
for server in self.session.servers:
|
||||||
|
conn = self.session.servers[server]
|
||||||
|
distributed.remote_cmd(conn, args)
|
||||||
|
|
||||||
# load default emane models
|
# load default emane models
|
||||||
self.load_models(EMANE_MODELS)
|
self.load_models(EMANE_MODELS)
|
||||||
|
|
|
@ -140,6 +140,11 @@ class Session(object):
|
||||||
self.options.set_config(key, value)
|
self.options.set_config(key, value)
|
||||||
self.metadata = SessionMetaData()
|
self.metadata = SessionMetaData()
|
||||||
|
|
||||||
|
# distributed servers
|
||||||
|
self.servers = {}
|
||||||
|
self.tunnels = {}
|
||||||
|
self.address = None
|
||||||
|
|
||||||
# initialize session feature helpers
|
# initialize session feature helpers
|
||||||
self.broker = CoreBroker(session=self)
|
self.broker = CoreBroker(session=self)
|
||||||
self.location = CoreLocation()
|
self.location = CoreLocation()
|
||||||
|
@ -148,11 +153,6 @@ class Session(object):
|
||||||
self.emane = EmaneManager(session=self)
|
self.emane = EmaneManager(session=self)
|
||||||
self.sdt = Sdt(session=self)
|
self.sdt = Sdt(session=self)
|
||||||
|
|
||||||
# distributed servers
|
|
||||||
self.servers = {}
|
|
||||||
self.tunnels = {}
|
|
||||||
self.address = None
|
|
||||||
|
|
||||||
# initialize default node services
|
# initialize default node services
|
||||||
self.services.default_services = {
|
self.services.default_services = {
|
||||||
"mdr": ("zebra", "OSPFv3MDR", "IPForward"),
|
"mdr": ("zebra", "OSPFv3MDR", "IPForward"),
|
||||||
|
|
|
@ -84,18 +84,24 @@ class NodeBase(object):
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def net_cmd(self, args, env=None):
|
def net_cmd(self, args, env=None, cwd=None, wait=True):
|
||||||
"""
|
"""
|
||||||
Runs a command that is used to configure and setup the network on the host
|
Runs a command that is used to configure and setup the network on the host
|
||||||
system.
|
system.
|
||||||
|
|
||||||
:param list[str]|str args: command to run
|
:param list[str]|str args: command to run
|
||||||
:param dict env: environment to run command with
|
: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
|
||||||
:return: combined stdout and stderr
|
:return: combined stdout and stderr
|
||||||
:rtype: str
|
:rtype: str
|
||||||
:raises CoreCommandError: when a non-zero exit status occurs
|
:raises CoreCommandError: when a non-zero exit status occurs
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
if self.server is None:
|
||||||
|
return utils.check_cmd(args, env=env, cwd=cwd)
|
||||||
|
else:
|
||||||
|
args = " ".join(args)
|
||||||
|
return distributed.remote_cmd(self.server, args, env, cwd, wait)
|
||||||
|
|
||||||
def setposition(self, x=None, y=None, z=None):
|
def setposition(self, x=None, y=None, z=None):
|
||||||
"""
|
"""
|
||||||
|
@ -381,40 +387,13 @@ class CoreNodeBase(NodeBase):
|
||||||
|
|
||||||
return common
|
return common
|
||||||
|
|
||||||
def net_cmd(self, args, env=None):
|
def node_net_cmd(self, args, wait=True):
|
||||||
"""
|
|
||||||
Runs a command that is used to configure and setup the network on the host
|
|
||||||
system.
|
|
||||||
|
|
||||||
:param list[str]|str args: command to run
|
|
||||||
:param dict env: environment to run command with
|
|
||||||
: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=env)
|
|
||||||
else:
|
|
||||||
args = " ".join(args)
|
|
||||||
return distributed.remote_cmd(self.server, args, env=env)
|
|
||||||
|
|
||||||
def node_net_cmd(self, args):
|
|
||||||
"""
|
"""
|
||||||
Runs a command that is used to configure and setup the network within a
|
Runs a command that is used to configure and setup the network within a
|
||||||
node.
|
node.
|
||||||
|
|
||||||
:param list[str]|str args: command to run
|
:param list[str]|str args: command to run
|
||||||
:return: combined stdout and stderr
|
:param bool wait: True to wait for status, False otherwise
|
||||||
:rtype: str
|
|
||||||
:raises CoreCommandError: when a non-zero exit status occurs
|
|
||||||
"""
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def check_cmd(self, args):
|
|
||||||
"""
|
|
||||||
Runs shell command on node.
|
|
||||||
|
|
||||||
:param list[str]|str args: command to run
|
|
||||||
:return: combined stdout and stderr
|
:return: combined stdout and stderr
|
||||||
:rtype: str
|
:rtype: str
|
||||||
:raises CoreCommandError: when a non-zero exit status occurs
|
:raises CoreCommandError: when a non-zero exit status occurs
|
||||||
|
@ -607,18 +586,6 @@ class CoreNode(CoreNodeBase):
|
||||||
args = " ".join(args)
|
args = " ".join(args)
|
||||||
return distributed.remote_cmd(self.server, args, wait=wait)
|
return distributed.remote_cmd(self.server, args, wait=wait)
|
||||||
|
|
||||||
def check_cmd(self, args):
|
|
||||||
"""
|
|
||||||
Runs shell command on node.
|
|
||||||
|
|
||||||
:param list[str]|str args: command to run
|
|
||||||
:param bool wait: True to wait for status, False otherwise
|
|
||||||
:return: combined stdout and stderr
|
|
||||||
:rtype: str
|
|
||||||
:raises CoreCommandError: when a non-zero exit status occurs
|
|
||||||
"""
|
|
||||||
return self.client.check_cmd(args)
|
|
||||||
|
|
||||||
def termcmdstring(self, sh="/bin/sh"):
|
def termcmdstring(self, sh="/bin/sh"):
|
||||||
"""
|
"""
|
||||||
Create a terminal command string.
|
Create a terminal command string.
|
||||||
|
|
|
@ -142,17 +142,6 @@ class DockerNode(CoreNode):
|
||||||
self.client.stop_container()
|
self.client.stop_container()
|
||||||
self.up = False
|
self.up = False
|
||||||
|
|
||||||
def check_cmd(self, args):
|
|
||||||
"""
|
|
||||||
Runs shell command on node.
|
|
||||||
|
|
||||||
:param list[str]|str args: command to run
|
|
||||||
:return: combined stdout and stderr
|
|
||||||
:rtype: str
|
|
||||||
:raises CoreCommandError: when a non-zero exit status occurs
|
|
||||||
"""
|
|
||||||
return self.client.check_cmd(args)
|
|
||||||
|
|
||||||
def node_net_cmd(self, args, wait=True):
|
def node_net_cmd(self, args, wait=True):
|
||||||
if not self.up:
|
if not self.up:
|
||||||
logging.debug("node down, not running network command: %s", args)
|
logging.debug("node down, not running network command: %s", args)
|
||||||
|
@ -178,7 +167,7 @@ class DockerNode(CoreNode):
|
||||||
"""
|
"""
|
||||||
logging.debug("creating node dir: %s", path)
|
logging.debug("creating node dir: %s", path)
|
||||||
args = "mkdir -p {path}".format(path=path)
|
args = "mkdir -p {path}".format(path=path)
|
||||||
self.check_cmd(args)
|
self.client.check_cmd(args)
|
||||||
|
|
||||||
def mount(self, source, target):
|
def mount(self, source, target):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -48,12 +48,23 @@ class CoreInterface(object):
|
||||||
self.server = server
|
self.server = server
|
||||||
self.net_client = LinuxNetClient(self.net_cmd)
|
self.net_client = LinuxNetClient(self.net_cmd)
|
||||||
|
|
||||||
def net_cmd(self, args):
|
def net_cmd(self, args, env=None, cwd=None, wait=True):
|
||||||
|
"""
|
||||||
|
Runs a command on the host system or distributed servers.
|
||||||
|
|
||||||
|
:param list[str]|str args: command to run
|
||||||
|
: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
|
||||||
|
:return: combined stdout and stderr
|
||||||
|
:rtype: str
|
||||||
|
:raises CoreCommandError: when a non-zero exit status occurs
|
||||||
|
"""
|
||||||
if self.server is None:
|
if self.server is None:
|
||||||
return utils.check_cmd(args)
|
return utils.check_cmd(args, env=env, cwd=cwd)
|
||||||
else:
|
else:
|
||||||
args = " ".join(args)
|
args = " ".join(args)
|
||||||
return distributed.remote_cmd(self.server, args)
|
return distributed.remote_cmd(self.server, args, env, cwd, wait)
|
||||||
|
|
||||||
def startup(self):
|
def startup(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -140,22 +140,11 @@ class LxcNode(CoreNode):
|
||||||
self.client.stop_container()
|
self.client.stop_container()
|
||||||
self.up = False
|
self.up = False
|
||||||
|
|
||||||
def check_cmd(self, args):
|
|
||||||
"""
|
|
||||||
Runs shell command on node.
|
|
||||||
|
|
||||||
:param list[str]|str args: command to run
|
|
||||||
:return: combined stdout and stderr
|
|
||||||
:rtype: str
|
|
||||||
:raises CoreCommandError: when a non-zero exit status occurs
|
|
||||||
"""
|
|
||||||
return self.client.check_cmd(args)
|
|
||||||
|
|
||||||
def node_net_cmd(self, args, wait=True):
|
def node_net_cmd(self, args, wait=True):
|
||||||
if not self.up:
|
if not self.up:
|
||||||
logging.debug("node down, not running network command: %s", args)
|
logging.debug("node down, not running network command: %s", args)
|
||||||
return ""
|
return ""
|
||||||
return self.check_cmd(args)
|
return self.client.check_cmd(args)
|
||||||
|
|
||||||
def termcmdstring(self, sh="/bin/sh"):
|
def termcmdstring(self, sh="/bin/sh"):
|
||||||
"""
|
"""
|
||||||
|
@ -175,7 +164,7 @@ class LxcNode(CoreNode):
|
||||||
"""
|
"""
|
||||||
logging.info("creating node dir: %s", path)
|
logging.info("creating node dir: %s", path)
|
||||||
args = "mkdir -p {path}".format(path=path)
|
args = "mkdir -p {path}".format(path=path)
|
||||||
self.check_cmd(args)
|
return self.client.check_cmd(args)
|
||||||
|
|
||||||
def mount(self, source, target):
|
def mount(self, source, target):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -5,7 +5,6 @@ Clients for dealing with bridge/interface commands.
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from core.constants import BRCTL_BIN, ETHTOOL_BIN, IP_BIN, OVS_BIN, TC_BIN
|
from core.constants import BRCTL_BIN, ETHTOOL_BIN, IP_BIN, OVS_BIN, TC_BIN
|
||||||
from core.utils import check_cmd
|
|
||||||
|
|
||||||
|
|
||||||
class LinuxNetClient(object):
|
class LinuxNetClient(object):
|
||||||
|
@ -275,7 +274,7 @@ class LinuxNetClient(object):
|
||||||
:param str name: bridge name
|
:param str name: bridge name
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
check_cmd([BRCTL_BIN, "setageing", name, "0"])
|
self.run([BRCTL_BIN, "setageing", name, "0"])
|
||||||
|
|
||||||
|
|
||||||
class OvsNetClient(LinuxNetClient):
|
class OvsNetClient(LinuxNetClient):
|
||||||
|
|
|
@ -308,24 +308,26 @@ class CoreNetwork(CoreNetworkBase):
|
||||||
self.startup()
|
self.startup()
|
||||||
ebq.startupdateloop(self)
|
ebq.startupdateloop(self)
|
||||||
|
|
||||||
def net_cmd(self, args, env=None):
|
def net_cmd(self, args, env=None, cwd=None, wait=True):
|
||||||
"""
|
"""
|
||||||
Runs a command that is used to configure and setup the network on the host
|
Runs a command that is used to configure and setup the network on the host
|
||||||
system and all configured distributed servers.
|
system and all configured distributed servers.
|
||||||
|
|
||||||
:param list[str]|str args: command to run
|
:param list[str]|str args: command to run
|
||||||
:param dict env: environment to run command with
|
: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
|
||||||
:return: combined stdout and stderr
|
:return: combined stdout and stderr
|
||||||
:rtype: str
|
:rtype: str
|
||||||
:raises CoreCommandError: when a non-zero exit status occurs
|
:raises CoreCommandError: when a non-zero exit status occurs
|
||||||
"""
|
"""
|
||||||
logging.info("network node(%s) cmd", self.name)
|
logging.info("network node(%s) cmd", self.name)
|
||||||
output = utils.check_cmd(args, env=env)
|
output = utils.check_cmd(args, env=env, cwd=cwd)
|
||||||
|
|
||||||
args = " ".join(args)
|
args = " ".join(args)
|
||||||
for server in self.session.servers:
|
for server in self.session.servers:
|
||||||
conn = self.session.servers[server]
|
conn = self.session.servers[server]
|
||||||
distributed.remote_cmd(conn, args, env=env)
|
distributed.remote_cmd(conn, args, env, cwd, wait)
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
|
@ -51,21 +51,6 @@ class PhysicalNode(CoreNodeBase):
|
||||||
"""
|
"""
|
||||||
return sh
|
return sh
|
||||||
|
|
||||||
def check_cmd(self, args):
|
|
||||||
"""
|
|
||||||
Runs shell command on node.
|
|
||||||
|
|
||||||
:param list[str]|str args: command to run
|
|
||||||
:return: combined stdout and stderr
|
|
||||||
:rtype: str
|
|
||||||
:raises CoreCommandError: when a non-zero exit status occurs
|
|
||||||
"""
|
|
||||||
os.chdir(self.nodedir)
|
|
||||||
return utils.check_cmd(args)
|
|
||||||
|
|
||||||
def shcmd(self, cmdstr, sh="/bin/sh"):
|
|
||||||
return self.node_net_cmd([sh, "-c", cmdstr])
|
|
||||||
|
|
||||||
def sethwaddr(self, ifindex, addr):
|
def sethwaddr(self, ifindex, addr):
|
||||||
"""
|
"""
|
||||||
Set hardware address for an interface.
|
Set hardware address for an interface.
|
||||||
|
@ -205,13 +190,13 @@ class PhysicalNode(CoreNodeBase):
|
||||||
source = os.path.abspath(source)
|
source = os.path.abspath(source)
|
||||||
logging.info("mounting %s at %s", source, target)
|
logging.info("mounting %s at %s", source, target)
|
||||||
os.makedirs(target)
|
os.makedirs(target)
|
||||||
self.check_cmd([constants.MOUNT_BIN, "--bind", source, target])
|
self.net_cmd([constants.MOUNT_BIN, "--bind", source, target], cwd=self.nodedir)
|
||||||
self._mounts.append((source, target))
|
self._mounts.append((source, target))
|
||||||
|
|
||||||
def umount(self, target):
|
def umount(self, target):
|
||||||
logging.info("unmounting '%s'" % target)
|
logging.info("unmounting '%s'" % target)
|
||||||
try:
|
try:
|
||||||
self.check_cmd([constants.UMOUNT_BIN, "-l", target])
|
self.net_cmd([constants.UMOUNT_BIN, "-l", target], cwd=self.nodedir)
|
||||||
except CoreCommandError:
|
except CoreCommandError:
|
||||||
logging.exception("unmounting failed for %s", target)
|
logging.exception("unmounting failed for %s", target)
|
||||||
|
|
||||||
|
@ -256,7 +241,8 @@ class Rj45Node(CoreNodeBase, CoreInterface):
|
||||||
:param str name: node name
|
:param str name: node name
|
||||||
:param mtu: rj45 mtu
|
:param mtu: rj45 mtu
|
||||||
:param bool start: start flag
|
:param bool start: start flag
|
||||||
:param str server: remote server node will run on, default is None for localhost
|
:param fabric.connection.Connection server: remote server node will run on,
|
||||||
|
default is None for localhost
|
||||||
"""
|
"""
|
||||||
CoreNodeBase.__init__(self, session, _id, name, start, server)
|
CoreNodeBase.__init__(self, session, _id, name, start, server)
|
||||||
CoreInterface.__init__(self, node=self, name=name, mtu=mtu)
|
CoreInterface.__init__(self, node=self, name=name, mtu=mtu)
|
||||||
|
@ -498,17 +484,6 @@ class Rj45Node(CoreNodeBase, CoreInterface):
|
||||||
CoreInterface.setposition(self, x, y, z)
|
CoreInterface.setposition(self, x, y, z)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def check_cmd(self, args):
|
|
||||||
"""
|
|
||||||
Runs shell command on node.
|
|
||||||
|
|
||||||
:param list[str]|str args: command to run
|
|
||||||
:return: exist status and combined stdout and stderr
|
|
||||||
:rtype: tuple[int, str]
|
|
||||||
:raises CoreCommandError: when a non-zero exit status occurs
|
|
||||||
"""
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def termcmdstring(self, sh):
|
def termcmdstring(self, sh):
|
||||||
"""
|
"""
|
||||||
Create a terminal command string.
|
Create a terminal command string.
|
||||||
|
|
|
@ -631,8 +631,9 @@ class CoreServices(object):
|
||||||
"""
|
"""
|
||||||
status = 0
|
status = 0
|
||||||
for args in service.shutdown:
|
for args in service.shutdown:
|
||||||
|
args = utils.split_args(args)
|
||||||
try:
|
try:
|
||||||
node.check_cmd(args)
|
node.node_net_cmd(args)
|
||||||
except CoreCommandError:
|
except CoreCommandError:
|
||||||
logging.exception("error running stop command %s", args)
|
logging.exception("error running stop command %s", args)
|
||||||
status = -1
|
status = -1
|
||||||
|
|
|
@ -30,7 +30,7 @@ class TestNodes:
|
||||||
assert os.path.exists(node.nodedir)
|
assert os.path.exists(node.nodedir)
|
||||||
assert node.alive()
|
assert node.alive()
|
||||||
assert node.up
|
assert node.up
|
||||||
assert node.check_cmd(["ip", "addr", "show", "lo"])
|
assert node.node_net_cmd(["ip", "addr", "show", "lo"])
|
||||||
|
|
||||||
def test_node_update(self, session):
|
def test_node_update(self, session):
|
||||||
# given
|
# given
|
||||||
|
|
Loading…
Add table
Reference in a new issue