diff --git a/gns3server/config.py b/gns3server/config.py index 44336e71..46cbebde 100644 --- a/gns3server/config.py +++ b/gns3server/config.py @@ -16,7 +16,7 @@ # along with this program. If not, see . """ -Reads the configuration file and store the settings for the server & modules. +Reads the configuration file and store the settings for the server & hypervisor. """ import sys diff --git a/gns3server/handlers/api/controller/hypervisor_handler.py b/gns3server/handlers/api/controller/hypervisor_handler.py index 3fd681e9..452bfb38 100644 --- a/gns3server/handlers/api/controller/hypervisor_handler.py +++ b/gns3server/handlers/api/controller/hypervisor_handler.py @@ -20,7 +20,7 @@ from aiohttp.web import HTTPForbidden from ....web.route import Route from ....config import Config -from ....modules.project_manager import ProjectManager +from ....hypervisor.project_manager import ProjectManager from ....schemas.hypervisor import HYPERVISOR_CREATE_SCHEMA, HYPERVISOR_OBJECT_SCHEMA from ....controller import Controller from ....controller.hypervisor import Hypervisor diff --git a/gns3server/handlers/api/hypervisor/docker_handler.py b/gns3server/handlers/api/hypervisor/docker_handler.py index b9018107..3d449394 100644 --- a/gns3server/handlers/api/hypervisor/docker_handler.py +++ b/gns3server/handlers/api/hypervisor/docker_handler.py @@ -19,7 +19,7 @@ import os from aiohttp.web import HTTPConflict from ....web.route import Route -from ....modules.docker import Docker +from ....hypervisor.docker import Docker from ....schemas.docker import ( DOCKER_CREATE_SCHEMA, diff --git a/gns3server/handlers/api/hypervisor/dynamips_device_handler.py b/gns3server/handlers/api/hypervisor/dynamips_device_handler.py index 0fa8d2a2..41fb2e52 100644 --- a/gns3server/handlers/api/hypervisor/dynamips_device_handler.py +++ b/gns3server/handlers/api/hypervisor/dynamips_device_handler.py @@ -23,7 +23,7 @@ from ....schemas.dynamips_device import DEVICE_UPDATE_SCHEMA from ....schemas.dynamips_device import DEVICE_OBJECT_SCHEMA from ....schemas.dynamips_device import DEVICE_NIO_SCHEMA from ....schemas.vm import VM_CAPTURE_SCHEMA -from ....modules.dynamips import Dynamips +from ....hypervisor.dynamips import Dynamips class DynamipsDeviceHandler: diff --git a/gns3server/handlers/api/hypervisor/dynamips_vm_handler.py b/gns3server/handlers/api/hypervisor/dynamips_vm_handler.py index 6b643821..dd381f23 100644 --- a/gns3server/handlers/api/hypervisor/dynamips_vm_handler.py +++ b/gns3server/handlers/api/hypervisor/dynamips_vm_handler.py @@ -27,9 +27,9 @@ from ....schemas.dynamips_vm import VM_UPDATE_SCHEMA from ....schemas.dynamips_vm import VM_OBJECT_SCHEMA from ....schemas.dynamips_vm import VM_CONFIGS_SCHEMA from ....schemas.vm import VM_CAPTURE_SCHEMA -from ....modules.dynamips import Dynamips -from ....modules.dynamips.dynamips_error import DynamipsError -from ....modules.project_manager import ProjectManager +from ....hypervisor.dynamips import Dynamips +from ....hypervisor.dynamips.dynamips_error import DynamipsError +from ....hypervisor.project_manager import ProjectManager DEFAULT_CHASSIS = { "c1700": "1720", diff --git a/gns3server/handlers/api/hypervisor/iou_handler.py b/gns3server/handlers/api/hypervisor/iou_handler.py index e466e797..466054e8 100644 --- a/gns3server/handlers/api/hypervisor/iou_handler.py +++ b/gns3server/handlers/api/hypervisor/iou_handler.py @@ -27,7 +27,7 @@ from ....schemas.iou import IOU_OBJECT_SCHEMA from ....schemas.iou import IOU_CONFIGS_SCHEMA from ....schemas.vm import VM_LIST_IMAGES_SCHEMA from ....schemas.vm import VM_CAPTURE_SCHEMA -from ....modules.iou import IOU +from ....hypervisor.iou import IOU class IOUHandler: diff --git a/gns3server/handlers/api/hypervisor/network_handler.py b/gns3server/handlers/api/hypervisor/network_handler.py index 526130b3..28e90f09 100644 --- a/gns3server/handlers/api/hypervisor/network_handler.py +++ b/gns3server/handlers/api/hypervisor/network_handler.py @@ -16,8 +16,8 @@ # along with this program. If not, see . from ....web.route import Route -from ....modules.port_manager import PortManager -from ....modules.project_manager import ProjectManager +from ....hypervisor.port_manager import PortManager +from ....hypervisor.project_manager import ProjectManager from ....utils.interfaces import interfaces diff --git a/gns3server/handlers/api/hypervisor/project_handler.py b/gns3server/handlers/api/hypervisor/project_handler.py index 96dc47d7..29c6bc82 100644 --- a/gns3server/handlers/api/hypervisor/project_handler.py +++ b/gns3server/handlers/api/hypervisor/project_handler.py @@ -23,8 +23,8 @@ import psutil from ....web.route import Route from ....schemas.project import PROJECT_OBJECT_SCHEMA, PROJECT_CREATE_SCHEMA, PROJECT_UPDATE_SCHEMA, PROJECT_FILE_LIST_SCHEMA, PROJECT_LIST_SCHEMA -from ....modules.project_manager import ProjectManager -from ....modules import MODULES +from ....hypervisor.project_manager import ProjectManager +from ....hypervisor import MODULES import logging log = logging.getLogger() diff --git a/gns3server/handlers/api/hypervisor/qemu_handler.py b/gns3server/handlers/api/hypervisor/qemu_handler.py index aa1b7c08..370826d0 100644 --- a/gns3server/handlers/api/hypervisor/qemu_handler.py +++ b/gns3server/handlers/api/hypervisor/qemu_handler.py @@ -20,7 +20,7 @@ import os.path from aiohttp.web import HTTPConflict from ....web.route import Route -from ....modules.project_manager import ProjectManager +from ....hypervisor.project_manager import ProjectManager from ....schemas.nio import NIO_SCHEMA from ....schemas.qemu import QEMU_CREATE_SCHEMA from ....schemas.qemu import QEMU_UPDATE_SCHEMA @@ -30,7 +30,7 @@ from ....schemas.qemu import QEMU_BINARY_LIST_SCHEMA from ....schemas.qemu import QEMU_CAPABILITY_LIST_SCHEMA from ....schemas.qemu import QEMU_IMAGE_CREATE_SCHEMA from ....schemas.vm import VM_LIST_IMAGES_SCHEMA -from ....modules.qemu import Qemu +from ....hypervisor.qemu import Qemu from ....config import Config diff --git a/gns3server/handlers/api/hypervisor/virtualbox_handler.py b/gns3server/handlers/api/hypervisor/virtualbox_handler.py index 3368f158..7065a20a 100644 --- a/gns3server/handlers/api/hypervisor/virtualbox_handler.py +++ b/gns3server/handlers/api/hypervisor/virtualbox_handler.py @@ -24,8 +24,8 @@ from ....schemas.virtualbox import VBOX_CREATE_SCHEMA from ....schemas.virtualbox import VBOX_UPDATE_SCHEMA from ....schemas.virtualbox import VBOX_OBJECT_SCHEMA from ....schemas.vm import VM_CAPTURE_SCHEMA -from ....modules.virtualbox import VirtualBox -from ....modules.project_manager import ProjectManager +from ....hypervisor.virtualbox import VirtualBox +from ....hypervisor.project_manager import ProjectManager class VirtualBoxHandler: diff --git a/gns3server/handlers/api/hypervisor/vmware_handler.py b/gns3server/handlers/api/hypervisor/vmware_handler.py index 0dd35305..faecf764 100644 --- a/gns3server/handlers/api/hypervisor/vmware_handler.py +++ b/gns3server/handlers/api/hypervisor/vmware_handler.py @@ -24,8 +24,8 @@ from ....schemas.vmware import VMWARE_UPDATE_SCHEMA from ....schemas.vmware import VMWARE_OBJECT_SCHEMA from ....schemas.vm import VM_CAPTURE_SCHEMA from ....schemas.nio import NIO_SCHEMA -from ....modules.vmware import VMware -from ....modules.project_manager import ProjectManager +from ....hypervisor.vmware import VMware +from ....hypervisor.project_manager import ProjectManager class VMwareHandler: diff --git a/gns3server/handlers/api/hypervisor/vpcs_handler.py b/gns3server/handlers/api/hypervisor/vpcs_handler.py index 4a172f08..c3256cb5 100644 --- a/gns3server/handlers/api/hypervisor/vpcs_handler.py +++ b/gns3server/handlers/api/hypervisor/vpcs_handler.py @@ -21,7 +21,7 @@ from ....schemas.nio import NIO_SCHEMA from ....schemas.vpcs import VPCS_CREATE_SCHEMA from ....schemas.vpcs import VPCS_UPDATE_SCHEMA from ....schemas.vpcs import VPCS_OBJECT_SCHEMA -from ....modules.vpcs import VPCS +from ....hypervisor.vpcs import VPCS class VPCSHandler: diff --git a/gns3server/handlers/index_handler.py b/gns3server/handlers/index_handler.py index 4ab3f4e9..18b1696a 100644 --- a/gns3server/handlers/index_handler.py +++ b/gns3server/handlers/index_handler.py @@ -16,8 +16,8 @@ from ..web.route import Route -from ..modules.port_manager import PortManager -from ..modules.project_manager import ProjectManager +from ..hypervisor.port_manager import PortManager +from ..hypervisor.project_manager import ProjectManager from ..version import __version__ diff --git a/gns3server/modules/__init__.py b/gns3server/hypervisor/__init__.py similarity index 100% rename from gns3server/modules/__init__.py rename to gns3server/hypervisor/__init__.py diff --git a/gns3server/modules/adapters/__init__.py b/gns3server/hypervisor/adapters/__init__.py similarity index 100% rename from gns3server/modules/adapters/__init__.py rename to gns3server/hypervisor/adapters/__init__.py diff --git a/gns3server/modules/adapters/adapter.py b/gns3server/hypervisor/adapters/adapter.py similarity index 100% rename from gns3server/modules/adapters/adapter.py rename to gns3server/hypervisor/adapters/adapter.py diff --git a/gns3server/modules/adapters/ethernet_adapter.py b/gns3server/hypervisor/adapters/ethernet_adapter.py similarity index 100% rename from gns3server/modules/adapters/ethernet_adapter.py rename to gns3server/hypervisor/adapters/ethernet_adapter.py diff --git a/gns3server/modules/adapters/serial_adapter.py b/gns3server/hypervisor/adapters/serial_adapter.py similarity index 100% rename from gns3server/modules/adapters/serial_adapter.py rename to gns3server/hypervisor/adapters/serial_adapter.py diff --git a/gns3server/modules/base_manager.py b/gns3server/hypervisor/base_manager.py similarity index 100% rename from gns3server/modules/base_manager.py rename to gns3server/hypervisor/base_manager.py diff --git a/gns3server/modules/base_vm.py b/gns3server/hypervisor/base_vm.py similarity index 100% rename from gns3server/modules/base_vm.py rename to gns3server/hypervisor/base_vm.py diff --git a/gns3server/modules/docker/__init__.py b/gns3server/hypervisor/docker/__init__.py similarity index 100% rename from gns3server/modules/docker/__init__.py rename to gns3server/hypervisor/docker/__init__.py diff --git a/gns3server/modules/docker/docker_error.py b/gns3server/hypervisor/docker/docker_error.py similarity index 100% rename from gns3server/modules/docker/docker_error.py rename to gns3server/hypervisor/docker/docker_error.py diff --git a/gns3server/modules/docker/docker_vm.py b/gns3server/hypervisor/docker/docker_vm.py similarity index 99% rename from gns3server/modules/docker/docker_vm.py rename to gns3server/hypervisor/docker/docker_vm.py index 55fc04d5..e1e928ce 100644 --- a/gns3server/modules/docker/docker_vm.py +++ b/gns3server/hypervisor/docker/docker_vm.py @@ -157,7 +157,7 @@ class DockerVM(BaseVM): """ binds = [] - binds.append("{}:/gns3:ro".format(get_resource("modules/docker/resources"))) + binds.append("{}:/gns3:ro".format(get_resource("hypervisor/docker/resources"))) volumes = image_infos.get("ContainerConfig", {}).get("Volumes") if volumes is None: diff --git a/gns3server/modules/docker/resources/init.sh b/gns3server/hypervisor/docker/resources/init.sh similarity index 100% rename from gns3server/modules/docker/resources/init.sh rename to gns3server/hypervisor/docker/resources/init.sh diff --git a/gns3server/modules/dynamips/__init__.py b/gns3server/hypervisor/dynamips/__init__.py similarity index 100% rename from gns3server/modules/dynamips/__init__.py rename to gns3server/hypervisor/dynamips/__init__.py diff --git a/gns3server/modules/dynamips/adapters/__init__.py b/gns3server/hypervisor/dynamips/adapters/__init__.py similarity index 100% rename from gns3server/modules/dynamips/adapters/__init__.py rename to gns3server/hypervisor/dynamips/adapters/__init__.py diff --git a/gns3server/modules/dynamips/adapters/adapter.py b/gns3server/hypervisor/dynamips/adapters/adapter.py similarity index 100% rename from gns3server/modules/dynamips/adapters/adapter.py rename to gns3server/hypervisor/dynamips/adapters/adapter.py diff --git a/gns3server/modules/dynamips/adapters/c1700_mb_1fe.py b/gns3server/hypervisor/dynamips/adapters/c1700_mb_1fe.py similarity index 100% rename from gns3server/modules/dynamips/adapters/c1700_mb_1fe.py rename to gns3server/hypervisor/dynamips/adapters/c1700_mb_1fe.py diff --git a/gns3server/modules/dynamips/adapters/c1700_mb_wic1.py b/gns3server/hypervisor/dynamips/adapters/c1700_mb_wic1.py similarity index 100% rename from gns3server/modules/dynamips/adapters/c1700_mb_wic1.py rename to gns3server/hypervisor/dynamips/adapters/c1700_mb_wic1.py diff --git a/gns3server/modules/dynamips/adapters/c2600_mb_1e.py b/gns3server/hypervisor/dynamips/adapters/c2600_mb_1e.py similarity index 100% rename from gns3server/modules/dynamips/adapters/c2600_mb_1e.py rename to gns3server/hypervisor/dynamips/adapters/c2600_mb_1e.py diff --git a/gns3server/modules/dynamips/adapters/c2600_mb_1fe.py b/gns3server/hypervisor/dynamips/adapters/c2600_mb_1fe.py similarity index 100% rename from gns3server/modules/dynamips/adapters/c2600_mb_1fe.py rename to gns3server/hypervisor/dynamips/adapters/c2600_mb_1fe.py diff --git a/gns3server/modules/dynamips/adapters/c2600_mb_2e.py b/gns3server/hypervisor/dynamips/adapters/c2600_mb_2e.py similarity index 100% rename from gns3server/modules/dynamips/adapters/c2600_mb_2e.py rename to gns3server/hypervisor/dynamips/adapters/c2600_mb_2e.py diff --git a/gns3server/modules/dynamips/adapters/c2600_mb_2fe.py b/gns3server/hypervisor/dynamips/adapters/c2600_mb_2fe.py similarity index 100% rename from gns3server/modules/dynamips/adapters/c2600_mb_2fe.py rename to gns3server/hypervisor/dynamips/adapters/c2600_mb_2fe.py diff --git a/gns3server/modules/dynamips/adapters/c7200_io_2fe.py b/gns3server/hypervisor/dynamips/adapters/c7200_io_2fe.py similarity index 100% rename from gns3server/modules/dynamips/adapters/c7200_io_2fe.py rename to gns3server/hypervisor/dynamips/adapters/c7200_io_2fe.py diff --git a/gns3server/modules/dynamips/adapters/c7200_io_fe.py b/gns3server/hypervisor/dynamips/adapters/c7200_io_fe.py similarity index 100% rename from gns3server/modules/dynamips/adapters/c7200_io_fe.py rename to gns3server/hypervisor/dynamips/adapters/c7200_io_fe.py diff --git a/gns3server/modules/dynamips/adapters/c7200_io_ge_e.py b/gns3server/hypervisor/dynamips/adapters/c7200_io_ge_e.py similarity index 100% rename from gns3server/modules/dynamips/adapters/c7200_io_ge_e.py rename to gns3server/hypervisor/dynamips/adapters/c7200_io_ge_e.py diff --git a/gns3server/modules/dynamips/adapters/gt96100_fe.py b/gns3server/hypervisor/dynamips/adapters/gt96100_fe.py similarity index 100% rename from gns3server/modules/dynamips/adapters/gt96100_fe.py rename to gns3server/hypervisor/dynamips/adapters/gt96100_fe.py diff --git a/gns3server/modules/dynamips/adapters/leopard_2fe.py b/gns3server/hypervisor/dynamips/adapters/leopard_2fe.py similarity index 100% rename from gns3server/modules/dynamips/adapters/leopard_2fe.py rename to gns3server/hypervisor/dynamips/adapters/leopard_2fe.py diff --git a/gns3server/modules/dynamips/adapters/nm_16esw.py b/gns3server/hypervisor/dynamips/adapters/nm_16esw.py similarity index 100% rename from gns3server/modules/dynamips/adapters/nm_16esw.py rename to gns3server/hypervisor/dynamips/adapters/nm_16esw.py diff --git a/gns3server/modules/dynamips/adapters/nm_1e.py b/gns3server/hypervisor/dynamips/adapters/nm_1e.py similarity index 100% rename from gns3server/modules/dynamips/adapters/nm_1e.py rename to gns3server/hypervisor/dynamips/adapters/nm_1e.py diff --git a/gns3server/modules/dynamips/adapters/nm_1fe_tx.py b/gns3server/hypervisor/dynamips/adapters/nm_1fe_tx.py similarity index 100% rename from gns3server/modules/dynamips/adapters/nm_1fe_tx.py rename to gns3server/hypervisor/dynamips/adapters/nm_1fe_tx.py diff --git a/gns3server/modules/dynamips/adapters/nm_4e.py b/gns3server/hypervisor/dynamips/adapters/nm_4e.py similarity index 100% rename from gns3server/modules/dynamips/adapters/nm_4e.py rename to gns3server/hypervisor/dynamips/adapters/nm_4e.py diff --git a/gns3server/modules/dynamips/adapters/nm_4t.py b/gns3server/hypervisor/dynamips/adapters/nm_4t.py similarity index 100% rename from gns3server/modules/dynamips/adapters/nm_4t.py rename to gns3server/hypervisor/dynamips/adapters/nm_4t.py diff --git a/gns3server/modules/dynamips/adapters/pa_2fe_tx.py b/gns3server/hypervisor/dynamips/adapters/pa_2fe_tx.py similarity index 100% rename from gns3server/modules/dynamips/adapters/pa_2fe_tx.py rename to gns3server/hypervisor/dynamips/adapters/pa_2fe_tx.py diff --git a/gns3server/modules/dynamips/adapters/pa_4e.py b/gns3server/hypervisor/dynamips/adapters/pa_4e.py similarity index 100% rename from gns3server/modules/dynamips/adapters/pa_4e.py rename to gns3server/hypervisor/dynamips/adapters/pa_4e.py diff --git a/gns3server/modules/dynamips/adapters/pa_4t.py b/gns3server/hypervisor/dynamips/adapters/pa_4t.py similarity index 100% rename from gns3server/modules/dynamips/adapters/pa_4t.py rename to gns3server/hypervisor/dynamips/adapters/pa_4t.py diff --git a/gns3server/modules/dynamips/adapters/pa_8e.py b/gns3server/hypervisor/dynamips/adapters/pa_8e.py similarity index 100% rename from gns3server/modules/dynamips/adapters/pa_8e.py rename to gns3server/hypervisor/dynamips/adapters/pa_8e.py diff --git a/gns3server/modules/dynamips/adapters/pa_8t.py b/gns3server/hypervisor/dynamips/adapters/pa_8t.py similarity index 100% rename from gns3server/modules/dynamips/adapters/pa_8t.py rename to gns3server/hypervisor/dynamips/adapters/pa_8t.py diff --git a/gns3server/modules/dynamips/adapters/pa_a1.py b/gns3server/hypervisor/dynamips/adapters/pa_a1.py similarity index 100% rename from gns3server/modules/dynamips/adapters/pa_a1.py rename to gns3server/hypervisor/dynamips/adapters/pa_a1.py diff --git a/gns3server/modules/dynamips/adapters/pa_fe_tx.py b/gns3server/hypervisor/dynamips/adapters/pa_fe_tx.py similarity index 100% rename from gns3server/modules/dynamips/adapters/pa_fe_tx.py rename to gns3server/hypervisor/dynamips/adapters/pa_fe_tx.py diff --git a/gns3server/modules/dynamips/adapters/pa_ge.py b/gns3server/hypervisor/dynamips/adapters/pa_ge.py similarity index 100% rename from gns3server/modules/dynamips/adapters/pa_ge.py rename to gns3server/hypervisor/dynamips/adapters/pa_ge.py diff --git a/gns3server/modules/dynamips/adapters/pa_pos_oc3.py b/gns3server/hypervisor/dynamips/adapters/pa_pos_oc3.py similarity index 100% rename from gns3server/modules/dynamips/adapters/pa_pos_oc3.py rename to gns3server/hypervisor/dynamips/adapters/pa_pos_oc3.py diff --git a/gns3server/modules/dynamips/adapters/wic_1enet.py b/gns3server/hypervisor/dynamips/adapters/wic_1enet.py similarity index 100% rename from gns3server/modules/dynamips/adapters/wic_1enet.py rename to gns3server/hypervisor/dynamips/adapters/wic_1enet.py diff --git a/gns3server/modules/dynamips/adapters/wic_1t.py b/gns3server/hypervisor/dynamips/adapters/wic_1t.py similarity index 100% rename from gns3server/modules/dynamips/adapters/wic_1t.py rename to gns3server/hypervisor/dynamips/adapters/wic_1t.py diff --git a/gns3server/modules/dynamips/adapters/wic_2t.py b/gns3server/hypervisor/dynamips/adapters/wic_2t.py similarity index 100% rename from gns3server/modules/dynamips/adapters/wic_2t.py rename to gns3server/hypervisor/dynamips/adapters/wic_2t.py diff --git a/gns3server/modules/dynamips/dynamips_device.py b/gns3server/hypervisor/dynamips/dynamips_device.py similarity index 100% rename from gns3server/modules/dynamips/dynamips_device.py rename to gns3server/hypervisor/dynamips/dynamips_device.py diff --git a/gns3server/modules/dynamips/dynamips_error.py b/gns3server/hypervisor/dynamips/dynamips_error.py similarity index 100% rename from gns3server/modules/dynamips/dynamips_error.py rename to gns3server/hypervisor/dynamips/dynamips_error.py diff --git a/gns3server/modules/dynamips/dynamips_hypervisor.py b/gns3server/hypervisor/dynamips/dynamips_hypervisor.py similarity index 100% rename from gns3server/modules/dynamips/dynamips_hypervisor.py rename to gns3server/hypervisor/dynamips/dynamips_hypervisor.py diff --git a/gns3server/modules/dynamips/dynamips_vm.py b/gns3server/hypervisor/dynamips/dynamips_vm.py similarity index 100% rename from gns3server/modules/dynamips/dynamips_vm.py rename to gns3server/hypervisor/dynamips/dynamips_vm.py diff --git a/gns3server/modules/dynamips/hypervisor.py b/gns3server/hypervisor/dynamips/hypervisor.py similarity index 100% rename from gns3server/modules/dynamips/hypervisor.py rename to gns3server/hypervisor/dynamips/hypervisor.py diff --git a/gns3server/modules/dynamips/nios/__init__.py b/gns3server/hypervisor/dynamips/nios/__init__.py similarity index 100% rename from gns3server/modules/dynamips/nios/__init__.py rename to gns3server/hypervisor/dynamips/nios/__init__.py diff --git a/gns3server/modules/dynamips/nios/nio.py b/gns3server/hypervisor/dynamips/nios/nio.py similarity index 100% rename from gns3server/modules/dynamips/nios/nio.py rename to gns3server/hypervisor/dynamips/nios/nio.py diff --git a/gns3server/modules/dynamips/nios/nio_generic_ethernet.py b/gns3server/hypervisor/dynamips/nios/nio_generic_ethernet.py similarity index 100% rename from gns3server/modules/dynamips/nios/nio_generic_ethernet.py rename to gns3server/hypervisor/dynamips/nios/nio_generic_ethernet.py diff --git a/gns3server/modules/dynamips/nios/nio_linux_ethernet.py b/gns3server/hypervisor/dynamips/nios/nio_linux_ethernet.py similarity index 100% rename from gns3server/modules/dynamips/nios/nio_linux_ethernet.py rename to gns3server/hypervisor/dynamips/nios/nio_linux_ethernet.py diff --git a/gns3server/modules/dynamips/nios/nio_null.py b/gns3server/hypervisor/dynamips/nios/nio_null.py similarity index 100% rename from gns3server/modules/dynamips/nios/nio_null.py rename to gns3server/hypervisor/dynamips/nios/nio_null.py diff --git a/gns3server/modules/dynamips/nios/nio_tap.py b/gns3server/hypervisor/dynamips/nios/nio_tap.py similarity index 100% rename from gns3server/modules/dynamips/nios/nio_tap.py rename to gns3server/hypervisor/dynamips/nios/nio_tap.py diff --git a/gns3server/modules/dynamips/nios/nio_udp.py b/gns3server/hypervisor/dynamips/nios/nio_udp.py similarity index 100% rename from gns3server/modules/dynamips/nios/nio_udp.py rename to gns3server/hypervisor/dynamips/nios/nio_udp.py diff --git a/gns3server/modules/dynamips/nios/nio_unix.py b/gns3server/hypervisor/dynamips/nios/nio_unix.py similarity index 100% rename from gns3server/modules/dynamips/nios/nio_unix.py rename to gns3server/hypervisor/dynamips/nios/nio_unix.py diff --git a/gns3server/modules/dynamips/nios/nio_vde.py b/gns3server/hypervisor/dynamips/nios/nio_vde.py similarity index 100% rename from gns3server/modules/dynamips/nios/nio_vde.py rename to gns3server/hypervisor/dynamips/nios/nio_vde.py diff --git a/gns3server/modules/dynamips/nodes/__init__.py b/gns3server/hypervisor/dynamips/nodes/__init__.py similarity index 100% rename from gns3server/modules/dynamips/nodes/__init__.py rename to gns3server/hypervisor/dynamips/nodes/__init__.py diff --git a/gns3server/modules/dynamips/nodes/atm_switch.py b/gns3server/hypervisor/dynamips/nodes/atm_switch.py similarity index 100% rename from gns3server/modules/dynamips/nodes/atm_switch.py rename to gns3server/hypervisor/dynamips/nodes/atm_switch.py diff --git a/gns3server/modules/dynamips/nodes/bridge.py b/gns3server/hypervisor/dynamips/nodes/bridge.py similarity index 100% rename from gns3server/modules/dynamips/nodes/bridge.py rename to gns3server/hypervisor/dynamips/nodes/bridge.py diff --git a/gns3server/modules/dynamips/nodes/c1700.py b/gns3server/hypervisor/dynamips/nodes/c1700.py similarity index 100% rename from gns3server/modules/dynamips/nodes/c1700.py rename to gns3server/hypervisor/dynamips/nodes/c1700.py diff --git a/gns3server/modules/dynamips/nodes/c2600.py b/gns3server/hypervisor/dynamips/nodes/c2600.py similarity index 100% rename from gns3server/modules/dynamips/nodes/c2600.py rename to gns3server/hypervisor/dynamips/nodes/c2600.py diff --git a/gns3server/modules/dynamips/nodes/c2691.py b/gns3server/hypervisor/dynamips/nodes/c2691.py similarity index 100% rename from gns3server/modules/dynamips/nodes/c2691.py rename to gns3server/hypervisor/dynamips/nodes/c2691.py diff --git a/gns3server/modules/dynamips/nodes/c3600.py b/gns3server/hypervisor/dynamips/nodes/c3600.py similarity index 100% rename from gns3server/modules/dynamips/nodes/c3600.py rename to gns3server/hypervisor/dynamips/nodes/c3600.py diff --git a/gns3server/modules/dynamips/nodes/c3725.py b/gns3server/hypervisor/dynamips/nodes/c3725.py similarity index 100% rename from gns3server/modules/dynamips/nodes/c3725.py rename to gns3server/hypervisor/dynamips/nodes/c3725.py diff --git a/gns3server/modules/dynamips/nodes/c3745.py b/gns3server/hypervisor/dynamips/nodes/c3745.py similarity index 100% rename from gns3server/modules/dynamips/nodes/c3745.py rename to gns3server/hypervisor/dynamips/nodes/c3745.py diff --git a/gns3server/modules/dynamips/nodes/c7200.py b/gns3server/hypervisor/dynamips/nodes/c7200.py similarity index 100% rename from gns3server/modules/dynamips/nodes/c7200.py rename to gns3server/hypervisor/dynamips/nodes/c7200.py diff --git a/gns3server/modules/dynamips/nodes/device.py b/gns3server/hypervisor/dynamips/nodes/device.py similarity index 100% rename from gns3server/modules/dynamips/nodes/device.py rename to gns3server/hypervisor/dynamips/nodes/device.py diff --git a/gns3server/modules/dynamips/nodes/ethernet_hub.py b/gns3server/hypervisor/dynamips/nodes/ethernet_hub.py similarity index 100% rename from gns3server/modules/dynamips/nodes/ethernet_hub.py rename to gns3server/hypervisor/dynamips/nodes/ethernet_hub.py diff --git a/gns3server/modules/dynamips/nodes/ethernet_switch.py b/gns3server/hypervisor/dynamips/nodes/ethernet_switch.py similarity index 100% rename from gns3server/modules/dynamips/nodes/ethernet_switch.py rename to gns3server/hypervisor/dynamips/nodes/ethernet_switch.py diff --git a/gns3server/modules/dynamips/nodes/frame_relay_switch.py b/gns3server/hypervisor/dynamips/nodes/frame_relay_switch.py similarity index 100% rename from gns3server/modules/dynamips/nodes/frame_relay_switch.py rename to gns3server/hypervisor/dynamips/nodes/frame_relay_switch.py diff --git a/gns3server/modules/dynamips/nodes/router.py b/gns3server/hypervisor/dynamips/nodes/router.py similarity index 100% rename from gns3server/modules/dynamips/nodes/router.py rename to gns3server/hypervisor/dynamips/nodes/router.py diff --git a/gns3server/modules/iou/__init__.py b/gns3server/hypervisor/iou/__init__.py similarity index 100% rename from gns3server/modules/iou/__init__.py rename to gns3server/hypervisor/iou/__init__.py diff --git a/gns3server/modules/iou/iou_error.py b/gns3server/hypervisor/iou/iou_error.py similarity index 100% rename from gns3server/modules/iou/iou_error.py rename to gns3server/hypervisor/iou/iou_error.py diff --git a/gns3server/modules/iou/iou_vm.py b/gns3server/hypervisor/iou/iou_vm.py similarity index 100% rename from gns3server/modules/iou/iou_vm.py rename to gns3server/hypervisor/iou/iou_vm.py diff --git a/gns3server/modules/iou/ioucon.py b/gns3server/hypervisor/iou/ioucon.py similarity index 100% rename from gns3server/modules/iou/ioucon.py rename to gns3server/hypervisor/iou/ioucon.py diff --git a/gns3server/modules/iou/utils/__init__.py b/gns3server/hypervisor/iou/utils/__init__.py similarity index 100% rename from gns3server/modules/iou/utils/__init__.py rename to gns3server/hypervisor/iou/utils/__init__.py diff --git a/gns3server/modules/iou/utils/iou_export.py b/gns3server/hypervisor/iou/utils/iou_export.py similarity index 100% rename from gns3server/modules/iou/utils/iou_export.py rename to gns3server/hypervisor/iou/utils/iou_export.py diff --git a/gns3server/modules/iou/utils/iou_import.py b/gns3server/hypervisor/iou/utils/iou_import.py similarity index 100% rename from gns3server/modules/iou/utils/iou_import.py rename to gns3server/hypervisor/iou/utils/iou_import.py diff --git a/gns3server/modules/nios/__init__.py b/gns3server/hypervisor/nios/__init__.py similarity index 100% rename from gns3server/modules/nios/__init__.py rename to gns3server/hypervisor/nios/__init__.py diff --git a/gns3server/modules/nios/nio.py b/gns3server/hypervisor/nios/nio.py similarity index 100% rename from gns3server/modules/nios/nio.py rename to gns3server/hypervisor/nios/nio.py diff --git a/gns3server/modules/nios/nio_generic_ethernet.py b/gns3server/hypervisor/nios/nio_generic_ethernet.py similarity index 100% rename from gns3server/modules/nios/nio_generic_ethernet.py rename to gns3server/hypervisor/nios/nio_generic_ethernet.py diff --git a/gns3server/modules/nios/nio_nat.py b/gns3server/hypervisor/nios/nio_nat.py similarity index 100% rename from gns3server/modules/nios/nio_nat.py rename to gns3server/hypervisor/nios/nio_nat.py diff --git a/gns3server/modules/nios/nio_tap.py b/gns3server/hypervisor/nios/nio_tap.py similarity index 100% rename from gns3server/modules/nios/nio_tap.py rename to gns3server/hypervisor/nios/nio_tap.py diff --git a/gns3server/modules/nios/nio_udp.py b/gns3server/hypervisor/nios/nio_udp.py similarity index 100% rename from gns3server/modules/nios/nio_udp.py rename to gns3server/hypervisor/nios/nio_udp.py diff --git a/gns3server/modules/port_manager.py b/gns3server/hypervisor/port_manager.py similarity index 100% rename from gns3server/modules/port_manager.py rename to gns3server/hypervisor/port_manager.py diff --git a/gns3server/modules/project.py b/gns3server/hypervisor/project.py similarity index 97% rename from gns3server/modules/project.py rename to gns3server/hypervisor/project.py index 8682490b..2b6dfea8 100644 --- a/gns3server/modules/project.py +++ b/gns3server/hypervisor/project.py @@ -152,7 +152,7 @@ class Project: @asyncio.coroutine def clean_old_path(self, old_path): """ - Called after a project location change. All the modules should + Called after a project location change. All the hypervisor should have been notified before """ if self._temporary: @@ -343,10 +343,10 @@ class Project: Closes the project, but keep information on disk """ - for module in self.modules(): + for module in self.hypervisor(): yield from module.instance().project_closing(self) yield from self._close_and_clean(self._temporary) - for module in self.modules(): + for module in self.hypervisor(): yield from module.instance().project_closed(self) @asyncio.coroutine @@ -400,7 +400,7 @@ class Project: vm = self._vms_to_destroy.pop() yield from vm.delete() self.remove_vm(vm) - for module in self.modules(): + for module in self.hypervisor(): yield from module.instance().project_committed(self) @asyncio.coroutine @@ -409,10 +409,10 @@ class Project: Removes project from disk """ - for module in self.modules(): + for module in self.hypervisor(): yield from module.instance().project_closing(self) yield from self._close_and_clean(True) - for module in self.modules(): + for module in self.hypervisor(): yield from module.instance().project_closed(self) @classmethod @@ -430,13 +430,13 @@ class Project: log.warning("Purge old temporary project {}".format(project)) shutil.rmtree(path) - def modules(self): + def hypervisor(self): """ - Returns all loaded VM modules. + Returns all loaded VM hypervisor. """ # We import it at the last time to avoid circular dependencies - from ..modules import MODULES + from ..hypervisor import MODULES return MODULES def emit(self, action, event): diff --git a/gns3server/modules/project_manager.py b/gns3server/hypervisor/project_manager.py similarity index 100% rename from gns3server/modules/project_manager.py rename to gns3server/hypervisor/project_manager.py diff --git a/gns3server/modules/qemu/__init__.py b/gns3server/hypervisor/qemu/__init__.py similarity index 100% rename from gns3server/modules/qemu/__init__.py rename to gns3server/hypervisor/qemu/__init__.py diff --git a/gns3server/modules/qemu/qemu_error.py b/gns3server/hypervisor/qemu/qemu_error.py similarity index 100% rename from gns3server/modules/qemu/qemu_error.py rename to gns3server/hypervisor/qemu/qemu_error.py diff --git a/gns3server/modules/qemu/qemu_vm.py b/gns3server/hypervisor/qemu/qemu_vm.py similarity index 100% rename from gns3server/modules/qemu/qemu_vm.py rename to gns3server/hypervisor/qemu/qemu_vm.py diff --git a/gns3server/modules/virtualbox/__init__.py b/gns3server/hypervisor/virtualbox/__init__.py similarity index 100% rename from gns3server/modules/virtualbox/__init__.py rename to gns3server/hypervisor/virtualbox/__init__.py diff --git a/gns3server/modules/virtualbox/virtualbox_error.py b/gns3server/hypervisor/virtualbox/virtualbox_error.py similarity index 100% rename from gns3server/modules/virtualbox/virtualbox_error.py rename to gns3server/hypervisor/virtualbox/virtualbox_error.py diff --git a/gns3server/modules/virtualbox/virtualbox_vm.py b/gns3server/hypervisor/virtualbox/virtualbox_vm.py similarity index 100% rename from gns3server/modules/virtualbox/virtualbox_vm.py rename to gns3server/hypervisor/virtualbox/virtualbox_vm.py diff --git a/gns3server/modules/vm_error.py b/gns3server/hypervisor/vm_error.py similarity index 100% rename from gns3server/modules/vm_error.py rename to gns3server/hypervisor/vm_error.py diff --git a/gns3server/modules/vmware/__init__.py b/gns3server/hypervisor/vmware/__init__.py similarity index 100% rename from gns3server/modules/vmware/__init__.py rename to gns3server/hypervisor/vmware/__init__.py diff --git a/gns3server/modules/vmware/nio_vmnet.py b/gns3server/hypervisor/vmware/nio_vmnet.py similarity index 100% rename from gns3server/modules/vmware/nio_vmnet.py rename to gns3server/hypervisor/vmware/nio_vmnet.py diff --git a/gns3server/modules/vmware/vmware_error.py b/gns3server/hypervisor/vmware/vmware_error.py similarity index 100% rename from gns3server/modules/vmware/vmware_error.py rename to gns3server/hypervisor/vmware/vmware_error.py diff --git a/gns3server/modules/vmware/vmware_vm.py b/gns3server/hypervisor/vmware/vmware_vm.py similarity index 100% rename from gns3server/modules/vmware/vmware_vm.py rename to gns3server/hypervisor/vmware/vmware_vm.py diff --git a/gns3server/modules/vpcs/__init__.py b/gns3server/hypervisor/vpcs/__init__.py similarity index 100% rename from gns3server/modules/vpcs/__init__.py rename to gns3server/hypervisor/vpcs/__init__.py diff --git a/gns3server/modules/vpcs/vpcs_error.py b/gns3server/hypervisor/vpcs/vpcs_error.py similarity index 100% rename from gns3server/modules/vpcs/vpcs_error.py rename to gns3server/hypervisor/vpcs/vpcs_error.py diff --git a/gns3server/modules/vpcs/vpcs_vm.py b/gns3server/hypervisor/vpcs/vpcs_vm.py similarity index 100% rename from gns3server/modules/vpcs/vpcs_vm.py rename to gns3server/hypervisor/vpcs/vpcs_vm.py diff --git a/gns3server/main.py b/gns3server/main.py index fc8e4d3f..85a72dec 100644 --- a/gns3server/main.py +++ b/gns3server/main.py @@ -21,7 +21,7 @@ Entry point of the server. It's support daemonize the process """ # WARNING -# Due to buggy user machines we choose to put this as the first loading modules +# Due to buggy user machines we choose to put this as the first loading hypervisor # otherwise the egg cache is initialized in his standard location and # if is not writetable the application crash. It's the user fault # because one day the user as used sudo to run an egg and break his diff --git a/gns3server/run.py b/gns3server/run.py index 1c140b01..c71a17b9 100644 --- a/gns3server/run.py +++ b/gns3server/run.py @@ -32,7 +32,7 @@ from gns3server.web.web_server import WebServer from gns3server.web.logger import init_logger from gns3server.version import __version__ from gns3server.config import Config -from gns3server.modules.project import Project +from gns3server.hypervisor.project import Project from gns3server.crash_report import CrashReport import logging diff --git a/gns3server/web/route.py b/gns3server/web/route.py index da2f31c1..5b2db39c 100644 --- a/gns3server/web/route.py +++ b/gns3server/web/route.py @@ -25,7 +25,7 @@ import traceback log = logging.getLogger(__name__) -from ..modules.vm_error import VMError +from ..hypervisor.vm_error import VMError from ..controller.controller_error import ControllerError from ..ubridge.ubridge_error import UbridgeError from .response import Response diff --git a/gns3server/web/web_server.py b/gns3server/web/web_server.py index 88188f1c..ab921f37 100644 --- a/gns3server/web/web_server.py +++ b/gns3server/web/web_server.py @@ -32,8 +32,8 @@ import atexit from .route import Route from .request_handler import RequestHandler from ..config import Config -from ..modules import MODULES -from ..modules.port_manager import PortManager +from ..hypervisor import MODULES +from ..hypervisor.port_manager import PortManager # do not delete this import import gns3server.handlers @@ -134,8 +134,8 @@ class WebServer: os.execv(sys.executable, [sys.executable] + sys.argv) # code extracted from tornado - for module in sys.modules.values(): - # Some modules play games with sys.modules (e.g. email/__init__.py + for module in sys.hypervisor.values(): + # Some hypervisor play games with sys.hypervisor (e.g. email/__init__.py # in the standard library), and occasionally this can cause strange # failures in getattr. Just ignore anything that's not an ordinary # module. diff --git a/tests/conftest.py b/tests/conftest.py index 0c26fa6a..90f437f2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -37,9 +37,9 @@ from gns3server.config import Config from gns3server.web.route import Route # TODO: get rid of * from gns3server.handlers import * -from gns3server.modules import MODULES -from gns3server.modules.port_manager import PortManager -from gns3server.modules.project_manager import ProjectManager +from gns3server.hypervisor import MODULES +from gns3server.hypervisor.port_manager import PortManager +from gns3server.hypervisor.project_manager import ProjectManager from gns3server.controller import Controller from tests.handlers.api.base import Query @@ -96,7 +96,7 @@ def http_server(request, loop, port_manager, monkeypatch): def tear_down(): for module in MODULES: instance = module.instance() - monkeypatch.setattr('gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.close', lambda self: True) + monkeypatch.setattr('gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.close', lambda self: True) loop.run_until_complete(instance.unload()) srv.close() srv.wait_closed() @@ -195,7 +195,7 @@ def run_around_tests(monkeypatch, port_manager, controller): # Force turn off KVM because it's not available on CI config.set("Qemu", "enable_kvm", False) - monkeypatch.setattr("gns3server.modules.project.Project._get_default_project_directory", lambda *args: os.path.join(tmppath, 'projects')) + monkeypatch.setattr("gns3server.hypervisor.project.Project._get_default_project_directory", lambda *args: os.path.join(tmppath, 'projects')) # Force sys.platform to the original value. Because it seem not be restore correctly at each tests sys.platform = sys.original_platform diff --git a/tests/handlers/api/hypervisor/test_docker.py b/tests/handlers/api/hypervisor/test_docker.py index d1f870ef..32c55222 100644 --- a/tests/handlers/api/hypervisor/test_docker.py +++ b/tests/handlers/api/hypervisor/test_docker.py @@ -24,7 +24,7 @@ import aiohttp from tests.utils import asyncio_patch from unittest.mock import patch, MagicMock, PropertyMock -from gns3server.modules.docker import Docker +from gns3server.hypervisor.docker import Docker @pytest.fixture @@ -44,8 +44,8 @@ def mock_connection(): @pytest.fixture def vm(http_hypervisor, project, base_params): - with asyncio_patch("gns3server.modules.docker.Docker.list_images", return_value=[{"image": "nginx"}]) as mock_list: - with asyncio_patch("gns3server.modules.docker.Docker.query", return_value={"Id": "8bd8153ea8f5"}) as mock: + with asyncio_patch("gns3server.hypervisor.docker.Docker.list_images", return_value=[{"image": "nginx"}]) as mock_list: + with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value={"Id": "8bd8153ea8f5"}) as mock: response = http_hypervisor.post("/projects/{project_id}/docker/vms".format(project_id=project.id), base_params) if response.status != 201: print(response.body) @@ -54,8 +54,8 @@ def vm(http_hypervisor, project, base_params): def test_docker_create(http_hypervisor, project, base_params): - with asyncio_patch("gns3server.modules.docker.Docker.list_images", return_value=[{"image": "nginx"}]) as mock_list: - with asyncio_patch("gns3server.modules.docker.Docker.query", return_value={"Id": "8bd8153ea8f5"}) as mock: + with asyncio_patch("gns3server.hypervisor.docker.Docker.list_images", return_value=[{"image": "nginx"}]) as mock_list: + with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value={"Id": "8bd8153ea8f5"}) as mock: response = http_hypervisor.post("/projects/{project_id}/docker/vms".format(project_id=project.id), base_params) assert response.status == 201 assert response.route == "/projects/{project_id}/docker/vms" @@ -68,35 +68,35 @@ def test_docker_create(http_hypervisor, project, base_params): def test_docker_start(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.docker.docker_vm.DockerVM.start", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.docker.docker_vm.DockerVM.start", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/docker/vms/{vm_id}/start".format(project_id=vm["project_id"], vm_id=vm["vm_id"])) assert mock.called assert response.status == 204 def test_docker_stop(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.docker.docker_vm.DockerVM.stop", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.docker.docker_vm.DockerVM.stop", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/docker/vms/{vm_id}/stop".format(project_id=vm["project_id"], vm_id=vm["vm_id"])) assert mock.called assert response.status == 204 def test_docker_reload(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.docker.docker_vm.DockerVM.restart", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.docker.docker_vm.DockerVM.restart", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/docker/vms/{vm_id}/reload".format(project_id=vm["project_id"], vm_id=vm["vm_id"])) assert mock.called assert response.status == 204 def test_docker_delete(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.docker.docker_vm.DockerVM.delete", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.docker.docker_vm.DockerVM.delete", return_value=True) as mock: response = http_hypervisor.delete("/projects/{project_id}/docker/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"])) assert mock.called assert response.status == 204 def test_docker_reload(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.docker.docker_vm.DockerVM.pause", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.docker.docker_vm.DockerVM.pause", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/docker/vms/{vm_id}/suspend".format(project_id=vm["project_id"], vm_id=vm["vm_id"])) assert mock.called assert response.status == 204 @@ -114,14 +114,14 @@ def test_docker_nio_create_udp(http_hypervisor, vm): def test_docker_delete_nio(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.docker.docker_vm.DockerVM.adapter_remove_nio_binding") as mock: + with asyncio_patch("gns3server.hypervisor.docker.docker_vm.DockerVM.adapter_remove_nio_binding") as mock: response = http_hypervisor.delete("/projects/{project_id}/docker/vms/{vm_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) assert response.status == 204 assert response.route == "/projects/{project_id}/docker/vms/{vm_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" def test_docker_update(http_hypervisor, vm, tmpdir, free_console_port): - with asyncio_patch("gns3server.modules.docker.docker_vm.DockerVM.update") as mock: + with asyncio_patch("gns3server.hypervisor.docker.docker_vm.DockerVM.update") as mock: response = http_hypervisor.put("/projects/{project_id}/docker/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"name": "test", "console": free_console_port, "start_command": "yes", @@ -137,8 +137,8 @@ def test_docker_update(http_hypervisor, vm, tmpdir, free_console_port): def test_docker_start_capture(http_hypervisor, vm, tmpdir, project): - with patch("gns3server.modules.docker.docker_vm.DockerVM.is_running", return_value=True) as mock: - with asyncio_patch("gns3server.modules.docker.docker_vm.DockerVM.start_capture") as start_capture: + with patch("gns3server.hypervisor.docker.docker_vm.DockerVM.is_running", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.docker.docker_vm.DockerVM.start_capture") as start_capture: params = {"capture_file_name": "test.pcap", "data_link_type": "DLT_EN10MB"} response = http_hypervisor.post("/projects/{project_id}/docker/vms/{vm_id}/adapters/0/ports/0/start_capture".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), body=params, example=True) @@ -151,8 +151,8 @@ def test_docker_start_capture(http_hypervisor, vm, tmpdir, project): def test_docker_start_capture_not_started(http_hypervisor, vm, tmpdir): - with patch("gns3server.modules.docker.docker_vm.DockerVM.is_running", return_value=False) as mock: - with asyncio_patch("gns3server.modules.docker.docker_vm.DockerVM.start_capture") as start_capture: + with patch("gns3server.hypervisor.docker.docker_vm.DockerVM.is_running", return_value=False) as mock: + with asyncio_patch("gns3server.hypervisor.docker.docker_vm.DockerVM.start_capture") as start_capture: params = {"capture_file_name": "test.pcap", "data_link_type": "DLT_EN10MB"} response = http_hypervisor.post("/projects/{project_id}/docker/vms/{vm_id}/adapters/0/ports/0/start_capture".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), body=params) @@ -163,8 +163,8 @@ def test_docker_start_capture_not_started(http_hypervisor, vm, tmpdir): def test_docker_stop_capture(http_hypervisor, vm, tmpdir, project): - with patch("gns3server.modules.docker.docker_vm.DockerVM.is_running", return_value=True) as mock: - with asyncio_patch("gns3server.modules.docker.docker_vm.DockerVM.stop_capture") as stop_capture: + with patch("gns3server.hypervisor.docker.docker_vm.DockerVM.is_running", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.docker.docker_vm.DockerVM.stop_capture") as stop_capture: response = http_hypervisor.post("/projects/{project_id}/docker/vms/{vm_id}/adapters/0/ports/0/stop_capture".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) @@ -175,8 +175,8 @@ def test_docker_stop_capture(http_hypervisor, vm, tmpdir, project): def test_docker_stop_capture_not_started(http_hypervisor, vm, tmpdir): - with patch("gns3server.modules.docker.docker_vm.DockerVM.is_running", return_value=False) as mock: - with asyncio_patch("gns3server.modules.docker.docker_vm.DockerVM.stop_capture") as stop_capture: + with patch("gns3server.hypervisor.docker.docker_vm.DockerVM.is_running", return_value=False) as mock: + with asyncio_patch("gns3server.hypervisor.docker.docker_vm.DockerVM.stop_capture") as stop_capture: response = http_hypervisor.post("/projects/{project_id}/docker/vms/{vm_id}/adapters/0/ports/0/stop_capture".format(project_id=vm["project_id"], vm_id=vm["vm_id"])) diff --git a/tests/handlers/api/hypervisor/test_dynamips.py b/tests/handlers/api/hypervisor/test_dynamips.py index f68116ab..81de3f72 100644 --- a/tests/handlers/api/hypervisor/test_dynamips.py +++ b/tests/handlers/api/hypervisor/test_dynamips.py @@ -27,7 +27,7 @@ from tests.utils import asyncio_patch # def vm(http_hypervisor, project): # # dynamips_path = "/fake/dynamips" -# with asyncio_patch("gns3server.modules.dynamips.nodes.router.Router.create", return_value=True) as mock: +# with asyncio_patch("gns3server.hypervisor.dynamips.nodes.router.Router.create", return_value=True) as mock: # response = http_hypervisor.post("/projects/{project_id}/dynamips/vms".format(project_id=project.id), {"name": "My router", # "platform": "c3745", # "image": "somewhere", @@ -35,13 +35,13 @@ from tests.utils import asyncio_patch # assert mock.called # assert response.status == 201 # -# with asyncio_patch("gns3server.modules.dynamips.Dynamips.find_dynamips", return_value=dynamips_path): +# with asyncio_patch("gns3server.hypervisor.dynamips.Dynamips.find_dynamips", return_value=dynamips_path): # yield response.json # # # def test_dynamips_vm_create(http_hypervisor, project): # -# with asyncio_patch("gns3server.modules.dynamips.nodes.router.Router.create", return_value=True): +# with asyncio_patch("gns3server.hypervisor.dynamips.nodes.router.Router.create", return_value=True): # response = http_hypervisor.post("/projects/{project_id}/dynamips/vms".format(project_id=project.id), {"name": "My router", # "platform": "c3745", # "image": "somewhere", @@ -62,28 +62,28 @@ from tests.utils import asyncio_patch # # # def test_dynamips_vm_start(http_hypervisor, vm): -# with asyncio_patch("gns3server.modules.dynamips.nodes.router.Router.start", return_value=True) as mock: +# with asyncio_patch("gns3server.hypervisor.dynamips.nodes.router.Router.start", return_value=True) as mock: # response = http_hypervisor.post("/projects/{project_id}/dynamips/vms/{vm_id}/start".format(project_id=vm["project_id"], vm_id=vm["vm_id"])) # assert mock.called # assert response.status == 204 # # # def test_dynamips_vm_stop(http_hypervisor, vm): -# with asyncio_patch("gns3server.modules.dynamips.nodes.router.Router.stop", return_value=True) as mock: +# with asyncio_patch("gns3server.hypervisor.dynamips.nodes.router.Router.stop", return_value=True) as mock: # response = http_hypervisor.post("/projects/{project_id}/dynamips/vms/{vm_id}/stop".format(project_id=vm["project_id"], vm_id=vm["vm_id"])) # assert mock.called # assert response.status == 204 # # # def test_dynamips_vm_suspend(http_hypervisor, vm): -# with asyncio_patch("gns3server.modules.dynamips.nodes.router.Router.suspend", return_value=True) as mock: +# with asyncio_patch("gns3server.hypervisor.dynamips.nodes.router.Router.suspend", return_value=True) as mock: # response = http_hypervisor.post("/projects/{project_id}/dynamips/vms/{vm_id}/suspend".format(project_id=vm["project_id"], vm_id=vm["vm_id"])) # assert mock.called # assert response.status == 204 # # # def test_dynamips_vm_resume(http_hypervisor, vm): -# with asyncio_patch("gns3server.modules.dynamips.nodes.router.Router.resume", return_value=True) as mock: +# with asyncio_patch("gns3server.hypervisor.dynamips.nodes.router.Router.resume", return_value=True) as mock: # response = http_hypervisor.post("/projects/{project_id}/dynamips/vms/{vm_id}/resume".format(project_id=vm["project_id"], vm_id=vm["vm_id"])) # assert mock.called # assert response.status == 204 @@ -91,7 +91,7 @@ from tests.utils import asyncio_patch # def test_vbox_nio_create_udp(http_hypervisor, vm): # -# with asyncio_patch('gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.adapter_add_nio_binding') as mock: +# with asyncio_patch('gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.adapter_add_nio_binding') as mock: # response = http_hypervisor.post("/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/0/nio".format(project_id=vm["project_id"], # vm_id=vm["vm_id"]), {"type": "nio_udp", # "lport": 4242, @@ -110,7 +110,7 @@ from tests.utils import asyncio_patch # # def test_vbox_delete_nio(http_hypervisor, vm): # -# with asyncio_patch('gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.adapter_remove_nio_binding') as mock: +# with asyncio_patch('gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.adapter_remove_nio_binding') as mock: # response = http_hypervisor.delete("/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) # # assert mock.called @@ -153,14 +153,14 @@ def fake_file(tmpdir): def test_vms(http_hypervisor, tmpdir, fake_dynamips, fake_file): - with patch("gns3server.modules.Dynamips.get_images_directory", return_value=str(tmpdir), example=True): + with patch("gns3server.hypervisor.Dynamips.get_images_directory", return_value=str(tmpdir), example=True): response = http_hypervisor.get("/dynamips/vms") assert response.status == 200 assert response.json == [{"filename": "7200.bin", "path": "7200.bin"}] def test_upload_vm(http_hypervisor, tmpdir): - with patch("gns3server.modules.Dynamips.get_images_directory", return_value=str(tmpdir),): + with patch("gns3server.hypervisor.Dynamips.get_images_directory", return_value=str(tmpdir),): response = http_hypervisor.post("/dynamips/vms/test2", body="TEST", raw=True) assert response.status == 204 @@ -177,6 +177,6 @@ def test_upload_vm_permission_denied(http_hypervisor, tmpdir): f.write("") os.chmod(str(tmpdir / "test2"), 0) - with patch("gns3server.modules.Dynamips.get_images_directory", return_value=str(tmpdir),): + with patch("gns3server.hypervisor.Dynamips.get_images_directory", return_value=str(tmpdir),): response = http_hypervisor.post("/dynamips/vms/test2", body="TEST", raw=True) assert response.status == 409 diff --git a/tests/handlers/api/hypervisor/test_iou.py b/tests/handlers/api/hypervisor/test_iou.py index 695dc223..69e359ea 100644 --- a/tests/handlers/api/hypervisor/test_iou.py +++ b/tests/handlers/api/hypervisor/test_iou.py @@ -136,7 +136,7 @@ def test_iou_get(http_hypervisor, project, vm): def test_iou_start(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.start", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM.start", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/iou/vms/{vm_id}/start".format(project_id=vm["project_id"], vm_id=vm["vm_id"])) assert mock.called assert response.status == 200 @@ -146,7 +146,7 @@ def test_iou_start(http_hypervisor, vm): def test_iou_start_with_iourc(http_hypervisor, vm, tmpdir): body = {"iourc_content": "test"} - with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.start", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM.start", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/iou/vms/{vm_id}/start".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), body=body, example=True) assert mock.called assert response.status == 200 @@ -158,21 +158,21 @@ def test_iou_start_with_iourc(http_hypervisor, vm, tmpdir): def test_iou_stop(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.stop", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM.stop", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/iou/vms/{vm_id}/stop".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) assert mock.called assert response.status == 204 def test_iou_reload(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.reload", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM.reload", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/iou/vms/{vm_id}/reload".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) assert mock.called assert response.status == 204 def test_iou_delete(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.iou.IOU.delete_vm", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.iou.IOU.delete_vm", return_value=True) as mock: response = http_hypervisor.delete("/projects/{project_id}/iou/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) assert mock.called assert response.status == 204 @@ -242,7 +242,7 @@ def test_iou_nio_create_ethernet_different_port(http_hypervisor, vm, ethernet_de def test_iou_nio_create_tap(http_hypervisor, vm, ethernet_device): - with patch("gns3server.modules.base_manager.BaseManager.has_privileged_access", return_value=True): + with patch("gns3server.hypervisor.base_manager.BaseManager.has_privileged_access", return_value=True): response = http_hypervisor.post("/projects/{project_id}/iou/vms/{vm_id}/adapters/1/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_tap", "tap_device": ethernet_device}) assert response.status == 201 @@ -262,8 +262,8 @@ def test_iou_delete_nio(http_hypervisor, vm): def test_iou_start_capture(http_hypervisor, vm, tmpdir, project): - with patch("gns3server.modules.iou.iou_vm.IOUVM.is_running", return_value=True) as mock: - with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.start_capture") as start_capture: + with patch("gns3server.hypervisor.iou.iou_vm.IOUVM.is_running", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM.start_capture") as start_capture: params = {"capture_file_name": "test.pcap", "data_link_type": "DLT_EN10MB"} response = http_hypervisor.post("/projects/{project_id}/iou/vms/{vm_id}/adapters/0/ports/0/start_capture".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), body=params, example=True) @@ -276,8 +276,8 @@ def test_iou_start_capture(http_hypervisor, vm, tmpdir, project): def test_iou_start_capture_not_started(http_hypervisor, vm, tmpdir): - with patch("gns3server.modules.iou.iou_vm.IOUVM.is_running", return_value=False) as mock: - with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.start_capture") as start_capture: + with patch("gns3server.hypervisor.iou.iou_vm.IOUVM.is_running", return_value=False) as mock: + with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM.start_capture") as start_capture: params = {"capture_file_name": "test.pcap", "data_link_type": "DLT_EN10MB"} response = http_hypervisor.post("/projects/{project_id}/iou/vms/{vm_id}/adapters/0/ports/0/start_capture".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), body=params) @@ -288,8 +288,8 @@ def test_iou_start_capture_not_started(http_hypervisor, vm, tmpdir): def test_iou_stop_capture(http_hypervisor, vm, tmpdir, project): - with patch("gns3server.modules.iou.iou_vm.IOUVM.is_running", return_value=True) as mock: - with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.stop_capture") as stop_capture: + with patch("gns3server.hypervisor.iou.iou_vm.IOUVM.is_running", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM.stop_capture") as stop_capture: response = http_hypervisor.post("/projects/{project_id}/iou/vms/{vm_id}/adapters/0/ports/0/stop_capture".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) @@ -300,8 +300,8 @@ def test_iou_stop_capture(http_hypervisor, vm, tmpdir, project): def test_iou_stop_capture_not_started(http_hypervisor, vm, tmpdir): - with patch("gns3server.modules.iou.iou_vm.IOUVM.is_running", return_value=False) as mock: - with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.stop_capture") as stop_capture: + with patch("gns3server.hypervisor.iou.iou_vm.IOUVM.is_running", return_value=False) as mock: + with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM.stop_capture") as stop_capture: response = http_hypervisor.post("/projects/{project_id}/iou/vms/{vm_id}/adapters/0/ports/0/stop_capture".format(project_id=vm["project_id"], vm_id=vm["vm_id"])) @@ -330,14 +330,14 @@ def test_get_configs_with_startup_config_file(http_hypervisor, project, vm): def test_vms(http_hypervisor, tmpdir, fake_iou_bin): - with patch("gns3server.modules.IOU.get_images_directory", return_value=str(tmpdir)): + with patch("gns3server.hypervisor.IOU.get_images_directory", return_value=str(tmpdir)): response = http_hypervisor.get("/iou/vms", example=True) assert response.status == 200 assert response.json == [{"filename": "iou.bin", "path": "iou.bin"}] def test_upload_vm(http_hypervisor, tmpdir): - with patch("gns3server.modules.IOU.get_images_directory", return_value=str(tmpdir),): + with patch("gns3server.hypervisor.IOU.get_images_directory", return_value=str(tmpdir),): response = http_hypervisor.post("/iou/vms/test2", body="TEST", raw=True) assert response.status == 204 @@ -354,6 +354,6 @@ def test_upload_vm_permission_denied(http_hypervisor, tmpdir): f.write("") os.chmod(str(tmpdir / "test2"), 0) - with patch("gns3server.modules.IOU.get_images_directory", return_value=str(tmpdir),): + with patch("gns3server.hypervisor.IOU.get_images_directory", return_value=str(tmpdir),): response = http_hypervisor.post("/iou/vms/test2", body="TEST", raw=True) assert response.status == 409 diff --git a/tests/handlers/api/hypervisor/test_project.py b/tests/handlers/api/hypervisor/test_project.py index b84a7e1f..dcf12ced 100644 --- a/tests/handlers/api/hypervisor/test_project.py +++ b/tests/handlers/api/hypervisor/test_project.py @@ -28,11 +28,11 @@ from unittest.mock import patch from tests.utils import asyncio_patch from gns3server.handlers.api.hypervisor.project_handler import ProjectHandler -from gns3server.modules.project_manager import ProjectManager +from gns3server.hypervisor.project_manager import ProjectManager def test_create_project_with_path(http_hypervisor, tmpdir): - with patch("gns3server.modules.project.Project.is_local", return_value=True): + with patch("gns3server.hypervisor.project.Project.is_local", return_value=True): response = http_hypervisor.post("/projects", {"name": "test", "path": str(tmpdir)}) assert response.status == 201 assert response.json["path"] == str(tmpdir) @@ -114,7 +114,7 @@ def test_update_path_project_temporary(http_hypervisor, tmpdir): os.makedirs(str(tmpdir / "a")) os.makedirs(str(tmpdir / "b")) - with patch("gns3server.modules.project.Project.is_local", return_value=True): + with patch("gns3server.hypervisor.project.Project.is_local", return_value=True): response = http_hypervisor.post("/projects", {"name": "first_name", "path": str(tmpdir / "a"), "temporary": True}) assert response.status == 201 assert response.json["name"] == "first_name" @@ -133,7 +133,7 @@ def test_update_path_project_non_temporary(http_hypervisor, tmpdir): os.makedirs(str(tmpdir / "a")) os.makedirs(str(tmpdir / "b")) - with patch("gns3server.modules.project.Project.is_local", return_value=True): + with patch("gns3server.hypervisor.project.Project.is_local", return_value=True): response = http_hypervisor.post("/projects", {"name": "first_name", "path": str(tmpdir / "a")}) assert response.status == 201 assert response.json["name"] == "first_name" @@ -149,7 +149,7 @@ def test_update_path_project_non_temporary(http_hypervisor, tmpdir): def test_update_path_project_non_local(http_hypervisor, tmpdir): - with patch("gns3server.modules.project.Project.is_local", return_value=False): + with patch("gns3server.hypervisor.project.Project.is_local", return_value=False): response = http_hypervisor.post("/projects", {"name": "first_name"}) assert response.status == 201 query = {"name": "second_name", "path": str(tmpdir)} @@ -158,7 +158,7 @@ def test_update_path_project_non_local(http_hypervisor, tmpdir): def test_commit_project(http_hypervisor, project): - with asyncio_patch("gns3server.modules.project.Project.commit", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.project.Project.commit", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/commit".format(project_id=project.id), example=True) assert response.status == 204 assert mock.called @@ -170,7 +170,7 @@ def test_commit_project_invalid_uuid(http_hypervisor): def test_delete_project(http_hypervisor, project): - with asyncio_patch("gns3server.modules.project.Project.delete", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.project.Project.delete", return_value=True) as mock: response = http_hypervisor.delete("/projects/{project_id}".format(project_id=project.id), example=True) assert response.status == 204 assert mock.called @@ -182,7 +182,7 @@ def test_delete_project_invalid_uuid(http_hypervisor): def test_close_project(http_hypervisor, project): - with asyncio_patch("gns3server.modules.project.Project.close", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.project.Project.close", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/close".format(project_id=project.id), example=True) assert response.status == 204 assert mock.called @@ -192,7 +192,7 @@ def test_close_project_two_client_connected(http_hypervisor, project): ProjectHandler._notifications_listening = {project.id: 2} - with asyncio_patch("gns3server.modules.project.Project.close", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.project.Project.close", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/close".format(project_id=project.id), example=True) assert response.status == 204 assert not mock.called @@ -238,7 +238,7 @@ def test_list_files(http_hypervisor, project): "md5sum": "098f6bcd4621d373cade4e832627b4f6" } ] - with asyncio_patch("gns3server.modules.project.Project.list_files", return_value=files) as mock: + with asyncio_patch("gns3server.hypervisor.project.Project.list_files", return_value=files) as mock: response = http_hypervisor.get("/projects/{project_id}/files".format(project_id=project.id), example=True) assert response.status == 200 assert response.json == files diff --git a/tests/handlers/api/hypervisor/test_qemu.py b/tests/handlers/api/hypervisor/test_qemu.py index 38b1c518..5bd37ad1 100644 --- a/tests/handlers/api/hypervisor/test_qemu.py +++ b/tests/handlers/api/hypervisor/test_qemu.py @@ -112,7 +112,7 @@ def test_qemu_get(http_hypervisor, project, vm): def test_qemu_start(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.qemu.qemu_vm.QemuVM.start", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.qemu.qemu_vm.QemuVM.start", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/qemu/vms/{vm_id}/start".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) assert mock.called assert response.status == 200 @@ -120,35 +120,35 @@ def test_qemu_start(http_hypervisor, vm): def test_qemu_stop(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.qemu.qemu_vm.QemuVM.stop", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.qemu.qemu_vm.QemuVM.stop", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/qemu/vms/{vm_id}/stop".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) assert mock.called assert response.status == 204 def test_qemu_reload(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.qemu.qemu_vm.QemuVM.reload", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.qemu.qemu_vm.QemuVM.reload", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/qemu/vms/{vm_id}/reload".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) assert mock.called assert response.status == 204 def test_qemu_suspend(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.qemu.qemu_vm.QemuVM.suspend", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.qemu.qemu_vm.QemuVM.suspend", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/qemu/vms/{vm_id}/suspend".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) assert mock.called assert response.status == 204 def test_qemu_resume(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.qemu.qemu_vm.QemuVM.resume", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.qemu.qemu_vm.QemuVM.resume", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/qemu/vms/{vm_id}/resume".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) assert mock.called assert response.status == 204 def test_qemu_delete(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.qemu.Qemu.delete_vm", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.qemu.Qemu.delete_vm", return_value=True) as mock: response = http_hypervisor.delete("/projects/{project_id}/qemu/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) assert mock.called assert response.status == 204 @@ -204,7 +204,7 @@ def test_qemu_delete_nio(http_hypervisor, vm): def test_qemu_list_binaries(http_hypervisor, vm): ret = [{"path": "/tmp/1", "version": "2.2.0"}, {"path": "/tmp/2", "version": "2.1.0"}] - with asyncio_patch("gns3server.modules.qemu.Qemu.binary_list", return_value=ret) as mock: + with asyncio_patch("gns3server.hypervisor.qemu.Qemu.binary_list", return_value=ret) as mock: response = http_hypervisor.get("/qemu/binaries".format(project_id=vm["project_id"]), example=True) assert mock.called_with(None) assert response.status == 200 @@ -217,7 +217,7 @@ def test_qemu_list_binaries_filter(http_hypervisor, vm): {"path": "/tmp/alpha", "version": "2.1.0"}, {"path": "/tmp/i386", "version": "2.1.0"} ] - with asyncio_patch("gns3server.modules.qemu.Qemu.binary_list", return_value=ret) as mock: + with asyncio_patch("gns3server.hypervisor.qemu.Qemu.binary_list", return_value=ret) as mock: response = http_hypervisor.get("/qemu/binaries".format(project_id=vm["project_id"]), body={"archs": ["i386"]}, example=True) assert response.status == 200 assert mock.called_with(["i386"]) @@ -232,7 +232,7 @@ def test_vms(http_hypervisor, tmpdir, fake_qemu_vm): def test_upload_vm(http_hypervisor, tmpdir): - with patch("gns3server.modules.Qemu.get_images_directory", return_value=str(tmpdir),): + with patch("gns3server.hypervisor.Qemu.get_images_directory", return_value=str(tmpdir),): response = http_hypervisor.post("/qemu/vms/test2", body="TEST", raw=True) assert response.status == 204 @@ -245,7 +245,7 @@ def test_upload_vm(http_hypervisor, tmpdir): def test_upload_vm_ova(http_hypervisor, tmpdir): - with patch("gns3server.modules.Qemu.get_images_directory", return_value=str(tmpdir),): + with patch("gns3server.hypervisor.Qemu.get_images_directory", return_value=str(tmpdir),): response = http_hypervisor.post("/qemu/vms/test2.ova/test2.vmdk", body="TEST", raw=True) assert response.status == 204 @@ -258,7 +258,7 @@ def test_upload_vm_ova(http_hypervisor, tmpdir): def test_upload_vm_forbiden_location(http_hypervisor, tmpdir): - with patch("gns3server.modules.Qemu.get_images_directory", return_value=str(tmpdir),): + with patch("gns3server.hypervisor.Qemu.get_images_directory", return_value=str(tmpdir),): response = http_hypervisor.post("/qemu/vms/../../test2", body="TEST", raw=True) assert response.status == 403 @@ -268,7 +268,7 @@ def test_upload_vm_permission_denied(http_hypervisor, tmpdir): f.write("") os.chmod(str(tmpdir / "test2"), 0) - with patch("gns3server.modules.Qemu.get_images_directory", return_value=str(tmpdir),): + with patch("gns3server.hypervisor.Qemu.get_images_directory", return_value=str(tmpdir),): response = http_hypervisor.post("/qemu/vms/test2", body="TEST", raw=True) assert response.status == 409 @@ -284,7 +284,7 @@ def test_create_img_relative(http_hypervisor): "lazy_refcounts": "off", "size": 100 } - with asyncio_patch("gns3server.modules.Qemu.create_disk"): + with asyncio_patch("gns3server.hypervisor.Qemu.create_disk"): response = http_hypervisor.post("/qemu/img", body=body, example=True) assert response.status == 201 @@ -305,7 +305,7 @@ def test_create_img_absolute_non_local(http_hypervisor): "lazy_refcounts": "off", "size": 100 } - with asyncio_patch("gns3server.modules.Qemu.create_disk"): + with asyncio_patch("gns3server.hypervisor.Qemu.create_disk"): response = http_hypervisor.post("/qemu/img", body=body, example=True) assert response.status == 403 @@ -326,13 +326,13 @@ def test_create_img_absolute_local(http_hypervisor): "lazy_refcounts": "off", "size": 100 } - with asyncio_patch("gns3server.modules.Qemu.create_disk"): + with asyncio_patch("gns3server.hypervisor.Qemu.create_disk"): response = http_hypervisor.post("/qemu/img", body=body, example=True) assert response.status == 201 def test_capabilities(http_hypervisor): - with asyncio_patch("gns3server.modules.Qemu.get_kvm_archs", return_value=["x86_64"]): + with asyncio_patch("gns3server.hypervisor.Qemu.get_kvm_archs", return_value=["x86_64"]): response = http_hypervisor.get("/qemu/capabilities", example=True) assert response.json["kvm"] == ["x86_64"] diff --git a/tests/handlers/api/hypervisor/test_virtualbox.py b/tests/handlers/api/hypervisor/test_virtualbox.py index ed58c829..1c931c9f 100644 --- a/tests/handlers/api/hypervisor/test_virtualbox.py +++ b/tests/handlers/api/hypervisor/test_virtualbox.py @@ -25,20 +25,20 @@ def vm(http_hypervisor, project, monkeypatch): vboxmanage_path = "/fake/VboxManage" - with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.create", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.create", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/virtualbox/vms".format(project_id=project.id), {"name": "VMTEST", "vmname": "VMTEST", "linked_clone": False}) assert mock.called assert response.status == 201 - with patch("gns3server.modules.virtualbox.VirtualBox.find_vboxmanage", return_value=vboxmanage_path): + with patch("gns3server.hypervisor.virtualbox.VirtualBox.find_vboxmanage", return_value=vboxmanage_path): yield response.json def test_vbox_create(http_hypervisor, project): - with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.create", return_value=True): + with asyncio_patch("gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.create", return_value=True): response = http_hypervisor.post("/projects/{project_id}/virtualbox/vms".format(project_id=project.id), {"name": "VM1", "vmname": "VM1", "linked_clone": False}, @@ -57,36 +57,36 @@ def test_vbox_get(http_hypervisor, project, vm): def test_vbox_start(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.check_hw_virtualization", return_value=True) as mock: - with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.start", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.check_hw_virtualization", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.start", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/virtualbox/vms/{vm_id}/start".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) assert mock.called assert response.status == 204 def test_vbox_stop(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.stop", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.stop", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/virtualbox/vms/{vm_id}/stop".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) assert mock.called assert response.status == 204 def test_vbox_suspend(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.suspend", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.suspend", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/virtualbox/vms/{vm_id}/suspend".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) assert mock.called assert response.status == 204 def test_vbox_resume(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.resume", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.resume", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/virtualbox/vms/{vm_id}/resume".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) assert mock.called assert response.status == 204 def test_vbox_reload(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.reload", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.reload", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/virtualbox/vms/{vm_id}/reload".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) assert mock.called assert response.status == 204 @@ -94,7 +94,7 @@ def test_vbox_reload(http_hypervisor, vm): def test_vbox_nio_create_udp(http_hypervisor, vm): - with asyncio_patch('gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.adapter_add_nio_binding') as mock: + with asyncio_patch('gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.adapter_add_nio_binding') as mock: response = http_hypervisor.post("/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_udp", "lport": 4242, @@ -113,7 +113,7 @@ def test_vbox_nio_create_udp(http_hypervisor, vm): def test_vbox_delete_nio(http_hypervisor, vm): - with asyncio_patch('gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.adapter_remove_nio_binding') as mock: + with asyncio_patch('gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.adapter_remove_nio_binding') as mock: response = http_hypervisor.delete("/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) assert mock.called diff --git a/tests/handlers/api/hypervisor/test_vpcs.py b/tests/handlers/api/hypervisor/test_vpcs.py index 106a3a8d..64e97614 100644 --- a/tests/handlers/api/hypervisor/test_vpcs.py +++ b/tests/handlers/api/hypervisor/test_vpcs.py @@ -79,7 +79,7 @@ def test_vpcs_nio_create_udp(http_hypervisor, vm): @pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows") def test_vpcs_nio_create_tap(http_hypervisor, vm, ethernet_device): - with patch("gns3server.modules.base_manager.BaseManager.has_privileged_access", return_value=True): + with patch("gns3server.hypervisor.base_manager.BaseManager.has_privileged_access", return_value=True): response = http_hypervisor.post("/projects/{project_id}/vpcs/vms/{vm_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_tap", "tap_device": ethernet_device}) assert response.status == 201 @@ -99,7 +99,7 @@ def test_vpcs_delete_nio(http_hypervisor, vm): def test_vpcs_start(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.start", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.VPCSVM.start", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/vpcs/vms/{vm_id}/start".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) assert mock.called assert response.status == 200 @@ -107,21 +107,21 @@ def test_vpcs_start(http_hypervisor, vm): def test_vpcs_stop(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.stop", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.VPCSVM.stop", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/vpcs/vms/{vm_id}/stop".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) assert mock.called assert response.status == 204 def test_vpcs_reload(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.reload", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.VPCSVM.reload", return_value=True) as mock: response = http_hypervisor.post("/projects/{project_id}/vpcs/vms/{vm_id}/reload".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) assert mock.called assert response.status == 204 def test_vpcs_delete(http_hypervisor, vm): - with asyncio_patch("gns3server.modules.vpcs.VPCS.delete_vm", return_value=True) as mock: + with asyncio_patch("gns3server.hypervisor.vpcs.VPCS.delete_vm", return_value=True) as mock: response = http_hypervisor.delete("/projects/{project_id}/vpcs/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) assert mock.called assert response.status == 204 diff --git a/tests/modules/docker/test_docker.py b/tests/hypervisor/docker/test_docker.py similarity index 95% rename from tests/modules/docker/test_docker.py rename to tests/hypervisor/docker/test_docker.py index fa6f1a7d..396f1b58 100644 --- a/tests/modules/docker/test_docker.py +++ b/tests/hypervisor/docker/test_docker.py @@ -20,8 +20,8 @@ import asyncio from unittest.mock import MagicMock from tests.utils import asyncio_patch -from gns3server.modules.docker import Docker -from gns3server.modules.docker.docker_error import DockerError +from gns3server.hypervisor.docker import Docker +from gns3server.hypervisor.docker.docker_error import DockerError def test_query_success(loop): @@ -125,7 +125,7 @@ def test_list_images(loop): } ] - with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock: + with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock: images = loop.run_until_complete(asyncio.async(Docker.instance().list_images())) mock.assert_called_with("GET", "images/json", params={"all": 0}) assert len(images) == 5 diff --git a/tests/modules/docker/test_docker_vm.py b/tests/hypervisor/docker/test_docker_vm.py similarity index 77% rename from tests/modules/docker/test_docker_vm.py rename to tests/hypervisor/docker/test_docker_vm.py index 0a21f255..a3f16f93 100644 --- a/tests/modules/docker/test_docker_vm.py +++ b/tests/hypervisor/docker/test_docker_vm.py @@ -22,9 +22,9 @@ import os from tests.utils import asyncio_patch, AsyncioMagicMock from gns3server.ubridge.ubridge_error import UbridgeNamespaceError -from gns3server.modules.docker.docker_vm import DockerVM -from gns3server.modules.docker.docker_error import * -from gns3server.modules.docker import Docker +from gns3server.hypervisor.docker.docker_vm import DockerVM +from gns3server.hypervisor.docker.docker_error import * +from gns3server.hypervisor.docker import Docker from gns3server.utils.get_resource import get_resource @@ -78,8 +78,8 @@ def test_create(loop, project, manager): "Id": "e90e34656806", "Warnings": [] } - with asyncio_patch("gns3server.modules.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images: - with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock: + with asyncio_patch("gns3server.hypervisor.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images: + with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock: vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu") loop.run_until_complete(asyncio.async(vm.create())) mock.assert_called_with("POST", "containers/create", data={ @@ -89,7 +89,7 @@ def test_create(loop, project, manager): "HostConfig": { "CapAdd": ["ALL"], - "Binds": ["{}:/gns3:ro".format(get_resource("modules/docker/resources"))], + "Binds": ["{}:/gns3:ro".format(get_resource("hypervisor/docker/resources"))], "Privileged": True }, "Volumes": {}, @@ -110,8 +110,8 @@ def test_create_vnc(loop, project, manager): "Warnings": [] } - with asyncio_patch("gns3server.modules.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images: - with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock: + with asyncio_patch("gns3server.hypervisor.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images: + with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock: vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu", console_type="vnc") vm._start_vnc = MagicMock() vm._display = 42 @@ -124,7 +124,7 @@ def test_create_vnc(loop, project, manager): { "CapAdd": ["ALL"], "Binds": [ - "{}:/gns3:ro".format(get_resource("modules/docker/resources")), + "{}:/gns3:ro".format(get_resource("hypervisor/docker/resources")), '/tmp/.X11-unix/:/tmp/.X11-unix/' ], "Privileged": True @@ -147,8 +147,8 @@ def test_create_start_cmd(loop, project, manager): "Id": "e90e34656806", "Warnings": [] } - with asyncio_patch("gns3server.modules.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images: - with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock: + with asyncio_patch("gns3server.hypervisor.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images: + with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock: vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu") vm._start_command = "/bin/ls" loop.run_until_complete(asyncio.async(vm.create())) @@ -159,7 +159,7 @@ def test_create_start_cmd(loop, project, manager): "HostConfig": { "CapAdd": ["ALL"], - "Binds": ["{}:/gns3:ro".format(get_resource("modules/docker/resources"))], + "Binds": ["{}:/gns3:ro".format(get_resource("hypervisor/docker/resources"))], "Privileged": True }, "Volumes": {}, @@ -179,8 +179,8 @@ def test_create_environment(loop, project, manager): "Id": "e90e34656806", "Warnings": [] } - with asyncio_patch("gns3server.modules.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images: - with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock: + with asyncio_patch("gns3server.hypervisor.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images: + with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock: vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu") vm.environment = "YES=1\nNO=0" loop.run_until_complete(asyncio.async(vm.create())) @@ -191,7 +191,7 @@ def test_create_environment(loop, project, manager): "HostConfig": { "CapAdd": ["ALL"], - "Binds": ["{}:/gns3:ro".format(get_resource("modules/docker/resources"))], + "Binds": ["{}:/gns3:ro".format(get_resource("hypervisor/docker/resources"))], "Privileged": True }, "Env": ["YES=1", "NO=0"], @@ -227,8 +227,8 @@ def test_create_image_not_available(loop, project, manager): vm._get_image_informations = MagicMock() vm._get_image_informations.side_effect = informations - with asyncio_patch("gns3server.modules.docker.DockerVM.pull_image", return_value=True) as mock_pull: - with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock: + with asyncio_patch("gns3server.hypervisor.docker.DockerVM.pull_image", return_value=True) as mock_pull: + with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock: loop.run_until_complete(asyncio.async(vm.create())) mock.assert_called_with("POST", "containers/create", data={ "Tty": True, @@ -237,7 +237,7 @@ def test_create_image_not_available(loop, project, manager): "HostConfig": { "CapAdd": ["ALL"], - "Binds": ["{}:/gns3:ro".format(get_resource("modules/docker/resources"))], + "Binds": ["{}:/gns3:ro".format(get_resource("hypervisor/docker/resources"))], "Privileged": True }, "Volumes": {}, @@ -266,17 +266,17 @@ def test_get_container_state(loop, vm): "StartedAt": "2015-01-06T15:47:32.072697474Z" } } - with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock: + with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock: assert loop.run_until_complete(asyncio.async(vm._get_container_state())) == "running" response["State"]["Running"] = False response["State"]["Paused"] = True - with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock: + with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock: assert loop.run_until_complete(asyncio.async(vm._get_container_state())) == "paused" response["State"]["Running"] = False response["State"]["Paused"] = False - with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock: + with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock: assert loop.run_until_complete(asyncio.async(vm._get_container_state())) == "exited" @@ -287,17 +287,17 @@ def test_is_running(loop, vm): "Paused": False } } - with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock: + with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock: assert loop.run_until_complete(asyncio.async(vm.is_running())) is False response["State"]["Running"] = True - with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock: + with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock: assert loop.run_until_complete(asyncio.async(vm.is_running())) is True def test_pause(loop, vm): - with asyncio_patch("gns3server.modules.docker.Docker.query") as mock: + with asyncio_patch("gns3server.hypervisor.docker.Docker.query") as mock: loop.run_until_complete(asyncio.async(vm.pause())) mock.assert_called_with("POST", "containers/e90e34656842/pause") @@ -306,7 +306,7 @@ def test_pause(loop, vm): def test_unpause(loop, vm): - with asyncio_patch("gns3server.modules.docker.Docker.query") as mock: + with asyncio_patch("gns3server.hypervisor.docker.Docker.query") as mock: loop.run_until_complete(asyncio.async(vm.unpause())) mock.assert_called_with("POST", "containers/e90e34656842/unpause") @@ -329,7 +329,7 @@ def test_start(loop, vm, manager, free_console_port): nio = manager.create_nio(0, {"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"}) loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio))) - with asyncio_patch("gns3server.modules.docker.Docker.query") as mock_query: + with asyncio_patch("gns3server.hypervisor.docker.Docker.query") as mock_query: loop.run_until_complete(asyncio.async(vm.start())) mock_query.assert_called_with("POST", "containers/e90e34656842/start") @@ -348,12 +348,12 @@ def test_start_namespace_failed(loop, vm, manager, free_console_port): nio = manager.create_nio(0, {"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"}) loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio))) - with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="stopped"): - with asyncio_patch("gns3server.modules.docker.Docker.query") as mock_query: - with asyncio_patch("gns3server.modules.docker.DockerVM._start_ubridge") as mock_start_ubridge: - with asyncio_patch("gns3server.modules.docker.DockerVM._get_namespace", return_value=42) as mock_namespace: - with asyncio_patch("gns3server.modules.docker.DockerVM._add_ubridge_connection", side_effect=UbridgeNamespaceError()) as mock_add_ubridge_connection: - with asyncio_patch("gns3server.modules.docker.DockerVM._get_log", return_value='Hello not available') as mock_log: + with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_container_state", return_value="stopped"): + with asyncio_patch("gns3server.hypervisor.docker.Docker.query") as mock_query: + with asyncio_patch("gns3server.hypervisor.docker.DockerVM._start_ubridge") as mock_start_ubridge: + with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_namespace", return_value=42) as mock_namespace: + with asyncio_patch("gns3server.hypervisor.docker.DockerVM._add_ubridge_connection", side_effect=UbridgeNamespaceError()) as mock_add_ubridge_connection: + with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_log", return_value='Hello not available') as mock_log: with pytest.raises(DockerError): loop.run_until_complete(asyncio.async(vm.start())) @@ -372,12 +372,12 @@ def test_start_without_nio(loop, vm, manager, free_console_port): assert vm.status != "started" vm.adapters = 1 - with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="stopped"): - with asyncio_patch("gns3server.modules.docker.Docker.query") as mock_query: - with asyncio_patch("gns3server.modules.docker.DockerVM._start_ubridge") as mock_start_ubridge: - with asyncio_patch("gns3server.modules.docker.DockerVM._get_namespace", return_value=42) as mock_namespace: - with asyncio_patch("gns3server.modules.docker.DockerVM._add_ubridge_connection") as mock_add_ubridge_connection: - with asyncio_patch("gns3server.modules.docker.DockerVM._start_console") as mock_start_console: + with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_container_state", return_value="stopped"): + with asyncio_patch("gns3server.hypervisor.docker.Docker.query") as mock_query: + with asyncio_patch("gns3server.hypervisor.docker.DockerVM._start_ubridge") as mock_start_ubridge: + with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_namespace", return_value=42) as mock_namespace: + with asyncio_patch("gns3server.hypervisor.docker.DockerVM._add_ubridge_connection") as mock_add_ubridge_connection: + with asyncio_patch("gns3server.hypervisor.docker.DockerVM._start_console") as mock_start_console: loop.run_until_complete(asyncio.async(vm.start())) mock_query.assert_called_with("POST", "containers/e90e34656842/start") @@ -389,8 +389,8 @@ def test_start_without_nio(loop, vm, manager, free_console_port): def test_start_unpause(loop, vm, manager, free_console_port): - with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="paused"): - with asyncio_patch("gns3server.modules.docker.DockerVM.unpause", return_value="paused") as mock: + with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_container_state", return_value="paused"): + with asyncio_patch("gns3server.hypervisor.docker.DockerVM.unpause", return_value="paused") as mock: loop.run_until_complete(asyncio.async(vm.start())) assert mock.called assert vm.status == "started" @@ -398,7 +398,7 @@ def test_start_unpause(loop, vm, manager, free_console_port): def test_restart(loop, vm): - with asyncio_patch("gns3server.modules.docker.Docker.query") as mock: + with asyncio_patch("gns3server.hypervisor.docker.Docker.query") as mock: loop.run_until_complete(asyncio.async(vm.restart())) mock.assert_called_with("POST", "containers/e90e34656842/restart") @@ -408,8 +408,8 @@ def test_stop(loop, vm): vm._ubridge_hypervisor = MagicMock() vm._ubridge_hypervisor.is_running.return_value = True - with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="running"): - with asyncio_patch("gns3server.modules.docker.Docker.query") as mock_query: + with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_container_state", return_value="running"): + with asyncio_patch("gns3server.hypervisor.docker.Docker.query") as mock_query: loop.run_until_complete(asyncio.async(vm.stop())) mock_query.assert_called_with("POST", "containers/e90e34656842/stop", params={"t": 5}) assert vm._ubridge_hypervisor.stop.called @@ -417,9 +417,9 @@ def test_stop(loop, vm): def test_stop_paused_container(loop, vm): - with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="paused"): - with asyncio_patch("gns3server.modules.docker.DockerVM.unpause") as mock_unpause: - with asyncio_patch("gns3server.modules.docker.Docker.query") as mock_query: + with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_container_state", return_value="paused"): + with asyncio_patch("gns3server.hypervisor.docker.DockerVM.unpause") as mock_unpause: + with asyncio_patch("gns3server.hypervisor.docker.Docker.query") as mock_query: loop.run_until_complete(asyncio.async(vm.stop())) mock_query.assert_called_with("POST", "containers/e90e34656842/stop", params={"t": 5}) assert mock_unpause.called @@ -434,9 +434,9 @@ def test_update(loop, vm): original_console = vm.console - with asyncio_patch("gns3server.modules.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images: - with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="stopped"): - with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock_query: + with asyncio_patch("gns3server.hypervisor.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images: + with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_container_state", return_value="stopped"): + with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock_query: loop.run_until_complete(asyncio.async(vm.update())) mock_query.assert_any_call("DELETE", "containers/e90e34656842", params={"force": 1}) @@ -447,7 +447,7 @@ def test_update(loop, vm): "HostConfig": { "CapAdd": ["ALL"], - "Binds": ["{}:/gns3:ro".format(get_resource("modules/docker/resources"))], + "Binds": ["{}:/gns3:ro".format(get_resource("hypervisor/docker/resources"))], "Privileged": True }, "Volumes": {}, @@ -471,9 +471,9 @@ def test_update_running(loop, vm): original_console = vm.console vm.start = MagicMock() - with asyncio_patch("gns3server.modules.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images: - with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="running"): - with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock_query: + with asyncio_patch("gns3server.hypervisor.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images: + with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_container_state", return_value="running"): + with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock_query: loop.run_until_complete(asyncio.async(vm.update())) mock_query.assert_any_call("DELETE", "containers/e90e34656842", params={"force": 1}) @@ -484,7 +484,7 @@ def test_update_running(loop, vm): "HostConfig": { "CapAdd": ["ALL"], - "Binds": ["{}:/gns3:ro".format(get_resource("modules/docker/resources"))], + "Binds": ["{}:/gns3:ro".format(get_resource("hypervisor/docker/resources"))], "Privileged": True }, "Volumes": {}, @@ -502,8 +502,8 @@ def test_update_running(loop, vm): def test_delete(loop, vm): - with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="stopped"): - with asyncio_patch("gns3server.modules.docker.Docker.query") as mock_query: + with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_container_state", return_value="stopped"): + with asyncio_patch("gns3server.hypervisor.docker.Docker.query") as mock_query: loop.run_until_complete(asyncio.async(vm.delete())) mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1}) @@ -516,8 +516,8 @@ def test_close(loop, vm, port_manager): nio = vm.manager.create_nio(0, nio) loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio))) - with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="stopped"): - with asyncio_patch("gns3server.modules.docker.Docker.query") as mock_query: + with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_container_state", return_value="stopped"): + with asyncio_patch("gns3server.hypervisor.docker.Docker.query") as mock_query: loop.run_until_complete(asyncio.async(vm.close())) mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1}) @@ -531,8 +531,8 @@ def test_close_vnc(loop, vm, port_manager): vm._x11vnc_process = MagicMock() vm._xvfb_process = MagicMock() - with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="stopped"): - with asyncio_patch("gns3server.modules.docker.Docker.query") as mock_query: + with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_container_state", return_value="stopped"): + with asyncio_patch("gns3server.hypervisor.docker.Docker.query") as mock_query: loop.run_until_complete(asyncio.async(vm.close())) mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1}) @@ -546,7 +546,7 @@ def test_get_namespace(loop, vm): "Pid": 42 } } - with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock_query: + with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock_query: assert loop.run_until_complete(asyncio.async(vm._get_namespace())) == 42 mock_query.assert_called_with("GET", "containers/e90e34656842/json") @@ -664,7 +664,7 @@ def test_adapter_remove_nio_binding(vm, loop): "rhost": "127.0.0.1"} nio = vm.manager.create_nio(0, nio) loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio))) - with asyncio_patch("gns3server.modules.docker.DockerVM._delete_ubridge_connection") as delete_ubridge_mock: + with asyncio_patch("gns3server.hypervisor.docker.DockerVM._delete_ubridge_connection") as delete_ubridge_mock: loop.run_until_complete(asyncio.async(vm.adapter_remove_nio_binding(0))) assert vm._ethernet_adapters[0].get_nio(0) is None delete_ubridge_mock.assert_called_with(0) @@ -697,7 +697,7 @@ def test_pull_image(loop, vm): mock_query = MagicMock() mock_query.content.return_value = Response() - with asyncio_patch("gns3server.modules.docker.Docker.http_query", return_value=mock_query) as mock: + with asyncio_patch("gns3server.hypervisor.docker.Docker.http_query", return_value=mock_query) as mock: images = loop.run_until_complete(asyncio.async(vm.pull_image("ubuntu"))) mock.assert_called_with("POST", "images/create", params={"fromImage": "ubuntu"}) @@ -730,7 +730,7 @@ def test_get_log(loop, vm): mock_query = MagicMock() mock_query.read = read - with asyncio_patch("gns3server.modules.docker.Docker.http_query", return_value=mock_query) as mock: + with asyncio_patch("gns3server.hypervisor.docker.Docker.http_query", return_value=mock_query) as mock: images = loop.run_until_complete(asyncio.async(vm._get_log())) mock.assert_called_with("GET", "containers/e90e34656842/logs", params={"stderr": 1, "stdout": 1}, data={}) @@ -738,7 +738,7 @@ def test_get_log(loop, vm): def test_get_image_informations(project, manager, loop): response = { } - with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock: + with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock: vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu") loop.run_until_complete(asyncio.async(vm._get_image_informations())) mock.assert_called_with("GET", "images/ubuntu/json") @@ -755,7 +755,7 @@ def test_mount_binds(vm, tmpdir): dst = os.path.join(vm.working_dir, "test/experimental") assert vm._mount_binds(image_infos) == [ - "{}:/gns3:ro".format(get_resource("modules/docker/resources")), + "{}:/gns3:ro".format(get_resource("hypervisor/docker/resources")), "{}:{}".format(dst, "/test/experimental") ] @@ -764,7 +764,7 @@ def test_mount_binds(vm, tmpdir): def test_start_vnc(vm, loop): with patch("shutil.which", return_value="/bin/x"): - with asyncio_patch("gns3server.modules.docker.docker_vm.wait_for_file_creation") as mock_wait: + with asyncio_patch("gns3server.hypervisor.docker.docker_vm.wait_for_file_creation") as mock_wait: with asyncio_patch("asyncio.create_subprocess_exec") as mock_exec: loop.run_until_complete(asyncio.async(vm._start_vnc())) assert vm._display is not None diff --git a/tests/modules/dynamips/test_dynamips_manager.py b/tests/hypervisor/dynamips/test_dynamips_manager.py similarity index 96% rename from tests/modules/dynamips/test_dynamips_manager.py rename to tests/hypervisor/dynamips/test_dynamips_manager.py index c744b29d..459201fc 100644 --- a/tests/modules/dynamips/test_dynamips_manager.py +++ b/tests/hypervisor/dynamips/test_dynamips_manager.py @@ -23,8 +23,8 @@ import uuid import os import asyncio -from gns3server.modules.dynamips import Dynamips -from gns3server.modules.dynamips.dynamips_error import DynamipsError +from gns3server.hypervisor.dynamips import Dynamips +from gns3server.hypervisor.dynamips.dynamips_error import DynamipsError from unittest.mock import patch diff --git a/tests/modules/dynamips/test_dynamips_router.py b/tests/hypervisor/dynamips/test_dynamips_router.py similarity index 90% rename from tests/modules/dynamips/test_dynamips_router.py rename to tests/hypervisor/dynamips/test_dynamips_router.py index f32b84ba..320246fd 100644 --- a/tests/modules/dynamips/test_dynamips_router.py +++ b/tests/hypervisor/dynamips/test_dynamips_router.py @@ -20,9 +20,9 @@ import asyncio import configparser from unittest.mock import patch -from gns3server.modules.dynamips.nodes.router import Router -from gns3server.modules.dynamips.dynamips_error import DynamipsError -from gns3server.modules.dynamips import Dynamips +from gns3server.hypervisor.dynamips.nodes.router import Router +from gns3server.hypervisor.dynamips.dynamips_error import DynamipsError +from gns3server.hypervisor.dynamips import Dynamips from gns3server.config import Config diff --git a/tests/modules/iou/test_iou_manager.py b/tests/hypervisor/iou/test_iou_manager.py similarity index 94% rename from tests/modules/iou/test_iou_manager.py rename to tests/hypervisor/iou/test_iou_manager.py index 6ff08636..384f435d 100644 --- a/tests/modules/iou/test_iou_manager.py +++ b/tests/hypervisor/iou/test_iou_manager.py @@ -25,10 +25,10 @@ import sys pytestmark = pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows") if not sys.platform.startswith("win"): - from gns3server.modules.iou import IOU - from gns3server.modules.iou.iou_error import IOUError + from gns3server.hypervisor.iou import IOU + from gns3server.hypervisor.iou.iou_error import IOUError -from gns3server.modules.project_manager import ProjectManager +from gns3server.hypervisor.project_manager import ProjectManager @pytest.fixture(scope="function") diff --git a/tests/modules/iou/test_iou_vm.py b/tests/hypervisor/iou/test_iou_vm.py similarity index 89% rename from tests/modules/iou/test_iou_vm.py rename to tests/hypervisor/iou/test_iou_vm.py index c5db24ff..4ad545e7 100644 --- a/tests/modules/iou/test_iou_vm.py +++ b/tests/hypervisor/iou/test_iou_vm.py @@ -32,9 +32,9 @@ from unittest.mock import patch, MagicMock, PropertyMock pytestmark = pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows") if not sys.platform.startswith("win"): - from gns3server.modules.iou.iou_vm import IOUVM - from gns3server.modules.iou.iou_error import IOUError - from gns3server.modules.iou import IOU + from gns3server.hypervisor.iou.iou_vm import IOUVM + from gns3server.hypervisor.iou.iou_error import IOUError + from gns3server.hypervisor.iou import IOU from gns3server.config import Config @@ -108,16 +108,17 @@ def test_vm_invalid_iouyap_path(project, manager, loop, fake_iou_bin): def test_start(loop, vm, monkeypatch): mock_process = MagicMock() - with patch("gns3server.modules.iou.iou_vm.IOUVM._check_requirements", return_value=True): - with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._check_iou_licence", return_value=True): - with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_ioucon", return_value=True): - with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True): + with patch("gns3server.hypervisor.iou.iou_vm.IOUVM._check_requirements", return_value=True): + with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._check_iou_licence", return_value=True): + with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._start_ioucon", return_value=True): + with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._start_iouyap", return_value=True): with asyncio_patch("asyncio.create_subprocess_exec", return_value=mock_process) as mock_exec: mock_process.returncode = None loop.run_until_complete(asyncio.async(vm.start())) assert vm.is_running() assert vm.command_line == ' '.join(mock_exec.call_args[0]) + def test_start_with_iourc(loop, vm, monkeypatch, tmpdir): fake_file = str(tmpdir / "iourc") @@ -125,10 +126,10 @@ def test_start_with_iourc(loop, vm, monkeypatch, tmpdir): f.write("1") mock_process = MagicMock() with patch("gns3server.config.Config.get_section_config", return_value={"iourc_path": fake_file, "iouyap_path": vm.iouyap_path}): - with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._check_requirements", return_value=True): - with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._check_iou_licence", return_value=True): - with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_ioucon", return_value=True): - with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True): + with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._check_requirements", return_value=True): + with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._check_iou_licence", return_value=True): + with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._start_ioucon", return_value=True): + with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._start_iouyap", return_value=True): with asyncio_patch("asyncio.create_subprocess_exec", return_value=mock_process) as exec_mock: mock_process.returncode = None loop.run_until_complete(asyncio.async(vm.start())) @@ -161,9 +162,9 @@ def test_stop(loop, vm): future.set_result(True) process.wait.return_value = future - with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._check_requirements", return_value=True): - with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_ioucon", return_value=True): - with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True): + with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._check_requirements", return_value=True): + with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._start_ioucon", return_value=True): + with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._start_iouyap", return_value=True): with asyncio_patch("asyncio.create_subprocess_exec", return_value=process): with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"): loop.run_until_complete(asyncio.async(vm.start())) @@ -183,9 +184,9 @@ def test_reload(loop, vm, fake_iou_bin): process.wait.return_value = future process.returncode = None - with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._check_requirements", return_value=True): - with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_ioucon", return_value=True): - with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True): + with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._check_requirements", return_value=True): + with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._start_ioucon", return_value=True): + with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._start_iouyap", return_value=True): with asyncio_patch("asyncio.create_subprocess_exec", return_value=process): with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"): loop.run_until_complete(asyncio.async(vm.start())) @@ -196,7 +197,7 @@ def test_reload(loop, vm, fake_iou_bin): def test_close(vm, port_manager, loop): - with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._check_requirements", return_value=True): + with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._check_requirements", return_value=True): with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()): vm.start() port = vm.console diff --git a/tests/modules/qemu/test_qemu_manager.py b/tests/hypervisor/qemu/test_qemu_manager.py similarity index 89% rename from tests/modules/qemu/test_qemu_manager.py rename to tests/hypervisor/qemu/test_qemu_manager.py index a032e82e..d79152b1 100644 --- a/tests/modules/qemu/test_qemu_manager.py +++ b/tests/hypervisor/qemu/test_qemu_manager.py @@ -22,8 +22,8 @@ import sys import pytest import platform -from gns3server.modules.qemu import Qemu -from gns3server.modules.qemu.qemu_error import QemuError +from gns3server.hypervisor.qemu import Qemu +from gns3server.hypervisor.qemu.qemu_error import QemuError from tests.utils import asyncio_patch from unittest.mock import patch, MagicMock @@ -40,7 +40,7 @@ def fake_qemu_img_binary(tmpdir): def test_get_qemu_version(loop): - with asyncio_patch("gns3server.modules.qemu.subprocess_check_output", return_value="QEMU emulator version 2.2.0, Copyright (c) 2003-2008 Fabrice Bellard") as mock: + with asyncio_patch("gns3server.hypervisor.qemu.subprocess_check_output", return_value="QEMU emulator version 2.2.0, Copyright (c) 2003-2008 Fabrice Bellard") as mock: version = loop.run_until_complete(asyncio.async(Qemu.get_qemu_version("/tmp/qemu-test"))) if sys.platform.startswith("win"): assert version == "" @@ -58,7 +58,7 @@ def test_binary_list(loop): f.write("1") os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) - with asyncio_patch("gns3server.modules.qemu.subprocess_check_output", return_value="QEMU emulator version 2.2.0, Copyright (c) 2003-2008 Fabrice Bellard") as mock: + with asyncio_patch("gns3server.hypervisor.qemu.subprocess_check_output", return_value="QEMU emulator version 2.2.0, Copyright (c) 2003-2008 Fabrice Bellard") as mock: if sys.platform.startswith("win"): version = "" else: @@ -97,7 +97,7 @@ def test_img_binary_list(loop): f.write("1") os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) - with asyncio_patch("gns3server.modules.qemu.subprocess_check_output", return_value="qemu-img version 2.2.0, Copyright (c) 2004-2008 Fabrice Bellard") as mock: + with asyncio_patch("gns3server.hypervisor.qemu.subprocess_check_output", return_value="qemu-img version 2.2.0, Copyright (c) 2004-2008 Fabrice Bellard") as mock: qemus = loop.run_until_complete(asyncio.async(Qemu.img_binary_list())) version = "2.2.0" @@ -151,7 +151,7 @@ def test_create_image_relative_path(loop, tmpdir, fake_qemu_img_binary): "size": 100 } with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process: - with patch("gns3server.modules.qemu.Qemu.get_images_directory", return_value=str(tmpdir)): + with patch("gns3server.hypervisor.qemu.Qemu.get_images_directory", return_value=str(tmpdir)): loop.run_until_complete(asyncio.async(Qemu.instance().create_disk(fake_qemu_img_binary, "hda.qcow2", options))) args, kwargs = process.call_args assert args == ( @@ -172,7 +172,7 @@ def test_create_image_exist(loop, tmpdir, fake_qemu_img_binary): "size": 100 } with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process: - with patch("gns3server.modules.qemu.Qemu.get_images_directory", return_value=str(tmpdir)): + with patch("gns3server.hypervisor.qemu.Qemu.get_images_directory", return_value=str(tmpdir)): with pytest.raises(QemuError): loop.run_until_complete(asyncio.async(Qemu.instance().create_disk(fake_qemu_img_binary, "hda.qcow2", options))) assert not process.called diff --git a/tests/modules/qemu/test_qemu_vm.py b/tests/hypervisor/qemu/test_qemu_vm.py similarity index 96% rename from tests/modules/qemu/test_qemu_vm.py rename to tests/hypervisor/qemu/test_qemu_vm.py index 209f270c..8d959ceb 100644 --- a/tests/modules/qemu/test_qemu_vm.py +++ b/tests/hypervisor/qemu/test_qemu_vm.py @@ -28,9 +28,9 @@ from tests.utils import asyncio_patch from unittest import mock from unittest.mock import patch, MagicMock -from gns3server.modules.qemu.qemu_vm import QemuVM -from gns3server.modules.qemu.qemu_error import QemuError -from gns3server.modules.qemu import Qemu +from gns3server.hypervisor.qemu.qemu_vm import QemuVM +from gns3server.hypervisor.qemu.qemu_error import QemuError +from gns3server.hypervisor.qemu import Qemu from gns3server.utils import force_unix_path @@ -175,7 +175,7 @@ def test_termination_callback_error(vm, tmpdir): def test_reload(loop, vm): - with asyncio_patch("gns3server.modules.qemu.QemuVM._control_vm") as mock: + with asyncio_patch("gns3server.hypervisor.qemu.QemuVM._control_vm") as mock: loop.run_until_complete(asyncio.async(vm.reload())) assert mock.called_with("system_reset") @@ -184,7 +184,7 @@ def test_suspend(loop, vm): control_vm_result = MagicMock() control_vm_result.match.group.decode.return_value = "running" - with asyncio_patch("gns3server.modules.qemu.QemuVM._control_vm", return_value=control_vm_result) as mock: + with asyncio_patch("gns3server.hypervisor.qemu.QemuVM._control_vm", return_value=control_vm_result) as mock: loop.run_until_complete(asyncio.async(vm.suspend())) assert mock.called_with("system_reset") @@ -197,7 +197,7 @@ def test_add_nio_binding_udp(vm, loop): @pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows") def test_add_nio_binding_ethernet(vm, loop, ethernet_device): - with patch("gns3server.modules.base_manager.BaseManager.has_privileged_access", return_value=True): + with patch("gns3server.hypervisor.base_manager.BaseManager.has_privileged_access", return_value=True): nio = Qemu.instance().create_nio(vm.qemu_path, {"type": "nio_generic_ethernet", "ethernet_device": ethernet_device}) loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio))) assert nio.ethernet_device == ethernet_device @@ -305,7 +305,7 @@ def test_set_qemu_path_kvm_binary(vm, tmpdir, fake_qemu_binary): def test_set_platform(project, manager): with patch("shutil.which", return_value="/bin/qemu-system-x86_64") as which_mock: - with patch("gns3server.modules.qemu.QemuVM._check_qemu_path"): + with patch("gns3server.hypervisor.qemu.QemuVM._check_qemu_path"): vm = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, platform="x86_64") if sys.platform.startswith("win"): which_mock.assert_called_with("qemu-system-x86_64w.exe", path=mock.ANY) @@ -480,7 +480,7 @@ def test_initrd(vm, tmpdir): vm.manager.config.set("Server", "images_path", str(tmpdir)) - with patch("gns3server.modules.project.Project.emit") as mock: + with patch("gns3server.hypervisor.project.Project.emit") as mock: vm.initrd = str(tmpdir / "test") assert vm.initrd == force_unix_path(str(tmpdir / "test")) vm.initrd = "test" @@ -492,7 +492,7 @@ def test_initrd_asa(vm, tmpdir): vm.manager.config.set("Server", "images_path", str(tmpdir)) - with patch("gns3server.modules.project.Project.emit") as mock: + with patch("gns3server.hypervisor.project.Project.emit") as mock: vm.initrd = str(tmpdir / "asa842-initrd.gz") assert vm.initrd == force_unix_path(str(tmpdir / "asa842-initrd.gz")) vm.initrd = "asa842-initrd.gz" diff --git a/tests/modules/test_base_vm.py b/tests/hypervisor/test_base_vm.py similarity index 93% rename from tests/modules/test_base_vm.py rename to tests/hypervisor/test_base_vm.py index c38f1bdc..85edd9ce 100644 --- a/tests/modules/test_base_vm.py +++ b/tests/hypervisor/test_base_vm.py @@ -23,11 +23,11 @@ from tests.utils import asyncio_patch from unittest.mock import patch, MagicMock -from gns3server.modules.vpcs.vpcs_vm import VPCSVM -from gns3server.modules.docker.docker_vm import DockerVM -from gns3server.modules.vpcs.vpcs_error import VPCSError -from gns3server.modules.vm_error import VMError -from gns3server.modules.vpcs import VPCS +from gns3server.hypervisor.vpcs.vpcs_vm import VPCSVM +from gns3server.hypervisor.docker.docker_vm import DockerVM +from gns3server.hypervisor.vpcs.vpcs_error import VPCSError +from gns3server.hypervisor.vm_error import VMError +from gns3server.hypervisor.vpcs import VPCS @pytest.fixture(scope="module") diff --git a/tests/modules/test_manager.py b/tests/hypervisor/test_manager.py similarity index 92% rename from tests/modules/test_manager.py rename to tests/hypervisor/test_manager.py index feb15cbd..f9d11df0 100644 --- a/tests/modules/test_manager.py +++ b/tests/hypervisor/test_manager.py @@ -21,9 +21,9 @@ import pytest from unittest.mock import patch -from gns3server.modules.vpcs import VPCS -from gns3server.modules.qemu import Qemu -from gns3server.modules.vm_error import VMError +from gns3server.hypervisor.vpcs import VPCS +from gns3server.hypervisor.qemu import Qemu +from gns3server.hypervisor.vm_error import VMError from gns3server.utils import force_unix_path @@ -67,7 +67,7 @@ def test_create_vm_new_topology_without_uuid(loop, project, vpcs): def test_create_vm_old_topology(loop, project, tmpdir, vpcs): - with patch("gns3server.modules.project.Project.is_local", return_value=True): + with patch("gns3server.hypervisor.project.Project.is_local", return_value=True): # Create an old topology directory project_dir = str(tmpdir / "testold") vm_dir = os.path.join(project_dir, "testold-files", "vpcs", "pc-1") @@ -158,7 +158,7 @@ def test_list_images(loop, qemu, tmpdir): with open(str(tmpdir / image), "w+") as f: f.write("1") - with patch("gns3server.modules.Qemu.get_images_directory", return_value=str(tmpdir)): + with patch("gns3server.hypervisor.Qemu.get_images_directory", return_value=str(tmpdir)): assert loop.run_until_complete(qemu.list_images()) == [ {"filename": "a.bin", "path": "a.bin"}, {"filename": "b.bin", "path": "b.bin"} @@ -177,7 +177,7 @@ def test_list_images_recursives(loop, qemu, tmpdir): with open(str(tmpdir / "c" / image), "w+") as f: f.write("1") - with patch("gns3server.modules.Qemu.get_images_directory", return_value=str(tmpdir)): + with patch("gns3server.hypervisor.Qemu.get_images_directory", return_value=str(tmpdir)): assert loop.run_until_complete(qemu.list_images()) == [ {"filename": "a.bin", "path": "a.bin"}, {"filename": "b.bin", "path": "b.bin"}, @@ -186,10 +186,10 @@ def test_list_images_recursives(loop, qemu, tmpdir): def test_list_images_empty(loop, qemu, tmpdir): - with patch("gns3server.modules.Qemu.get_images_directory", return_value=str(tmpdir)): + with patch("gns3server.hypervisor.Qemu.get_images_directory", return_value=str(tmpdir)): assert loop.run_until_complete(qemu.list_images()) == [] def test_list_images_directory_not_exist(loop, qemu): - with patch("gns3server.modules.Qemu.get_images_directory", return_value="/bla"): + with patch("gns3server.hypervisor.Qemu.get_images_directory", return_value="/bla"): assert loop.run_until_complete(qemu.list_images()) == [] diff --git a/tests/modules/test_port_manager.py b/tests/hypervisor/test_port_manager.py similarity index 84% rename from tests/modules/test_port_manager.py rename to tests/hypervisor/test_port_manager.py index c41ad664..7d7d6e5e 100644 --- a/tests/modules/test_port_manager.py +++ b/tests/hypervisor/test_port_manager.py @@ -19,15 +19,15 @@ import aiohttp import pytest import sys from unittest.mock import patch -from gns3server.modules.port_manager import PortManager -from gns3server.modules.project import Project +from gns3server.hypervisor.port_manager import PortManager +from gns3server.hypervisor.project import Project def test_reserve_tcp_port(): pm = PortManager() project = Project() pm.reserve_tcp_port(2001, project) - with patch("gns3server.modules.project.Project.emit") as mock_emit: + with patch("gns3server.hypervisor.project.Project.emit") as mock_emit: port = pm.reserve_tcp_port(2001, project) assert port != 2001 assert mock_emit.call_args[0][0] == "log.warning" @@ -36,7 +36,7 @@ def test_reserve_tcp_port(): def test_reserve_tcp_port_outside_range(): pm = PortManager() project = Project() - with patch("gns3server.modules.project.Project.emit") as mock_emit: + with patch("gns3server.hypervisor.project.Project.emit") as mock_emit: port = pm.reserve_tcp_port(80, project) assert port != 80 assert mock_emit.call_args[0][0] == "log.warning" @@ -50,7 +50,7 @@ def test_reserve_tcp_port_already_used_by_another_program(): pm = PortManager() project = Project() - with patch("gns3server.modules.port_manager.PortManager._check_port") as mock_check: + with patch("gns3server.hypervisor.port_manager.PortManager._check_port") as mock_check: def execute_mock(host, port, *args): if port == 2001: @@ -60,7 +60,7 @@ def test_reserve_tcp_port_already_used_by_another_program(): mock_check.side_effect = execute_mock - with patch("gns3server.modules.project.Project.emit") as mock_emit: + with patch("gns3server.hypervisor.project.Project.emit") as mock_emit: port = pm.reserve_tcp_port(2001, project) assert port != 2001 assert mock_emit.call_args[0][0] == "log.warning" @@ -74,7 +74,7 @@ def test_reserve_tcp_port_already_used(): pm = PortManager() project = Project() - with patch("gns3server.modules.port_manager.PortManager._check_port") as mock_check: + with patch("gns3server.hypervisor.port_manager.PortManager._check_port") as mock_check: def execute_mock(host, port, *args): if port == 2001: @@ -84,7 +84,7 @@ def test_reserve_tcp_port_already_used(): mock_check.side_effect = execute_mock - with patch("gns3server.modules.project.Project.emit") as mock_emit: + with patch("gns3server.hypervisor.project.Project.emit") as mock_emit: port = pm.reserve_tcp_port(2001, project) assert port != 2001 assert mock_emit.call_args[0][0] == "log.warning" diff --git a/tests/modules/test_project.py b/tests/hypervisor/test_project.py similarity index 90% rename from tests/modules/test_project.py rename to tests/hypervisor/test_project.py index 1a9a1b93..8ca7a935 100644 --- a/tests/modules/test_project.py +++ b/tests/hypervisor/test_project.py @@ -24,8 +24,8 @@ from uuid import uuid4 from unittest.mock import patch from tests.utils import asyncio_patch -from gns3server.modules.project import Project -from gns3server.modules.vpcs import VPCS, VPCSVM +from gns3server.hypervisor.project import Project +from gns3server.hypervisor.vpcs import VPCS, VPCSVM @pytest.fixture(scope="module") @@ -50,7 +50,7 @@ def test_affect_uuid(): def test_path(tmpdir): - with patch("gns3server.modules.project.Project.is_local", return_value=True): + with patch("gns3server.hypervisor.project.Project.is_local", return_value=True): p = Project(location=str(tmpdir)) assert p.path == os.path.join(str(tmpdir), p.id) assert os.path.exists(os.path.join(str(tmpdir), p.id)) @@ -59,14 +59,14 @@ def test_path(tmpdir): def test_init_path(tmpdir): - with patch("gns3server.modules.project.Project.is_local", return_value=True): + with patch("gns3server.hypervisor.project.Project.is_local", return_value=True): p = Project(path=str(tmpdir)) assert p.path == str(tmpdir) def test_changing_path_temporary_flag(tmpdir): - with patch("gns3server.modules.project.Project.is_local", return_value=True): + with patch("gns3server.hypervisor.project.Project.is_local", return_value=True): p = Project(temporary=True) assert os.path.exists(p.path) original_path = p.path @@ -90,20 +90,20 @@ def test_remove_temporary_flag(): def test_changing_location_not_allowed(tmpdir): - with patch("gns3server.modules.project.Project.is_local", return_value=False): + with patch("gns3server.hypervisor.project.Project.is_local", return_value=False): with pytest.raises(aiohttp.web.HTTPForbidden): p = Project(location=str(tmpdir)) def test_changing_path_not_allowed(tmpdir): - with patch("gns3server.modules.project.Project.is_local", return_value=False): + with patch("gns3server.hypervisor.project.Project.is_local", return_value=False): with pytest.raises(aiohttp.web.HTTPForbidden): p = Project() p.path = str(tmpdir) def test_changing_path_with_quote_not_allowed(tmpdir): - with patch("gns3server.modules.project.Project.is_local", return_value=True): + with patch("gns3server.hypervisor.project.Project.is_local", return_value=True): with pytest.raises(aiohttp.web.HTTPForbidden): p = Project() p.path = str(tmpdir / "project\"53") @@ -115,7 +115,7 @@ def test_json(tmpdir): def test_vm_working_directory(tmpdir, vm): - with patch("gns3server.modules.project.Project.is_local", return_value=True): + with patch("gns3server.hypervisor.project.Project.is_local", return_value=True): p = Project(location=str(tmpdir)) assert p.vm_working_directory(vm) == os.path.join(str(tmpdir), p.id, 'project-files', vm.module_name, vm.id) assert os.path.exists(p.vm_working_directory(vm)) @@ -184,7 +184,7 @@ def test_project_add_vm(manager): def test_project_close(loop, vm, project): - with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.close") as mock: + with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.VPCSVM.close") as mock: loop.run_until_complete(asyncio.async(project.close())) assert mock.called assert vm.id not in vm.manager._vms diff --git a/tests/modules/test_project_manager.py b/tests/hypervisor/test_project_manager.py similarity index 94% rename from tests/modules/test_project_manager.py rename to tests/hypervisor/test_project_manager.py index 0f2d6ed3..7d359a99 100644 --- a/tests/modules/test_project_manager.py +++ b/tests/hypervisor/test_project_manager.py @@ -17,7 +17,7 @@ import aiohttp import pytest -from gns3server.modules.project_manager import ProjectManager +from gns3server.hypervisor.project_manager import ProjectManager def test_create_project(): diff --git a/tests/modules/virtualbox/test_virtualbox_manager.py b/tests/hypervisor/virtualbox/test_virtualbox_manager.py similarity index 93% rename from tests/modules/virtualbox/test_virtualbox_manager.py rename to tests/hypervisor/virtualbox/test_virtualbox_manager.py index 2dfda065..c0f4f855 100644 --- a/tests/modules/virtualbox/test_virtualbox_manager.py +++ b/tests/hypervisor/virtualbox/test_virtualbox_manager.py @@ -25,8 +25,8 @@ import asyncio from unittest.mock import patch -from gns3server.modules.virtualbox import VirtualBox -from gns3server.modules.virtualbox.virtualbox_error import VirtualBoxError +from gns3server.hypervisor.virtualbox import VirtualBox +from gns3server.hypervisor.virtualbox.virtualbox_error import VirtualBoxError from tests.utils import asyncio_patch @@ -90,7 +90,7 @@ def test_list_images(manager, loop): return ["memory=256"] assert False, "Unknow {} {}".format(cmd, args) - with asyncio_patch("gns3server.modules.virtualbox.VirtualBox.execute") as mock: + with asyncio_patch("gns3server.hypervisor.virtualbox.VirtualBox.execute") as mock: mock.side_effect = execute_mock vms = loop.run_until_complete(asyncio.async(manager.list_images())) assert vms == [ diff --git a/tests/modules/virtualbox/test_virtualbox_vm.py b/tests/hypervisor/virtualbox/test_virtualbox_vm.py similarity index 84% rename from tests/modules/virtualbox/test_virtualbox_vm.py rename to tests/hypervisor/virtualbox/test_virtualbox_vm.py index 3144d1a9..5a2ed514 100644 --- a/tests/modules/virtualbox/test_virtualbox_vm.py +++ b/tests/hypervisor/virtualbox/test_virtualbox_vm.py @@ -19,9 +19,9 @@ import pytest import asyncio from tests.utils import asyncio_patch -from gns3server.modules.virtualbox.virtualbox_vm import VirtualBoxVM -from gns3server.modules.virtualbox.virtualbox_error import VirtualBoxError -from gns3server.modules.virtualbox import VirtualBox +from gns3server.hypervisor.virtualbox.virtualbox_vm import VirtualBoxVM +from gns3server.hypervisor.virtualbox.virtualbox_error import VirtualBoxError +from gns3server.hypervisor.virtualbox import VirtualBox @pytest.fixture(scope="module") @@ -44,13 +44,13 @@ def test_vm(project, manager): def test_vm_valid_virtualbox_api_version(loop, project, manager): - with asyncio_patch("gns3server.modules.virtualbox.VirtualBox.execute", return_value=["API version: 4_3"]): + with asyncio_patch("gns3server.hypervisor.virtualbox.VirtualBox.execute", return_value=["API version: 4_3"]): vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, "test", False) loop.run_until_complete(asyncio.async(vm.create())) def test_vm_invalid_virtualbox_api_version(loop, project, manager): - with asyncio_patch("gns3server.modules.virtualbox.VirtualBox.execute", return_value=["API version: 4_2"]): + with asyncio_patch("gns3server.hypervisor.virtualbox.VirtualBox.execute", return_value=["API version: 4_2"]): with pytest.raises(VirtualBoxError): vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, "test", False) loop.run_until_complete(asyncio.async(vm.create())) diff --git a/tests/modules/vmware/test_vmware_manager.py b/tests/hypervisor/vmware/test_vmware_manager.py similarity index 96% rename from tests/modules/vmware/test_vmware_manager.py rename to tests/hypervisor/vmware/test_vmware_manager.py index 79089d2c..89025af6 100644 --- a/tests/modules/vmware/test_vmware_manager.py +++ b/tests/hypervisor/vmware/test_vmware_manager.py @@ -25,7 +25,7 @@ import asyncio from unittest.mock import patch -from gns3server.modules.vmware import VMware +from gns3server.hypervisor.vmware import VMware from tests.utils import asyncio_patch diff --git a/tests/modules/vmware/test_vmware_vm.py b/tests/hypervisor/vmware/test_vmware_vm.py similarity index 93% rename from tests/modules/vmware/test_vmware_vm.py rename to tests/hypervisor/vmware/test_vmware_vm.py index 76688497..cd56f5ee 100644 --- a/tests/modules/vmware/test_vmware_vm.py +++ b/tests/hypervisor/vmware/test_vmware_vm.py @@ -19,9 +19,9 @@ import pytest import asyncio from tests.utils import asyncio_patch -from gns3server.modules.vmware.vmware_vm import VMwareVM -from gns3server.modules.vmware.vmware_error import VMwareError -from gns3server.modules.vmware import VMware +from gns3server.hypervisor.vmware.vmware_vm import VMwareVM +from gns3server.hypervisor.vmware.vmware_error import VMwareError +from gns3server.hypervisor.vmware import VMware @pytest.fixture(scope="module") diff --git a/tests/modules/vpcs/test_vpcs_manager.py b/tests/hypervisor/vpcs/test_vpcs_manager.py similarity index 93% rename from tests/modules/vpcs/test_vpcs_manager.py rename to tests/hypervisor/vpcs/test_vpcs_manager.py index c7194de3..ba45a06c 100644 --- a/tests/modules/vpcs/test_vpcs_manager.py +++ b/tests/hypervisor/vpcs/test_vpcs_manager.py @@ -20,9 +20,9 @@ import pytest import uuid -from gns3server.modules.vpcs import VPCS -from gns3server.modules.vpcs.vpcs_error import VPCSError -from gns3server.modules.project_manager import ProjectManager +from gns3server.hypervisor.vpcs import VPCS +from gns3server.hypervisor.vpcs.vpcs_error import VPCSError +from gns3server.hypervisor.project_manager import ProjectManager def test_get_mac_id(loop, project, port_manager): diff --git a/tests/modules/vpcs/test_vpcs_vm.py b/tests/hypervisor/vpcs/test_vpcs_vm.py similarity index 87% rename from tests/modules/vpcs/test_vpcs_vm.py rename to tests/hypervisor/vpcs/test_vpcs_vm.py index 41558516..de8660c3 100644 --- a/tests/modules/vpcs/test_vpcs_vm.py +++ b/tests/hypervisor/vpcs/test_vpcs_vm.py @@ -25,9 +25,9 @@ from tests.utils import asyncio_patch from pkg_resources import parse_version from unittest.mock import patch, MagicMock -from gns3server.modules.vpcs.vpcs_vm import VPCSVM -from gns3server.modules.vpcs.vpcs_error import VPCSError -from gns3server.modules.vpcs import VPCS +from gns3server.hypervisor.vpcs.vpcs_vm import VPCSVM +from gns3server.hypervisor.vpcs.vpcs_error import VPCSError +from gns3server.hypervisor.vpcs import VPCS @pytest.fixture(scope="module") @@ -51,19 +51,19 @@ def test_vm(project, manager): def test_vm_check_vpcs_version(loop, vm, manager): - with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.subprocess_check_output", return_value="Welcome to Virtual PC Simulator, version 0.9"): + with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.subprocess_check_output", return_value="Welcome to Virtual PC Simulator, version 0.9"): loop.run_until_complete(asyncio.async(vm._check_vpcs_version())) assert vm._vpcs_version == parse_version("0.9") def test_vm_check_vpcs_version_0_6_1(loop, vm, manager): - with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.subprocess_check_output", return_value="Welcome to Virtual PC Simulator, version 0.6.1"): + with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.subprocess_check_output", return_value="Welcome to Virtual PC Simulator, version 0.6.1"): loop.run_until_complete(asyncio.async(vm._check_vpcs_version())) assert vm._vpcs_version == parse_version("0.6.1") def test_vm_invalid_vpcs_version(loop, manager, vm): - with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.subprocess_check_output", return_value="Welcome to Virtual PC Simulator, version 0.1"): + with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.subprocess_check_output", return_value="Welcome to Virtual PC Simulator, version 0.1"): with pytest.raises(VPCSError): nio = manager.create_nio(vm.vpcs_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"}) vm.port_add_nio_binding(0, nio) @@ -73,7 +73,7 @@ def test_vm_invalid_vpcs_version(loop, manager, vm): def test_vm_invalid_vpcs_path(vm, manager, loop): - with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.vpcs_path", return_value="/tmp/fake/path/vpcs"): + with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.VPCSVM.vpcs_path", return_value="/tmp/fake/path/vpcs"): with pytest.raises(VPCSError): nio = manager.create_nio(vm.vpcs_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"}) vm.port_add_nio_binding(0, nio) @@ -87,7 +87,7 @@ def test_start(loop, vm): process.returncode = None queue = vm.project.get_listen_queue() - with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True): + with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True): with asyncio_patch("asyncio.create_subprocess_exec", return_value=process) as mock_exec: nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"}) vm.port_add_nio_binding(0, nio) @@ -123,7 +123,7 @@ def test_start_0_6_1(loop, vm): queue = vm.project.get_listen_queue() vm._vpcs_version = parse_version("0.6.1") - with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True): + with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True): with asyncio_patch("asyncio.create_subprocess_exec", return_value=process) as mock_exec: nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"}) vm.port_add_nio_binding(0, nio) @@ -156,7 +156,7 @@ def test_stop(loop, vm): process.wait.return_value = future process.returncode = None - with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True): + with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True): with asyncio_patch("asyncio.create_subprocess_exec", return_value=process): nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"}) vm.port_add_nio_binding(0, nio) @@ -189,7 +189,7 @@ def test_reload(loop, vm): process.wait.return_value = future process.returncode = None - with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True): + with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True): with asyncio_patch("asyncio.create_subprocess_exec", return_value=process): nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"}) vm.port_add_nio_binding(0, nio) @@ -214,14 +214,14 @@ def test_add_nio_binding_udp(vm): @pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows") def test_add_nio_binding_tap(vm, ethernet_device): - with patch("gns3server.modules.base_manager.BaseManager.has_privileged_access", return_value=True): + with patch("gns3server.hypervisor.base_manager.BaseManager.has_privileged_access", return_value=True): nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_tap", "tap_device": ethernet_device}) vm.port_add_nio_binding(0, nio) assert nio.tap_device == ethernet_device # def test_add_nio_binding_tap_no_privileged_access(vm): -# with patch("gns3server.modules.base_manager.BaseManager.has_privileged_access", return_value=False): +# with patch("gns3server.hypervisor.base_manager.BaseManager.has_privileged_access", return_value=False): # with pytest.raises(aiohttp.web.HTTPForbidden): # nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_tap", "tap_device": "test"}) # vm.port_add_nio_binding(0, nio) @@ -285,7 +285,7 @@ def test_change_name(vm, tmpdir): def test_close(vm, port_manager, loop): - with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True): + with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True): with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()): vm.start() loop.run_until_complete(asyncio.async(vm.close()))