2015-02-11 13:31:21 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# Copyright (C) 2015 GNS3 Technologies Inc.
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
import pytest
|
2015-04-14 16:46:55 +00:00
|
|
|
from unittest.mock import patch
|
2015-02-11 13:31:21 +00:00
|
|
|
import uuid
|
2015-04-27 13:09:42 +00:00
|
|
|
import sys
|
2015-02-11 13:31:21 +00:00
|
|
|
|
2015-04-27 13:09:42 +00:00
|
|
|
pytestmark = pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
|
|
|
|
|
|
|
if not sys.platform.startswith("win"):
|
2016-04-15 15:57:06 +00:00
|
|
|
from gns3server.compute.iou import IOU
|
|
|
|
from gns3server.compute.iou.iou_error import IOUError
|
2015-02-11 13:31:21 +00:00
|
|
|
|
2016-04-15 15:57:06 +00:00
|
|
|
from gns3server.compute.project_manager import ProjectManager
|
2015-02-11 13:31:21 +00:00
|
|
|
|
|
|
|
|
2015-04-14 16:46:55 +00:00
|
|
|
@pytest.fixture(scope="function")
|
|
|
|
def iou(port_manager):
|
|
|
|
# Cleanup the IOU object
|
|
|
|
IOU._instance = None
|
|
|
|
iou = IOU.instance()
|
|
|
|
iou.port_manager = port_manager
|
|
|
|
return iou
|
|
|
|
|
|
|
|
|
2018-03-12 06:38:50 +00:00
|
|
|
def test_application_id(loop, project, iou):
|
2015-02-11 13:31:21 +00:00
|
|
|
vm1_id = str(uuid.uuid4())
|
|
|
|
vm2_id = str(uuid.uuid4())
|
|
|
|
vm3_id = str(uuid.uuid4())
|
2018-03-12 06:38:50 +00:00
|
|
|
vm1 = loop.run_until_complete(iou.create_node("PC 1", project.id, vm1_id))
|
|
|
|
vm2 = loop.run_until_complete(iou.create_node("PC 2", project.id, vm2_id))
|
|
|
|
assert vm1.application_id == 1
|
|
|
|
assert vm2.application_id == 2
|
2016-05-11 17:35:36 +00:00
|
|
|
loop.run_until_complete(iou.delete_node(vm1_id))
|
2018-03-12 06:38:50 +00:00
|
|
|
vm3 = loop.run_until_complete(iou.create_node("PC 3", project.id, vm3_id))
|
|
|
|
assert vm3.application_id == 1
|
2015-02-11 13:31:21 +00:00
|
|
|
|
|
|
|
|
2015-04-13 12:33:13 +00:00
|
|
|
def test_get_application_id_multiple_project(loop, iou):
|
2015-02-11 13:31:21 +00:00
|
|
|
vm1_id = str(uuid.uuid4())
|
|
|
|
vm2_id = str(uuid.uuid4())
|
|
|
|
vm3_id = str(uuid.uuid4())
|
2016-03-10 09:32:07 +00:00
|
|
|
project1 = ProjectManager.instance().create_project(project_id=str(uuid.uuid4()))
|
|
|
|
project2 = ProjectManager.instance().create_project(project_id=str(uuid.uuid4()))
|
2018-03-12 06:38:50 +00:00
|
|
|
vm1 = loop.run_until_complete(iou.create_node("PC 1", project1.id, vm1_id))
|
|
|
|
vm2 = loop.run_until_complete(iou.create_node("PC 2", project1.id, vm2_id))
|
|
|
|
vm3 = loop.run_until_complete(iou.create_node("PC 2", project2.id, vm3_id))
|
|
|
|
assert vm1.application_id == 1
|
|
|
|
assert vm2.application_id == 2
|
|
|
|
assert vm3.application_id == 3
|
2015-02-11 13:31:21 +00:00
|
|
|
|
|
|
|
|
2015-04-13 12:33:13 +00:00
|
|
|
def test_get_application_id_no_id_available(loop, project, iou):
|
2015-02-11 13:31:21 +00:00
|
|
|
with pytest.raises(IOUError):
|
|
|
|
for i in range(1, 513):
|
2016-05-11 17:35:36 +00:00
|
|
|
node_id = str(uuid.uuid4())
|
2018-03-12 06:38:50 +00:00
|
|
|
vm = loop.run_until_complete(iou.create_node("PC {}".format(i), project.id, node_id))
|
|
|
|
assert vm.application_id == i
|
2015-04-14 16:46:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_get_images_directory(iou, tmpdir):
|
|
|
|
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}):
|
|
|
|
assert iou.get_images_directory() == str(tmpdir / "IOU")
|