[lnst] NetTestSlave: cleanup on controller disconnect
by Jiří Pírko
commit 7b5f5c9759783cc7086cfae617b3012ff35a8ed2
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Fri Jul 26 12:59:43 2013 +0200
NetTestSlave: cleanup on controller disconnect
This commit moves the construction of a NetConfig object to the
NetTestSlave class, so that it can call configuration cleanup when a
disconnect is detected. The disconnect handling is also changed to
reflect that.
I also made some minor code cleanup in this commit, but since it is all
related to the main part of this commit I didn't split it into a
sepparate commit.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
lnst/Slave/NetTestSlave.py | 49 +++++++++++++++++++------------------------
1 files changed, 22 insertions(+), 27 deletions(-)
---
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index dee2d83..182bb41 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -44,9 +44,9 @@ class SlaveMethods:
'''
Exported xmlrpc methods
'''
- def __init__(self, command_context, log_ctl):
+ def __init__(self, command_context, netconfig, log_ctl):
self._packet_captures = {}
- self._netconfig = NetConfig()
+ self._netconfig = netconfig
self._command_context = command_context
self._log_ctl = log_ctl
@@ -61,6 +61,7 @@ class SlaveMethods:
self._resource_table = {}
def hello(self, recipe_path):
+ logging.info("Recieved a controller connection.")
self.clear_resource_table()
self._cache.del_old_entries()
self.reset_file_transfers()
@@ -381,6 +382,7 @@ class ServerHandler(object):
messages = self._connection_handler.check_connections()
addr = self._c_socket[1]
if self._connection_handler.get_connection(addr) == None:
+ logging.info("Lost controller connection.")
self._c_socket = None
return messages
@@ -410,7 +412,9 @@ class NetTestSlave:
die_when_parent_die()
self._cmd_context = NetTestCommandContext()
- self._methods = SlaveMethods(self._cmd_context, log_ctl)
+ self._netconfig = NetConfig()
+ self._methods = SlaveMethods(self._cmd_context, self._netconfig,
+ log_ctl)
self.register_die_signal(signal.SIGHUP)
self.register_die_signal(signal.SIGINT)
@@ -425,6 +429,13 @@ class NetTestSlave:
def run(self):
while not self._finished:
if self._server_handler.get_ctl_sock() == None:
+ self._log_ctl.cancel_connection()
+ logging.info("Waiting for connection, performing cleanup.")
+ logging.info("Cleaning up leftover commands.")
+ self._cmd_context.cleanup()
+ logging.info("Cleaning up configured interfaces.")
+ self._netconfig.deconfigure_all()
+ self._netconfig.cleanup()
try:
self._server_handler.accept_connection()
except socket.error:
@@ -438,10 +449,6 @@ class NetTestSlave:
for msg in msgs:
self._process_msg(msg[1])
- if self._server_handler.get_ctl_sock() == None:
- self._cmd_context.cleanup()
- self._log_ctl.cancel_connection()
-
self._cmd_context.cleanup()
def _process_msg(self, msg):
@@ -455,24 +462,18 @@ class NetTestSlave:
type, value, tb = sys.exc_info()
exc_trace = ''.join(traceback.format_exception(type,
value, tb))
- response = {"type": "exception",
- "Exception": exc_trace}
- if not self._server_handler.send_data_to_ctl(response):
- self._cmd_context.cleanup()
- self._log_ctl.cancel_connection()
+ response = {"type": "exception", "Exception": exc_trace}
+
+ self._server_handler.send_data_to_ctl(response)
return
if result != None:
response = {"type": "result", "result": result}
- if not self._server_handler.send_data_to_ctl(response):
- self._cmd_context.cleanup()
- self._log_ctl.cancel_connection()
+ self._server_handler.send_data_to_ctl(response)
else:
err = "Method '%s' not supported." % msg["method_name"]
response = {"type": "error", "err": err}
- if not self._server_handler.send_data_to_ctl(response):
- self._cmd_context.cleanup()
- self._log_ctl.cancel_connection()
+ self._server_handler.send_data_to_ctl(response)
elif msg["type"] == "log":
logger = logging.getLogger()
record = logging.makeLogRecord(msg["record"])
@@ -487,15 +488,11 @@ class NetTestSlave:
cmd = self._cmd_context.get_cmd(msg["cmd_id"])
cmd.join()
self._cmd_context.del_cmd(cmd)
- if not self._server_handler.send_data_to_ctl(msg):
- self._cmd_context.cleanup()
- self._log_ctl.cancel_connection()
+ self._server_handler.send_data_to_ctl(msg)
elif msg["type"] == "result":
if msg["cmd_id"] == None:
del msg["cmd_id"]
- if not self._server_handler.send_data_to_ctl(msg):
- self._cmd_context.cleanup()
- self._log_ctl.cancel_connection()
+ self._server_handler.send_data_to_ctl(msg)
cmd = self._cmd_context.get_cmd(None)
cmd.join()
self._cmd_context.del_cmd(cmd)
@@ -505,9 +502,7 @@ class NetTestSlave:
del msg["cmd_id"]
if cmd.finished():
- if not self._server_handler.send_data_to_ctl(msg):
- self._cmd_context.cleanup()
- self._log_ctl.cancel_connection()
+ self._server_handler.send_data_to_ctl(msg)
self._cmd_context.del_cmd(cmd)
else:
cmd.set_result(msg["result"])
10 years, 9 months
[lnst] NetConfig: store references to NetConfigDevice objects
by Jiří Pírko
commit 988898bd9b581cb6d7fc9d256d5bc64729c79e94
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Fri Jul 26 12:59:42 2013 +0200
NetConfig: store references to NetConfigDevice objects
The NetConfig class created NetConfigDevice objects for one use only and
always discarded them. This works fine because we store the config
dictionaries that are needed to create these objects. However it
sometimes requires small hacks to work and it defeats the purpose of
using objects at all since they're not allowed to remember their state.
There will probably be some other changes made later to take advantage
of this.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
lnst/Slave/NetConfig.py | 26 +++++++++++++++-----------
1 files changed, 15 insertions(+), 11 deletions(-)
---
diff --git a/lnst/Slave/NetConfig.py b/lnst/Slave/NetConfig.py
index 4b0e5a3..a9c3729 100644
--- a/lnst/Slave/NetConfig.py
+++ b/lnst/Slave/NetConfig.py
@@ -23,6 +23,7 @@ class NetConfig:
config = {}
self._devnames = devnames
self._config = config
+ self._dev_configs = {}
def _get_leafs(self):
leafs = []
@@ -59,19 +60,23 @@ class NetConfig:
return types
def add_interface_config(self, if_id, config):
- dev_type = config["type"]
- if not dev_type in self._get_used_types():
- logging.info("Initializing '%s' device class", dev_type)
- NetConfigDeviceType(dev_type).type_init()
-
self._config[if_id] = config
self._devnames.rescan_netdevs()
self._devnames.assign_name(if_id, self._config)
+ dev_config = NetConfigDevice(config, self._config)
+ self._dev_configs[if_id] = dev_config
+
+ dev_type = config["type"]
+ if not dev_type in self._get_used_types():
+ logging.info("Initializing '%s' device class", dev_type)
+ dev_config.type_init()
+
def remove_interface_config(self, if_id):
config = self._config[if_id]
del self._config[if_id]
+ del self._dev_configs[if_id]
dev_type = config["type"]
if not dev_type in self._get_used_types():
@@ -82,8 +87,7 @@ class NetConfig:
return self._config[if_id]
def configure(self, dev_id):
- netdev = self._config[dev_id]
- device = NetConfigDevice(netdev, self._config)
+ device = self._dev_configs[dev_id]
device.configure()
device.up()
@@ -93,8 +97,7 @@ class NetConfig:
self.configure(dev_id)
def deconfigure(self, dev_id):
- netdev = self._config[dev_id]
- device = NetConfigDevice(netdev, self._config)
+ device = self._dev_configs[dev_id]
device.down()
device.deconfigure()
@@ -156,7 +159,8 @@ class NetConfig:
return True
def cleanup(self):
- tmp = copy.deepcopy(self._config)
- for dev_id in tmp:
+ for dev_id in self._config.keys():
del self._config[dev_id]
+ for dev_id in self._dev_configs.keys():
+ del self._dev_configs[dev_id]
self._devnames.rescan_netdevs()
10 years, 9 months
[lnst] NmConfigDevice: fix no bond options bug
by Jiří Pírko
commit 4b3447736ec58f00a75bc60cbb08c38a871ce363
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Tue Jul 23 11:12:09 2013 +0200
NmConfigDevice: fix no bond options bug
When there are no bond options specified in the recipe file, lnst
created an empty dbus.Dictionary which is not accepted by NM.
This commit fixes that.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
lnst/Slave/NmConfigDevice.py | 15 +++++++++++----
1 files changed, 11 insertions(+), 4 deletions(-)
---
diff --git a/lnst/Slave/NmConfigDevice.py b/lnst/Slave/NmConfigDevice.py
index 88c2817..e7d6418 100644
--- a/lnst/Slave/NmConfigDevice.py
+++ b/lnst/Slave/NmConfigDevice.py
@@ -290,7 +290,10 @@ class NmConfigDeviceBond(NmConfigDeviceGeneric):
'''
value = self._config[int(value)]["name"]
options[option] = value
- return dbus.Dictionary(options, signature="ss")
+ if options:
+ return dbus.Dictionary(options, signature="ss")
+ else:
+ return None
def _add_bond(self):
netdev = self._netdev
@@ -304,9 +307,13 @@ class NmConfigDeviceBond(NmConfigDeviceGeneric):
options = self._setup_options()
- s_bond = dbus.Dictionary({
- 'interface-name': netdev["name"],
- 'options': options})
+ if options:
+ s_bond = dbus.Dictionary({
+ 'interface-name': netdev["name"],
+ 'options': options})
+ else:
+ s_bond = dbus.Dictionary({
+ 'interface-name': netdev["name"]})
s_ipv4, s_ipv6 = self._nm_make_ip_settings(netdev["addresses"])
10 years, 9 months
[lnst] Config: make lnst configuration globally accesible
by Jiří Pírko
commit 87734efe03b678d6b716d059edd0cc41f34faf0d
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Tue Jul 23 11:11:58 2013 +0200
Config: make lnst configuration globally accesible
LNST configuration was created as a single Config object that was passed
around as an argument to the modules that needed it. This was ok at
first because it was only needed in a few modules, but it became
tiresome to send this object everywhere as an argument.
This commit creates a single globally accesible object lnst_config that
is creted when the module lnst.Common.Config is first imported in
lnst-ctl or lnst-slave, where the contents of the object will be
initialized and loaded.
After that all the modules just import this object and can use it.
This commit also changes all the modules that were using the lnst
configuration so that they use this global object instead.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
lnst-ctl | 33 ++++++++++++++++-----------------
lnst-slave | 18 +++++++++---------
lnst/Common/Colours.py | 5 +++--
lnst/Common/Config.py | 22 +++++++++-------------
lnst/Controller/NetTestController.py | 16 ++++++++--------
lnst/Controller/SlavePool.py | 7 +++----
lnst/Slave/NetConfig.py | 16 +++++++---------
lnst/Slave/NetConfigDevice.py | 7 ++++---
lnst/Slave/NetTestSlave.py | 21 ++++++++++-----------
9 files changed, 69 insertions(+), 76 deletions(-)
---
diff --git a/lnst-ctl b/lnst-ctl
index 3e9b62b..97039ed 100755
--- a/lnst-ctl
+++ b/lnst-ctl
@@ -18,7 +18,7 @@ import os
import re
import datetime
from lnst.Common.Logs import LoggingCtl, log_exc_traceback
-from lnst.Common.Config import Config
+from lnst.Common.Config import lnst_config
from lnst.Common.Colours import load_presets_from_config
from lnst.Controller.NetTestController import NetTestController, NetTestError
from lnst.Controller.NetTestResultSerializer import NetTestResultSerializer
@@ -46,10 +46,10 @@ def usage():
sys.exit()
def process_recipe(action, file_path, cleanup, res_serializer,
- packet_capture, config, log_ctl, pool_checks):
+ packet_capture, log_ctl, pool_checks):
nettestctl = NetTestController(file_path, log_ctl, cleanup=cleanup,
res_serializer=res_serializer,
- config=config, pool_checks=pool_checks)
+ pool_checks=pool_checks)
if action == "run":
return nettestctl.run_recipe(packet_capture)
elif action == "dump":
@@ -63,14 +63,14 @@ def process_recipe(action, file_path, cleanup, res_serializer,
usage();
def get_recipe_result(args, file_path, cleanup, res_serializer, packet_capture,
- config, log_ctl, pool_checks):
+ log_ctl, pool_checks):
res_serializer.add_recipe(file_path)
log_ctl.set_recipe(file_path)
res = None
try:
res = process_recipe(args, file_path, cleanup, res_serializer,
- packet_capture, config, log_ctl, pool_checks)
+ packet_capture, log_ctl, pool_checks)
except Exception as err:
log_exc_traceback()
logging.error(err)
@@ -95,22 +95,22 @@ def main():
usage()
sys.exit()
- config = Config("controller")
+ lnst_config.controller_init()
dirname = os.path.dirname(sys.argv[0])
gitcfg = os.path.join(dirname, "lnst-ctl.conf")
if os.path.isfile(gitcfg):
- config.load_config(gitcfg)
+ lnst_config.load_config(gitcfg)
else:
- config.load_config('/etc/lnst-ctl.conf')
+ lnst_config.load_config('/etc/lnst-ctl.conf')
usr_cfg = os.path.expanduser('~/.lnst/lnst-ctl.conf')
if os.path.isfile(usr_cfg):
- config.load_config(usr_cfg)
+ lnst_config.load_config(usr_cfg)
else:
if not os.path.isdir(os.path.dirname(usr_cfg)):
os.makedirs(os.path.dirname(usr_cfg))
with open(usr_cfg, 'w') as f:
- f.write(config.dump_config())
+ f.write(lnst_config.dump_config())
debug = 0
recipe_path = None
@@ -118,7 +118,7 @@ def main():
result_path = None
packet_capture = False
pool_checks = True
- coloured_output = not config.get_option("colours", "disable_colours")
+ coloured_output = not lnst_config.get_option("colours", "disable_colours")
for opt, arg in opts:
if opt in ("-d", "--debug"):
debug += 1
@@ -135,12 +135,12 @@ def main():
elif opt in ("-m", "--no-colours"):
coloured_output = False
- load_presets_from_config(config)
+ load_presets_from_config()
date = datetime.datetime.now().strftime("%Y-%m-%d_%H:%M:%S")
log_ctl = LoggingCtl(debug,
- log_dir=config.get_option('environment', 'log_dir'),
- log_subdir=date, colours=coloured_output)
+ log_dir=lnst_config.get_option('environment', 'log_dir'),
+ log_subdir=date, colours=coloured_output)
action = args.pop()
@@ -167,13 +167,12 @@ def main():
cleanup,
res_serializer,
packet_capture,
- config, log_ctl,
- pool_checks))
+ log_ctl, pool_checks))
else:
summary.append(get_recipe_result(action, recipe_path,
cleanup, res_serializer,
packet_capture,
- config, log_ctl, pool_checks))
+ log_ctl, pool_checks))
log_ctl.set_recipe("", clean=False)
diff --git a/lnst-slave b/lnst-slave
index 996cd32..1e7dee8 100755
--- a/lnst-slave
+++ b/lnst-slave
@@ -17,7 +17,7 @@ import os
import logging
from lnst.Common.Daemon import Daemon
from lnst.Common.Logs import LoggingCtl
-from lnst.Common.Config import Config
+from lnst.Common.Config import lnst_config
from lnst.Slave.NetTestSlave import NetTestSlave
def usage():
@@ -49,19 +49,19 @@ def main():
usage()
sys.exit()
- config = Config("slave")
+ lnst_config.slave_init()
dirname = os.path.dirname(sys.argv[0])
gitcfg = os.path.join(dirname, "lnst-slave.conf")
if os.path.isfile(gitcfg):
- config.load_config(gitcfg)
+ lnst_config.load_config(gitcfg)
else:
- config.load_config('/etc/lnst-slave.conf')
+ lnst_config.load_config('/etc/lnst-slave.conf')
debug = False
daemon = False
pidfile = "lnst-slave.pid"
port = None
- coloured_output = not config.get_option("colours", "disable_colours")
+ coloured_output = not lnst_config.get_option("colours", "disable_colours")
for opt, arg in opts:
if opt in ("-d", "--debug"):
debug = True
@@ -77,14 +77,14 @@ def main():
coloured_output = False
log_ctl = LoggingCtl(debug,
- log_dir=config.get_option('environment', 'log_dir'),
- colours=coloured_output)
+ log_dir=lnst_config.get_option('environment', 'log_dir'),
+ colours=coloured_output)
logging.info("Started")
if port:
- nettestslave = NetTestSlave(config, log_ctl, port=port)
+ nettestslave = NetTestSlave(log_ctl, port=port)
else:
- nettestslave = NetTestSlave(config, log_ctl)
+ nettestslave = NetTestSlave(log_ctl)
if daemon:
daemon = Daemon(pidfile)
diff --git a/lnst/Common/Colours.py b/lnst/Common/Colours.py
index 5a5d385..c88bf5d 100644
--- a/lnst/Common/Colours.py
+++ b/lnst/Common/Colours.py
@@ -14,6 +14,7 @@ import logging
import os
import re
from lnst.Common.Utils import bool_it
+from lnst.Common.Config import lnst_config
COLOURS = {
"black": 30,
@@ -165,9 +166,9 @@ def decorate_with_preset(string, preset):
def strip_colours(text):
return re.sub("\033\[[0-9]+(;[0-9]+){0,2}m", "", text)
-def load_presets_from_config(config):
+def load_presets_from_config():
for preset_name in PRESETS:
- preset = config.get_option("colours", preset_name)
+ preset = lnst_config.get_option("colours", preset_name)
if preset == None:
continue
fg, bg, bf = preset
diff --git a/lnst/Common/Config.py b/lnst/Common/Config.py
index c79c436..2a74c25 100644
--- a/lnst/Common/Config.py
+++ b/lnst/Common/Config.py
@@ -27,20 +27,10 @@ class Config():
options = None
_scheme = None
- def __init__(self, scheme):
+ def __init__(self):
self.options = dict()
- self._scheme = scheme
- if self._scheme == "controller":
- self.controller_scheme()
- elif self._scheme == "slave":
- self.slave_scheme()
- else:
- msg = "Unknow scheme: '%s', can't set up configuration"\
- % self._scheme
- raise ConfigError(msg)
-
- def controller_scheme(self):
+ def controller_init(self):
self.options['environment'] = dict()
self.options['environment']['mac_pool_range'] = {\
"value" : ['52:54:01:00:00:01', '52:54:01:FF:FF:FF'],
@@ -76,7 +66,7 @@ class Config():
self.colours_scheme()
- def slave_scheme(self):
+ def slave_init(self):
self.options['environment'] = dict()
self.options['environment']['log_dir'] = {\
"value" : os.path.abspath(os.path.join(
@@ -283,3 +273,9 @@ class Config():
string = str(value)
return string
+
+#Global object containing lnst configuration, available across modules
+#The object is created here but the contents are initialized
+#in lnst-ctl and lnst-slave, after that the modules that need the configuration
+#just import this object
+lnst_config = Config()
diff --git a/lnst/Controller/NetTestController.py b/lnst/Controller/NetTestController.py
index 88d3156..47c615a 100644
--- a/lnst/Controller/NetTestController.py
+++ b/lnst/Controller/NetTestController.py
@@ -32,6 +32,7 @@ from lnst.Controller.SlavePool import SlavePool
from lnst.Controller.Machine import Machine, MachineError
from lnst.Common.ConnectionHandler import send_data, recv_data
from lnst.Common.ConnectionHandler import ConnectionHandler
+from lnst.Common.Config import lnst_config
class NetTestError(Exception):
pass
@@ -41,17 +42,16 @@ def ignore_event(**kwarg):
class NetTestController:
def __init__(self, recipe_path, log_ctl, cleanup=False,
- res_serializer=None, config=None, pool_checks=True):
+ res_serializer=None, pool_checks=True):
self._docleanup = cleanup
self._res_serializer = res_serializer
self._remote_capture_files = {}
- self._config = config
self._log_ctl = log_ctl
self._recipe_path = recipe_path
self._msg_dispatcher = MessageDispatcher(log_ctl)
- sp = SlavePool(config.get_option('environment', 'pool_dirs'),
- check_process_running("libvirtd"), config, pool_checks)
+ sp = SlavePool(lnst_config.get_option('environment', 'pool_dirs'),
+ check_process_running("libvirtd"), pool_checks)
self._slave_pool = sp
self._machines = {}
@@ -62,7 +62,7 @@ class NetTestController:
recipe["machines"] = {}
recipe["switches"] = {}
- mac_pool_range = config.get_option('environment', 'mac_pool_range')
+ mac_pool_range = lnst_config.get_option('environment', 'mac_pool_range')
self._mac_pool = MacPool(mac_pool_range[0], mac_pool_range[1])
parser = RecipeParse(recipe_path)
@@ -74,8 +74,8 @@ class NetTestController:
parser.register_event_handler("interface_config_ready",
self._prepare_interface)
- modules_dirs = config.get_option('environment', 'module_dirs')
- tools_dirs = config.get_option('environment', 'tool_dirs')
+ modules_dirs = lnst_config.get_option('environment', 'module_dirs')
+ tools_dirs = lnst_config.get_option('environment', 'tool_dirs')
self._resource_table = {}
self._resource_table["module"] = self._load_test_modules(modules_dirs)
@@ -131,7 +131,7 @@ class NetTestController:
address = socket.gethostbyname(machine.get_hostname())
self._log_ctl.add_slave(m_id, address)
- port = self._config.get_option('environment', 'rpcport')
+ port = lnst_config.get_option('environment', 'rpcport')
machine.set_rpc(self._msg_dispatcher, port)
machine.set_mac_pool(self._mac_pool)
machine.set_network_bridges(self._network_bridges)
diff --git a/lnst/Controller/SlavePool.py b/lnst/Controller/SlavePool.py
index b875d59..05c6041 100644
--- a/lnst/Controller/SlavePool.py
+++ b/lnst/Controller/SlavePool.py
@@ -22,6 +22,7 @@ from lnst.Common.XmlProcessing import XmlDomTreeInit
from lnst.Common.NetUtils import test_tcp_connection
from lnst.Controller.SlaveMachineParse import SlaveMachineParse
from lnst.Controller.Machine import Machine
+from lnst.Common.Config import lnst_config
class SlavePool:
"""
@@ -38,9 +39,7 @@ class SlavePool:
_allow_virt = False
_pool_checks = True
- def __init__(self, pool_dirs, allow_virtual=False, config=None,
- pool_checks=True):
- self._config = config
+ def __init__(self, pool_dirs, allow_virtual=False, pool_checks=True):
self._allow_virt = allow_virtual
self._pool_checks = pool_checks
for pool_dir in pool_dirs:
@@ -76,7 +75,7 @@ class SlavePool:
if "rpcport" in machine:
port = machine["params"]["rpcport"]
else:
- port = self._config.get_option('environment', 'rpcport')
+ port = lnst_config.get_option('environment', 'rpcport')
logging.info("Querying slave machine %s." % m_id)
if not test_tcp_connection(hostname, port):
diff --git a/lnst/Slave/NetConfig.py b/lnst/Slave/NetConfig.py
index 28f6240..4b0e5a3 100644
--- a/lnst/Slave/NetConfig.py
+++ b/lnst/Slave/NetConfig.py
@@ -18,14 +18,12 @@ from lnst.Slave.NetConfigDevice import NetConfigDeviceType
from lnst.Slave.NetConfigCommon import get_slaves
class NetConfig:
- def __init__(self, lnst_config):
+ def __init__(self):
devnames = NetConfigDevNames()
config = {}
self._devnames = devnames
self._config = config
- self._lnst_config = lnst_config
-
def _get_leafs(self):
leafs = []
for dev_id in self._config:
@@ -64,7 +62,7 @@ class NetConfig:
dev_type = config["type"]
if not dev_type in self._get_used_types():
logging.info("Initializing '%s' device class", dev_type)
- NetConfigDeviceType(dev_type, self._lnst_config).type_init()
+ NetConfigDeviceType(dev_type).type_init()
self._config[if_id] = config
@@ -78,14 +76,14 @@ class NetConfig:
dev_type = config["type"]
if not dev_type in self._get_used_types():
logging.info("Cleaning up '%s' device class.", dev_type)
- NetConfigDeviceType(dev_type, self._lnst_config).type_cleanup()
+ NetConfigDeviceType(dev_type).type_cleanup()
def get_interface_config(self, if_id):
return self._config[if_id]
def configure(self, dev_id):
netdev = self._config[dev_id]
- device = NetConfigDevice(netdev, self._config, self._lnst_config)
+ device = NetConfigDevice(netdev, self._config)
device.configure()
device.up()
@@ -96,7 +94,7 @@ class NetConfig:
def deconfigure(self, dev_id):
netdev = self._config[dev_id]
- device = NetConfigDevice(netdev, self._config, self._lnst_config)
+ device = NetConfigDevice(netdev, self._config)
device.down()
device.deconfigure()
@@ -144,7 +142,7 @@ class NetConfig:
elif slave_dev_id in netdev["slaves"]:
return False
netdev["slaves"].append(slave_dev_id)
- device = NetConfigDevice(netdev, self._config, self._lnst_config)
+ device = NetConfigDevice(netdev, self._config)
device.slave_add(slave_dev_id)
return True
@@ -153,7 +151,7 @@ class NetConfig:
if not "slaves" in netdev or not slave_dev_id in netdev["slaves"]:
return False
netdev["slaves"].remove(slave_dev_id)
- device = NetConfigDevice(netdev, self._config, self._lnst_config)
+ device = NetConfigDevice(netdev, self._config)
device.slave_del(slave_dev_id)
return True
diff --git a/lnst/Slave/NetConfigDevice.py b/lnst/Slave/NetConfigDevice.py
index 6fcd4b5..c66fa50 100644
--- a/lnst/Slave/NetConfigDevice.py
+++ b/lnst/Slave/NetConfigDevice.py
@@ -19,6 +19,7 @@ from lnst.Slave.NetConfigCommon import get_slaves, get_option, get_slave_option
from lnst.Common.Utils import kmod_in_use, bool_it
from lnst.Slave.NmConfigDevice import type_class_mapping as nm_type_class_mapping
from lnst.Common.Utils import check_process_running
+from lnst.Common.Config import lnst_config
class NetConfigDeviceGeneric:
@@ -292,7 +293,7 @@ type_class_mapping = {
"team": NetConfigDeviceTeam
}
-def NetConfigDevice(netdev, config, lnst_config):
+def NetConfigDevice(netdev, config):
'''
Class dispatcher
'''
@@ -302,7 +303,7 @@ def NetConfigDevice(netdev, config, lnst_config):
else:
return type_class_mapping[netdev["type"]](netdev, config)
-def NetConfigDeviceType(dev_type, lnst_config):
+def NetConfigDeviceType(dev_type):
'''
Class dispatcher for classmethods
'''
@@ -312,7 +313,7 @@ def NetConfigDeviceType(dev_type, lnst_config):
else:
return type_class_mapping[dev_type]
-def NetConfigDeviceAllCleanup(lnst_config):
+def NetConfigDeviceAllCleanup():
if check_process_running("NetworkManager") and \
lnst_config.get_option("environment", "use_nm"):
for dev_type in nm_type_class_mapping:
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index 4be56ce..dee2d83 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -36,6 +36,7 @@ from lnst.Common.Utils import check_process_running
from lnst.Common.ConnectionHandler import recv_data, send_data
from lnst.Common.ConnectionHandler import ConnectionHandler
from lnst.Common.NetTestCommand import NetTestCommandSystemConfig
+from lnst.Common.Config import lnst_config
DefaultRPCPort = 9999
@@ -43,12 +44,10 @@ class SlaveMethods:
'''
Exported xmlrpc methods
'''
- def __init__(self, command_context, config, log_ctl):
- self._netconfig = None
+ def __init__(self, command_context, log_ctl):
self._packet_captures = {}
- self._netconfig = NetConfig(config)
+ self._netconfig = NetConfig()
self._command_context = command_context
- self._config = config
self._log_ctl = log_ctl
self._capture_files = {}
@@ -56,8 +55,8 @@ class SlaveMethods:
self._copy_sources = {}
self._system_config = {}
- self._cache = ResourceCache(config.get_option("cache", "dir"),
- config.get_option("cache", "expiration_period"))
+ self._cache = ResourceCache(lnst_config.get_option("cache", "dir"),
+ lnst_config.get_option("cache", "expiration_period"))
self._resource_table = {}
@@ -73,7 +72,7 @@ class SlaveMethods:
if check_process_running("NetworkManager"):
logging.warning("=============================================")
logging.warning("NetworkManager is running on a slave machine!")
- if self._config.get_option("environment", "use_nm"):
+ if lnst_config.get_option("environment", "use_nm"):
logging.warning("Support of NM is still experimental!")
else:
logging.warning("Usage of NM is disabled!")
@@ -118,7 +117,7 @@ class SlaveMethods:
for dev in devs:
if check_process_running("NetworkManager") and\
- self._config.get_option("environment", "use_nm"):
+ lnst_config.get_option("environment", "use_nm"):
bus = dbus.SystemBus()
nm_obj = bus.get_object("org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager")
@@ -260,7 +259,7 @@ class SlaveMethods:
return True
def machine_cleanup(self):
- NetConfigDeviceAllCleanup(self._config)
+ NetConfigDeviceAllCleanup()
self._netconfig.cleanup()
self._command_context.cleanup()
self._cache.del_old_entries()
@@ -407,11 +406,11 @@ class ServerHandler(object):
self.add_connection(key, connection)
class NetTestSlave:
- def __init__(self, config, log_ctl, port = DefaultRPCPort):
+ def __init__(self, log_ctl, port = DefaultRPCPort):
die_when_parent_die()
self._cmd_context = NetTestCommandContext()
- self._methods = SlaveMethods(self._cmd_context, config, log_ctl)
+ self._methods = SlaveMethods(self._cmd_context, log_ctl)
self.register_die_signal(signal.SIGHUP)
self.register_die_signal(signal.SIGINT)
10 years, 9 months
[PATCH] NmConfigDevice: fix no bond options bug
by Ondrej Lichtner
From: Ondrej Lichtner <olichtne(a)redhat.com>
When there are no bond options specified in the recipe file, lnst
created an empty dbus.Dictionary which is not accepted by NM.
This commit fixes that.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Slave/NmConfigDevice.py | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/lnst/Slave/NmConfigDevice.py b/lnst/Slave/NmConfigDevice.py
index 88c2817..e7d6418 100644
--- a/lnst/Slave/NmConfigDevice.py
+++ b/lnst/Slave/NmConfigDevice.py
@@ -290,7 +290,10 @@ class NmConfigDeviceBond(NmConfigDeviceGeneric):
'''
value = self._config[int(value)]["name"]
options[option] = value
- return dbus.Dictionary(options, signature="ss")
+ if options:
+ return dbus.Dictionary(options, signature="ss")
+ else:
+ return None
def _add_bond(self):
netdev = self._netdev
@@ -304,9 +307,13 @@ class NmConfigDeviceBond(NmConfigDeviceGeneric):
options = self._setup_options()
- s_bond = dbus.Dictionary({
- 'interface-name': netdev["name"],
- 'options': options})
+ if options:
+ s_bond = dbus.Dictionary({
+ 'interface-name': netdev["name"],
+ 'options': options})
+ else:
+ s_bond = dbus.Dictionary({
+ 'interface-name': netdev["name"]})
s_ipv4, s_ipv6 = self._nm_make_ip_settings(netdev["addresses"])
--
1.8.3.1
10 years, 9 months
[PATCH] Config: make lnst configuration globally accesible
by Ondrej Lichtner
From: Ondrej Lichtner <olichtne(a)redhat.com>
LNST configuration was created as a single Config object that was passed
around as an argument to the modules that needed it. This was ok at
first because it was only needed in a few modules, but it became
tiresome to send this object everywhere as an argument.
This commit creates a single globally accesible object lnst_config that
is creted when the module lnst.Common.Config is first imported in
lnst-ctl or lnst-slave, where the contents of the object will be
initialized and loaded.
After that all the modules just import this object and can use it.
This commit also changes all the modules that were using the lnst
configuration so that they use this global object instead.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst-ctl | 33 ++++++++++++++++-----------------
lnst-slave | 18 +++++++++---------
lnst/Common/Colours.py | 5 +++--
lnst/Common/Config.py | 22 +++++++++-------------
lnst/Controller/NetTestController.py | 16 ++++++++--------
lnst/Controller/SlavePool.py | 7 +++----
lnst/Slave/NetConfig.py | 16 +++++++---------
lnst/Slave/NetConfigDevice.py | 7 ++++---
lnst/Slave/NetTestSlave.py | 21 ++++++++++-----------
9 files changed, 69 insertions(+), 76 deletions(-)
diff --git a/lnst-ctl b/lnst-ctl
index 3e9b62b..97039ed 100755
--- a/lnst-ctl
+++ b/lnst-ctl
@@ -18,7 +18,7 @@ import os
import re
import datetime
from lnst.Common.Logs import LoggingCtl, log_exc_traceback
-from lnst.Common.Config import Config
+from lnst.Common.Config import lnst_config
from lnst.Common.Colours import load_presets_from_config
from lnst.Controller.NetTestController import NetTestController, NetTestError
from lnst.Controller.NetTestResultSerializer import NetTestResultSerializer
@@ -46,10 +46,10 @@ def usage():
sys.exit()
def process_recipe(action, file_path, cleanup, res_serializer,
- packet_capture, config, log_ctl, pool_checks):
+ packet_capture, log_ctl, pool_checks):
nettestctl = NetTestController(file_path, log_ctl, cleanup=cleanup,
res_serializer=res_serializer,
- config=config, pool_checks=pool_checks)
+ pool_checks=pool_checks)
if action == "run":
return nettestctl.run_recipe(packet_capture)
elif action == "dump":
@@ -63,14 +63,14 @@ def process_recipe(action, file_path, cleanup, res_serializer,
usage();
def get_recipe_result(args, file_path, cleanup, res_serializer, packet_capture,
- config, log_ctl, pool_checks):
+ log_ctl, pool_checks):
res_serializer.add_recipe(file_path)
log_ctl.set_recipe(file_path)
res = None
try:
res = process_recipe(args, file_path, cleanup, res_serializer,
- packet_capture, config, log_ctl, pool_checks)
+ packet_capture, log_ctl, pool_checks)
except Exception as err:
log_exc_traceback()
logging.error(err)
@@ -95,22 +95,22 @@ def main():
usage()
sys.exit()
- config = Config("controller")
+ lnst_config.controller_init()
dirname = os.path.dirname(sys.argv[0])
gitcfg = os.path.join(dirname, "lnst-ctl.conf")
if os.path.isfile(gitcfg):
- config.load_config(gitcfg)
+ lnst_config.load_config(gitcfg)
else:
- config.load_config('/etc/lnst-ctl.conf')
+ lnst_config.load_config('/etc/lnst-ctl.conf')
usr_cfg = os.path.expanduser('~/.lnst/lnst-ctl.conf')
if os.path.isfile(usr_cfg):
- config.load_config(usr_cfg)
+ lnst_config.load_config(usr_cfg)
else:
if not os.path.isdir(os.path.dirname(usr_cfg)):
os.makedirs(os.path.dirname(usr_cfg))
with open(usr_cfg, 'w') as f:
- f.write(config.dump_config())
+ f.write(lnst_config.dump_config())
debug = 0
recipe_path = None
@@ -118,7 +118,7 @@ def main():
result_path = None
packet_capture = False
pool_checks = True
- coloured_output = not config.get_option("colours", "disable_colours")
+ coloured_output = not lnst_config.get_option("colours", "disable_colours")
for opt, arg in opts:
if opt in ("-d", "--debug"):
debug += 1
@@ -135,12 +135,12 @@ def main():
elif opt in ("-m", "--no-colours"):
coloured_output = False
- load_presets_from_config(config)
+ load_presets_from_config()
date = datetime.datetime.now().strftime("%Y-%m-%d_%H:%M:%S")
log_ctl = LoggingCtl(debug,
- log_dir=config.get_option('environment', 'log_dir'),
- log_subdir=date, colours=coloured_output)
+ log_dir=lnst_config.get_option('environment', 'log_dir'),
+ log_subdir=date, colours=coloured_output)
action = args.pop()
@@ -167,13 +167,12 @@ def main():
cleanup,
res_serializer,
packet_capture,
- config, log_ctl,
- pool_checks))
+ log_ctl, pool_checks))
else:
summary.append(get_recipe_result(action, recipe_path,
cleanup, res_serializer,
packet_capture,
- config, log_ctl, pool_checks))
+ log_ctl, pool_checks))
log_ctl.set_recipe("", clean=False)
diff --git a/lnst-slave b/lnst-slave
index 996cd32..1e7dee8 100755
--- a/lnst-slave
+++ b/lnst-slave
@@ -17,7 +17,7 @@ import os
import logging
from lnst.Common.Daemon import Daemon
from lnst.Common.Logs import LoggingCtl
-from lnst.Common.Config import Config
+from lnst.Common.Config import lnst_config
from lnst.Slave.NetTestSlave import NetTestSlave
def usage():
@@ -49,19 +49,19 @@ def main():
usage()
sys.exit()
- config = Config("slave")
+ lnst_config.slave_init()
dirname = os.path.dirname(sys.argv[0])
gitcfg = os.path.join(dirname, "lnst-slave.conf")
if os.path.isfile(gitcfg):
- config.load_config(gitcfg)
+ lnst_config.load_config(gitcfg)
else:
- config.load_config('/etc/lnst-slave.conf')
+ lnst_config.load_config('/etc/lnst-slave.conf')
debug = False
daemon = False
pidfile = "lnst-slave.pid"
port = None
- coloured_output = not config.get_option("colours", "disable_colours")
+ coloured_output = not lnst_config.get_option("colours", "disable_colours")
for opt, arg in opts:
if opt in ("-d", "--debug"):
debug = True
@@ -77,14 +77,14 @@ def main():
coloured_output = False
log_ctl = LoggingCtl(debug,
- log_dir=config.get_option('environment', 'log_dir'),
- colours=coloured_output)
+ log_dir=lnst_config.get_option('environment', 'log_dir'),
+ colours=coloured_output)
logging.info("Started")
if port:
- nettestslave = NetTestSlave(config, log_ctl, port=port)
+ nettestslave = NetTestSlave(log_ctl, port=port)
else:
- nettestslave = NetTestSlave(config, log_ctl)
+ nettestslave = NetTestSlave(log_ctl)
if daemon:
daemon = Daemon(pidfile)
diff --git a/lnst/Common/Colours.py b/lnst/Common/Colours.py
index 5a5d385..c88bf5d 100644
--- a/lnst/Common/Colours.py
+++ b/lnst/Common/Colours.py
@@ -14,6 +14,7 @@ import logging
import os
import re
from lnst.Common.Utils import bool_it
+from lnst.Common.Config import lnst_config
COLOURS = {
"black": 30,
@@ -165,9 +166,9 @@ def decorate_with_preset(string, preset):
def strip_colours(text):
return re.sub("\033\[[0-9]+(;[0-9]+){0,2}m", "", text)
-def load_presets_from_config(config):
+def load_presets_from_config():
for preset_name in PRESETS:
- preset = config.get_option("colours", preset_name)
+ preset = lnst_config.get_option("colours", preset_name)
if preset == None:
continue
fg, bg, bf = preset
diff --git a/lnst/Common/Config.py b/lnst/Common/Config.py
index c79c436..2a74c25 100644
--- a/lnst/Common/Config.py
+++ b/lnst/Common/Config.py
@@ -27,20 +27,10 @@ class Config():
options = None
_scheme = None
- def __init__(self, scheme):
+ def __init__(self):
self.options = dict()
- self._scheme = scheme
- if self._scheme == "controller":
- self.controller_scheme()
- elif self._scheme == "slave":
- self.slave_scheme()
- else:
- msg = "Unknow scheme: '%s', can't set up configuration"\
- % self._scheme
- raise ConfigError(msg)
-
- def controller_scheme(self):
+ def controller_init(self):
self.options['environment'] = dict()
self.options['environment']['mac_pool_range'] = {\
"value" : ['52:54:01:00:00:01', '52:54:01:FF:FF:FF'],
@@ -76,7 +66,7 @@ class Config():
self.colours_scheme()
- def slave_scheme(self):
+ def slave_init(self):
self.options['environment'] = dict()
self.options['environment']['log_dir'] = {\
"value" : os.path.abspath(os.path.join(
@@ -283,3 +273,9 @@ class Config():
string = str(value)
return string
+
+#Global object containing lnst configuration, available across modules
+#The object is created here but the contents are initialized
+#in lnst-ctl and lnst-slave, after that the modules that need the configuration
+#just import this object
+lnst_config = Config()
diff --git a/lnst/Controller/NetTestController.py b/lnst/Controller/NetTestController.py
index 88d3156..47c615a 100644
--- a/lnst/Controller/NetTestController.py
+++ b/lnst/Controller/NetTestController.py
@@ -32,6 +32,7 @@ from lnst.Controller.SlavePool import SlavePool
from lnst.Controller.Machine import Machine, MachineError
from lnst.Common.ConnectionHandler import send_data, recv_data
from lnst.Common.ConnectionHandler import ConnectionHandler
+from lnst.Common.Config import lnst_config
class NetTestError(Exception):
pass
@@ -41,17 +42,16 @@ def ignore_event(**kwarg):
class NetTestController:
def __init__(self, recipe_path, log_ctl, cleanup=False,
- res_serializer=None, config=None, pool_checks=True):
+ res_serializer=None, pool_checks=True):
self._docleanup = cleanup
self._res_serializer = res_serializer
self._remote_capture_files = {}
- self._config = config
self._log_ctl = log_ctl
self._recipe_path = recipe_path
self._msg_dispatcher = MessageDispatcher(log_ctl)
- sp = SlavePool(config.get_option('environment', 'pool_dirs'),
- check_process_running("libvirtd"), config, pool_checks)
+ sp = SlavePool(lnst_config.get_option('environment', 'pool_dirs'),
+ check_process_running("libvirtd"), pool_checks)
self._slave_pool = sp
self._machines = {}
@@ -62,7 +62,7 @@ class NetTestController:
recipe["machines"] = {}
recipe["switches"] = {}
- mac_pool_range = config.get_option('environment', 'mac_pool_range')
+ mac_pool_range = lnst_config.get_option('environment', 'mac_pool_range')
self._mac_pool = MacPool(mac_pool_range[0], mac_pool_range[1])
parser = RecipeParse(recipe_path)
@@ -74,8 +74,8 @@ class NetTestController:
parser.register_event_handler("interface_config_ready",
self._prepare_interface)
- modules_dirs = config.get_option('environment', 'module_dirs')
- tools_dirs = config.get_option('environment', 'tool_dirs')
+ modules_dirs = lnst_config.get_option('environment', 'module_dirs')
+ tools_dirs = lnst_config.get_option('environment', 'tool_dirs')
self._resource_table = {}
self._resource_table["module"] = self._load_test_modules(modules_dirs)
@@ -131,7 +131,7 @@ class NetTestController:
address = socket.gethostbyname(machine.get_hostname())
self._log_ctl.add_slave(m_id, address)
- port = self._config.get_option('environment', 'rpcport')
+ port = lnst_config.get_option('environment', 'rpcport')
machine.set_rpc(self._msg_dispatcher, port)
machine.set_mac_pool(self._mac_pool)
machine.set_network_bridges(self._network_bridges)
diff --git a/lnst/Controller/SlavePool.py b/lnst/Controller/SlavePool.py
index b875d59..05c6041 100644
--- a/lnst/Controller/SlavePool.py
+++ b/lnst/Controller/SlavePool.py
@@ -22,6 +22,7 @@ from lnst.Common.XmlProcessing import XmlDomTreeInit
from lnst.Common.NetUtils import test_tcp_connection
from lnst.Controller.SlaveMachineParse import SlaveMachineParse
from lnst.Controller.Machine import Machine
+from lnst.Common.Config import lnst_config
class SlavePool:
"""
@@ -38,9 +39,7 @@ class SlavePool:
_allow_virt = False
_pool_checks = True
- def __init__(self, pool_dirs, allow_virtual=False, config=None,
- pool_checks=True):
- self._config = config
+ def __init__(self, pool_dirs, allow_virtual=False, pool_checks=True):
self._allow_virt = allow_virtual
self._pool_checks = pool_checks
for pool_dir in pool_dirs:
@@ -76,7 +75,7 @@ class SlavePool:
if "rpcport" in machine:
port = machine["params"]["rpcport"]
else:
- port = self._config.get_option('environment', 'rpcport')
+ port = lnst_config.get_option('environment', 'rpcport')
logging.info("Querying slave machine %s." % m_id)
if not test_tcp_connection(hostname, port):
diff --git a/lnst/Slave/NetConfig.py b/lnst/Slave/NetConfig.py
index 28f6240..4b0e5a3 100644
--- a/lnst/Slave/NetConfig.py
+++ b/lnst/Slave/NetConfig.py
@@ -18,14 +18,12 @@ from lnst.Slave.NetConfigDevice import NetConfigDeviceType
from lnst.Slave.NetConfigCommon import get_slaves
class NetConfig:
- def __init__(self, lnst_config):
+ def __init__(self):
devnames = NetConfigDevNames()
config = {}
self._devnames = devnames
self._config = config
- self._lnst_config = lnst_config
-
def _get_leafs(self):
leafs = []
for dev_id in self._config:
@@ -64,7 +62,7 @@ class NetConfig:
dev_type = config["type"]
if not dev_type in self._get_used_types():
logging.info("Initializing '%s' device class", dev_type)
- NetConfigDeviceType(dev_type, self._lnst_config).type_init()
+ NetConfigDeviceType(dev_type).type_init()
self._config[if_id] = config
@@ -78,14 +76,14 @@ class NetConfig:
dev_type = config["type"]
if not dev_type in self._get_used_types():
logging.info("Cleaning up '%s' device class.", dev_type)
- NetConfigDeviceType(dev_type, self._lnst_config).type_cleanup()
+ NetConfigDeviceType(dev_type).type_cleanup()
def get_interface_config(self, if_id):
return self._config[if_id]
def configure(self, dev_id):
netdev = self._config[dev_id]
- device = NetConfigDevice(netdev, self._config, self._lnst_config)
+ device = NetConfigDevice(netdev, self._config)
device.configure()
device.up()
@@ -96,7 +94,7 @@ class NetConfig:
def deconfigure(self, dev_id):
netdev = self._config[dev_id]
- device = NetConfigDevice(netdev, self._config, self._lnst_config)
+ device = NetConfigDevice(netdev, self._config)
device.down()
device.deconfigure()
@@ -144,7 +142,7 @@ class NetConfig:
elif slave_dev_id in netdev["slaves"]:
return False
netdev["slaves"].append(slave_dev_id)
- device = NetConfigDevice(netdev, self._config, self._lnst_config)
+ device = NetConfigDevice(netdev, self._config)
device.slave_add(slave_dev_id)
return True
@@ -153,7 +151,7 @@ class NetConfig:
if not "slaves" in netdev or not slave_dev_id in netdev["slaves"]:
return False
netdev["slaves"].remove(slave_dev_id)
- device = NetConfigDevice(netdev, self._config, self._lnst_config)
+ device = NetConfigDevice(netdev, self._config)
device.slave_del(slave_dev_id)
return True
diff --git a/lnst/Slave/NetConfigDevice.py b/lnst/Slave/NetConfigDevice.py
index 6fcd4b5..c66fa50 100644
--- a/lnst/Slave/NetConfigDevice.py
+++ b/lnst/Slave/NetConfigDevice.py
@@ -19,6 +19,7 @@ from lnst.Slave.NetConfigCommon import get_slaves, get_option, get_slave_option
from lnst.Common.Utils import kmod_in_use, bool_it
from lnst.Slave.NmConfigDevice import type_class_mapping as nm_type_class_mapping
from lnst.Common.Utils import check_process_running
+from lnst.Common.Config import lnst_config
class NetConfigDeviceGeneric:
@@ -292,7 +293,7 @@ type_class_mapping = {
"team": NetConfigDeviceTeam
}
-def NetConfigDevice(netdev, config, lnst_config):
+def NetConfigDevice(netdev, config):
'''
Class dispatcher
'''
@@ -302,7 +303,7 @@ def NetConfigDevice(netdev, config, lnst_config):
else:
return type_class_mapping[netdev["type"]](netdev, config)
-def NetConfigDeviceType(dev_type, lnst_config):
+def NetConfigDeviceType(dev_type):
'''
Class dispatcher for classmethods
'''
@@ -312,7 +313,7 @@ def NetConfigDeviceType(dev_type, lnst_config):
else:
return type_class_mapping[dev_type]
-def NetConfigDeviceAllCleanup(lnst_config):
+def NetConfigDeviceAllCleanup():
if check_process_running("NetworkManager") and \
lnst_config.get_option("environment", "use_nm"):
for dev_type in nm_type_class_mapping:
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index 4be56ce..dee2d83 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -36,6 +36,7 @@ from lnst.Common.Utils import check_process_running
from lnst.Common.ConnectionHandler import recv_data, send_data
from lnst.Common.ConnectionHandler import ConnectionHandler
from lnst.Common.NetTestCommand import NetTestCommandSystemConfig
+from lnst.Common.Config import lnst_config
DefaultRPCPort = 9999
@@ -43,12 +44,10 @@ class SlaveMethods:
'''
Exported xmlrpc methods
'''
- def __init__(self, command_context, config, log_ctl):
- self._netconfig = None
+ def __init__(self, command_context, log_ctl):
self._packet_captures = {}
- self._netconfig = NetConfig(config)
+ self._netconfig = NetConfig()
self._command_context = command_context
- self._config = config
self._log_ctl = log_ctl
self._capture_files = {}
@@ -56,8 +55,8 @@ class SlaveMethods:
self._copy_sources = {}
self._system_config = {}
- self._cache = ResourceCache(config.get_option("cache", "dir"),
- config.get_option("cache", "expiration_period"))
+ self._cache = ResourceCache(lnst_config.get_option("cache", "dir"),
+ lnst_config.get_option("cache", "expiration_period"))
self._resource_table = {}
@@ -73,7 +72,7 @@ class SlaveMethods:
if check_process_running("NetworkManager"):
logging.warning("=============================================")
logging.warning("NetworkManager is running on a slave machine!")
- if self._config.get_option("environment", "use_nm"):
+ if lnst_config.get_option("environment", "use_nm"):
logging.warning("Support of NM is still experimental!")
else:
logging.warning("Usage of NM is disabled!")
@@ -118,7 +117,7 @@ class SlaveMethods:
for dev in devs:
if check_process_running("NetworkManager") and\
- self._config.get_option("environment", "use_nm"):
+ lnst_config.get_option("environment", "use_nm"):
bus = dbus.SystemBus()
nm_obj = bus.get_object("org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager")
@@ -260,7 +259,7 @@ class SlaveMethods:
return True
def machine_cleanup(self):
- NetConfigDeviceAllCleanup(self._config)
+ NetConfigDeviceAllCleanup()
self._netconfig.cleanup()
self._command_context.cleanup()
self._cache.del_old_entries()
@@ -407,11 +406,11 @@ class ServerHandler(object):
self.add_connection(key, connection)
class NetTestSlave:
- def __init__(self, config, log_ctl, port = DefaultRPCPort):
+ def __init__(self, log_ctl, port = DefaultRPCPort):
die_when_parent_die()
self._cmd_context = NetTestCommandContext()
- self._methods = SlaveMethods(self._cmd_context, config, log_ctl)
+ self._methods = SlaveMethods(self._cmd_context, log_ctl)
self.register_die_signal(signal.SIGHUP)
self.register_die_signal(signal.SIGINT)
--
1.8.3.1
10 years, 9 months
Temporary fix for use_nm = false setups
by Jan Tluka
Hi, seems that LNST is broken if use_nm = false is set on slaves.
LNST will crash with following traceback:
Traceback (most recent call last):
File "/root/lnst/lnst/Slave/NetTestSlave.py", line 433, in _process_msg
result = method(*msg["args"])
File "/root/lnst/lnst/Slave/NetTestSlave.py", line 243, in machine_cleanup
NetConfigDeviceAllCleanup(self._config)
File "/root/lnst/lnst/Slave/NetConfigDevice.py", line 322, in NetConfigDeviceAllCleanup
NetConfigDeviceType(dev_type).type_cleanup()
TypeError: NetConfigDeviceType() takes exactly 2 arguments (1 given)
Ondrej is working on a complex patch that's going to fix this bug.
I'm attaching simple patch that should help you to use LNST until
Ondrej's patch is ready.
-Jan
10 years, 9 months
[PATCH] Provide more information for soft devices unsupported by NetworkManager
by Jan Tluka
---
lnst/Slave/NmConfigDevice.py | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lnst/Slave/NmConfigDevice.py b/lnst/Slave/NmConfigDevice.py
index 88c2817..320842f 100644
--- a/lnst/Slave/NmConfigDevice.py
+++ b/lnst/Slave/NmConfigDevice.py
@@ -473,6 +473,8 @@ class NmConfigDeviceBridge(NmConfigDeviceGeneric):
class NmConfigDeviceMacvlan(NmConfigDeviceGeneric):
#Not supported by NetworkManager yet
+ logging.info("Macvlan device is not supported by NetworkManager yet.")
+ logging.info("For macvlan device try to disable NetworkManager using 'use_nm=false' in lnst-slave.conf")
pass
class NmConfigDeviceVlan(NmConfigDeviceGeneric):
@@ -534,6 +536,8 @@ class NmConfigDeviceVlan(NmConfigDeviceGeneric):
class NmConfigDeviceTeam(NmConfigDeviceGeneric):
#Not supported by NetworkManager yet
+ logging.info("Team device is not supported by NetworkManager yet.")
+ logging.info("For team device try to disable NetworkManager using 'use_nm=false' in lnst-slave.conf")
pass
type_class_mapping = {
--
1.8.1.4
10 years, 9 months
[PATCH] NetTestSlave: method set_device_down detects NM
by Ondrej Lichtner
From: Ondrej Lichtner <olichtne(a)redhat.com>
This method is automatically called by the controller when initializing
interfaces before they are configured.
When the interface is managed by NM calling ip link set <if> down will
make NM see it as unavailable to repair this we had to set the if back
to up before using NM. Instead when NM is present we will disconnect the
device through the dbus interface.
I didn't remove the code that "resets" the interface if it's unavailable
before using NM, just in case there will be similar problems in the
future.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Slave/NetTestSlave.py | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index 77ad679..4be56ce 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -17,6 +17,7 @@ import os
import sys, traceback
import datetime
import socket
+import dbus
from time import sleep
from xmlrpclib import Binary
from tempfile import NamedTemporaryFile
@@ -116,7 +117,26 @@ class SlaveMethods:
devs = self.get_devices_by_hwaddr(hwaddr)
for dev in devs:
- exec_cmd("ip link set %s down" % dev["name"])
+ if check_process_running("NetworkManager") and\
+ self._config.get_option("environment", "use_nm"):
+ bus = dbus.SystemBus()
+ nm_obj = bus.get_object("org.freedesktop.NetworkManager",
+ "/org/freedesktop/NetworkManager")
+ nm_if = dbus.Interface(nm_obj, "org.freedesktop.NetworkManager")
+ dev_obj_path = nm_if.GetDeviceByIpIface(dev["name"])
+ dev_obj = bus.get_object("org.freedesktop.NetworkManager",
+ dev_obj_path)
+ dev_props = dbus.Interface(dev_obj,
+ "org.freedesktop.DBus.Properties")
+ if dev_props.Get("org.freedesktop.NetworkManager.Device",
+ "ActiveConnection") != "/":
+ dev_if = dbus.Interface(dev_obj,
+ "org.freedesktop.NetworkManager.Device")
+ logging.debug("Disconnecting device %s: %s" %
+ (dev["name"], dev_obj_path))
+ dev_if.Disconnect()
+ else:
+ exec_cmd("ip link set %s down" % dev["name"])
return True
--
1.8.3.1
10 years, 9 months
[lnst] NetTestSlave: method set_device_down detects NM
by Jiří Pírko
commit aa0bbb4af915f49247efed886a438d243a751c2e
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Fri Jul 19 14:16:44 2013 +0200
NetTestSlave: method set_device_down detects NM
This method is automatically called by the controller when initializing
interfaces before they are configured.
When the interface is managed by NM calling ip link set <if> down will
make NM see it as unavailable to repair this we had to set the if back
to up before using NM. Instead when NM is present we will disconnect the
device through the dbus interface.
I didn't remove the code that "resets" the interface if it's unavailable
before using NM, just in case there will be similar problems in the
future.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
lnst/Slave/NetTestSlave.py | 22 +++++++++++++++++++++-
1 files changed, 21 insertions(+), 1 deletions(-)
---
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index 77ad679..4be56ce 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -17,6 +17,7 @@ import os
import sys, traceback
import datetime
import socket
+import dbus
from time import sleep
from xmlrpclib import Binary
from tempfile import NamedTemporaryFile
@@ -116,7 +117,26 @@ class SlaveMethods:
devs = self.get_devices_by_hwaddr(hwaddr)
for dev in devs:
- exec_cmd("ip link set %s down" % dev["name"])
+ if check_process_running("NetworkManager") and\
+ self._config.get_option("environment", "use_nm"):
+ bus = dbus.SystemBus()
+ nm_obj = bus.get_object("org.freedesktop.NetworkManager",
+ "/org/freedesktop/NetworkManager")
+ nm_if = dbus.Interface(nm_obj, "org.freedesktop.NetworkManager")
+ dev_obj_path = nm_if.GetDeviceByIpIface(dev["name"])
+ dev_obj = bus.get_object("org.freedesktop.NetworkManager",
+ dev_obj_path)
+ dev_props = dbus.Interface(dev_obj,
+ "org.freedesktop.DBus.Properties")
+ if dev_props.Get("org.freedesktop.NetworkManager.Device",
+ "ActiveConnection") != "/":
+ dev_if = dbus.Interface(dev_obj,
+ "org.freedesktop.NetworkManager.Device")
+ logging.debug("Disconnecting device %s: %s" %
+ (dev["name"], dev_obj_path))
+ dev_if.Disconnect()
+ else:
+ exec_cmd("ip link set %s down" % dev["name"])
return True
10 years, 9 months