mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-23 14:24:34 +02:00
refactor: remove platform-specific code for Darwin and Windows. Clean up Qemu options handling
This commit is contained in:
20 files changed
+77
-532
No files matched your search
@@ -307,10 +307,6 @@ class BaseManager:
|
|||||||
:returns: True or False
|
:returns: True or False
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if sys.platform.startswith("darwin"):
|
|
||||||
if os.stat(executable).st_uid == 0:
|
|
||||||
return True
|
|
||||||
|
|
||||||
if os.geteuid() == 0:
|
if os.geteuid() == 0:
|
||||||
# we are root, so we should have privileged access.
|
# we are root, so we should have privileged access.
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -340,12 +340,7 @@ class Cloud(BaseNode):
|
|||||||
f"Interface '{port_info['interface']}' could not be found on this system, please update '{self.name}'"
|
f"Interface '{port_info['interface']}' could not be found on this system, please update '{self.name}'"
|
||||||
)
|
)
|
||||||
|
|
||||||
if sys.platform.startswith("linux") or sys.platform.startswith("openbsd"):
|
await self._add_linux_ethernet(port_info, bridge_name)
|
||||||
await self._add_linux_ethernet(port_info, bridge_name)
|
|
||||||
elif sys.platform.startswith("darwin"):
|
|
||||||
await self._add_osx_ethernet(port_info, bridge_name)
|
|
||||||
else:
|
|
||||||
await self._add_windows_ethernet(port_info, bridge_name)
|
|
||||||
|
|
||||||
elif port_info["type"] == "tap":
|
elif port_info["type"] == "tap":
|
||||||
await self._add_tap_interface(port_info, bridge_name)
|
await self._add_tap_interface(port_info, bridge_name)
|
||||||
@@ -410,28 +405,6 @@ class Cloud(BaseNode):
|
|||||||
else:
|
else:
|
||||||
await self._ubridge_send(f'bridge add_nio_linux_raw {bridge_name} "{interface}"')
|
await self._ubridge_send(f'bridge add_nio_linux_raw {bridge_name} "{interface}"')
|
||||||
|
|
||||||
async def _add_osx_ethernet(self, port_info, bridge_name):
|
|
||||||
"""
|
|
||||||
Connects an Ethernet interface on OSX using libpcap.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Wireless adapters are not well supported by the libpcap on OSX
|
|
||||||
if await self._is_wifi_adapter_osx(port_info["interface"]):
|
|
||||||
raise NodeError("Connecting to a Wireless adapter is not supported on Mac OS")
|
|
||||||
if port_info["interface"].startswith("vmnet"):
|
|
||||||
# Use a special NIO to connect to VMware vmnet interfaces on OSX (libpcap doesn't support them)
|
|
||||||
await self._ubridge_send(
|
|
||||||
'bridge add_nio_fusion_vmnet {name} "{interface}"'.format(
|
|
||||||
name=bridge_name, interface=port_info["interface"]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return
|
|
||||||
if not gns3server.utils.interfaces.has_netmask(port_info["interface"]):
|
|
||||||
raise NodeError(f"Interface {port_info['interface']} has no netmask, interface down?")
|
|
||||||
await self._ubridge_send(
|
|
||||||
'bridge add_nio_ethernet {name} "{interface}"'.format(name=bridge_name, interface=port_info["interface"])
|
|
||||||
)
|
|
||||||
|
|
||||||
async def _add_windows_ethernet(self, port_info, bridge_name):
|
async def _add_windows_ethernet(self, port_info, bridge_name):
|
||||||
"""
|
"""
|
||||||
Connects an Ethernet interface on Windows.
|
Connects an Ethernet interface on Windows.
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import re
|
|||||||
import shlex
|
import shlex
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
|
||||||
|
|
||||||
from ...utils.asyncio import subprocess_check_output
|
from ...utils.asyncio import subprocess_check_output
|
||||||
from ...utils.get_resource import get_resource
|
from ...utils.get_resource import get_resource
|
||||||
@@ -113,16 +112,6 @@ class Qemu(BaseManager):
|
|||||||
paths.update(os.environ["PATH"].split(os.pathsep))
|
paths.update(os.environ["PATH"].split(os.pathsep))
|
||||||
else:
|
else:
|
||||||
log.warning("The PATH environment variable doesn't exist")
|
log.warning("The PATH environment variable doesn't exist")
|
||||||
# look for Qemu binaries in the current working directory and $PATH
|
|
||||||
if sys.platform.startswith("darwin") and hasattr(sys, "frozen"):
|
|
||||||
# add specific locations on Mac OS X regardless of what's in $PATH
|
|
||||||
paths.update(["/usr/bin", "/usr/local/bin", "/opt/local/bin"])
|
|
||||||
try:
|
|
||||||
exec_dir = os.path.dirname(os.path.abspath(sys.executable))
|
|
||||||
paths.add(os.path.abspath(os.path.join(exec_dir, "qemu/bin")))
|
|
||||||
# If the user run the server by hand from outside
|
|
||||||
except FileNotFoundError:
|
|
||||||
paths.add("/Applications/GNS3.app/Contents/MacOS/qemu/bin")
|
|
||||||
return paths
|
return paths
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import shutil
|
|||||||
import socket
|
import socket
|
||||||
import struct
|
import struct
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
|
||||||
import time
|
import time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@@ -1014,25 +1013,13 @@ class QemuVM(KernelDatapathMixin, BaseNode):
|
|||||||
|
|
||||||
log.debug(f'QEMU VM "{self._name}" [{self._id}] has set the QEMU options to {options}')
|
log.debug(f'QEMU VM "{self._name}" [{self._id}] has set the QEMU options to {options}')
|
||||||
|
|
||||||
# "-no-kvm" and "-no-hax' are deprecated since Qemu v5.2
|
# "-no-kvm" is deprecated since Qemu v5.2
|
||||||
|
# https://www.qemu.org/docs/master/about/removed-features.html#no-kvm-removed-in-5-2
|
||||||
if "-no-kvm" in options:
|
if "-no-kvm" in options:
|
||||||
options = options.replace("-no-kvm", "-machine accel=tcg")
|
options = options.replace("-no-kvm", "-machine accel=tcg")
|
||||||
if "-no-hax" in options:
|
|
||||||
options = options.replace("-no-hax", "-machine accel=tcg")
|
|
||||||
|
|
||||||
if "-enable-kvm" in options:
|
if "-enable-kvm" in options:
|
||||||
if not sys.platform.startswith("linux"):
|
options = options.replace("-enable-kvm", "-machine accel=kvm")
|
||||||
# KVM can only be enabled on Linux
|
|
||||||
options = options.replace("-enable-kvm", "")
|
|
||||||
else:
|
|
||||||
options = options.replace("-enable-kvm", "-machine accel=kvm")
|
|
||||||
|
|
||||||
if "-enable-hax" in options:
|
|
||||||
if not sys.platform.startswith("darwin"):
|
|
||||||
# HAXM is only available on macOS
|
|
||||||
options = options.replace("-enable-hax", "")
|
|
||||||
else:
|
|
||||||
options = options.replace("-enable-hax", "-machine accel=hax")
|
|
||||||
|
|
||||||
self._options = options.strip()
|
self._options = options.strip()
|
||||||
|
|
||||||
@@ -1263,7 +1250,7 @@ class QemuVM(KernelDatapathMixin, BaseNode):
|
|||||||
await self._set_process_priority()
|
await self._set_process_priority()
|
||||||
if self._cpu_throttling:
|
if self._cpu_throttling:
|
||||||
self._set_cpu_throttling()
|
self._set_cpu_throttling()
|
||||||
if "-enable-kvm" in command_string or "-enable-hax" in command_string:
|
if "-machine accel=kvm" in command_string:
|
||||||
self._hw_virtualization = True
|
self._hw_virtualization = True
|
||||||
|
|
||||||
set_link_commands = []
|
set_link_commands = []
|
||||||
@@ -2774,23 +2761,13 @@ class QemuVM(KernelDatapathMixin, BaseNode):
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if sys.platform.startswith("linux") and not os.path.exists("/dev/kvm"):
|
if not os.path.exists("/dev/kvm"):
|
||||||
if require_hardware_accel:
|
if require_hardware_accel:
|
||||||
raise QemuError(
|
raise QemuError(
|
||||||
"KVM acceleration cannot be used (/dev/kvm doesn't exist). It is possible to turn off KVM support in the gns3_server.conf by adding enable_hardware_acceleration = false to the [Qemu] section."
|
"KVM acceleration cannot be used (/dev/kvm doesn't exist). It is possible to turn off KVM support in the gns3_server.conf by adding enable_hardware_acceleration = false to the [Qemu] section."
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
elif sys.platform.startswith("darwin"):
|
|
||||||
process = await asyncio.create_subprocess_shell("kextstat | grep com.intel.kext.intelhaxm")
|
|
||||||
await process.wait()
|
|
||||||
if process.returncode != 0:
|
|
||||||
if require_hardware_accel:
|
|
||||||
raise QemuError(
|
|
||||||
"HAXM acceleration support is not installed on this host (com.intel.kext.intelhaxm extension not loaded)"
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -2933,11 +2910,8 @@ class QemuVM(KernelDatapathMixin, BaseNode):
|
|||||||
command.extend(["-smp", f"cpus={self._cpus},maxcpus={maxcpus},sockets=1"])
|
command.extend(["-smp", f"cpus={self._cpus},maxcpus={maxcpus},sockets=1"])
|
||||||
kvm = False
|
kvm = False
|
||||||
if await self._run_with_hardware_acceleration(self.qemu_path, self._options):
|
if await self._run_with_hardware_acceleration(self.qemu_path, self._options):
|
||||||
if sys.platform.startswith("linux"):
|
command.extend(["-machine", "accel=kvm"])
|
||||||
command.extend(["-enable-kvm"])
|
kvm = True
|
||||||
kvm = True
|
|
||||||
elif sys.platform.startswith("darwin"):
|
|
||||||
command.extend(["-enable-hax"])
|
|
||||||
command.extend(["-boot", f"order={self._boot_priority}"])
|
command.extend(["-boot", f"order={self._boot_priority}"])
|
||||||
command.extend(self._cdrom_option())
|
command.extend(self._cdrom_option())
|
||||||
command.extend(await self._disk_options())
|
command.extend(await self._disk_options())
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import os
|
|||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -61,10 +60,6 @@ class VirtualBox(BaseManager):
|
|||||||
vboxmanage_path = shutil.which(vboxmanage_path)
|
vboxmanage_path = shutil.which(vboxmanage_path)
|
||||||
else:
|
else:
|
||||||
log.info("A path to VBoxManage has not been configured, trying to find it...")
|
log.info("A path to VBoxManage has not been configured, trying to find it...")
|
||||||
if sys.platform.startswith("darwin"):
|
|
||||||
vboxmanage_path_osx = "/Applications/VirtualBox.app/Contents/MacOS/VBoxManage"
|
|
||||||
if os.path.exists(vboxmanage_path_osx):
|
|
||||||
vboxmanage_path = vboxmanage_path_osx
|
|
||||||
if not vboxmanage_path:
|
if not vboxmanage_path:
|
||||||
vboxmanage_path = shutil.which("vboxmanage")
|
vboxmanage_path = shutil.which("vboxmanage")
|
||||||
if not vboxmanage_path:
|
if not vboxmanage_path:
|
||||||
|
|||||||
@@ -92,10 +92,7 @@ class VMware(BaseManager):
|
|||||||
# look for vmrun
|
# look for vmrun
|
||||||
vmrun_path = self.config.settings.VMware.vmrun_path
|
vmrun_path = self.config.settings.VMware.vmrun_path
|
||||||
if not vmrun_path:
|
if not vmrun_path:
|
||||||
if sys.platform.startswith("darwin"):
|
vmrun_path = "vmrun"
|
||||||
vmrun_path = "/Applications/VMware Fusion.app/Contents/Library/vmrun"
|
|
||||||
else:
|
|
||||||
vmrun_path = "vmrun"
|
|
||||||
|
|
||||||
if vmrun_path and not os.path.isabs(vmrun_path):
|
if vmrun_path and not os.path.isabs(vmrun_path):
|
||||||
vmrun_path = shutil.which(vmrun_path)
|
vmrun_path = shutil.which(vmrun_path)
|
||||||
@@ -186,14 +183,6 @@ class VMware(BaseManager):
|
|||||||
Check VMware version
|
Check VMware version
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if sys.platform.startswith("darwin"):
|
|
||||||
if not os.path.isdir("/Applications/VMware Fusion.app"):
|
|
||||||
raise VMwareError(
|
|
||||||
"VMware Fusion is not installed in the standard location /Applications/VMware Fusion.app"
|
|
||||||
)
|
|
||||||
self._host_type = "fusion"
|
|
||||||
return # FIXME: no version checking on Mac OS X but we support all versions of fusion
|
|
||||||
|
|
||||||
vmware_path = VMware._get_linux_vmware_binary()
|
vmware_path = VMware._get_linux_vmware_binary()
|
||||||
if vmware_path is None:
|
if vmware_path is None:
|
||||||
raise VMwareError("VMware is not installed (vmware or vmplayer executable could not be found in $PATH)")
|
raise VMwareError("VMware is not installed (vmware or vmplayer executable could not be found in $PATH)")
|
||||||
@@ -223,11 +212,7 @@ class VMware(BaseManager):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_vmnet_interfaces():
|
def _get_vmnet_interfaces():
|
||||||
|
|
||||||
if sys.platform.startswith("darwin"):
|
vmware_networking_file = "/etc/vmware/networking"
|
||||||
vmware_networking_file = "/Library/Preferences/VMware Fusion/networking"
|
|
||||||
else:
|
|
||||||
# location on Linux
|
|
||||||
vmware_networking_file = "/etc/vmware/networking"
|
|
||||||
vmnet_interfaces = {}
|
vmnet_interfaces = {}
|
||||||
try:
|
try:
|
||||||
with open(vmware_networking_file, encoding="utf-8") as f:
|
with open(vmware_networking_file, encoding="utf-8") as f:
|
||||||
@@ -620,10 +605,7 @@ class VMware(BaseManager):
|
|||||||
:returns: path to the inventory file
|
:returns: path to the inventory file
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if sys.platform.startswith("darwin"):
|
return os.path.expanduser("~/.vmware/inventory.vmls")
|
||||||
return os.path.expanduser("~/Library/Application Support/VMware Fusion/vmInventory")
|
|
||||||
else:
|
|
||||||
return os.path.expanduser("~/.vmware/inventory.vmls")
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_vmware_preferences_path():
|
def get_vmware_preferences_path():
|
||||||
@@ -633,10 +615,7 @@ class VMware(BaseManager):
|
|||||||
:returns: path to the preferences file
|
:returns: path to the preferences file
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if sys.platform.startswith("darwin"):
|
return os.path.expanduser("~/.vmware/preferences")
|
||||||
return os.path.expanduser("~/Library/Preferences/VMware Fusion/preferences")
|
|
||||||
else:
|
|
||||||
return os.path.expanduser("~/.vmware/preferences")
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_vmware_default_vm_paths():
|
def get_vmware_default_vm_paths():
|
||||||
@@ -646,10 +625,7 @@ class VMware(BaseManager):
|
|||||||
:returns: path to the default VM directory
|
:returns: path to the default VM directory
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if sys.platform.startswith("darwin"):
|
return [os.path.expanduser("~/vmware")]
|
||||||
return [os.path.expanduser("~/Documents/Virtual Machines.localized")]
|
|
||||||
else:
|
|
||||||
return [os.path.expanduser("~/vmware")]
|
|
||||||
|
|
||||||
async def list_vms(self):
|
async def list_vms(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import asyncio
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import sys
|
|
||||||
import tempfile
|
import tempfile
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
@@ -260,12 +259,7 @@ class VMwareVM(BaseNode):
|
|||||||
if self._get_vmx_setting(connected):
|
if self._get_vmx_setting(connected):
|
||||||
del self._vmx_pairs[connected]
|
del self._vmx_pairs[connected]
|
||||||
|
|
||||||
use_ubridge = True
|
self.manager.refresh_vmnet_list(ubridge=True)
|
||||||
# use alternative method to find vmnet interfaces on macOS >= 11.0 (BigSur)
|
|
||||||
# because "bridge" interfaces are used instead and they are only created on the VM starts
|
|
||||||
if sys.platform.startswith("darwin") and parse_version(platform.mac_ver()[0]) >= parse_version("11.0.0"):
|
|
||||||
use_ubridge = False
|
|
||||||
self.manager.refresh_vmnet_list(ubridge=use_ubridge)
|
|
||||||
# then configure VMware network adapters
|
# then configure VMware network adapters
|
||||||
for adapter_number in range(0, self._adapters):
|
for adapter_number in range(0, self._adapters):
|
||||||
custom_adapter = self._get_custom_adapter_settings(adapter_number)
|
custom_adapter = self._get_custom_adapter_settings(adapter_number)
|
||||||
@@ -350,20 +344,7 @@ class VMwareVM(BaseNode):
|
|||||||
await self._ubridge_send(f"bridge create {vnet}")
|
await self._ubridge_send(f"bridge create {vnet}")
|
||||||
vmnet_interface = os.path.basename(self._vmx_pairs[vnet])
|
vmnet_interface = os.path.basename(self._vmx_pairs[vnet])
|
||||||
block_host_traffic = self.manager.config.settings.VMware.block_host_traffic
|
block_host_traffic = self.manager.config.settings.VMware.block_host_traffic
|
||||||
|
await self._add_ubridge_ethernet_connection(vnet, vmnet_interface, block_host_traffic)
|
||||||
if sys.platform.startswith("darwin"):
|
|
||||||
if parse_version(platform.mac_ver()[0]) >= parse_version("11.0.0"):
|
|
||||||
# a bridge interface (bridge100, bridge101 etc.) is used instead of a vmnet interface
|
|
||||||
# on macOS >= 11.0 (Big Sur)
|
|
||||||
vmnet_interface = self.manager.find_bridge_interface(vmnet_interface)
|
|
||||||
if not vmnet_interface:
|
|
||||||
raise VMwareError(f"Could not find bridge interface linked with {vmnet_interface}")
|
|
||||||
await self._add_ubridge_ethernet_connection(vnet, vmnet_interface, block_host_traffic)
|
|
||||||
else:
|
|
||||||
# special case on macOS, we cannot bind VMnet interfaces using the libpcap
|
|
||||||
await self._ubridge_send(f'bridge add_nio_fusion_vmnet {vnet} "{vmnet_interface}"')
|
|
||||||
else:
|
|
||||||
await self._add_ubridge_ethernet_connection(vnet, vmnet_interface, block_host_traffic)
|
|
||||||
|
|
||||||
if isinstance(nio, NIOUDP):
|
if isinstance(nio, NIOUDP):
|
||||||
await self._ubridge_send(f"bridge add_nio_udp {vnet} {nio.lport} {nio.rhost} {nio.rport}")
|
await self._ubridge_send(f"bridge add_nio_udp {vnet} {nio.lport} {nio.rhost} {nio.rport}")
|
||||||
|
|||||||
@@ -68,10 +68,8 @@ class GNS3VM:
|
|||||||
"support_headless": True,
|
"support_headless": True,
|
||||||
"support_ram": True,
|
"support_ram": True,
|
||||||
}
|
}
|
||||||
if sys.platform.startswith("darwin"):
|
|
||||||
vmware_info["name"] = "VMware Fusion (recommended)"
|
vmware_info["name"] = "VMware Workstation / Player (recommended)"
|
||||||
else:
|
|
||||||
vmware_info["name"] = "VMware Workstation / Player (recommended)"
|
|
||||||
|
|
||||||
download_url = (
|
download_url = (
|
||||||
f"https://github.com/GNS3/gns3-gui/releases/download/v{__version__}/GNS3.VM.Hyper-V.{__version__}.zip"
|
f"https://github.com/GNS3/gns3-gui/releases/download/v{__version__}/GNS3.VM.Hyper-V.{__version__}.zip"
|
||||||
|
|||||||
@@ -275,23 +275,10 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
|
|||||||
f'VM "{self.vmname}" must have a NAT interface or NAT Network configured in order to start'
|
f'VM "{self.vmname}" must have a NAT interface or NAT Network configured in order to start'
|
||||||
)
|
)
|
||||||
|
|
||||||
if sys.platform.startswith("darwin") and parse_version(self._system_properties["API version"]) >= parse_version(
|
backend_type = "hostonlyadapter"
|
||||||
"7_0"
|
backend_description = "host-only adapter"
|
||||||
):
|
vboxnet_type = "hostonlyifs"
|
||||||
# VirtualBox 7.0+ on macOS requires a host-only network interface
|
interface_number = await self._look_for_interface("hostonly")
|
||||||
backend_type = "hostonly-network"
|
|
||||||
backend_description = "host-only network"
|
|
||||||
vboxnet_type = "hostonlynets"
|
|
||||||
interface_number = await self._look_for_interface("hostonlynetwork")
|
|
||||||
if interface_number < 0:
|
|
||||||
raise GNS3VMError(
|
|
||||||
f'VM "{self.vmname}" must have a network adapter attached to a host-only network in order to start'
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
backend_type = "hostonlyadapter"
|
|
||||||
backend_description = "host-only adapter"
|
|
||||||
vboxnet_type = "hostonlyifs"
|
|
||||||
interface_number = await self._look_for_interface("hostonly")
|
|
||||||
|
|
||||||
if interface_number < 0:
|
if interface_number < 0:
|
||||||
raise GNS3VMError(
|
raise GNS3VMError(
|
||||||
|
|||||||
@@ -22,11 +22,7 @@ import shutil
|
|||||||
import sys
|
import sys
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
if sys.platform.startswith("darwin"):
|
VMWARE_NETWORKING_FILE = "/etc/vmware/networking"
|
||||||
VMWARE_NETWORKING_FILE = "/Library/Preferences/VMware Fusion/networking"
|
|
||||||
else:
|
|
||||||
# location on Linux
|
|
||||||
VMWARE_NETWORKING_FILE = "/etc/vmware/networking"
|
|
||||||
|
|
||||||
if sys.platform.startswith("win"):
|
if sys.platform.startswith("win"):
|
||||||
DEFAULT_RANGE = [1, 19]
|
DEFAULT_RANGE = [1, 19]
|
||||||
@@ -74,15 +70,8 @@ def write_networking_file(version, pairs):
|
|||||||
raise SystemExit(f"Cannot open {VMWARE_NETWORKING_FILE}: {e}")
|
raise SystemExit(f"Cannot open {VMWARE_NETWORKING_FILE}: {e}")
|
||||||
|
|
||||||
# restart VMware networking service
|
# restart VMware networking service
|
||||||
if sys.platform.startswith("darwin"):
|
os.system("vmware-networks --stop")
|
||||||
if not os.path.exists("/Applications/VMware Fusion.app/Contents/Library/vmnet-cli"):
|
os.system("vmware-networks --start")
|
||||||
raise SystemExit("VMware Fusion is not installed in Applications")
|
|
||||||
os.system(r"/Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --configure")
|
|
||||||
os.system(r"/Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --stop")
|
|
||||||
os.system(r"/Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --start")
|
|
||||||
else:
|
|
||||||
os.system("vmware-networks --stop")
|
|
||||||
os.system("vmware-networks --start")
|
|
||||||
|
|
||||||
|
|
||||||
def parse_vmnet_range(start, end):
|
def parse_vmnet_range(start, end):
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ async def _no_tap_probe():
|
|||||||
|
|
||||||
|
|
||||||
class TestCapabilitiesRoutes:
|
class TestCapabilitiesRoutes:
|
||||||
async def test_get(self, app: FastAPI, compute_client: AsyncClient, windows_platform, monkeypatch) -> None:
|
async def test_get(self, app: FastAPI, compute_client: AsyncClient, monkeypatch) -> None:
|
||||||
|
|
||||||
async def no_probe():
|
async def no_probe():
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ async def test_json_without_ports(on_gns3vm, compute_project, manager):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_kernel_datapath_interfaces_are_hidden(linux_platform, compute_project, manager):
|
async def test_kernel_datapath_interfaces_are_hidden(compute_project, manager):
|
||||||
"""
|
"""
|
||||||
Kernel-datapath interfaces (node anchors, cascade veths, VXLAN devices)
|
Kernel-datapath interfaces (node anchors, cascade veths, VXLAN devices)
|
||||||
are neither pre-filled as cloud ports nor listed as host interfaces,
|
are neither pre-filled as cloud ports nor listed as host interfaces,
|
||||||
@@ -221,7 +221,7 @@ async def test_update_port_mappings(on_gns3vm, compute_project):
|
|||||||
assert cloud.ports_mapping == ports1
|
assert cloud.ports_mapping == ports1
|
||||||
|
|
||||||
|
|
||||||
async def test_linux_ethernet_raw_add_nio(linux_platform, compute_project, nio):
|
async def test_linux_ethernet_raw_add_nio(compute_project, nio):
|
||||||
ports = [{"interface": "eth0", "name": "eth0", "port_number": 0, "type": "ethernet"}]
|
ports = [{"interface": "eth0", "name": "eth0", "port_number": 0, "type": "ethernet"}]
|
||||||
cloud = Cloud("cloud1", str(uuid.uuid4()), compute_project, MagicMock(), ports=ports)
|
cloud = Cloud("cloud1", str(uuid.uuid4()), compute_project, MagicMock(), ports=ports)
|
||||||
cloud.status = "started"
|
cloud.status = "started"
|
||||||
@@ -243,7 +243,7 @@ async def test_linux_ethernet_raw_add_nio(linux_platform, compute_project, nio):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_linux_ethernet_raw_add_nio_bridge(linux_platform, compute_project, nio):
|
async def test_linux_ethernet_raw_add_nio_bridge(compute_project, nio):
|
||||||
"""
|
"""
|
||||||
Bridge can't be connected directly to a cloud we use a tap in the middle
|
Bridge can't be connected directly to a cloud we use a tap in the middle
|
||||||
"""
|
"""
|
||||||
@@ -275,7 +275,7 @@ async def test_linux_ethernet_raw_add_nio_bridge(linux_platform, compute_project
|
|||||||
|
|
||||||
@pytest.mark.parametrize("bridge", [None, "virbr0"])
|
@pytest.mark.parametrize("bridge", [None, "virbr0"])
|
||||||
@pytest.mark.parametrize("existing_master", [False, True])
|
@pytest.mark.parametrize("existing_master", [False, True])
|
||||||
async def test_tap_bridge_recreated(linux_platform, compute_project, manager, nio, bridge, existing_master):
|
async def test_tap_bridge_recreated(compute_project, manager, nio, bridge, existing_master):
|
||||||
ports = [{"interface": "tap0", "name": "tap0", "port_number": 0, "type": "tap"}]
|
ports = [{"interface": "tap0", "name": "tap0", "port_number": 0, "type": "tap"}]
|
||||||
if bridge:
|
if bridge:
|
||||||
ports[0]["bridge"] = bridge
|
ports[0]["bridge"] = bridge
|
||||||
@@ -302,8 +302,8 @@ async def test_tap_bridge_recreated(linux_platform, compute_project, manager, ni
|
|||||||
assert attach_call not in send.call_args_list
|
assert attach_call not in send.call_args_list
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("failure", ["missing", "not_bridge", "other_master", "invalid_name", "non_linux"])
|
@pytest.mark.parametrize("failure", ["missing", "not_bridge", "other_master", "invalid_name"])
|
||||||
async def test_tap_bridge_validation(linux_platform, compute_project, manager, nio, failure):
|
async def test_tap_bridge_validation(compute_project, manager, nio, failure):
|
||||||
ports = [{"interface": "tap0", "name": "tap0", "port_number": 0, "type": "tap", "bridge": "virbr0"}]
|
ports = [{"interface": "tap0", "name": "tap0", "port_number": 0, "type": "tap", "bridge": "virbr0"}]
|
||||||
if failure == "invalid_name":
|
if failure == "invalid_name":
|
||||||
ports[0]["interface"] = 'tap0"\nbridge delete all'
|
ports[0]["interface"] = 'tap0"\nbridge delete all'
|
||||||
@@ -314,14 +314,13 @@ async def test_tap_bridge_validation(linux_platform, compute_project, manager, n
|
|||||||
patch("gns3server.utils.interfaces.is_interface_bridge", return_value=failure != "not_bridge"),
|
patch("gns3server.utils.interfaces.is_interface_bridge", return_value=failure != "not_bridge"),
|
||||||
patch("gns3server.compute.builtin.nodes.cloud.os.path.exists", return_value=failure == "other_master"),
|
patch("gns3server.compute.builtin.nodes.cloud.os.path.exists", return_value=failure == "other_master"),
|
||||||
patch("gns3server.compute.builtin.nodes.cloud.os.path.realpath", return_value="/sys/class/net/another0"),
|
patch("gns3server.compute.builtin.nodes.cloud.os.path.realpath", return_value="/sys/class/net/another0"),
|
||||||
patch("gns3server.compute.builtin.nodes.cloud.sys.platform", "darwin" if failure == "non_linux" else "linux"),
|
|
||||||
):
|
):
|
||||||
with pytest.raises(NodeError):
|
with pytest.raises(NodeError):
|
||||||
await cloud._add_ubridge_connection(nio, 0)
|
await cloud._add_ubridge_connection(nio, 0)
|
||||||
assert not any("add_nio_tap" in c.args[0] or "brctl addif" in c.args[0] for c in send.call_args_list)
|
assert not any("add_nio_tap" in c.args[0] or "brctl addif" in c.args[0] for c in send.call_args_list)
|
||||||
|
|
||||||
|
|
||||||
async def test_tap_bridge_attachment_failure(linux_platform, compute_project, manager, nio):
|
async def test_tap_bridge_attachment_failure(compute_project, manager, nio):
|
||||||
ports = [{"interface": "tap0", "name": "tap0", "port_number": 0, "type": "tap", "bridge": "virbr0"}]
|
ports = [{"interface": "tap0", "name": "tap0", "port_number": 0, "type": "tap", "bridge": "virbr0"}]
|
||||||
cloud = Cloud("cloud1", str(uuid.uuid4()), compute_project, manager, ports=ports)
|
cloud = Cloud("cloud1", str(uuid.uuid4()), compute_project, manager, ports=ports)
|
||||||
cloud.status = "started"
|
cloud.status = "started"
|
||||||
@@ -342,7 +341,7 @@ async def test_tap_bridge_attachment_failure(linux_platform, compute_project, ma
|
|||||||
assert cloud.status == "stopped"
|
assert cloud.status == "stopped"
|
||||||
|
|
||||||
|
|
||||||
async def test_cloud_lists_linux_bridges(linux_platform, compute_project, manager):
|
async def test_cloud_lists_linux_bridges(compute_project, manager):
|
||||||
cloud = Cloud(
|
cloud = Cloud(
|
||||||
"cloud1",
|
"cloud1",
|
||||||
str(uuid.uuid4()),
|
str(uuid.uuid4()),
|
||||||
@@ -400,7 +399,7 @@ async def test_bridged_tap_name_validation_preserves_legacy_names(name):
|
|||||||
((1 << 12) | (1 << 13), True, True),
|
((1 << 12) | (1 << 13), True, True),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_bridged_tap_requires_net_admin(linux_platform, tmp_path, caps, legacy_allowed, bridge_allowed):
|
async def test_bridged_tap_requires_net_admin(tmp_path, caps, legacy_allowed, bridge_allowed):
|
||||||
executable = tmp_path / "ubridge"
|
executable = tmp_path / "ubridge"
|
||||||
executable.write_text("")
|
executable.write_text("")
|
||||||
with (
|
with (
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
from gns3server.compute.builtin.nodes.nat import Nat
|
from gns3server.compute.builtin.nodes.nat import Nat
|
||||||
|
|
||||||
@@ -40,57 +40,3 @@ def test_json_gns3vm(on_gns3vm, compute_project):
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_json_darwin(darwin_platform, compute_project):
|
|
||||||
|
|
||||||
with patch(
|
|
||||||
"gns3server.utils.interfaces.interfaces",
|
|
||||||
return_value=[
|
|
||||||
{"name": "eth0", "special": False, "type": "ethernet"},
|
|
||||||
{"name": "vmnet8", "special": True, "type": "ethernet"},
|
|
||||||
],
|
|
||||||
):
|
|
||||||
nat = Nat("nat1", str(uuid.uuid4()), compute_project, MagicMock())
|
|
||||||
assert nat.asdict() == {
|
|
||||||
"name": "nat1",
|
|
||||||
"usage": "",
|
|
||||||
"node_id": nat.id,
|
|
||||||
"project_id": compute_project.id,
|
|
||||||
"status": "started",
|
|
||||||
"ports_mapping": [{"interface": "vmnet8", "name": "nat0", "port_number": 0, "type": "ethernet"}],
|
|
||||||
"interfaces": [
|
|
||||||
{
|
|
||||||
"name": "vmnet8",
|
|
||||||
"type": "ethernet",
|
|
||||||
"special": True,
|
|
||||||
"ip_addresses": [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def test_json_windows_with_full_name_of_interface(windows_platform, project):
|
|
||||||
with patch(
|
|
||||||
"gns3server.utils.interfaces.interfaces",
|
|
||||||
return_value=[{"name": "VMware Network Adapter VMnet8", "special": True, "type": "ethernet"}],
|
|
||||||
):
|
|
||||||
nat = Nat("nat1", str(uuid.uuid4()), project, MagicMock())
|
|
||||||
assert nat.asdict() == {
|
|
||||||
"name": "nat1",
|
|
||||||
"usage": "",
|
|
||||||
"node_id": nat.id,
|
|
||||||
"project_id": project.id,
|
|
||||||
"status": "started",
|
|
||||||
"ports_mapping": [
|
|
||||||
{"interface": "VMware Network Adapter VMnet8", "name": "nat0", "port_number": 0, "type": "ethernet"}
|
|
||||||
],
|
|
||||||
"interfaces": [
|
|
||||||
{
|
|
||||||
"name": "VMware Network Adapter VMnet8",
|
|
||||||
"type": "ethernet",
|
|
||||||
"special": True,
|
|
||||||
"ip_addresses": [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
@@ -17,7 +17,6 @@
|
|||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import stat
|
import stat
|
||||||
import sys
|
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -29,10 +28,7 @@ from tests.utils import asyncio_patch
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def fake_qemu_img_binary(tmpdir):
|
def fake_qemu_img_binary(tmpdir):
|
||||||
|
|
||||||
if sys.platform.startswith("win"):
|
bin_path = str(tmpdir / "qemu-img")
|
||||||
bin_path = str(tmpdir / "qemu-img.EXE")
|
|
||||||
else:
|
|
||||||
bin_path = str(tmpdir / "qemu-img")
|
|
||||||
with open(bin_path, "w+") as f:
|
with open(bin_path, "w+") as f:
|
||||||
f.write("1")
|
f.write("1")
|
||||||
os.chmod(bin_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
|
os.chmod(bin_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import asyncio
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import stat
|
import stat
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
@@ -46,10 +45,7 @@ async def manager(port_manager):
|
|||||||
def fake_qemu_img_binary(monkeypatch, tmpdir):
|
def fake_qemu_img_binary(monkeypatch, tmpdir):
|
||||||
|
|
||||||
monkeypatch.setenv("PATH", str(tmpdir))
|
monkeypatch.setenv("PATH", str(tmpdir))
|
||||||
if sys.platform.startswith("win"):
|
bin_path = os.path.join(os.environ["PATH"], "qemu-img")
|
||||||
bin_path = os.path.join(os.environ["PATH"], "qemu-img.EXE")
|
|
||||||
else:
|
|
||||||
bin_path = os.path.join(os.environ["PATH"], "qemu-img")
|
|
||||||
with open(bin_path, "w+") as f:
|
with open(bin_path, "w+") as f:
|
||||||
f.write("1")
|
f.write("1")
|
||||||
os.chmod(bin_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
|
os.chmod(bin_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
|
||||||
@@ -72,7 +68,7 @@ async def vm(compute_project, manager, fake_qemu_binary, fake_qemu_img_binary):
|
|||||||
|
|
||||||
manager.port_manager.console_host = "127.0.0.1"
|
manager.port_manager.console_host = "127.0.0.1"
|
||||||
vm = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager, qemu_path=fake_qemu_binary)
|
vm = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager, qemu_path=fake_qemu_binary)
|
||||||
vm._process_priority = "normal" # Avoid complexity for Windows tests
|
vm._process_priority = "normal"
|
||||||
vm._replicate_network_connection_state = False # to avoid delay when starting/stopping the VM
|
vm._replicate_network_connection_state = False # to avoid delay when starting/stopping the VM
|
||||||
vm._start_ubridge = AsyncioMagicMock()
|
vm._start_ubridge = AsyncioMagicMock()
|
||||||
vm._ubridge_hypervisor = MagicMock()
|
vm._ubridge_hypervisor = MagicMock()
|
||||||
@@ -432,7 +428,6 @@ async def test_bios_option(vm, tmpdir, fake_qemu_img_binary):
|
|||||||
assert " ".join(["-bios", str(tmpdir / "test.img")]) in " ".join(options)
|
assert " ".join(["-bios", str(tmpdir / "test.img")]) in " ".join(options)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Test not working on Windows")
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_uefi_boot_mode_option(vm, tmpdir, images_dir, fake_qemu_img_binary):
|
async def test_uefi_boot_mode_option(vm, tmpdir, images_dir, fake_qemu_img_binary):
|
||||||
|
|
||||||
@@ -657,7 +652,7 @@ async def test_build_command_manual_uuid(vm):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_build_command_kvm_below_6_2(linux_platform, vm, fake_qemu_binary):
|
async def test_build_command_kvm_below_6_2(vm, fake_qemu_binary):
|
||||||
"""
|
"""
|
||||||
Qemu 2.4 introduce an issue with KVM
|
Qemu 2.4 introduce an issue with KVM
|
||||||
"""
|
"""
|
||||||
@@ -821,7 +816,6 @@ async def test_build_command_with_invalid_options(vm):
|
|||||||
await vm._build_command()
|
await vm._build_command()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_build_command_with_forbidden_options(vm):
|
async def test_build_command_with_forbidden_options(vm):
|
||||||
|
|
||||||
@@ -843,7 +837,7 @@ async def _build_command_with_kvm(vm, clocksource):
|
|||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.parametrize("clocksource", ["hyperv_clocksource_tsc_page", "hyperv_clocksource_msr"])
|
@pytest.mark.parametrize("clocksource", ["hyperv_clocksource_tsc_page", "hyperv_clocksource_msr"])
|
||||||
async def test_build_command_kvmclock_off_on_hyperv_host(linux_platform, vm, clocksource):
|
async def test_build_command_kvmclock_off_on_hyperv_host(vm, clocksource):
|
||||||
"""
|
"""
|
||||||
A host running on Hyper-V without a usable TSC falls back to a Hyper-V clocksource:
|
A host running on Hyper-V without a usable TSC falls back to a Hyper-V clocksource:
|
||||||
kvmclock runs away in KVM guests there (Linux guests panic with soft lockups) and
|
kvmclock runs away in KVM guests there (Linux guests panic with soft lockups) and
|
||||||
@@ -852,16 +846,16 @@ async def test_build_command_kvmclock_off_on_hyperv_host(linux_platform, vm, clo
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
cmd = await _build_command_with_kvm(vm, clocksource)
|
cmd = await _build_command_with_kvm(vm, clocksource)
|
||||||
assert "-enable-kvm" in cmd
|
assert "accel=kvm" in cmd
|
||||||
assert cmd[cmd.index("-cpu") + 1] == "qemu64,kvmclock=off,tsc-deadline=off"
|
assert cmd[cmd.index("-cpu") + 1] == "qemu64,kvmclock=off,tsc-deadline=off"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.parametrize("clocksource", ["tsc", None])
|
@pytest.mark.parametrize("clocksource", ["tsc", None])
|
||||||
async def test_build_command_kvmclock_kept_on_other_hosts(linux_platform, vm, clocksource):
|
async def test_build_command_kvmclock_kept_on_other_hosts(vm, clocksource):
|
||||||
|
|
||||||
cmd = await _build_command_with_kvm(vm, clocksource)
|
cmd = await _build_command_with_kvm(vm, clocksource)
|
||||||
assert "-enable-kvm" in cmd
|
assert "accel=kvm" in cmd
|
||||||
assert "-cpu" not in cmd
|
assert "-cpu" not in cmd
|
||||||
|
|
||||||
|
|
||||||
@@ -875,7 +869,7 @@ async def test_build_command_kvmclock_kept_without_kvm(vm):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_build_command_kvmclock_off_on_user_cpu(linux_platform, vm):
|
async def test_build_command_kvmclock_off_on_user_cpu(vm):
|
||||||
"""
|
"""
|
||||||
A -cpu given in the additional options keeps its model and gets the features turned off.
|
A -cpu given in the additional options keeps its model and gets the features turned off.
|
||||||
"""
|
"""
|
||||||
@@ -894,7 +888,7 @@ async def test_build_command_kvmclock_off_on_user_cpu(linux_platform, vm):
|
|||||||
("max,-kvmclock,+tsc-deadline", "max,-kvmclock,+tsc-deadline"),
|
("max,-kvmclock,+tsc-deadline", "max,-kvmclock,+tsc-deadline"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_build_command_kvmclock_user_choice_kept(linux_platform, vm, cpu, expected):
|
async def test_build_command_kvmclock_user_choice_kept(vm, cpu, expected):
|
||||||
|
|
||||||
vm.options = f"-cpu {cpu}"
|
vm.options = f"-cpu {cpu}"
|
||||||
cmd = await _build_command_with_kvm(vm, "hyperv_clocksource_tsc_page")
|
cmd = await _build_command_with_kvm(vm, "hyperv_clocksource_tsc_page")
|
||||||
@@ -903,7 +897,7 @@ async def test_build_command_kvmclock_user_choice_kept(linux_platform, vm, cpu,
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_build_command_kvmclock_off_i386(linux_platform, vm):
|
async def test_build_command_kvmclock_off_i386(vm):
|
||||||
|
|
||||||
vm._platform = "i386"
|
vm._platform = "i386"
|
||||||
cmd = await _build_command_with_kvm(vm, "hyperv_clocksource_tsc_page")
|
cmd = await _build_command_with_kvm(vm, "hyperv_clocksource_tsc_page")
|
||||||
@@ -918,7 +912,7 @@ async def test_build_command_kvmclock_off_i386(linux_platform, vm):
|
|||||||
("enabled", "hyperv_clocksource_tsc_page", False),
|
("enabled", "hyperv_clocksource_tsc_page", False),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_build_command_kvmclock_setting(linux_platform, vm, setting, clocksource, kvmclock_off):
|
async def test_build_command_kvmclock_setting(vm, setting, clocksource, kvmclock_off):
|
||||||
|
|
||||||
vm.manager.config.settings.Qemu.kvmclock = setting
|
vm.manager.config.settings.Qemu.kvmclock = setting
|
||||||
cmd = await _build_command_with_kvm(vm, clocksource)
|
cmd = await _build_command_with_kvm(vm, clocksource)
|
||||||
@@ -1031,7 +1025,7 @@ def test_initrd_asa(vm, images_dir):
|
|||||||
assert mock.called
|
assert mock.called
|
||||||
|
|
||||||
|
|
||||||
def test_options(linux_platform, vm):
|
def test_options(vm):
|
||||||
vm.kvm = False
|
vm.kvm = False
|
||||||
vm.options = "-usb"
|
vm.options = "-usb"
|
||||||
assert vm.options == "-usb"
|
assert vm.options == "-usb"
|
||||||
@@ -1044,23 +1038,12 @@ def test_options(linux_platform, vm):
|
|||||||
assert vm.options == "-machine accel=kvm"
|
assert vm.options == "-machine accel=kvm"
|
||||||
|
|
||||||
|
|
||||||
def test_options_windows(windows_platform, vm):
|
|
||||||
vm.options = "-no-kvm"
|
|
||||||
assert vm.options == "-machine accel=tcg"
|
|
||||||
|
|
||||||
vm.options = "-enable-kvm"
|
|
||||||
assert vm.options == ""
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_qemu_img(vm, tmpdir):
|
def test_get_qemu_img(vm, tmpdir):
|
||||||
|
|
||||||
open(str(tmpdir / "qemu-system-x86_64"), "w+").close()
|
open(str(tmpdir / "qemu-system-x86_64"), "w+").close()
|
||||||
open(str(tmpdir / "qemu-img"), "w+").close()
|
open(str(tmpdir / "qemu-img"), "w+").close()
|
||||||
vm._qemu_path = str(tmpdir / "qemu-system-x86_64")
|
vm._qemu_path = str(tmpdir / "qemu-system-x86_64")
|
||||||
if sys.platform.startswith("win"):
|
assert vm._get_qemu_img() == str(tmpdir / "qemu-img")
|
||||||
assert vm._get_qemu_img() == str(tmpdir / "qemu-img.EXE")
|
|
||||||
else:
|
|
||||||
assert vm._get_qemu_img() == str(tmpdir / "qemu-img")
|
|
||||||
|
|
||||||
|
|
||||||
# def test_get_qemu_img_not_exist(vm, tmpdir):
|
# def test_get_qemu_img_not_exist(vm, tmpdir):
|
||||||
@@ -1072,21 +1055,7 @@ def test_get_qemu_img(vm, tmpdir):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_run_with_hardware_acceleration_darwin(darwin_platform, vm):
|
async def test_run_with_kvm(vm):
|
||||||
|
|
||||||
vm.manager.config.settings.Qemu.enable_hardware_acceleration = False
|
|
||||||
assert await vm._run_with_hardware_acceleration("qemu-system-x86_64", "") is False
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_run_with_hardware_acceleration_windows(windows_platform, vm):
|
|
||||||
|
|
||||||
vm.manager.config.settings.Qemu.enable_hardware_acceleration = False
|
|
||||||
assert await vm._run_with_hardware_acceleration("qemu-system-x86_64", "") is False
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_run_with_kvm_linux(linux_platform, vm):
|
|
||||||
|
|
||||||
with patch("os.path.exists", return_value=True) as os_path:
|
with patch("os.path.exists", return_value=True) as os_path:
|
||||||
vm.manager.config.settings.Qemu.enable_hardware_acceleration = True
|
vm.manager.config.settings.Qemu.enable_hardware_acceleration = True
|
||||||
@@ -1095,7 +1064,7 @@ async def test_run_with_kvm_linux(linux_platform, vm):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_run_with_kvm_linux_options_no_kvm(linux_platform, vm):
|
async def test_run_with_kvm_options_no_kvm(vm):
|
||||||
|
|
||||||
with patch("os.path.exists", return_value=True) as os_path:
|
with patch("os.path.exists", return_value=True) as os_path:
|
||||||
vm.manager.config.settings.Qemu.enable_hardware_acceleration = True
|
vm.manager.config.settings.Qemu.enable_hardware_acceleration = True
|
||||||
@@ -1103,7 +1072,7 @@ async def test_run_with_kvm_linux_options_no_kvm(linux_platform, vm):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_run_with_kvm_not_x86(linux_platform, vm):
|
async def test_run_with_kvm_not_x86(vm):
|
||||||
|
|
||||||
with patch("os.path.exists", return_value=True):
|
with patch("os.path.exists", return_value=True):
|
||||||
vm.manager.config.settings.Qemu.enable_hardware_acceleration = True
|
vm.manager.config.settings.Qemu.enable_hardware_acceleration = True
|
||||||
@@ -1113,7 +1082,7 @@ async def test_run_with_kvm_not_x86(linux_platform, vm):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_run_with_kvm_linux_dev_kvm_missing(linux_platform, vm):
|
async def test_run_with_kvm_dev_kvm_missing(vm):
|
||||||
|
|
||||||
with patch("os.path.exists", return_value=False):
|
with patch("os.path.exists", return_value=False):
|
||||||
vm.manager.config.settings.Qemu.enable_hardware_acceleration = True
|
vm.manager.config.settings.Qemu.enable_hardware_acceleration = True
|
||||||
|
|||||||
+6
-44
@@ -2,7 +2,6 @@ import asyncio
|
|||||||
import base64
|
import base64
|
||||||
import configparser
|
import configparser
|
||||||
import os
|
import os
|
||||||
import platform
|
|
||||||
import resource
|
import resource
|
||||||
import shutil
|
import shutil
|
||||||
import stat
|
import stat
|
||||||
@@ -43,12 +42,11 @@ def pytest_configure(config):
|
|||||||
Increases the maximum number of open file descriptors before running tests (Unix only).
|
Increases the maximum number of open file descriptors before running tests (Unix only).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if platform.system() != "Windows":
|
soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
|
||||||
soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
|
# Set soft limit to hard limit, or a safe high number like 4096
|
||||||
# Set soft limit to hard limit, or a safe high number like 4096
|
new_soft = min(4096, hard)
|
||||||
new_soft = min(4096, hard)
|
if soft < new_soft:
|
||||||
if soft < new_soft:
|
resource.setrlimit(resource.RLIMIT_NOFILE, (new_soft, hard))
|
||||||
resource.setrlimit(resource.RLIMIT_NOFILE, (new_soft, hard))
|
|
||||||
|
|
||||||
|
|
||||||
@pytest_asyncio.fixture(loop_scope="class", scope="class")
|
@pytest_asyncio.fixture(loop_scope="class", scope="class")
|
||||||
@@ -320,43 +318,7 @@ def free_console_port(port_manager, compute_project):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def darwin_platform():
|
def on_gns3vm():
|
||||||
"""
|
|
||||||
Change sys.plaform to Darwin
|
|
||||||
"""
|
|
||||||
|
|
||||||
old_platform = sys.platform
|
|
||||||
sys.platform = "darwin10.10"
|
|
||||||
yield
|
|
||||||
sys.plaform = old_platform
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def windows_platform():
|
|
||||||
"""
|
|
||||||
Change sys.platform to Windows
|
|
||||||
"""
|
|
||||||
|
|
||||||
old_platform = sys.platform
|
|
||||||
sys.platform = "win10"
|
|
||||||
yield
|
|
||||||
sys.plaform = old_platform
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def linux_platform():
|
|
||||||
"""
|
|
||||||
Change sys.platform to Linux
|
|
||||||
"""
|
|
||||||
|
|
||||||
old_platform = sys.platform
|
|
||||||
sys.platform = "linuxdebian"
|
|
||||||
yield
|
|
||||||
sys.plaform = old_platform
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def on_gns3vm(linux_platform):
|
|
||||||
"""
|
"""
|
||||||
Mock the hostname to emulate the GNS3 VM
|
Mock the hostname to emulate the GNS3 VM
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -33,27 +33,3 @@ async def gns3vm(controller):
|
|||||||
def vmx_path(tmpdir):
|
def vmx_path(tmpdir):
|
||||||
|
|
||||||
return str(tmpdir / "vmwware_vm.vmx")
|
return str(tmpdir / "vmwware_vm.vmx")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_set_extra_options(gns3vm, vmx_path, windows_platform):
|
|
||||||
|
|
||||||
gns3vm._vmx_path = vmx_path
|
|
||||||
|
|
||||||
# when there is not an entry, we modify it
|
|
||||||
with open(vmx_path, "w") as f:
|
|
||||||
f.write("")
|
|
||||||
|
|
||||||
await gns3vm._set_extra_options()
|
|
||||||
|
|
||||||
with open(vmx_path) as f:
|
|
||||||
assert f.read() == 'vhv.enable = "TRUE"\n'
|
|
||||||
|
|
||||||
# when there is an entry, we don't modify it
|
|
||||||
with open(vmx_path, "w") as f:
|
|
||||||
f.write('vhv.enable = "FALSE"\n')
|
|
||||||
|
|
||||||
await gns3vm._set_extra_options()
|
|
||||||
|
|
||||||
with open(vmx_path) as f:
|
|
||||||
assert f.read() == 'vhv.enable = "FALSE"\n'
|
|
||||||
@@ -256,7 +256,7 @@ async def test_import_with_images(config, tmpdir, controller):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_import_iou_linux_no_vm(linux_platform, tmpdir, controller):
|
async def test_import_iou_linux_no_vm(tmpdir, controller):
|
||||||
"""
|
"""
|
||||||
On non linux host IOU should be local if we don't have a GNS3 VM
|
On non linux host IOU should be local if we don't have a GNS3 VM
|
||||||
"""
|
"""
|
||||||
@@ -294,7 +294,7 @@ async def test_import_iou_linux_no_vm(linux_platform, tmpdir, controller):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_import_iou_linux_with_vm(linux_platform, tmpdir, controller):
|
async def test_import_iou_linux_with_vm(tmpdir, controller):
|
||||||
"""
|
"""
|
||||||
On non linux host IOU should be vm if we have a GNS3 VM configured
|
On non linux host IOU should be vm if we have a GNS3 VM configured
|
||||||
"""
|
"""
|
||||||
@@ -340,112 +340,7 @@ async def test_import_iou_linux_with_vm(linux_platform, tmpdir, controller):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_import_nat_non_linux(windows_platform, tmpdir, controller):
|
async def test_import_node_id(tmpdir, controller):
|
||||||
"""
|
|
||||||
On non linux host NAT should be moved to the GNS3 VM
|
|
||||||
"""
|
|
||||||
|
|
||||||
project_id = str(uuid.uuid4())
|
|
||||||
controller._computes["vm"] = AsyncioMagicMock()
|
|
||||||
|
|
||||||
topology = {
|
|
||||||
"project_id": str(uuid.uuid4()),
|
|
||||||
"name": "test",
|
|
||||||
"type": "topology",
|
|
||||||
"topology": {
|
|
||||||
"nodes": [
|
|
||||||
{
|
|
||||||
"compute_id": "local",
|
|
||||||
"node_id": "0fd3dd4d-dc93-4a04-a9b9-7396a9e22e8b",
|
|
||||||
"node_type": "nat",
|
|
||||||
"name": "test",
|
|
||||||
"properties": {},
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"links": [],
|
|
||||||
"computes": [],
|
|
||||||
"drawings": [],
|
|
||||||
},
|
|
||||||
"revision": 5,
|
|
||||||
"version": "2.0.0",
|
|
||||||
}
|
|
||||||
|
|
||||||
with open(str(tmpdir / "project.gns3"), "w+") as f:
|
|
||||||
json.dump(topology, f)
|
|
||||||
|
|
||||||
zip_path = str(tmpdir / "project.zip")
|
|
||||||
with zipfile.ZipFile(zip_path, "w") as myzip:
|
|
||||||
myzip.write(str(tmpdir / "project.gns3"), "project.gns3")
|
|
||||||
|
|
||||||
with open(zip_path, "rb") as f:
|
|
||||||
project = await import_project(controller, project_id, f)
|
|
||||||
|
|
||||||
with open(os.path.join(project.path, "test.gns3")) as f:
|
|
||||||
topo = json.load(f)
|
|
||||||
assert topo["topology"]["nodes"][0]["compute_id"] == "vm"
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_import_iou_non_linux(windows_platform, tmpdir, controller):
|
|
||||||
"""
|
|
||||||
On non linux host IOU should be moved to the GNS3 VM
|
|
||||||
"""
|
|
||||||
|
|
||||||
project_id = str(uuid.uuid4())
|
|
||||||
controller._computes["vm"] = AsyncioMagicMock()
|
|
||||||
|
|
||||||
topology = {
|
|
||||||
"project_id": str(uuid.uuid4()),
|
|
||||||
"name": "test",
|
|
||||||
"type": "topology",
|
|
||||||
"topology": {
|
|
||||||
"nodes": [
|
|
||||||
{
|
|
||||||
"compute_id": "local",
|
|
||||||
"node_id": "0fd3dd4d-dc93-4a04-a9b9-7396a9e22e8b",
|
|
||||||
"node_type": "iou",
|
|
||||||
"name": "test",
|
|
||||||
"properties": {},
|
|
||||||
},
|
|
||||||
{"compute_id": "local", "node_type": "vpcs", "name": "test2", "properties": {}},
|
|
||||||
],
|
|
||||||
"links": [],
|
|
||||||
"computes": [],
|
|
||||||
"drawings": [],
|
|
||||||
},
|
|
||||||
"revision": 5,
|
|
||||||
"version": "2.0.0",
|
|
||||||
}
|
|
||||||
|
|
||||||
with open(str(tmpdir / "project.gns3"), "w+") as f:
|
|
||||||
json.dump(topology, f)
|
|
||||||
|
|
||||||
zip_path = str(tmpdir / "project.zip")
|
|
||||||
with zipfile.ZipFile(zip_path, "w") as myzip:
|
|
||||||
myzip.write(str(tmpdir / "project.gns3"), "project.gns3")
|
|
||||||
|
|
||||||
with open(zip_path, "rb") as f:
|
|
||||||
with asyncio_patch("gns3server.controller.import_project._move_files_to_compute") as mock:
|
|
||||||
project = await import_project(controller, project_id, f)
|
|
||||||
controller._computes["vm"].post.assert_called_with(
|
|
||||||
"/projects", data={"name": "test", "project_id": project_id}
|
|
||||||
)
|
|
||||||
|
|
||||||
with open(os.path.join(project.path, "test.gns3")) as f:
|
|
||||||
topo = json.load(f)
|
|
||||||
assert topo["topology"]["nodes"][0]["compute_id"] == "vm"
|
|
||||||
assert topo["topology"]["nodes"][1]["compute_id"] == "local"
|
|
||||||
|
|
||||||
mock.assert_called_with(
|
|
||||||
controller._computes["vm"],
|
|
||||||
project_id,
|
|
||||||
project.path,
|
|
||||||
os.path.join("project-files", "iou", topo["topology"]["nodes"][0]["node_id"]),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_import_node_id(linux_platform, tmpdir, controller):
|
|
||||||
"""
|
"""
|
||||||
When importing a node, node_id should change
|
When importing a node, node_id should change
|
||||||
"""
|
"""
|
||||||
@@ -536,52 +431,6 @@ async def test_import_node_id(linux_platform, tmpdir, controller):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_import_keep_compute_ids(windows_platform, tmpdir, controller):
|
|
||||||
"""
|
|
||||||
On linux host IOU should be moved to the GNS3 VM
|
|
||||||
"""
|
|
||||||
|
|
||||||
project_id = str(uuid.uuid4())
|
|
||||||
controller._computes["vm"] = AsyncioMagicMock()
|
|
||||||
|
|
||||||
topology = {
|
|
||||||
"project_id": str(uuid.uuid4()),
|
|
||||||
"name": "test",
|
|
||||||
"type": "topology",
|
|
||||||
"topology": {
|
|
||||||
"nodes": [
|
|
||||||
{
|
|
||||||
"compute_id": "local",
|
|
||||||
"node_id": "0fd3dd4d-dc93-4a04-a9b9-7396a9e22e8b",
|
|
||||||
"node_type": "iou",
|
|
||||||
"name": "test",
|
|
||||||
"properties": {},
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"links": [],
|
|
||||||
"computes": [],
|
|
||||||
"drawings": [],
|
|
||||||
},
|
|
||||||
"revision": 5,
|
|
||||||
"version": "2.0.0",
|
|
||||||
}
|
|
||||||
|
|
||||||
with open(str(tmpdir / "project.gns3"), "w+") as f:
|
|
||||||
json.dump(topology, f)
|
|
||||||
|
|
||||||
zip_path = str(tmpdir / "project.zip")
|
|
||||||
with zipfile.ZipFile(zip_path, "w") as myzip:
|
|
||||||
myzip.write(str(tmpdir / "project.gns3"), "project.gns3")
|
|
||||||
|
|
||||||
with open(zip_path, "rb") as f:
|
|
||||||
project = await import_project(controller, project_id, f, keep_compute_ids=True)
|
|
||||||
|
|
||||||
with open(os.path.join(project.path, "test.gns3")) as f:
|
|
||||||
topo = json.load(f)
|
|
||||||
assert topo["topology"]["nodes"][0]["compute_id"] == "local"
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_move_files_to_compute(tmpdir):
|
async def test_move_files_to_compute(tmpdir):
|
||||||
|
|
||||||
|
|||||||
+12
-15
@@ -15,7 +15,6 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -131,15 +130,14 @@ async def test_list_images(tmpdir, config):
|
|||||||
small_file = tmpdir / "images1" / "too_small.image"
|
small_file = tmpdir / "images1" / "too_small.image"
|
||||||
small_file.write(b"1", ensure=True)
|
small_file.write(b"1", ensure=True)
|
||||||
|
|
||||||
if sys.platform.startswith("linux"):
|
# 64-bit IOU image
|
||||||
# 64-bit IOU image
|
iou_image_1 = tmpdir / "images1" / "IOU" / "iou64.bin"
|
||||||
iou_image_1 = tmpdir / "images1" / "IOU" / "iou64.bin"
|
iou_image_1.write(b"\x7fELF\x02\x01\x01", ensure=True)
|
||||||
iou_image_1.write(b"\x7fELF\x02\x01\x01", ensure=True)
|
iou_image_1 = force_unix_path(str(iou_image_1))
|
||||||
iou_image_1 = force_unix_path(str(iou_image_1))
|
# 32-bit IOU image
|
||||||
# 32-bit IOU image
|
iou_image_2 = tmpdir / "images1" / "IOU" / "iou32.bin"
|
||||||
iou_image_2 = tmpdir / "images1" / "IOU" / "iou32.bin"
|
iou_image_2.write(b"\x7fELF\x01\x01\x01", ensure=True) # 32-bit IOU image
|
||||||
iou_image_2.write(b"\x7fELF\x01\x01\x01", ensure=True) # 32-bit IOU image
|
iou_image_2 = force_unix_path(str(iou_image_2))
|
||||||
iou_image_2 = force_unix_path(str(iou_image_2))
|
|
||||||
|
|
||||||
# Qemu image
|
# Qemu image
|
||||||
qemu_image_1 = tmpdir / "images1" / "QEMU" / "qemu_image.qcow2"
|
qemu_image_1 = tmpdir / "images1" / "QEMU" / "qemu_image.qcow2"
|
||||||
@@ -173,11 +171,10 @@ async def test_list_images(tmpdir, config):
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
if sys.platform.startswith("linux"):
|
assert sorted(await list_images("iou"), key=lambda k: k["filename"]) == [
|
||||||
assert sorted(await list_images("iou"), key=lambda k: k["filename"]) == [
|
{"filename": "iou32.bin", "filesize": 7, "md5sum": "e573e8f5c93c6c00783f20c7a170aa6c", "path": "iou32.bin"},
|
||||||
{"filename": "iou32.bin", "filesize": 7, "md5sum": "e573e8f5c93c6c00783f20c7a170aa6c", "path": "iou32.bin"},
|
{"filename": "iou64.bin", "filesize": 7, "md5sum": "c73626d23469519894d58bc98bee9655", "path": "iou64.bin"},
|
||||||
{"filename": "iou64.bin", "filesize": 7, "md5sum": "c73626d23469519894d58bc98bee9655", "path": "iou64.bin"},
|
]
|
||||||
]
|
|
||||||
|
|
||||||
assert await list_images("qemu") == [
|
assert await list_images("qemu") == [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
import collections
|
import collections
|
||||||
import socket
|
import socket
|
||||||
import sys
|
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
@@ -153,16 +152,10 @@ def test_interfaces_without_stats_entry(config):
|
|||||||
|
|
||||||
def test_has_netmask(config):
|
def test_has_netmask(config):
|
||||||
|
|
||||||
if sys.platform.startswith("darwin"):
|
assert has_netmask("lo") is True
|
||||||
assert has_netmask("lo0") is True
|
|
||||||
else:
|
|
||||||
assert has_netmask("lo") is True
|
|
||||||
|
|
||||||
|
|
||||||
def test_is_interface_up():
|
def test_is_interface_up():
|
||||||
|
|
||||||
if sys.platform.startswith("darwin"):
|
assert is_interface_up("lo") is True
|
||||||
assert is_interface_up("lo0") is True
|
assert is_interface_up("fake0") is False
|
||||||
else:
|
|
||||||
assert is_interface_up("lo") is True
|
|
||||||
assert is_interface_up("fake0") is False
|
|
||||||
Reference in new issue
Block a user