Manage error when GNS3VM failed to start

Fix https://github.com/GNS3/gns3-gui/issues/1446
This commit is contained in:
Julien Duponchelle committed 2016-09-01 15:36:41 +02:00
1 parent f216422d0f
commit 4bbd8938ab
7 files changed
+101 -12

No files matched your search

+46 -1
View File
@@ -16,9 +16,31 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
from tests.utils import asyncio_patch
from tests.utils import asyncio_patch, AsyncioMagicMock
from gns3server.controller.gns3vm import GNS3VM
from gns3server.controller.gns3vm.gns3_vm_error import GNS3VMError
@pytest.fixture
def dummy_engine():
engine = AsyncioMagicMock()
engine.running = False
engine.ip_address = "vm.local"
engine.protocol = "https"
engine.port = 8442
engine.user = "hello"
engine.password = "world"
return engine
@pytest.fixture
def dummy_gns3vm(controller, dummy_engine):
vm = GNS3VM(controller)
vm._settings["engine"] = "dummy"
vm._settings["vmname"] = "Test VM"
vm._settings["enable"] = True
vm._engines["dummy"] = dummy_engine
return vm
def test_list(async_run, controller):
@@ -50,3 +72,26 @@ def test_update_settings(controller, async_run):
assert "vm" in controller.computes
async_run(vm.update_settings({"enable": False}))
assert "vm" not in controller.computes
def test_auto_start(async_run, controller, dummy_gns3vm, dummy_engine):
"""
When start the compute should be add to the controller
"""
async_run(dummy_gns3vm.auto_start_vm())
assert dummy_engine.start.called
assert controller.computes["vm"].name == "GNS3 VM (Test VM)"
assert controller.computes["vm"].host == "vm.local"
assert controller.computes["vm"].port == 8442
assert controller.computes["vm"].protocol == "https"
assert controller.computes["vm"].user == "hello"
assert controller.computes["vm"].password == "world"
def test_auto_start_with_error(async_run, controller, dummy_gns3vm, dummy_engine):
dummy_engine.start.side_effect = GNS3VMError("Dummy error")
async_run(dummy_gns3vm.auto_start_vm())
assert dummy_engine.start.called
assert controller.computes["vm"].name == "GNS3 VM (Test VM)"