mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-06 15:21:13 +02:00
API for duplication a Node
Support: * VPCS * Dynamips router * Ethernet switch Ref #1065
This commit is contained in:
18 files changed
+382
-32
No files matched your search
@@ -26,6 +26,7 @@ import asyncio
|
||||
from gns3server.compute.dynamips import Dynamips
|
||||
from gns3server.compute.dynamips.dynamips_error import DynamipsError
|
||||
from unittest.mock import patch
|
||||
from tests.utils import asyncio_patch, AsyncioMagicMock
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -82,7 +83,7 @@ def test_release_dynamips_id(manager):
|
||||
manager.release_dynamips_id(project_2, 0)
|
||||
|
||||
|
||||
def test_project_closed(manager, project, loop):
|
||||
def test_project_closed(manager, project, async_run):
|
||||
|
||||
manager._dynamips_ids[project.id] = set([1, 2, 3])
|
||||
|
||||
@@ -90,7 +91,38 @@ def test_project_closed(manager, project, loop):
|
||||
os.makedirs(project_dir)
|
||||
open(os.path.join(project_dir, "test.ghost"), "w+").close()
|
||||
|
||||
loop.run_until_complete(asyncio.async(manager.project_closed(project)))
|
||||
async_run(manager.project_closed(project))
|
||||
|
||||
assert not os.path.exists(os.path.join(project_dir, "test.ghost"))
|
||||
assert project.id not in manager._dynamips_ids
|
||||
|
||||
|
||||
def test_duplicate_node(manager, project, async_run):
|
||||
"""
|
||||
Duplicate dynamips do nothing it's manage outside the
|
||||
filesystem
|
||||
"""
|
||||
with asyncio_patch('gns3server.compute.dynamips.nodes.c7200.C7200.create'):
|
||||
source_node = async_run(manager.create_node(
|
||||
'R1',
|
||||
project.id,
|
||||
str(uuid.uuid4()),
|
||||
platform="c7200"
|
||||
))
|
||||
destination_node = async_run(manager.create_node(
|
||||
'R2',
|
||||
project.id,
|
||||
str(uuid.uuid4()),
|
||||
platform="c7200"
|
||||
))
|
||||
destination_node._hypervisor = AsyncioMagicMock()
|
||||
|
||||
with open(os.path.join(source_node.working_dir, 'c3600_i1_nvram'), 'w+') as f:
|
||||
f.write("1")
|
||||
with open(source_node.startup_config_path, 'w+') as f:
|
||||
f.write('hostname R1\necho TEST')
|
||||
async_run(manager.duplicate_node(source_node.id, destination_node.id))
|
||||
assert not os.path.exists(os.path.join(destination_node.working_dir, 'c3600_i1_nvram'))
|
||||
with open(destination_node.startup_config_path) as f:
|
||||
content = f.read()
|
||||
assert content == '!\nhostname R2\necho TEST'
|
||||
@@ -19,9 +19,11 @@ import uuid
|
||||
import os
|
||||
import pytest
|
||||
from unittest.mock import patch
|
||||
from tests.utils import AsyncioMagicMock, asyncio_patch
|
||||
|
||||
|
||||
from gns3server.compute.vpcs import VPCS
|
||||
from gns3server.compute.dynamips import Dynamips
|
||||
from gns3server.compute.qemu import Qemu
|
||||
from gns3server.compute.error import NodeError, ImageMissingError
|
||||
from gns3server.utils import force_unix_path
|
||||
@@ -273,3 +275,25 @@ def test_delete_node(async_run, vpcs, project):
|
||||
async_run(vpcs.delete_node(node_id))
|
||||
mock_emit.assert_called_with("node.deleted", node)
|
||||
assert node not in project.nodes
|
||||
|
||||
|
||||
def test_duplicate_vpcs(async_run, vpcs, project):
|
||||
source_node_id = str(uuid.uuid4())
|
||||
source_node = async_run(vpcs.create_node("PC-1", project.id, source_node_id, console=2222))
|
||||
with open(os.path.join(source_node.working_dir, "startup.vpc"), "w+") as f:
|
||||
f.write("set pcname PC-1\nip dhcp\n")
|
||||
destination_node_id = str(uuid.uuid4())
|
||||
destination_node = async_run(vpcs.create_node("PC-2", project.id, destination_node_id, console=2223))
|
||||
async_run(vpcs.duplicate_node(source_node_id, destination_node_id))
|
||||
with open(os.path.join(destination_node.working_dir, "startup.vpc")) as f:
|
||||
assert f.read() == "set pcname PC-2\nip dhcp\n"
|
||||
|
||||
|
||||
def test_duplicate_ethernet_switch(async_run, project):
|
||||
with asyncio_patch('gns3server.compute.dynamips.nodes.ethernet_switch.EthernetSwitch.create'):
|
||||
dynamips_manager = Dynamips.instance()
|
||||
source_node_id = str(uuid.uuid4())
|
||||
source_node = async_run(dynamips_manager.create_node("SW-1", project.id, source_node_id, node_type='ethernet_switch'))
|
||||
destination_node_id = str(uuid.uuid4())
|
||||
destination_node = async_run(dynamips_manager.create_node("SW-2", project.id, destination_node_id, node_type='ethernet_switch'))
|
||||
async_run(dynamips_manager.duplicate_node(source_node_id, destination_node_id))
|
||||
@@ -255,7 +255,7 @@ def test_update_startup_script_h(vm):
|
||||
def test_update_startup_script_with_escaping_characters_in_name(vm):
|
||||
vm.startup_script = "set pcname initial-name\n"
|
||||
vm.name = "test\\"
|
||||
assert vm.startup_script == "set pcname test\\{}".format(os.linesep)
|
||||
assert vm.startup_script == "set pcname test{}".format(os.linesep)
|
||||
|
||||
|
||||
def test_get_startup_script(vm):
|
||||
|
||||
Reference in new issue
Block a user