from xml.dom.minidom import getDOMImplementation
from xml.dom.minidom import parse as parseXML
+the_root_prefix = ""
+def root_prefix():
+ """Returns a string to prefix to all file name references, which
+ is useful for testing."""
+ return the_root_prefix
+def set_root_prefix(prefix):
+ global the_root_prefix
+ the_root_prefix = prefix
+
#
# Logging.
#
def run_command(command):
log("Running command: " + ' '.join(command))
- rc = os.spawnl(os.P_WAIT, command[0], *command)
+ rc = os.spawnl(os.P_WAIT, root_prefix() + command[0], *command)
if rc != 0:
log("Command failed %d: " % rc + ' '.join(command))
return False
class DatabaseCache(object):
def __read_xensource_inventory(self):
- filename = "/etc/xensource-inventory"
+ filename = root_prefix() + "/etc/xensource-inventory"
f = open(filename, "r")
lines = [x.strip("\n") for x in f.readlines()]
f.close()
else:
log("Loading xapi database cache from %s" % cache_file)
- xml = parseXML(cache_file)
+ xml = parseXML(root_prefix() + cache_file)
self.__pifs = {}
self.__bonds = {}
#
def netdev_exists(netdev):
- return os.path.exists("/sys/class/net/" + netdev)
+ return os.path.exists(root_prefix() + "/sys/class/net/" + netdev)
def pif_netdev_name(pif):
"""Get the netdev name for a PIF."""
# XXX Need a datapath object for bridgeless PIFs
try:
- network_conf = open("/etc/xensource/network.conf", 'r')
+ network_conf = open(root_prefix() + "/etc/xensource/network.conf", 'r')
network_backend = network_conf.readline().strip()
network_conf.close()
except Exception, e: