#2706 - Commented out references to UserSessionManager to remove the dependency.

This commit is contained in:
Charlie Crane
2024-07-30 15:24:37 +01:00
parent 09084574a8
commit 3698e6ff5f
3 changed files with 30 additions and 10 deletions

View File

@@ -15,7 +15,7 @@
"source": [ "source": [
"This notebook serves as a guide on the functionality and use of the new Terminal simulation component.\n", "This notebook serves as a guide on the functionality and use of the new Terminal simulation component.\n",
"\n", "\n",
"By default, the Terminal will come pre-installed on any simulation component which inherits from `HostNode`, and simulates the Secure Shell (SSH) protocol as the communication method." "By default, the Terminal will come pre-installed on any simulation component which inherits from `HostNode` (Computer, Server, Printer), and simulates the Secure Shell (SSH) protocol as the communication method."
] ]
}, },
{ {
@@ -131,6 +131,13 @@
"\n", "\n",
"computer_b.file_system.show()" "computer_b.file_system.show()"
] ]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The resultant call to `computer_b.file_system.show()` shows that the new folder has been created."
]
} }
], ],
"metadata": { "metadata": {

View File

@@ -3,6 +3,7 @@ from __future__ import annotations
from ipaddress import IPv4Address from ipaddress import IPv4Address
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional
from uuid import uuid4
from prettytable import MARKDOWN, PrettyTable from prettytable import MARKDOWN, PrettyTable
from pydantic import BaseModel from pydantic import BaseModel
@@ -88,10 +89,6 @@ class Terminal(Service):
state = super().describe_state() state = super().describe_state()
return state return state
def apply_request(self, request: List[str | int | float | Dict], context: Dict | None = None) -> RequestResponse:
"""Apply Terminal Request."""
return super().apply_request(request, context)
def show(self, markdown: bool = False): def show(self, markdown: bool = False):
""" """
Display the remote connections to this terminal instance in tabular format. Display the remote connections to this terminal instance in tabular format.
@@ -141,7 +138,8 @@ class Terminal(Service):
def _logoff() -> RequestResponse: def _logoff() -> RequestResponse:
"""Logoff from connection.""" """Logoff from connection."""
self.parent.UserSessionManager.logoff(self.connection_uuid) # TODO: Uncomment this when UserSessionManager merged.
# self.parent.UserSessionManager.logoff(self.connection_uuid)
self.disconnect(self.connection_uuid) self.disconnect(self.connection_uuid)
return RequestResponse(status="success", data={}) return RequestResponse(status="success", data={})
@@ -204,7 +202,9 @@ class Terminal(Service):
def _process_local_login(self, username: str, password: str) -> bool: def _process_local_login(self, username: str, password: str) -> bool:
"""Local session login to terminal.""" """Local session login to terminal."""
self.connection_uuid = self.parent.UserSessionManager.login(username=username, password=password) # TODO: Un-comment this when UserSessionManager is merged.
# self.connection_uuid = self.parent.UserSessionManager.login(username=username, password=password)
self.connection_uuid = str(uuid4())
self.is_connected = True self.is_connected = True
if self.connection_uuid: if self.connection_uuid:
self.sys_log.info(f"Login request authorised, connection uuid: {self.connection_uuid}") self.sys_log.info(f"Login request authorised, connection uuid: {self.connection_uuid}")
@@ -239,7 +239,9 @@ class Terminal(Service):
username: str = payload.user_account.username username: str = payload.user_account.username
password: str = payload.user_account.password password: str = payload.user_account.password
self.sys_log.info(f"Sending UserAuth request to UserSessionManager, username={username}, password={password}") self.sys_log.info(f"Sending UserAuth request to UserSessionManager, username={username}, password={password}")
connection_uuid = self.parent.UserSessionManager.remote_login(username=username, password=password) # TODO: Un-comment this when UserSessionManager is merged.
# connection_uuid = self.parent.UserSessionManager.remote_login(username=username, password=password)
connection_uuid = str(uuid4())
self.is_connected = True self.is_connected = True
if connection_uuid: if connection_uuid:
# Send uuid to remote # Send uuid to remote

View File

@@ -45,6 +45,17 @@ def basic_network() -> Network:
return network return network
@pytest.fixture
def game_and_agent_fixture(game_and_agent):
"""Create a game with a simple agent that can be controlled by the tests."""
game, agent = game_and_agent
client_1: Computer = game.simulation.network.get_node_by_hostname("client_1")
client_1.start_up_duration = 3
return (game, agent)
def test_terminal_creation(terminal_on_computer): def test_terminal_creation(terminal_on_computer):
terminal, computer = terminal_on_computer terminal, computer = terminal_on_computer
terminal.describe_state() terminal.describe_state()
@@ -273,10 +284,10 @@ def test_terminal_receives_requests(game_and_agent_fixture: Tuple[PrimaiteGame,
game, agent = game_and_agent_fixture game, agent = game_and_agent_fixture
network: Network = game.simulation.network network: Network = game.simulation.network
computer_a: Computer = network.get_node_by_hostname("node_a") computer_a: Computer = network.get_node_by_hostname("client_1")
terminal_a: Terminal = computer_a.software_manager.software.get("Terminal") terminal_a: Terminal = computer_a.software_manager.software.get("Terminal")
computer_b: Computer = network.get_node_by_hostname("node_b") computer_b: Computer = network.get_node_by_hostname("client_2")
assert terminal_a.is_connected is False assert terminal_a.is_connected is False