mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-30 20:28:08 +00:00
Raise an error if image is missing on compute
This commit is contained in:
parent
dcebaf61b8
commit
d8bdd16e13
@ -39,7 +39,7 @@ from .nios.nio_udp import NIOUDP
|
|||||||
from .nios.nio_tap import NIOTAP
|
from .nios.nio_tap import NIOTAP
|
||||||
from .nios.nio_ethernet import NIOEthernet
|
from .nios.nio_ethernet import NIOEthernet
|
||||||
from ..utils.images import md5sum, remove_checksum
|
from ..utils.images import md5sum, remove_checksum
|
||||||
from .node_error import NodeError
|
from .error import NodeError, ImageMissingError
|
||||||
|
|
||||||
|
|
||||||
class BaseManager:
|
class BaseManager:
|
||||||
@ -432,18 +432,27 @@ class BaseManager:
|
|||||||
path = self._recursive_search_file_in_directory(directory, orig_path)
|
path = self._recursive_search_file_in_directory(directory, orig_path)
|
||||||
if path:
|
if path:
|
||||||
return force_unix_path(path)
|
return force_unix_path(path)
|
||||||
# Not found we return the default directory
|
|
||||||
|
# Not found we try the default directory
|
||||||
s = os.path.split(orig_path)
|
s = os.path.split(orig_path)
|
||||||
return force_unix_path(os.path.join(self.get_images_directory(), *s))
|
path = force_unix_path(os.path.join(self.get_images_directory(), *s))
|
||||||
|
if os.path.exists(path):
|
||||||
|
return path
|
||||||
|
raise ImageMissingError(path)
|
||||||
|
|
||||||
# For non local server we disallow using absolute path outside image directory
|
# For non local server we disallow using absolute path outside image directory
|
||||||
if server_config.get("local", False) is True:
|
if server_config.get("local", False) is True:
|
||||||
return force_unix_path(path)
|
path = force_unix_path(path)
|
||||||
|
if os.path.exists(path):
|
||||||
|
return path
|
||||||
|
raise ImageMissingError(path)
|
||||||
|
|
||||||
path = force_unix_path(path)
|
path = force_unix_path(path)
|
||||||
for directory in self.images_directories():
|
for directory in self.images_directories():
|
||||||
if os.path.commonprefix([directory, path]) == directory:
|
if os.path.commonprefix([directory, path]) == directory:
|
||||||
return path
|
if os.path.exists(path):
|
||||||
|
return path
|
||||||
|
raise ImageMissingError(path)
|
||||||
raise NodeError("{} is not allowed on this remote server. Please use only a filename in {}.".format(path, self.get_images_directory()))
|
raise NodeError("{} is not allowed on this remote server. Please use only a filename in {}.".format(path, self.get_images_directory()))
|
||||||
|
|
||||||
def _recursive_search_file_in_directory(self, directory, searched_file):
|
def _recursive_search_file_in_directory(self, directory, searched_file):
|
||||||
|
@ -28,7 +28,7 @@ import platform
|
|||||||
from ..utils.asyncio import wait_run_in_executor
|
from ..utils.asyncio import wait_run_in_executor
|
||||||
from ..ubridge.hypervisor import Hypervisor
|
from ..ubridge.hypervisor import Hypervisor
|
||||||
from ..ubridge.ubridge_error import UbridgeError
|
from ..ubridge.ubridge_error import UbridgeError
|
||||||
from .node_error import NodeError
|
from .error import NodeError
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
from ..node_error import NodeError
|
from ..error import NodeError
|
||||||
from .nodes.cloud import Cloud
|
from .nodes.cloud import Cloud
|
||||||
from .nodes.ethernet_hub import EthernetHub
|
from .nodes.ethernet_hub import EthernetHub
|
||||||
from .nodes.ethernet_switch import EthernetSwitch
|
from .nodes.ethernet_switch import EthernetSwitch
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from ...node_error import NodeError
|
from ...error import NodeError
|
||||||
from ...base_node import BaseNode
|
from ...base_node import BaseNode
|
||||||
from ...nios.nio_udp import NIOUDP
|
from ...nios.nio_udp import NIOUDP
|
||||||
|
|
||||||
@ -181,7 +181,6 @@ class Cloud(BaseNode):
|
|||||||
yield from self._ubridge_send('bridge start_capture {name} "{pcap_file}"'.format(name=bridge_name,
|
yield from self._ubridge_send('bridge start_capture {name} "{pcap_file}"'.format(name=bridge_name,
|
||||||
pcap_file=nio.pcap_output_file))
|
pcap_file=nio.pcap_output_file))
|
||||||
|
|
||||||
|
|
||||||
yield from self._ubridge_send('bridge start {name}'.format(name=bridge_name))
|
yield from self._ubridge_send('bridge start {name}'.format(name=bridge_name))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@ -269,7 +268,6 @@ class Cloud(BaseNode):
|
|||||||
id=self.id,
|
id=self.id,
|
||||||
port_number=port_number))
|
port_number=port_number))
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def stop_capture(self, port_number):
|
def stop_capture(self, port_number):
|
||||||
"""
|
"""
|
||||||
@ -291,5 +289,5 @@ class Cloud(BaseNode):
|
|||||||
yield from self._ubridge_send("bridge stop_capture {name}".format(name=bridge_name))
|
yield from self._ubridge_send("bridge stop_capture {name}".format(name=bridge_name))
|
||||||
|
|
||||||
log.info("Cloud'{name}' [{id}]: stopping packet capture on port {port_number}".format(name=self.name,
|
log.info("Cloud'{name}' [{id}]: stopping packet capture on port {port_number}".format(name=self.name,
|
||||||
id=self.id,
|
id=self.id,
|
||||||
port_number=port_number))
|
port_number=port_number))
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from ...node_error import NodeError
|
from ...error import NodeError
|
||||||
from ...base_node import BaseNode
|
from ...base_node import BaseNode
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from ...node_error import NodeError
|
from ...error import NodeError
|
||||||
from ...base_node import BaseNode
|
from ...base_node import BaseNode
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
Custom exceptions for the Docker module.
|
Custom exceptions for the Docker module.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from ..node_error import NodeError
|
from ..error import NodeError
|
||||||
|
|
||||||
|
|
||||||
class DockerError(NodeError):
|
class DockerError(NodeError):
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
Custom exceptions for the Dynamips module.
|
Custom exceptions for the Dynamips module.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from ..node_error import NodeError
|
from ..error import NodeError
|
||||||
|
|
||||||
|
|
||||||
class DynamipsError(NodeError):
|
class DynamipsError(NodeError):
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
class NodeError(Exception):
|
class NodeError(Exception):
|
||||||
|
|
||||||
def __init__(self, message, original_exception=None):
|
def __init__(self, message, original_exception=None):
|
||||||
|
|
||||||
super().__init__(message)
|
super().__init__(message)
|
||||||
if isinstance(message, Exception):
|
if isinstance(message, Exception):
|
||||||
message = str(message)
|
message = str(message)
|
||||||
@ -27,9 +26,16 @@ class NodeError(Exception):
|
|||||||
self._original_exception = original_exception
|
self._original_exception = original_exception
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|
||||||
return self._message
|
return self._message
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
||||||
return self._message
|
return self._message
|
||||||
|
|
||||||
|
|
||||||
|
class ImageMissingError(Exception):
|
||||||
|
"""
|
||||||
|
Raised when an image is missing
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, image):
|
||||||
|
super().__init__("The image {} is missing".format(image))
|
@ -19,7 +19,7 @@
|
|||||||
Custom exceptions for the IOU module.
|
Custom exceptions for the IOU module.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from ..node_error import NodeError
|
from ..error import NodeError
|
||||||
|
|
||||||
|
|
||||||
class IOUError(NodeError):
|
class IOUError(NodeError):
|
||||||
|
@ -91,6 +91,9 @@ class IOUVM(BaseNode):
|
|||||||
self._ram = 256 # Megabytes
|
self._ram = 256 # Megabytes
|
||||||
self._l1_keepalives = False # used to overcome the always-up Ethernet interfaces (not supported by all IOSes).
|
self._l1_keepalives = False # used to overcome the always-up Ethernet interfaces (not supported by all IOSes).
|
||||||
|
|
||||||
|
def _config(self):
|
||||||
|
return self._manager.config.get_section_config("IOU")
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def close(self):
|
def close(self):
|
||||||
"""
|
"""
|
||||||
@ -129,15 +132,6 @@ class IOUVM(BaseNode):
|
|||||||
|
|
||||||
self._path = self.manager.get_abs_image_path(path)
|
self._path = self.manager.get_abs_image_path(path)
|
||||||
|
|
||||||
# In 1.2 users uploaded images to the images roots
|
|
||||||
# after the migration their images are inside images/IOU
|
|
||||||
# but old topologies use old path
|
|
||||||
if "IOU" not in self._path:
|
|
||||||
location, filename = os.path.split(self._path)
|
|
||||||
fix_path = os.path.join(location, "IOU", filename)
|
|
||||||
if os.path.isfile(fix_path):
|
|
||||||
self._path = fix_path
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def use_default_iou_values(self):
|
def use_default_iou_values(self):
|
||||||
"""
|
"""
|
||||||
@ -232,7 +226,7 @@ class IOUVM(BaseNode):
|
|||||||
:returns: path to IOUYAP
|
:returns: path to IOUYAP
|
||||||
"""
|
"""
|
||||||
|
|
||||||
path = self._manager.config.get_section_config("IOU").get("iouyap_path", "iouyap")
|
path = self._config().get("iouyap_path", "iouyap")
|
||||||
if path == "iouyap":
|
if path == "iouyap":
|
||||||
path = shutil.which("iouyap")
|
path = shutil.which("iouyap")
|
||||||
return path
|
return path
|
||||||
@ -245,7 +239,7 @@ class IOUVM(BaseNode):
|
|||||||
:returns: path to IOURC
|
:returns: path to IOURC
|
||||||
"""
|
"""
|
||||||
|
|
||||||
iourc_path = self._manager.config.get_section_config("IOU").get("iourc_path")
|
iourc_path = self._config().get("iourc_path")
|
||||||
if not iourc_path:
|
if not iourc_path:
|
||||||
# look for the iourc file in the user home dir.
|
# look for the iourc file in the user home dir.
|
||||||
path = os.path.join(os.path.expanduser("~/"), ".iourc")
|
path = os.path.join(os.path.expanduser("~/"), ".iourc")
|
||||||
@ -380,7 +374,7 @@ class IOUVM(BaseNode):
|
|||||||
Checks for a valid IOU key in the iourc file (paranoid mode).
|
Checks for a valid IOU key in the iourc file (paranoid mode).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
license_check = self._manager.config.get_section_config("IOU").getboolean("license_check", True)
|
license_check = self._config().getboolean("license_check", True)
|
||||||
if license_check is False:
|
if license_check is False:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
Custom exceptions for the Qemu module.
|
Custom exceptions for the Qemu module.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from ..node_error import NodeError
|
from ..error import NodeError
|
||||||
|
|
||||||
|
|
||||||
class QemuError(NodeError):
|
class QemuError(NodeError):
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
Custom exceptions for the VirtualBox module.
|
Custom exceptions for the VirtualBox module.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from ..node_error import NodeError
|
from ..error import NodeError
|
||||||
|
|
||||||
|
|
||||||
class VirtualBoxError(NodeError):
|
class VirtualBoxError(NodeError):
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
Custom exceptions for the VMware module.
|
Custom exceptions for the VMware module.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from ..node_error import NodeError
|
from ..error import NodeError
|
||||||
|
|
||||||
|
|
||||||
class VMwareError(NodeError):
|
class VMwareError(NodeError):
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
Custom exceptions for the VPCS module.
|
Custom exceptions for the VPCS module.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from ..node_error import NodeError
|
from ..error import NodeError
|
||||||
|
|
||||||
|
|
||||||
class VPCSError(NodeError):
|
class VPCSError(NodeError):
|
||||||
|
@ -25,7 +25,7 @@ import traceback
|
|||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
from ..compute.node_error import NodeError
|
from ..compute.error import NodeError
|
||||||
from ..controller.controller_error import ControllerError
|
from ..controller.controller_error import ControllerError
|
||||||
from ..ubridge.ubridge_error import UbridgeError
|
from ..ubridge.ubridge_error import UbridgeError
|
||||||
from .response import Response
|
from .response import Response
|
||||||
@ -197,11 +197,11 @@ class Route(object):
|
|||||||
response = Response(request=request, route=route)
|
response = Response(request=request, route=route)
|
||||||
response.set_status(409)
|
response.set_status(409)
|
||||||
response.json({"message": str(e), "status": 409})
|
response.json({"message": str(e), "status": 409})
|
||||||
except (NodeError, UbridgeError) as e:
|
except (NodeError, UbridgeError, ImageMissingError) as e:
|
||||||
log.error("Node error detected: {type}".format(type=type(e)), exc_info=1)
|
log.error("Node error detected: {type}".format(type=type(e)), exc_info=1)
|
||||||
response = Response(request=request, route=route)
|
response = Response(request=request, route=route)
|
||||||
response.set_status(409)
|
response.set_status(409)
|
||||||
response.json({"message": str(e), "status": 409})
|
response.json({"message": str(e), "status": 409, "exception": str(e.__class__)})
|
||||||
except asyncio.futures.CancelledError as e:
|
except asyncio.futures.CancelledError as e:
|
||||||
log.error("Request canceled")
|
log.error("Request canceled")
|
||||||
response = Response(request=request, route=route)
|
response = Response(request=request, route=route)
|
||||||
|
@ -72,11 +72,10 @@ def iourc_file(tmpdir):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def fake_iou_bin(tmpdir):
|
def fake_iou_bin(images_dir):
|
||||||
"""Create a fake IOU image on disk"""
|
"""Create a fake IOU image on disk"""
|
||||||
|
|
||||||
os.makedirs(str(tmpdir / "IOU"), exist_ok=True)
|
path = os.path.join(images_dir, "iou.bin")
|
||||||
path = str(tmpdir / "IOU" / "iou.bin")
|
|
||||||
with open(path, "w+") as f:
|
with open(path, "w+") as f:
|
||||||
f.write('\x7fELF\x01\x01\x01')
|
f.write('\x7fELF\x01\x01\x01')
|
||||||
os.chmod(path, stat.S_IREAD | stat.S_IEXEC)
|
os.chmod(path, stat.S_IREAD | stat.S_IEXEC)
|
||||||
@ -97,11 +96,11 @@ def test_vm_startup_config_content(project, manager):
|
|||||||
assert vm.id == "00010203-0405-0607-0808-0a0b0c0d0e0f"
|
assert vm.id == "00010203-0405-0607-0808-0a0b0c0d0e0f"
|
||||||
|
|
||||||
|
|
||||||
@patch("gns3server.config.Config.get_section_config", return_value={"iouyap_path": "/bin/test_fake"})
|
@patch("gns3server.compute.iou.iou_vm.IOUVM._config", return_value={"iouyap_path": "/bin/test_fake"})
|
||||||
def test_vm_invalid_iouyap_path(project, manager, loop, fake_iou_bin):
|
def test_vm_invalid_iouyap_path(project, manager, loop, fake_iou_bin):
|
||||||
with pytest.raises(IOUError):
|
with pytest.raises(IOUError):
|
||||||
vm = IOUVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0e", project, manager)
|
vm = IOUVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0e", project, manager)
|
||||||
vm.path = "iou.bin"
|
vm.path = fake_iou_bin
|
||||||
loop.run_until_complete(asyncio.async(vm.start()))
|
loop.run_until_complete(asyncio.async(vm.start()))
|
||||||
|
|
||||||
|
|
||||||
@ -213,20 +212,8 @@ def test_path(vm, fake_iou_bin):
|
|||||||
assert vm.path == fake_iou_bin
|
assert vm.path == fake_iou_bin
|
||||||
|
|
||||||
|
|
||||||
def test_path_12_location(vm, fake_iou_bin):
|
|
||||||
|
|
||||||
# In 1.2 users uploaded images to the images roots
|
|
||||||
# after the migration their images are inside images/IOU
|
|
||||||
# but old topologies use old path
|
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
|
||||||
vm.path = fake_iou_bin.replace("/IOU", "")
|
|
||||||
assert vm.path == fake_iou_bin
|
|
||||||
|
|
||||||
|
|
||||||
def test_path_relative(vm, fake_iou_bin, tmpdir):
|
def test_path_relative(vm, fake_iou_bin, tmpdir):
|
||||||
|
|
||||||
config = Config.instance()
|
|
||||||
config.set("Server", "images_path", str(tmpdir))
|
|
||||||
vm.path = "iou.bin"
|
vm.path = "iou.bin"
|
||||||
assert vm.path == fake_iou_bin
|
assert vm.path == fake_iou_bin
|
||||||
|
|
||||||
@ -235,9 +222,6 @@ def test_path_invalid_bin(vm, tmpdir):
|
|||||||
|
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
||||||
path = str(tmpdir / "test.bin")
|
path = str(tmpdir / "test.bin")
|
||||||
with pytest.raises(IOUError):
|
|
||||||
vm.path = path
|
|
||||||
vm._check_requirements()
|
|
||||||
|
|
||||||
with open(path, "w+") as f:
|
with open(path, "w+") as f:
|
||||||
f.write("BUG")
|
f.write("BUG")
|
||||||
|
@ -506,52 +506,52 @@ def test_build_command_with_invalid_options(vm, loop, fake_qemu_binary):
|
|||||||
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
|
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
|
||||||
|
|
||||||
|
|
||||||
def test_hda_disk_image(vm, tmpdir):
|
def test_hda_disk_image(vm, images_dir):
|
||||||
|
|
||||||
vm.manager.config.set("Server", "images_path", str(tmpdir))
|
open(os.path.join(images_dir, "test1"), "w+").close()
|
||||||
|
vm.hda_disk_image = os.path.join(images_dir, "test1")
|
||||||
vm.hda_disk_image = str(tmpdir / "test1")
|
assert vm.hda_disk_image == force_unix_path(os.path.join(images_dir, "test1"))
|
||||||
assert vm.hda_disk_image == force_unix_path(str(tmpdir / "test1"))
|
open(os.path.join(images_dir, "QEMU", "test2"), "w+").close()
|
||||||
vm.hda_disk_image = "test2"
|
vm.hda_disk_image = "test2"
|
||||||
assert vm.hda_disk_image == force_unix_path(str(tmpdir / "QEMU" / "test2"))
|
assert vm.hda_disk_image == force_unix_path(os.path.join(images_dir, "QEMU", "test2"))
|
||||||
|
|
||||||
|
|
||||||
def test_hda_disk_image_ova(vm, tmpdir):
|
def test_hda_disk_image_ova(vm, images_dir):
|
||||||
|
|
||||||
vm.manager.config.set("Server", "images_path", str(tmpdir))
|
|
||||||
|
|
||||||
|
os.makedirs(os.path.join(images_dir, "QEMU", "test.ovf"))
|
||||||
|
open(os.path.join(images_dir, "QEMU", "test.ovf", "test.vmdk"), "w+").close()
|
||||||
vm.hda_disk_image = "test.ovf/test.vmdk"
|
vm.hda_disk_image = "test.ovf/test.vmdk"
|
||||||
assert vm.hda_disk_image == force_unix_path(str(tmpdir / "QEMU" / "test.ovf" / "test.vmdk"))
|
assert vm.hda_disk_image == force_unix_path(os.path.join(images_dir, "QEMU", "test.ovf", "test.vmdk"))
|
||||||
|
|
||||||
|
|
||||||
def test_hdb_disk_image(vm, tmpdir):
|
def test_hdb_disk_image(vm, images_dir):
|
||||||
|
|
||||||
vm.manager.config.set("Server", "images_path", str(tmpdir))
|
open(os.path.join(images_dir, "test1"), "w+").close()
|
||||||
|
vm.hdb_disk_image = os.path.join(images_dir, "test1")
|
||||||
vm.hdb_disk_image = str(tmpdir / "test")
|
assert vm.hdb_disk_image == force_unix_path(os.path.join(images_dir, "test1"))
|
||||||
assert vm.hdb_disk_image == force_unix_path(str(tmpdir / "test"))
|
open(os.path.join(images_dir, "QEMU", "test2"), "w+").close()
|
||||||
vm.hdb_disk_image = "test"
|
vm.hdb_disk_image = "test2"
|
||||||
assert vm.hdb_disk_image == force_unix_path(str(tmpdir / "QEMU" / "test"))
|
assert vm.hdb_disk_image == force_unix_path(os.path.join(images_dir, "QEMU", "test2"))
|
||||||
|
|
||||||
|
|
||||||
def test_hdc_disk_image(vm, tmpdir):
|
def test_hdc_disk_image(vm, images_dir):
|
||||||
|
|
||||||
vm.manager.config.set("Server", "images_path", str(tmpdir))
|
open(os.path.join(images_dir, "test1"), "w+").close()
|
||||||
|
vm.hdc_disk_image = os.path.join(images_dir, "test1")
|
||||||
vm.hdc_disk_image = str(tmpdir / "test")
|
assert vm.hdc_disk_image == force_unix_path(os.path.join(images_dir, "test1"))
|
||||||
assert vm.hdc_disk_image == force_unix_path(str(tmpdir / "test"))
|
open(os.path.join(images_dir, "QEMU", "test2"), "w+").close()
|
||||||
vm.hdc_disk_image = "test"
|
vm.hdc_disk_image = "test2"
|
||||||
assert vm.hdc_disk_image == force_unix_path(str(tmpdir / "QEMU" / "test"))
|
assert vm.hdc_disk_image == force_unix_path(os.path.join(images_dir, "QEMU", "test2"))
|
||||||
|
|
||||||
|
|
||||||
def test_hdd_disk_image(vm, tmpdir):
|
def test_hdd_disk_image(vm, images_dir):
|
||||||
|
|
||||||
vm.manager.config.set("Server", "images_path", str(tmpdir))
|
open(os.path.join(images_dir, "test1"), "w+").close()
|
||||||
|
vm.hdd_disk_image = os.path.join(images_dir, "test1")
|
||||||
vm.hdd_disk_image = str(tmpdir / "test")
|
assert vm.hdd_disk_image == force_unix_path(os.path.join(images_dir, "test1"))
|
||||||
assert vm.hdd_disk_image == force_unix_path(str(tmpdir / "test"))
|
open(os.path.join(images_dir, "QEMU", "test2"), "w+").close()
|
||||||
vm.hdd_disk_image = "test"
|
vm.hdd_disk_image = "test2"
|
||||||
assert vm.hdd_disk_image == force_unix_path(str(tmpdir / "QEMU" / "test"))
|
assert vm.hdd_disk_image == force_unix_path(os.path.join(images_dir, "QEMU", "test2"))
|
||||||
|
|
||||||
|
|
||||||
def test_initrd(vm, tmpdir):
|
def test_initrd(vm, tmpdir):
|
||||||
|
@ -26,7 +26,7 @@ from unittest.mock import patch, MagicMock
|
|||||||
from gns3server.compute.vpcs.vpcs_vm import VPCSVM
|
from gns3server.compute.vpcs.vpcs_vm import VPCSVM
|
||||||
from gns3server.compute.docker.docker_vm import DockerVM
|
from gns3server.compute.docker.docker_vm import DockerVM
|
||||||
from gns3server.compute.vpcs.vpcs_error import VPCSError
|
from gns3server.compute.vpcs.vpcs_error import VPCSError
|
||||||
from gns3server.compute.node_error import NodeError
|
from gns3server.compute.error import NodeError
|
||||||
from gns3server.compute.vpcs import VPCS
|
from gns3server.compute.vpcs import VPCS
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ from unittest.mock import patch
|
|||||||
|
|
||||||
from gns3server.compute.vpcs import VPCS
|
from gns3server.compute.vpcs import VPCS
|
||||||
from gns3server.compute.qemu import Qemu
|
from gns3server.compute.qemu import Qemu
|
||||||
from gns3server.compute.node_error import NodeError
|
from gns3server.compute.error import NodeError, ImageMissingError
|
||||||
from gns3server.utils import force_unix_path
|
from gns3server.utils import force_unix_path
|
||||||
|
|
||||||
|
|
||||||
@ -165,8 +165,8 @@ def test_get_abs_image_additional_image_paths(qemu, tmpdir):
|
|||||||
# Absolute path
|
# Absolute path
|
||||||
assert qemu.get_abs_image_path(str(path2)) == path2
|
assert qemu.get_abs_image_path(str(path2)) == path2
|
||||||
|
|
||||||
# If not found return the default path
|
with pytest.raises(ImageMissingError):
|
||||||
assert qemu.get_abs_image_path("test4.bin") == os.path.join(qemu.get_images_directory(), "test4.bin")
|
qemu.get_abs_image_path("test4.bin")
|
||||||
|
|
||||||
|
|
||||||
def test_get_abs_image_recursive(qemu, tmpdir):
|
def test_get_abs_image_recursive(qemu, tmpdir):
|
||||||
|
@ -230,6 +230,18 @@ def run_around_tests(monkeypatch, port_manager, controller, config):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def images_dir(config):
|
||||||
|
"""
|
||||||
|
Get the location of images
|
||||||
|
"""
|
||||||
|
path = config.get_section_config("Server").get("images_path")
|
||||||
|
os.makedirs(path, exist_ok=True)
|
||||||
|
os.makedirs(os.path.join(path, "QEMU"))
|
||||||
|
os.makedirs(os.path.join(path, "IOU"))
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture
|
@pytest.yield_fixture
|
||||||
def darwin_platform():
|
def darwin_platform():
|
||||||
"""
|
"""
|
||||||
|
@ -29,10 +29,10 @@ pytestmark = pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supp
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def fake_iou_bin(tmpdir):
|
def fake_iou_bin(images_dir):
|
||||||
"""Create a fake IOU image on disk"""
|
"""Create a fake IOU image on disk"""
|
||||||
|
|
||||||
path = str(tmpdir / "iou.bin")
|
path = os.path.join(images_dir, "IOU", "iou.bin")
|
||||||
with open(path, "w+") as f:
|
with open(path, "w+") as f:
|
||||||
f.write('\x7fELF\x01\x01\x01')
|
f.write('\x7fELF\x01\x01\x01')
|
||||||
os.chmod(path, stat.S_IREAD | stat.S_IEXEC)
|
os.chmod(path, stat.S_IREAD | stat.S_IEXEC)
|
||||||
@ -222,7 +222,7 @@ def test_iou_nio_create_udp(http_compute, vm):
|
|||||||
def test_iou_nio_create_ethernet(http_compute, vm, ethernet_device):
|
def test_iou_nio_create_ethernet(http_compute, vm, ethernet_device):
|
||||||
response = http_compute.post("/projects/{project_id}/iou/nodes/{node_id}/adapters/1/ports/0/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), {"type": "nio_ethernet",
|
response = http_compute.post("/projects/{project_id}/iou/nodes/{node_id}/adapters/1/ports/0/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), {"type": "nio_ethernet",
|
||||||
"ethernet_device": ethernet_device,
|
"ethernet_device": ethernet_device,
|
||||||
},
|
},
|
||||||
example=True)
|
example=True)
|
||||||
assert response.status == 201
|
assert response.status == 201
|
||||||
assert response.route == "/projects/{project_id}/iou/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio"
|
assert response.route == "/projects/{project_id}/iou/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio"
|
||||||
@ -233,7 +233,7 @@ def test_iou_nio_create_ethernet(http_compute, vm, ethernet_device):
|
|||||||
def test_iou_nio_create_ethernet_different_port(http_compute, vm, ethernet_device):
|
def test_iou_nio_create_ethernet_different_port(http_compute, vm, ethernet_device):
|
||||||
response = http_compute.post("/projects/{project_id}/iou/nodes/{node_id}/adapters/0/ports/3/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), {"type": "nio_ethernet",
|
response = http_compute.post("/projects/{project_id}/iou/nodes/{node_id}/adapters/0/ports/3/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), {"type": "nio_ethernet",
|
||||||
"ethernet_device": ethernet_device,
|
"ethernet_device": ethernet_device,
|
||||||
},
|
},
|
||||||
example=False)
|
example=False)
|
||||||
assert response.status == 201
|
assert response.status == 201
|
||||||
assert response.route == "/projects/{project_id}/iou/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio"
|
assert response.route == "/projects/{project_id}/iou/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio"
|
||||||
@ -328,10 +328,9 @@ def test_get_configs_with_startup_config_file(http_compute, project, vm):
|
|||||||
assert response.json["startup_config_content"] == "TEST"
|
assert response.json["startup_config_content"] == "TEST"
|
||||||
|
|
||||||
|
|
||||||
def test_images(http_compute, tmpdir, fake_iou_bin):
|
def test_images(http_compute, fake_iou_bin):
|
||||||
|
|
||||||
with patch("gns3server.compute.IOU.get_images_directory", return_value=str(tmpdir)):
|
response = http_compute.get("/iou/images", example=True)
|
||||||
response = http_compute.get("/iou/images", example=True)
|
|
||||||
assert response.status == 200
|
assert response.status == 200
|
||||||
assert response.json == [{"filename": "iou.bin", "path": "iou.bin"}]
|
assert response.json == [{"filename": "iou.bin", "path": "iou.bin"}]
|
||||||
|
|
||||||
|
@ -38,11 +38,9 @@ def fake_qemu_bin():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def fake_qemu_vm(tmpdir):
|
def fake_qemu_vm(images_dir):
|
||||||
|
|
||||||
img_dir = Config.instance().get_section_config("Server").get("images_path")
|
img_dir = os.path.join(images_dir, "QEMU")
|
||||||
img_dir = os.path.join(img_dir, "QEMU")
|
|
||||||
os.makedirs(img_dir)
|
|
||||||
bin_path = os.path.join(img_dir, "linux载.img")
|
bin_path = os.path.join(img_dir, "linux载.img")
|
||||||
with open(bin_path, "w+") as f:
|
with open(bin_path, "w+") as f:
|
||||||
f.write("1")
|
f.write("1")
|
||||||
@ -154,18 +152,18 @@ def test_qemu_delete(http_compute, vm):
|
|||||||
assert response.status == 204
|
assert response.status == 204
|
||||||
|
|
||||||
|
|
||||||
def test_qemu_update(http_compute, vm, tmpdir, free_console_port, project, fake_qemu_vm):
|
def test_qemu_update(http_compute, vm, free_console_port, project, fake_qemu_vm):
|
||||||
params = {
|
params = {
|
||||||
"name": "test",
|
"name": "test",
|
||||||
"console": free_console_port,
|
"console": free_console_port,
|
||||||
"ram": 1024,
|
"ram": 1024,
|
||||||
"hdb_disk_image": "linux.img"
|
"hdb_disk_image": "linux载.img"
|
||||||
}
|
}
|
||||||
response = http_compute.put("/projects/{project_id}/qemu/nodes/{node_id}".format(project_id=vm["project_id"], node_id=vm["node_id"]), params, example=True)
|
response = http_compute.put("/projects/{project_id}/qemu/nodes/{node_id}".format(project_id=vm["project_id"], node_id=vm["node_id"]), params, example=True)
|
||||||
assert response.status == 200
|
assert response.status == 200
|
||||||
assert response.json["name"] == "test"
|
assert response.json["name"] == "test"
|
||||||
assert response.json["console"] == free_console_port
|
assert response.json["console"] == free_console_port
|
||||||
assert response.json["hdb_disk_image"] == "linux.img"
|
assert response.json["hdb_disk_image"] == "linux载.img"
|
||||||
assert response.json["ram"] == 1024
|
assert response.json["ram"] == 1024
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user