#1796: apply PR suggestions + fix tests
This commit is contained in:
@@ -25,8 +25,6 @@ from primaite.simulator.system.core.session_manager import SessionManager
|
||||
from primaite.simulator.system.core.software_manager import SoftwareManager
|
||||
from primaite.simulator.system.core.sys_log import SysLog
|
||||
from primaite.simulator.system.processes.process import Process
|
||||
from primaite.simulator.system.services.dns.dns_client import DNSClient
|
||||
from primaite.simulator.system.services.ftp.ftp_client import FTPClient
|
||||
from primaite.simulator.system.services.service import Service
|
||||
|
||||
_LOGGER = getLogger(__name__)
|
||||
@@ -945,11 +943,7 @@ class Node(SimComponent):
|
||||
|
||||
def _install_system_software(self):
|
||||
"""Install System Software - software that is usually provided with the OS."""
|
||||
# DNS Client
|
||||
self.software_manager.install(DNSClient)
|
||||
|
||||
# FTP
|
||||
self.software_manager.install(FTPClient)
|
||||
pass
|
||||
|
||||
def describe_state(self) -> Dict:
|
||||
"""
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
from primaite.simulator.network.hardware.base import NIC, Node
|
||||
from primaite.simulator.system.services.dns.dns_client import DNSClient
|
||||
from primaite.simulator.system.services.ftp.ftp_client import FTPClient
|
||||
|
||||
|
||||
class Computer(Node):
|
||||
@@ -36,3 +38,14 @@ class Computer(Node):
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.connect_nic(NIC(ip_address=kwargs["ip_address"], subnet_mask=kwargs["subnet_mask"]))
|
||||
self._install_system_software()
|
||||
|
||||
def _install_system_software(self):
|
||||
"""Install System Software - software that is usually provided with the OS."""
|
||||
# DNS Client
|
||||
self.software_manager.install(DNSClient)
|
||||
|
||||
# FTP
|
||||
self.software_manager.install(FTPClient)
|
||||
|
||||
super()._install_system_software()
|
||||
|
||||
@@ -83,15 +83,7 @@ class DatabaseService(Service):
|
||||
self.backup_server = backup_server
|
||||
|
||||
def backup_database(self) -> bool:
|
||||
"""
|
||||
Create a backup of the database to the configured backup server.
|
||||
|
||||
:param: backup_directory: Name of directory where backup will be stored. Optional.
|
||||
:type: backup_directory: Optional[str]
|
||||
|
||||
:param: backup_file_name: Name of file where backup will be stored. Optional.
|
||||
:type: backup_file_name: Optional[str]
|
||||
"""
|
||||
"""Create a backup of the database to the configured backup server."""
|
||||
# check if the backup server was configured
|
||||
if self.backup_server is None:
|
||||
self.sys_log.error(f"{self.name} - {self.sys_log.hostname}: not configured.")
|
||||
@@ -120,15 +112,7 @@ class DatabaseService(Service):
|
||||
return False
|
||||
|
||||
def restore_backup(self) -> bool:
|
||||
"""
|
||||
Restore a backup from backup server.
|
||||
|
||||
:param: backup_directory: Name of directory where backup will be stored. Optional.
|
||||
:type: backup_directory: Optional[str]
|
||||
|
||||
:param: backup_file_name: Name of file where backup will be stored. Optional.
|
||||
:type: backup_file_name: Optional[str]
|
||||
"""
|
||||
"""Restore a backup from backup server."""
|
||||
software_manager: SoftwareManager = self.software_manager
|
||||
ftp_client_service: FTPClient = software_manager.software["FTPClient"]
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ class FTPClient(FTPServiceABC):
|
||||
payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port
|
||||
)
|
||||
if payload.status_code == FTPStatusCode.OK:
|
||||
self.connected = None
|
||||
self.connected = False
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -162,13 +162,16 @@ class FTPClient(FTPServiceABC):
|
||||
else:
|
||||
self.sys_log.info(f"Sending file {src_folder_name}/{src_file_name} to {str(dest_ip_address)}")
|
||||
# send STOR request
|
||||
return self._send_data(
|
||||
if self._send_data(
|
||||
file=file_to_transfer,
|
||||
dest_folder_name=dest_folder_name,
|
||||
dest_file_name=dest_file_name,
|
||||
dest_ip_address=dest_ip_address,
|
||||
dest_port=dest_port,
|
||||
)
|
||||
):
|
||||
return self._disconnect_from_server(dest_ip_address=dest_ip_address, dest_port=dest_port)
|
||||
|
||||
return False
|
||||
|
||||
def request_file(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user