further removal and refactoring of methods used within misc/utils.py

This commit is contained in:
Blake J. Harnden 2018-03-02 09:15:52 -08:00
parent 6211b09585
commit 00b3c97448
23 changed files with 181 additions and 293 deletions

View file

@ -86,4 +86,4 @@ def ngloadkernelmodule(name):
:param str name: module name
:return: nothing
"""
utils.mutecall(["kldload", name])
utils.check_cmd(["kldload", name])

View file

@ -263,7 +263,7 @@ class SimpleJailNode(PyCoreNode):
self.attachnet(ifindex, net)
if hwaddr:
self.sethwaddr(ifindex, hwaddr)
for addr in utils.maketuple(addrlist):
for addr in utils.make_tuple(addrlist):
self.addaddr(ifindex, addr)
self.ifup(ifindex)
return ifindex

View file

@ -93,7 +93,7 @@ class CoreRequestHandler(SocketServer.BaseRequestHandler):
self.master = False
self.session = None
utils.closeonexec(request.fileno())
utils.close_onexec(request.fileno())
SocketServer.BaseRequestHandler.__init__(self, request, client_address, server)
def setup(self):
@ -371,7 +371,7 @@ class CoreRequestHandler(SocketServer.BaseRequestHandler):
try:
header = self.request.recv(coreapi.CoreMessage.header_len)
if len(header) > 0:
logger.debug("received message header: %s", utils.hexdump(header))
logger.debug("received message header: %s", utils.hex_dump(header))
except IOError as e:
raise IOError("error receiving header (%s)" % e)
@ -388,7 +388,7 @@ class CoreRequestHandler(SocketServer.BaseRequestHandler):
data = ""
while len(data) < message_len:
data += self.request.recv(message_len - len(data))
logger.debug("received message data: %s" % utils.hexdump(data))
logger.debug("received message data: %s" % utils.hex_dump(data))
if len(data) > message_len:
error_message = "received message length does not match received data (%s != %s)" % (
len(data), message_len)
@ -1110,8 +1110,7 @@ class CoreRequestHandler(SocketServer.BaseRequestHandler):
# execute the command with no response
else:
if message.flags & MessageFlags.LOCAL.value:
# TODO: get this consolidated into utils
utils.mutedetach(shlex.split(command))
utils.mute_detach(command)
else:
node.cmd(command, wait=False)
except KeyError:

View file

@ -182,7 +182,7 @@ class EmaneManager(ConfigurableManager):
if self.service:
for f in self.service._readFd, self.service._writeFd, self.service._socket, self.service._socketOTA:
if f:
utils.closeonexec(f)
utils.close_onexec(f)
if filename is not None:
os.environ.pop(EmaneManager.EVENTCFGVAR)

View file

@ -190,7 +190,7 @@ class EmaneModel(WirelessModel):
multiple values.
"""
try:
values = utils.maketuplefromstr(value, str)
values = utils.make_tuple_fromstr(value, str)
except SyntaxError:
logger.exception("error in value string to param list")
return None

View file

@ -136,7 +136,7 @@ router ospf6
:param routerid: router id
:param str redistribute: redistribute value
"""
ospf6ifs = utils.maketuple(ospf6ifs)
ospf6ifs = utils.make_tuple(ospf6ifs)
interfaces = "\n!\n".join(map(str, ospf6ifs))
ospfifs = "\n ".join(map(lambda x: "interface %s area %s" % (x.name(), area), ospf6ifs))
Conf.__init__(self, interfaces=interfaces, routerid=routerid, ospfifs=ospfifs, redistribute=redistribute)
@ -163,9 +163,9 @@ $forwarding
:param str logfile: log file name
:param debugs: debug options
"""
routers = "\n!\n".join(map(str, utils.maketuple(routers)))
routers = "\n!\n".join(map(str, utils.make_tuple(routers)))
if debugs:
debugs = "\n".join(utils.maketuple(debugs))
debugs = "\n".join(utils.make_tuple(debugs))
else:
debugs = "! no debugs"
forwarding = "ip forwarding\nipv6 forwarding"

View file

