Use $PATH also for dynamips and cleanup some $PATH usages

Fix #655
This commit is contained in:
Julien Duponchelle 2016-08-29 11:27:35 +02:00
parent 0eafb6f06c
commit da1cd9a3e7
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
6 changed files with 24 additions and 15 deletions

View File

@ -403,11 +403,10 @@ class BaseVM:
""" """
path = self._manager.config.get_section_config("Server").get("ubridge_path", "ubridge") path = self._manager.config.get_section_config("Server").get("ubridge_path", "ubridge")
if path == "ubridge": path = shutil.which(path)
path = shutil.which("ubridge")
if path is None or len(path) == 0: if path is None or len(path) == 0:
raise VMError("uBridge is not installed") raise VMError("uBridge is not installed or uBridge path is invalid")
return path return path
@asyncio.coroutine @asyncio.coroutine

View File

@ -336,16 +336,16 @@ class Dynamips(BaseManager):
def find_dynamips(self): def find_dynamips(self):
# look for Dynamips # look for Dynamips
dynamips_path = self.config.get_section_config("Dynamips").get("dynamips_path") dynamips_path = self.config.get_section_config("Dynamips").get("dynamips_path", "dynamips")
if not dynamips_path: if not os.path.isabs(dynamips_path):
dynamips_path = shutil.which("dynamips") dynamips_path = shutil.which(dynamips_path)
if not dynamips_path: if not dynamips_path:
raise DynamipsError("Could not find Dynamips") raise DynamipsError("Could not find Dynamips")
if not os.path.isfile(dynamips_path): if not os.path.isfile(dynamips_path):
raise DynamipsError("Dynamips {} is not accessible".format(dynamips_path)) raise DynamipsError("Dynamips {} is not accessible".format(dynamips_path))
if not os.access(dynamips_path, os.X_OK): if not os.access(dynamips_path, os.X_OK):
raise DynamipsError("Dynamips is not executable") raise DynamipsError("Dynamips {} is not executable".format(dynamips_path))
self._dynamips_path = dynamips_path self._dynamips_path = dynamips_path
return dynamips_path return dynamips_path

View File

@ -230,9 +230,11 @@ class IOUVM(BaseVM):
:returns: path to IOUYAP :returns: path to IOUYAP
""" """
path = self._manager.config.get_section_config("IOU").get("iouyap_path", "iouyap") search_path = self._manager.config.get_section_config("IOU").get("iouyap_path", "iouyap")
if path == "iouyap": path = shutil.which(search_path)
path = shutil.which("iouyap") # shutil.which return None if the path doesn't exists
if not path:
return search_path
return path return path
@property @property

View File

@ -66,7 +66,10 @@ class VirtualBox(BaseManager):
elif sys.platform.startswith("darwin"): elif sys.platform.startswith("darwin"):
vboxmanage_path = "/Applications/VirtualBox.app/Contents/MacOS/VBoxManage" vboxmanage_path = "/Applications/VirtualBox.app/Contents/MacOS/VBoxManage"
else: else:
vboxmanage_path = shutil.which("vboxmanage") vboxmanage_path = "vboxmanage"
if not os.path.abspath(vboxmanage_path):
vboxmanage_path = shutil.which(vboxmanage_path)
if not vboxmanage_path: if not vboxmanage_path:
raise VirtualBoxError("Could not find VBoxManage") raise VirtualBoxError("Could not find VBoxManage")

View File

@ -105,7 +105,10 @@ class VMware(BaseManager):
elif sys.platform.startswith("darwin"): elif sys.platform.startswith("darwin"):
vmrun_path = "/Applications/VMware Fusion.app/Contents/Library/vmrun" vmrun_path = "/Applications/VMware Fusion.app/Contents/Library/vmrun"
else: else:
vmrun_path = shutil.which("vmrun") vmrun_path = "vmrun"
if not os.path.abspath(vmrun_path):
vmrun_path = shutil.which(vmrun_path)
if not vmrun_path: if not vmrun_path:
raise VMwareError("Could not find VMware vmrun, please make sure it is installed") raise VMwareError("Could not find VMware vmrun, please make sure it is installed")

View File

@ -139,9 +139,11 @@ class VPCSVM(BaseVM):
:returns: path to VPCS :returns: path to VPCS
""" """
path = self._manager.config.get_section_config("VPCS").get("vpcs_path", "vpcs") search_path = self._manager.config.get_section_config("VPCS").get("vpcs_path", "vpcs")
if path == "vpcs": path = shutil.which(search_path)
path = shutil.which("vpcs") # shutil.which return None if the path doesn't exists
if not path:
return search_path
return path return path
@BaseVM.name.setter @BaseVM.name.setter