Skip to content

Commit

Permalink
Merge pull request #39 from GNS3/fix-1.0.0dev12
Browse files Browse the repository at this point in the history
Release 1.0.0b6
  • Loading branch information
grossmj authored Dec 7, 2023
2 parents 3e4bc2a + d7a9a3c commit 2ebfe73
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
4 changes: 2 additions & 2 deletions gns3_webclient_pack/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _exec_command(self, command):

if sys.platform.startswith("win"):
# use the string on Windows
process = subprocess.call(command, env=os.environ)
process = subprocess.Popen(command, env=os.environ)
else:
# use arguments on other platforms
try:
Expand All @@ -108,7 +108,7 @@ def _exec_command(self, command):
# inject gnome-terminal environment variables
if "GNOME_TERMINAL_SERVICE" not in env or "GNOME_TERMINAL_SCREEN" not in env:
env.update(self.gnome_terminal_env())
process = subprocess.call(args, env=env)
process = subprocess.Popen(args, env=env)

if sys.platform.startswith("win") and not hasattr(sys, '_called_from_test'):
# bring the launched application to the front (Windows only)
Expand Down
6 changes: 5 additions & 1 deletion gns3_webclient_pack/launcher_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@

class LauncherError(Exception):

def __init__(self, message):
def __init__(self, message, status=None):
super().__init__(message)
if isinstance(message, Exception):
message = str(message)
self._message = message
self._status = status

def status(self):
return self._status

def __repr__(self):
return self._message
Expand Down
15 changes: 9 additions & 6 deletions gns3_webclient_pack/pcap_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,14 @@ def start(self, timeout: int = 30) -> None:
self._executeHTTPQuery("GET", "/version", wait=True)
log.info("API version 2 detected")
endpoint = "pcap"
except LauncherError:
log.info("API version 3 detected")
self._api_version = "v3"
self._executeHTTPQuery("GET", "/access/users/me", wait=True) # check if we are authenticated
endpoint = "capture/stream" # pcap endpoint was renamed in v3
except LauncherError as e:
if e.status() == 404:
log.info("API version 3 detected")
self._api_version = "v3"
self._executeHTTPQuery("GET", "/access/users/me", wait=True) # check if we are authenticated
endpoint = "capture/stream" # pcap endpoint was renamed in v3
else:
raise

