2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-21 14:49:41 +00:00

xenserver: Add --root-prefix feature to interface-reconfigure.

This makes it easier to do unit tests (some of which will be added in an
upcoming commit) by allowing fake configuration files and scripts to be
added in a directory other than the real root.

Signed-off-by: Ben Pfaff <blp@nicira.com>
This commit is contained in:
Ben Pfaff
2010-02-22 16:25:54 -08:00
parent 86e1bb44da
commit 64ddb6fecf
3 changed files with 34 additions and 21 deletions

View File

@@ -15,7 +15,7 @@ from InterfaceReconfigure import *
import sys
import time
sysfs_bonding_masters = "/sys/class/net/bonding_masters"
sysfs_bonding_masters = root_prefix() + "/sys/class/net/bonding_masters"
def open_pif_ifcfg(pif):
pifrec = db().get_pif_record(pif)
@@ -23,7 +23,7 @@ def open_pif_ifcfg(pif):
interface = pif_netdev_name(pif)
log("Configuring %s (%s)" % (interface, pifrec['MAC']))
f = ConfigurationFile("/etc/sysconfig/network-scripts/ifcfg-%s" % interface)
f = ConfigurationFile("%s/etc/sysconfig/network-scripts/ifcfg-%s" % (root_prefix(), interface))
f.write("# DO NOT EDIT: This file (%s) was autogenerated by %s\n" % \
(os.path.basename(f.path()), os.path.basename(sys.argv[0])))
@@ -69,7 +69,7 @@ def load_bonding_driver():
log("Failed to load bonding driver: %s" % e)
def bonding_driver_loaded():
lines = open("/proc/modules").read().split("\n")
lines = open(root_prefix() + "/proc/modules").read().split("\n")
modules = [line.split(" ")[0] for line in lines]
return "bonding" in modules
@@ -226,7 +226,7 @@ def bring_down_interface(pif, destroy=False):
def interface_is_up(pif):
try:
interface = pif_netdev_name(pif)
state = open("/sys/class/net/%s/operstate" % interface).read().strip()
state = open("%s/sys/class/net/%s/operstate" % (root_prefix(), interface)).read().strip()
return state == "up"
except:
return False # interface prolly doesn't exist
@@ -294,7 +294,7 @@ def pif_get_bond_slaves_sorted(pif):
# which they were attached. The first slave attached must be the last detached since
# the bond is using its MAC address.
try:
attached_slaves = open("/sys/class/net/%s/bonding/slaves" % pifrec['device']).readline().split()
attached_slaves = open("%s/sys/class/net/%s/bonding/slaves" % (root_prefix(), pifrec['device'])).readline().split()
for slave in attached_slaves:
pifs = [p for p in db().get_pifs_by_device(slave) if not pif_is_vlan(p)]
slave_pif = pifs[0]