@ -17,7 +17,74 @@ from core import logger
DEVNULL = open(os.devnull, "wb")
def closeonexec(fd):
def _detach_init():
"""
Fork a child process and exit.
:return: nothing
"""
if os.fork():
# parent exits
os._exit(0)
os.setsid()
def _valid_module(path, file_name):
"""
Check if file is a valid python module.
:param str path: path to file
:param str file_name: file name to check
:return: True if a valid python module file, False otherwise
:rtype: bool
"""
file_path = os.path.join(path, file_name)
if not os.path.isfile(file_path):
return False
if file_name.startswith("_"):
return False
if not file_name.endswith(".py"):
return False
return True
def _is_class(module, member, clazz):
"""
Validates if a module member is a class and an instance of a CoreService.
:param module: module to validate for service
:param member: member to validate for service
:param clazz: clazz type to check for validation
:return: True if a valid service, False otherwise
:rtype: bool
"""
if not inspect.isclass(member):
return False
if not issubclass(member, clazz):
return False
if member.__module__ != module.__name__:
return False
return True
def _is_exe(file_path):
"""
Check if a given file path exists and is an executable file.
:param str file_path: file path to check
:return: True if the file is considered and executable file, False otherwise
:rtype: bool
"""
return os.path.isfile(file_path) and os.access(file_path, os.X_OK)
def close_onexec(fd):
"""
Close on execution of a shell process.
@ -37,56 +104,11 @@ def check_executables(executables):
:raises EnvironmentError: when an executable doesn't exist or is not executable
"""
for executable in executables:
if not is_exe(executable):
if not _is_exe(executable):
raise EnvironmentError("executable not found: %s" % executable)
def is_exe(file_path):
"""
Check if a given file path exists and is an executable file.
:param str file_path: file path to check
:return: True if the file is considered and executable file, False otherwise
:rtype: bool
"""
return os.path.isfile(file_path) and os.access(file_path, os.X_OK)
def which(program):
"""
From: http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
:param str program: program to check for
:return: path if it exists, none otherwise
"""
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip("\"")
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def ensurepath(pathlist):
"""
Checks a list of paths are contained within the environment path, if not add it to the path.
:param list[str] pathlist: list of paths to check
:return: nothing
"""
searchpath = os.environ["PATH"].split(":")
for p in set(pathlist):
if p not in searchpath:
os.environ["PATH"] += ":" + p
def maketuple(obj):
def make_tuple(obj):
"""
Create a tuple from an object, or return the object itself.
@ -100,7 +122,7 @@ def maketuple(obj):
return obj,
def maketuplefromstr(s, value_type):
def make_tuple_fromstr(s, value_type):
"""
Create a tuple from a string.
@ -122,101 +144,22 @@ def split_args(args):
:return: shell-like syntax list
:rtype: list
"""
# split shell string to shell array for convenience
if type(args) == str:
args = shlex.split(args)
return args
def mutecall(*args, **kwargs):
"""
Run a muted call command.
:param list args: arguments for the command
:param dict kwargs: keyword arguments for the command
:return: command result
:rtype: int
"""
kwargs["stdout"] = DEVNULL
kwargs["stderr"] = subprocess.STDOUT
return subprocess.call(*args, **kwargs)
def mutecheck_call(*args, **kwargs):
"""
Run a muted check call command.
:param list args: arguments for the command
:param dict kwargs: keyword arguments for the command
:return: command result
:rtype: int
"""
kwargs["stdout"] = DEVNULL
kwargs["stderr"] = subprocess.STDOUT
return subprocess.check_call(*args, **kwargs)
def spawn(*args, **kwargs):
"""
Wrapper for running a spawn command and returning the process id.
:param list args: arguments for the command
:param dict kwargs: keyword arguments for the command
:return: process id of the command
:rtype: int
"""
return subprocess.Popen(*args, **kwargs).pid
def mutespawn(*args, **kwargs):
"""
Wrapper for running a muted spawned command.
:param list args: arguments for the command
:param dict kwargs: keyword arguments for the command
:return: process id of the command
:rtype: int
"""
kwargs["stdout"] = DEVNULL
kwargs["stderr"] = subprocess.STDOUT
return subprocess.Popen(*args, **kwargs).pid
def detachinit():
"""
Fork a child process and exit.
:return: nothing
"""
if os.fork():
# parent exits
os._exit(0)
os.setsid()
def detach(*args, **kwargs):
"""
Run a detached process by forking it.
:param list args: arguments for the command
:param dict kwargs: keyword arguments for the command
:return: process id of the command
:rtype: int
"""
kwargs["preexec_fn"] = detachinit
return subprocess.Popen(*args, **kwargs).pid
def mutedetach(*args, **kwargs):
def mute_detach(args, **kwargs):
"""
Run a muted detached process by forking it.
:param list args: arguments for the command
:param list[str]|str args: arguments for the command
:param dict kwargs: keyword arguments for the command
:return: process id of the command
:rtype: int
"""
kwargs["preexec_fn"] = detachinit
args = split_args(args)
kwargs["preexec_fn"] = _detach_init
kwargs["stdout"] = DEVNULL
kwargs["stderr"] = subprocess.STDOUT
return subprocess.Popen(*args, **kwargs).pid
@ -286,7 +229,7 @@ def check_cmd(args, **kwargs):
raise subprocess.CalledProcessError(-1, args)
def hexdump(s, bytes_per_word=2, words_per_line=8):
def hex_dump(s, bytes_per_word=2, words_per_line=8):
"""
Hex dump of a string.
@ -297,10 +240,11 @@ def hexdump(s, bytes_per_word=2, words_per_line=8):
"""
dump = ""
count = 0
bytes = bytes_per_word * words_per_line
total_bytes = bytes_per_word * words_per_line
while s:
line = s[:bytes]
s = s[bytes:]
line = s[:total_bytes]
s = s[total_bytes:]
tmp = map(lambda x: ("%02x" * bytes_per_word) % x,
zip(*[iter(map(ord, line))] * bytes_per_word))
if len(line) % 2:
@ -310,7 +254,7 @@ def hexdump(s, bytes_per_word=2, words_per_line=8):
return dump[:-1]
def filemunge(pathname, header, text):
def file_munge(pathname, header, text):
"""
Insert text at the end of a file, surrounded by header comments.
@ -320,15 +264,15 @@ def filemunge(pathname, header, text):
:return: nothing
"""
# prevent duplicates
filedemunge(pathname, header)
f = open(pathname, "a")
f.write("# BEGIN %s\n" % header)
f.write(text)
f.write("# END %s\n" % header)
f.close()
file_demunge(pathname, header)
with open(pathname, "a") as append_file:
append_file.write("# BEGIN %s\n" % header)
append_file.write(text)
append_file.write("# END %s\n" % header)
def filedemunge(pathname, header):
def file_demunge(pathname, header):
"""
Remove text that was inserted in a file surrounded by header comments.
@ -336,25 +280,27 @@ def filedemunge(pathname, header):
:param str header: header text to target for removal
:return: nothing
"""
f = open(pathname, "r")
lines = f.readlines()
f.close()
with open(pathname, "r") as read_file:
lines = read_file.readlines()
start = None
end = None
for i in range(len(lines)):
if lines[i] == "# BEGIN %s\n" % header:
start = i
elif lines[i] == "# END %s\n" % header:
end = i + 1
if start is None or end is None:
return
f = open(pathname, "w")
lines = lines[:start] + lines[end:]
f.write("".join(lines))
f.close()
with open(pathname, "w") as write_file:
lines = lines[:start] + lines[end:]
write_file.write("".join(lines))
def expandcorepath(pathname, session=None, node=None):
def expand_corepath(pathname, session=None, node=None):
"""
Expand a file path given session information.
@ -369,13 +315,15 @@ def expandcorepath(pathname, session=None, node=None):
pathname = pathname.replace("%SESSION%", str(session.session_id))
pathname = pathname.replace("%SESSION_DIR%", session.session_dir)
pathname = pathname.replace("%SESSION_USER%", session.user)
if node is not None:
pathname = pathname.replace("%NODE%", str(node.objid))
pathname = pathname.replace("%NODENAME%", node.name)
return pathname
def sysctldevname(devname):
def sysctl_devname(devname):
"""
Translate a device name to the name used with sysctl.
@ -477,7 +425,7 @@ def daemonize(rootdir="/", umask=0, close_fds=False, dontclose=(),
logger.exception("error closing file descriptor")
def readfileintodict(filename, d):
def load_config(filename, d):
"""
Read key=value pairs from a file, into a dict. Skip comments; strip newline characters and spacing.
@ -487,78 +435,18 @@ def readfileintodict(filename, d):
"""
with open(filename, "r") as f:
lines = f.readlines()
for l in lines:
if l[:1] == "#":
for line in lines:
if line[:1] == "#":
continue
try:
key, value = l.split("=", 1)
key, value = line.split("=", 1)
d[key] = value.strip()
except ValueError:
logger.exception("error reading file to dict: %s", filename)
def checkforkernelmodule(name):
"""
Return a string if a Linux kernel module is loaded, None otherwise.
The string is the line from /proc/modules containing the module name,
memory size (bytes), number of loaded instances, dependencies, state,
and kernel memory offset.
:param str name: name of kernel module to check for
:return: kernel module line, None otherwise
:rtype: str
"""
with open("/proc/modules", "r") as f:
for line in f:
if line.startswith(name + " "):
return line.rstrip()
return None
def _valid_module(path, file_name):
"""
Check if file is a valid python module.
:param str path: path to file
:param str file_name: file name to check
:return: True if a valid python module file, False otherwise
:rtype: bool
"""
file_path = os.path.join(path, file_name)
if not os.path.isfile(file_path):
return False
if file_name.startswith("_"):
return False
if not file_name.endswith(".py"):
return False
return True
def _is_class(module, member, clazz):
"""
Validates if a module member is a class and an instance of a CoreService.
:param module: module to validate for service
:param member: member to validate for service
:param clazz: clazz type to check for validation
:return: True if a valid service, False otherwise
:rtype: bool
"""
if not inspect.isclass(member):
return False
if not issubclass(member, clazz):
return False
if member.__module__ != module.__name__:
return False
return True
def load_classes(path, clazz):
"""
Dynamically load classes for use within CORE.

