diff --git a/gns3/vnc_console.py b/gns3/vnc_console.py index 5ff4c0f5..509e06fa 100644 --- a/gns3/vnc_console.py +++ b/gns3/vnc_console.py @@ -53,6 +53,7 @@ def vncConsole(node, port, command): command = command.replace("%P", node.project().name().replace('"', '\\"')) command = command.replace("%i", node.project().id()) command = command.replace("%n", str(node.id())) + command = command.replace("%c", Controller.instance().httpClient().fullUrl()) command = command.replace("{host}", host) command = command.replace("{port}", str(port)) diff --git a/tests/conftest.py b/tests/conftest.py index 0b2c28f1..12b2a109 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -75,6 +75,7 @@ def controller(): Controller._instance = None c = Controller.instance() c._http_client = MagicMock() + c._http_client.fullUrl.return_value = "http://localhost:3080" return c diff --git a/tests/test_spice_console.py b/tests/test_spice_console.py index 10fc1458..b17ca089 100644 --- a/tests/test_spice_console.py +++ b/tests/test_spice_console.py @@ -17,28 +17,30 @@ import os import shlex -import unittest from unittest.mock import patch from gns3.spice_console import spiceConsole def test_spice_console_on_linux_and_mac(vpcs_device): + with patch('subprocess.Popen') as popen, \ patch('sys.platform', new="linux"): - vpcs_device.settings()["console_host"] = "localhost" spiceConsole(vpcs_device, '2525', 'command %h %p') - popen.assert_called_once_with(shlex.split('command localhost 2525'), env=os.environ) - + popen.assert_called_with(shlex.split('command localhost 2525'), env=os.environ) + spiceConsole(vpcs_device, '2525', 'command {host} {port}') + popen.assert_called_with(shlex.split('command localhost 2525'), env=os.environ) def test_spice_console_on_windows(vpcs_device): - with patch('subprocess.call') as popen, \ + + with patch('subprocess.call') as p, \ patch('sys.platform', new="win"): vpcs_device.settings()["console_host"] = "localhost" spiceConsole(vpcs_device, '2525', 'command %h %p') - popen.assert_called_once_with('command localhost 2525', env=unittest.mock.ANY) - + p.assert_called_with('command localhost 2525', env=os.environ) + spiceConsole(vpcs_device, '2525', 'command {host} {port}') + p.assert_called_with('command localhost 2525', env=os.environ) # def test_spice_console_on_linux_with_popen_issues(): # with patch('subprocess.Popen', side_effect=OSError("Dummy")), \ @@ -49,9 +51,11 @@ def test_spice_console_on_windows(vpcs_device): def test_spice_console_with_ipv6_support(vpcs_device): + with patch('subprocess.Popen') as popen, \ patch('sys.platform', new="linux"): - vpcs_device.settings()["console_host"] = "::1" spiceConsole(vpcs_device, '2525', 'command %h %p') - popen.assert_called_once_with(shlex.split('command [::1] 2525'), env=os.environ) + popen.assert_called_with(shlex.split('command [::1] 2525'), env=os.environ) + spiceConsole(vpcs_device, '2525', 'command {host} {port}') + popen.assert_called_with(shlex.split('command [::1] 2525'), env=os.environ) diff --git a/tests/test_vnc_console.py b/tests/test_vnc_console.py index 78eb5d97..d095803f 100644 --- a/tests/test_vnc_console.py +++ b/tests/test_vnc_console.py @@ -17,31 +17,36 @@ import os import shlex -import unittest from unittest.mock import patch from gns3.vnc_console import vncConsole - def test_vnc_console_on_linux_and_mac(vpcs_device): - with patch('subprocess.Popen') as popen, \ + + with patch('subprocess.call') as p, \ patch('sys.platform', new="linux"): vpcs_device.settings()["console_host"] = "localhost" - vncConsole(vpcs_device, 6000, 'command %h %p %P') - popen.assert_called_once_with(shlex.split('command localhost 6000 100'), env=os.environ) + vncConsole(vpcs_device, 6000, 'command %h %p %D') + p.assert_called_with(shlex.split('command localhost 6000 100'), env=os.environ) + vncConsole(vpcs_device, 6000, 'command {host} {port} {display}') + p.assert_called_with(shlex.split('command localhost 6000 100'), env=os.environ) def test_vnc_console_on_windows(vpcs_device): - with patch('subprocess.call') as popen, \ + + with patch('subprocess.call') as p, \ patch('sys.platform', new="win"): vpcs_device.settings()["console_host"] = "localhost" - vncConsole(vpcs_device, 6000, 'command %h %p %P') - popen.assert_called_once_with('command localhost 6000 100', env=unittest.mock.ANY) + vncConsole(vpcs_device, 6000, 'command %h %p %D') + p.assert_called_with('command localhost 6000 100', env=os.environ) + vncConsole(vpcs_device, 6000, 'command {host} {port} {display}') + p.assert_called_with('command localhost 6000 100', env=os.environ) -# def test_vnc_console_on_linux_with_popen_issues(): -# with patch('subprocess.Popen', side_effect=OSError("Dummy")), \ +# def test_vnc_console_on_linux_with_popen_issues(vpcs_device): +# with patch('subprocess.call', side_effect=subprocess.SubprocessError()), \ # patch('sys.platform', new="linux"): +# vpcs_device.settings()["console_host"] = "localhost" # -# with pytest.raises(OSError): -# vncConsole('localhost', 6000, 'command %h %p %P') +# with pytest.raises(subprocess.SubprocessError): +# vncConsole(vpcs_device, 6000, 'command %h %p %P')