def test_add_builtin_node_from_template(async_run, controller):
    """
    For a local server we send the project path
    """
    compute = MagicMock()
    compute.id = "local"
    project = Project(controller=controller, name="Test")
    project.emit_notification = MagicMock()
    template = Template(str(uuid.uuid4()), {
        "name": "Builtin-switch",
        "template_type": "ethernet_switch",
    },
                        builtin=True)
    controller.template_manager.templates[template.id] = template
    template.__json__()
    controller._computes["local"] = compute

    response = MagicMock()
    response.json = {"console": 2048}
    compute.post = AsyncioMagicMock(return_value=response)

    node = async_run(
        project.add_node_from_template(template.id,
                                       x=23,
                                       y=12,
                                       compute_id="local"))
    compute.post.assert_any_call('/projects',
                                 data={
                                     "name": project._name,
                                     "project_id": project._id,
                                     "path": project._path
                                 })

    assert compute in project._project_created_on_compute
    project.emit_notification.assert_any_call("node.created", node.__json__())
Beispiel #2
0
def test_template_json():
    a = Template(None, {
        "node_type": "qemu",
        "name": "Test",
        "default_name_format": "{name}-{0}",
        "category": 0,
        "symbol": "qemu.svg",
        "server": "local",
        "platform": "i386"
    })
    settings = a.__json__()
    assert settings["template_id"] == a.id
    assert settings["template_type"] == "qemu"
    assert settings["builtin"] == False
def test_template_json():
    a = Template(
        None, {
            "node_type": "qemu",
            "name": "Test",
            "default_name_format": "{name}-{0}",
            "category": 0,
            "symbol": "qemu.svg",
            "server": "local",
            "platform": "i386"
        })
    settings = a.__json__()
    assert settings["template_id"] == a.id
    assert settings["template_type"] == "qemu"
    assert settings["builtin"] == False
async def test_create_node_from_template(controller_api, controller, project):

    id = str(uuid.uuid4())
    controller.template_manager._templates = {
        id:
        Template(
            id, {
                "template_type": "qemu",
                "category": 0,
                "name": "test",
                "symbol": "guest.svg",
                "default_name_format": "{name}-{0}",
                "compute_id": "example.com"
            })
    }
    with asyncio_patch(
            "gns3server.controller.project.Project.add_node_from_template",
            return_value={
                "name": "test",
                "node_type": "qemu",
                "compute_id": "example.com"
            }) as mock:
        response = await controller_api.post(
            "/projects/{}/templates/{}".format(project.id, id), {
                "x": 42,
                "y": 12
            })
    mock.assert_called_with(id, x=42, y=12, compute_id=None)
    assert response.route == "/projects/{project_id}/templates/{template_id}"
    assert response.status == 201
Beispiel #5
0
def test_template_json_with_platform():
    a = Template(None, {
        "node_type": "dynamips",
        "name": "Test",
        "default_name_format": "{name}-{0}",
        "category": 0,
        "symbol": "dynamips.svg",
        "image": "IOS_image.bin",
        "server": "local",
        "platform": "c3725"
    })
    settings = a.__json__()
    assert settings["template_id"] == a.id
    assert settings["template_type"] == "dynamips"
    assert settings["builtin"] == False
    assert settings["platform"] == "c3725"
Beispiel #6
0
def test_template_json_with_platform():
    a = Template(
        None, {
            "node_type": "dynamips",
            "name": "Test",
            "default_name_format": "{name}-{0}",
            "category": 0,
            "symbol": "dynamips.svg",
            "image": "IOS_image.bin",
            "server": "local",
            "platform": "c3725"
        })
    settings = a.__json__()
    assert settings["template_id"] == a.id
    assert settings["template_type"] == "dynamips"
    assert settings["builtin"] == False
    assert settings["platform"] == "c3725"
Beispiel #7
0
def test_template_json_with_not_known_category():
    with pytest.raises(jsonschema.ValidationError):
        a = Template(
            None, {
                "node_type": "qemu",
                "name": "Test",
                "default_name_format": "{name}-{0}",
                "category": 'Not known',
                "symbol": "qemu.svg",
                "server": "local",
                "platform": "i386"
            })
Beispiel #8
0
def test_template_list(http_controller, controller):

    id = str(uuid.uuid4())
    controller.template_manager.load_templates()
    controller.template_manager._templates[id] = Template(id, {
        "template_type": "qemu",
        "category": 0,
        "name": "test",
        "symbol": "guest.svg",
        "default_name_format": "{name}-{0}",
        "compute_id": "local"
    })
    response = http_controller.get("/templates", example=True)
    assert response.status == 200
    assert response.route == "/templates"
    assert len(response.json) > 0
Beispiel #9
0
def test_template_fix_linked_base():
    """
    Version of the gui before 2.1 use linked_base and the server
    linked_clone
    """
    a = Template(
        None, {
            "node_type": "qemu",
            "name": "Test",
            "default_name_format": "{name}-{0}",
            "category": 0,
            "symbol": "qemu.svg",
            "server": "local",
            "linked_base": True
        })
    assert a.settings["linked_clone"]
    assert "linked_base" not in a.settings