View file

@ -487,7 +487,7 @@ class RJ45Node(PyCoreNode, PyCoreNetIf):
try:
utils.check_cmd([constants.IP_BIN, "link", "set", self.localname, "down"])
utils.check_cmd([constants.IP_BIN, "addr", "flush", "dev", self.localname])
utils.mutecall([constants.TC_BIN, "qdisc", "del", "dev", self.localname, "root"])
utils.check_cmd([constants.TC_BIN, "qdisc", "del", "dev", self.localname, "root"])
except subprocess.CalledProcessError as e:
logger.exception("error shutting down: %s", e.output)
@ -541,7 +541,7 @@ class RJ45Node(PyCoreNode, PyCoreNetIf):
self.attachnet(net)
if addrlist:
for addr in utils.maketuple(addrlist):
for addr in utils.make_tuple(addrlist):
self.addaddr(addr)
return ifindex

View file

@ -36,12 +36,9 @@ utils.check_executables([
def ebtables_commands(call, commands):
ebtables_lock.acquire()
try:
with ebtables_lock:
for command in commands:
call(command)
finally:
ebtables_lock.release()
class OvsNet(PyCoreNet):
@ -109,16 +106,18 @@ class OvsNet(PyCoreNet):
ebtables_queue.stopupdateloop(self)
utils.mutecall([constants.IP_BIN, "link", "set", self.bridge_name, "down"])
utils.mutecall([constants.OVS_BIN, "del-br", self.bridge_name])
ebtables_commands(utils.mutecall, [
[constants.EBTABLES_BIN, "-D", "FORWARD", "--logical-in", self.bridge_name, "-j", self.bridge_name],
[constants.EBTABLES_BIN, "-X", self.bridge_name]
])
try:
utils.check_cmd([constants.IP_BIN, "link", "set", self.bridge_name, "down"])
utils.check_cmd([constants.OVS_BIN, "del-br", self.bridge_name])
ebtables_commands(utils.check_cmd, [
[constants.EBTABLES_BIN, "-D", "FORWARD", "--logical-in", self.bridge_name, "-j", self.bridge_name],
[constants.EBTABLES_BIN, "-X", self.bridge_name]
])
except subprocess.CalledProcessError as e:
logger.exception("error bringing bridge down and removing it: %s", e.output)
# removes veth pairs used for bridge-to-bridge connections
for interface in self.netifs():
# removes veth pairs used for bridge-to-bridge connections
interface.shutdown()
self._netif.clear()

View file

@ -67,7 +67,7 @@ class VEth(PyCoreNetIf):
logger.exception("error shutting down interface")
if self.localname:
utils.mutedetach([constants.IP_BIN, "link", "delete", self.localname])
utils.mute_detach([constants.IP_BIN, "link", "delete", self.localname])
self.up = False
@ -164,8 +164,8 @@ class TunTap(PyCoreNetIf):
"""
def localdevexists():
args = (constants.IP_BIN, "link", "show", self.localname)
return utils.mutecall(args)
args = [constants.IP_BIN, "link", "show", self.localname]
return utils.cmd(args)
self.waitfor(localdevexists)
@ -269,7 +269,7 @@ class GreTap(PyCoreNetIf):
if remoteip is None:
raise ValueError, "missing remote IP required for GRE TAP device"
args = ("ip", "link", "add", self.localname, "type", "gretap",
"remote", str(remoteip))
"remote", str(remoteip))
if localip:
args += ("local", str(localip))
if ttl:

View file

@ -313,15 +313,21 @@ class LxBrNet(PyCoreNet):
if not self.up:
return
ebq.stopupdateloop(self)
utils.mutecall([constants.IP_BIN, "link", "set", self.brname, "down"])
utils.mutecall([constants.BRCTL_BIN, "delbr", self.brname])
ebtablescmds(utils.mutecall, [
[constants.EBTABLES_BIN, "-D", "FORWARD",
"--logical-in", self.brname, "-j", self.brname],
[constants.EBTABLES_BIN, "-X", self.brname]])
try:
utils.check_cmd([constants.IP_BIN, "link", "set", self.brname, "down"])
utils.check_cmd([constants.BRCTL_BIN, "delbr", self.brname])
ebtablescmds(utils.check_cmd, [
[constants.EBTABLES_BIN, "-D", "FORWARD", "--logical-in", self.brname, "-j", self.brname],
[constants.EBTABLES_BIN, "-X", self.brname]
])
except subprocess.CalledProcessError as e:
logger.exception("error during shutdown: %s", e.output)
# removes veth pairs used for bridge-to-bridge connections
for netif in self.netifs():
# removes veth pairs used for bridge-to-bridge connections
netif.shutdown()
self._netif.clear()
self._linked.clear()
del self.session

View file

@ -461,7 +461,7 @@ class SimpleLxcNode(PyCoreNode):
self.attachnet(ifindex, net)
netif = self.netif(ifindex)
netif.sethwaddr(hwaddr)
for address in utils.maketuple(addrlist):
for address in utils.make_tuple(addrlist):
netif.addaddr(address)
return ifindex
else:
@ -473,7 +473,7 @@ class SimpleLxcNode(PyCoreNode):
if hwaddr:
self.sethwaddr(ifindex, hwaddr)
for address in utils.maketuple(addrlist):
for address in utils.make_tuple(addrlist):
self.addaddr(ifindex, address)
self.ifup(ifindex)

View file

@ -158,7 +158,7 @@ class PhysicalNode(PyCoreNode):
netif.localname = netif.name
if hwaddr:
self.sethwaddr(ifindex, hwaddr)
for addr in utils.maketuple(addrlist):
for addr in utils.make_tuple(addrlist):
self.addaddr(ifindex, addr)
if self.up:
self.cmd([constants.IP_BIN, "link", "set", "dev", netif.localname, "up"])

View file

@ -372,7 +372,7 @@ class CoreServices(ConfigurableManager):
if cfg[:7] == 'file://':
src = cfg[7:]
src = src.split('\n')[0]
src = utils.expandcorepath(src, node.session, node)
src = utils.expand_corepath(src, node.session, node)
# TODO: glob here
node.nodefilecopy(filename, src, mode=0644)
return True
@ -968,7 +968,7 @@ class CoreService(object):
elif key == "meta":
value = str(value)
else:
value = utils.maketuplefromstr(value, str)
value = utils.make_tuple_fromstr(value, str)
if key == "dirs":
self._dirs = value

View file

@ -57,7 +57,7 @@ class MgenSinkService(NrlService):
def generateconfig(cls, node, filename, services):
cfg = "0.0 LISTEN UDP 5000\n"
for ifc in node.netifs():
name = utils.sysctldevname(ifc.name)
name = utils.sysctl_devname(ifc.name)
cfg += "0.0 Join 224.225.1.2 INTERFACE %s\n" % name
return cfg

View file

@ -60,7 +60,7 @@ class IPForwardService(UtilService):
%(sysctl)s -w net.ipv4.conf.default.rp_filter=0
""" % {'sysctl': constants.SYSCTL_BIN}
for ifc in node.netifs():
name = utils.sysctldevname(ifc.name)
name = utils.sysctl_devname(ifc.name)
cfg += "%s -w net.ipv4.conf.%s.forwarding=1\n" % (constants.SYSCTL_BIN, name)
cfg += "%s -w net.ipv4.conf.%s.send_redirects=0\n" % \
(constants.SYSCTL_BIN, name)

View file

@ -7,7 +7,6 @@ import atexit
import os
import pprint
import random
import shlex
import shutil
import subprocess
import tempfile
@ -520,7 +519,7 @@ class Session(object):
environment_config_file = os.path.join(constants.CORE_CONF_DIR, "environment")
try:
if os.path.isfile(environment_config_file):
utils.readfileintodict(environment_config_file, env)
utils.load_config(environment_config_file, env)
except IOError:
logger.warn("environment configuration file does not exist: %s", environment_config_file)
@ -528,7 +527,7 @@ class Session(object):
if self.user:
environment_user_file = os.path.join("/home", self.user, ".core", "environment")
try:
utils.readfileintodict(environment_user_file, env)
utils.load_config(environment_user_file, env)
except IOError:
logger.warn("error reading user core environment settings file: %s", environment_user_file)
@ -1189,7 +1188,7 @@ class Session(object):
header = "CORE session %s host entries" % self.session_id
if remove:
logger.info("Removing /etc/hosts file entries.")
utils.filedemunge("/etc/hosts", header)
utils.file_demunge("/etc/hosts", header)
return
entries = []
@ -1200,7 +1199,7 @@ class Session(object):
logger.info("Adding %d /etc/hosts file entries." % len(entries))
utils.filemunge("/etc/hosts", header, "\n".join(entries) + "\n")
utils.file_munge("/etc/hosts", header, "\n".join(entries) + "\n")
def runtime(self):
"""
@ -1254,9 +1253,7 @@ class Session(object):
logger.info("running event %s at time %s cmd=%s" % (name, now, data))
if not node_id:
# TODO: look to consolidate shlex to utils
commands = shlex.split(data)
utils.mutedetach(commands)
utils.mute_detach(data)
else:
node = self.get_object(node_id)
node.cmd(data, wait=False)

View file

@ -237,7 +237,7 @@ class XenNode(PyCoreNode):
# unpause VM
logger.warn("XEN PVM boot() unpause domU %s", self.vmname)
utils.mutecheck_call([XM_PATH, "unpause", self.vmname])
utils.check_cmd([XM_PATH, "unpause", self.vmname])
self.booted = True
finally:
@ -261,7 +261,7 @@ class XenNode(PyCoreNode):
try:
# RJE XXX what to do here
if self.booted:
utils.mutecheck_call([XM_PATH, "destroy", self.vmname])
utils.check_cmd([XM_PATH, "destroy", self.vmname])
self.booted = False
except (OSError, subprocess.CalledProcessError):
# ignore this error too, the VM may have exited already
@ -272,9 +272,9 @@ class XenNode(PyCoreNode):
while os.path.exists(self.lvpath):
try:
subprocess.check_call([UDEVADM_PATH, "settle"])
utils.mutecall([LVCHANGE_PATH, "-an", self.lvpath])
utils.check_cmd([LVCHANGE_PATH, "-an", self.lvpath])
lvm_remove_count += 1
utils.mutecall([LVREMOVE_PATH, "-f", self.lvpath])
utils.check_cmd([LVREMOVE_PATH, "-f", self.lvpath])
except OSError:
logger.exception("error during shutdown")
@ -296,8 +296,8 @@ class XenNode(PyCoreNode):
"""
if os.path.exists(self.lvpath):
raise Exception, "LVM volume already exists"
utils.mutecheck_call([LVCREATE_PATH, "--size", self.disksize,
"--name", self.lvname, self.vgname])
utils.check_cmd([LVCREATE_PATH, "--size", self.disksize,
"--name", self.lvname, self.vgname])
def createpartitions(self):
"""
@ -337,8 +337,8 @@ class XenNode(PyCoreNode):
persistdev = "/dev/mapper/" + lines[0].strip().split(" ")[0].strip()
swapdev = "/dev/mapper/" + lines[1].strip().split(" ")[0].strip()
subprocess.check_call([KPARTX_PATH, "-a", self.lvpath])
utils.mutecheck_call([MKFSEXT4_PATH, "-L", "persist", persistdev])
utils.mutecheck_call([MKSWAP_PATH, "-f", "-L", "swap", swapdev])
utils.check_cmd([MKFSEXT4_PATH, "-L", "persist", persistdev])
utils.check_cmd([MKSWAP_PATH, "-f", "-L", "swap", swapdev])
return persistdev
def untarpersistent(self, tarname, iso):
@ -431,7 +431,7 @@ class XenNode(PyCoreNode):
for action in ("poweroff", "reboot", "suspend", "crash", "halt"):
args.append("on_%s=destroy" % action)
args.append("extra=" + self.getconfigitem("xm_create_extra"))
utils.mutecheck_call(args)
utils.check_cmd(args)
# from class LxcNode
def privatedir(self, path):
@ -710,7 +710,7 @@ class XenNode(PyCoreNode):
if hwaddr:
self.sethwaddr(ifindex, hwaddr)
for addr in utils.maketuple(addrlist):
for addr in utils.make_tuple(addrlist):
self.addaddr(ifindex, addr)
# self.ifup(ifindex)
return ifindex

View file

@ -18,7 +18,7 @@ from string import Template
from core.constants import QUAGGA_STATE_DIR
from core.misc import ipaddress
from core.misc.utils import mutecall
from core.misc.utils import check_cmd
from core.netns import nodes
# this is the /etc/core/core.conf default
@ -33,8 +33,7 @@ try:
if os.path.exists(os.path.join(p, "zebra")):
quagga_path = p
break
mutecall([os.path.join(quagga_path, "zebra"),
"-u", "root", "-g", "root", "-v"])
check_cmd([os.path.join(quagga_path, "zebra"), "-u", "root", "-g", "root", "-v"])
except OSError:
sys.stderr.write("ERROR: running zebra failed\n")
sys.exit(1)

View file

@ -13,12 +13,12 @@ import optparse
import sys
from core.misc import ipaddress
from core.misc.utils import mutecall
from core.misc.utils import check_cmd
from core.netns import nodes
from core.session import Session
try:
mutecall(["iperf", "-v"])
check_cmd(["iperf", "-v"])
except OSError:
sys.stderr.write("ERROR: running iperf failed\n")
sys.exit(1)

View file

@ -13,12 +13,12 @@ import optparse
import sys
from core.misc import ipaddress
from core.misc.utils import mutecall
from core.misc.utils import check_cmd
from core.netns import nodes
from core.session import Session
try:
mutecall(["iperf", "-v"])
check_cmd(["iperf", "-v"])
except OSError:
sys.stderr.write("ERROR: running iperf failed\n")
sys.exit(1)

View file

@ -35,7 +35,7 @@ from core.corehandlers import CoreDatagramRequestHandler
from core.enumerations import MessageFlags
from core.enumerations import RegisterTlvs
from core.misc import nodeutils
from core.misc.utils import closeonexec
from core.misc.utils import close_onexec
from core.misc.utils import daemonize
from core.service import ServiceManager
@ -84,11 +84,11 @@ def cored(cfg=None):
logger.exception("error starting main server on: %s:%s", host, port)
sys.exit(1)
closeonexec(server.fileno())
close_onexec(server.fileno())
logger.info("main server started, listening on: %s:%s\n" % (host, port))
udpserver = startudp(server, (host, port))
closeonexec(udpserver.fileno())
close_onexec(udpserver.fileno())
server.serve_forever()

View file

@ -21,7 +21,7 @@ from core.coreobj import PyCoreNet
from core.enumerations import EventTypes
from core.enumerations import LinkTypes
from core.enumerations import NodeTypes
from core.misc.utils import maketuple
from core.misc.utils import make_tuple
from core.mobility import WayPointMobility
from core.netns.nodes import CoreNode
from core.session import Session
@ -65,7 +65,7 @@ class CoreNs3Node(CoreNode, ns.network.Node):
self.attachnet(ifindex, net)
netif = self.netif(ifindex)
netif.sethwaddr(hwaddr)
for addr in maketuple(addrlist):
for addr in make_tuple(addrlist):
netif.addaddr(addr)
addrstr = netif.addrlist[0]