url = QtCore.QUrl(
"{protocol}://{host}:{port}/{api_version}/projects/{project_id}/links/{link_id}/{endpoint}".format(
Expand Down Expand Up @@ -340,7 +343,7 @@ def _executeHTTPQuery(
if status == 401 and response.rawHeader(b"WWW-Authenticate") == b"Bearer":
self._handleUnauthorizedRequest(response)
else:
raise LauncherError(f"{response.errorString()}")
raise LauncherError(f"{response.errorString()}", status=status)


def _addBodyToRequest(
Expand Down
2 changes: 1 addition & 1 deletion gns3_webclient_pack/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# or negative for a release candidate or beta (after the base version
# number has been incremented)

__version__ = "1.0.0b5"
__version__ = "1.0.0b6"
__version_info__ = (1, 0, 0, -99)

# Add the commit ID if this is a development version
Expand Down
20 changes: 10 additions & 10 deletions tests/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
def test_telnet_command_on_linux(local_config):

local_config.loadSectionSettings("CommandsSettings", {"telnet_command": "telnet {host} {port}"})
with patch('subprocess.call') as proc, \
with patch('subprocess.Popen') as proc, \
patch('os.environ', new={}), \
patch('sys.platform', new="linux"):
launcher("gns3+telnet://localhost:6000")
Expand All @@ -36,7 +36,7 @@ def test_telnet_command_on_linux(local_config):
def test_telnet_command_on_windows(local_config):

local_config.loadSectionSettings("CommandsSettings", {"telnet_command": "telnet {host} {port}"})
with patch('subprocess.call') as proc, \
with patch('subprocess.Popen') as proc, \
patch('sys.platform', new="win"):
launcher("gns3+telnet://localhost:6000")
proc.assert_called_once_with("telnet localhost 6000", env=os.environ)
Expand All @@ -45,7 +45,7 @@ def test_telnet_command_on_windows(local_config):
def test_telnet_command_no_port_on_windows(local_config):

local_config.loadSectionSettings("CommandsSettings", {"telnet_command": "telnet {host} {port}"})
with patch('subprocess.call') as proc, \
with patch('subprocess.Popen') as proc, \
patch('sys.platform', new="win"):
launcher("gns3+telnet://localhost")
proc.assert_called_once_with("telnet localhost", env=os.environ)
Expand All @@ -54,7 +54,7 @@ def test_telnet_command_no_port_on_windows(local_config):
def test_vnc_command_with_params(local_config):

local_config.loadSectionSettings("CommandsSettings", {"vnc_command": "vncviewer {host} {port} {name} {project_id} {node_id} {display} {url}"})
with patch('subprocess.call') as proc, \
with patch('subprocess.Popen') as proc, \
patch('os.environ', new={}), \
patch('sys.platform', new="linux"):
url = "gns3+vnc://localhost:5901?name=R1&project_id=1234&node_id=5678"
Expand All @@ -72,15 +72,15 @@ def test_vnc_command_with_invalid_port(qtbot, monkeypatch):
def test_telnet_command_with_non_ascii_characters(local_config):

local_config.loadSectionSettings("CommandsSettings", {"telnet_command": "telnet {host} {port} {name}"})
with patch('subprocess.call') as proc, \
with patch('subprocess.Popen') as proc, \
patch('sys.platform', new="win"):
url = "gns3+telnet://localhost:6000?name=áÆÑß"
launcher(url)
proc.assert_called_once_with("telnet localhost 6000 áÆÑß", env=os.environ)


def test_telnet_command_with_popen_issues(qtbot, monkeypatch):
with patch('subprocess.call', side_effect=OSError("Dummy")):
with patch('subprocess.Popen', side_effect=OSError("Dummy")):
monkeypatch.setattr(QtWidgets.QMessageBox, "critical", lambda *args: QtWidgets.QMessageBox.Ok)
with pytest.raises(LauncherError):
launcher("gns3+telnet://localhost:6000")
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_telnet_command_with_port_out_of_range_in_url(qtbot, monkeypatch):
def test_vnc_command_on_linux(local_config):

local_config.loadSectionSettings("CommandsSettings", {"vnc_command": "vncviewer {host} {port}"})
with patch('subprocess.call') as proc, \
with patch('subprocess.Popen') as proc, \
patch('os.environ', new={}), \
patch('sys.platform', new="linux"):
launcher("gns3+vnc://localhost:6000")
Expand All @@ -119,7 +119,7 @@ def test_vnc_command_on_linux(local_config):
def test_vnc_command_on_windows(local_config):

local_config.loadSectionSettings("CommandsSettings", {"vnc_command": "vncviewer {host} {port}"})
with patch('subprocess.call') as proc, \
with patch('subprocess.Popen') as proc, \
patch('sys.platform', new="win"):
launcher("gns3+vnc://localhost:6000")
proc.assert_called_once_with("vncviewer localhost 6000", env=os.environ)
Expand All @@ -128,7 +128,7 @@ def test_vnc_command_on_windows(local_config):
def test_spice_command_on_linux(local_config):

local_config.loadSectionSettings("CommandsSettings", {"spice_command": "remote-viewer {host} {port}"})
with patch('subprocess.call') as proc, \
with patch('subprocess.Popen') as proc, \
patch('os.environ', new={}), \
patch('sys.platform', new="linux"):
launcher("gns3+spice://localhost:6000")
Expand All @@ -138,7 +138,7 @@ def test_spice_command_on_linux(local_config):
def test_spice_command_on_windows(local_config):

local_config.loadSectionSettings("CommandsSettings", {"spice_command": "remote-viewer {host} {port}"})
with patch('subprocess.call') as proc, \
with patch('subprocess.Popen') as proc, \
patch('sys.platform', new="win"):
launcher("gns3+spice://localhost:6000")
proc.assert_called_once_with("remote-viewer localhost 6000", env=os.environ)

0 comments on commit 2ebfe73

Please sign in to comment.