#1816 - Added the final pieces of the puzzle to get data up from NIC → session manager → software manager → service.
- Implemented a basic sim DB that matches UC2 data manipulation DB in IY. - Added a test that confirms DB queries can be sent over the network.
This commit is contained in:
@@ -1,52 +1,46 @@
|
||||
from primaite.simulator.network.hardware.base import Node
|
||||
from primaite.simulator.network.transmission.transport_layer import Port
|
||||
from primaite.simulator.system.services.database import DatabaseService
|
||||
from primaite.simulator.system.services.service import ServiceOperatingState
|
||||
from primaite.simulator.system.software import SoftwareCriticality, SoftwareHealthState
|
||||
from ipaddress import IPv4Address
|
||||
|
||||
from primaite.simulator.network.hardware.nodes.computer import Computer
|
||||
from primaite.simulator.network.networks import arcd_uc2_network
|
||||
from primaite.simulator.network.transmission.data_link_layer import Frame, EthernetHeader
|
||||
from primaite.simulator.network.transmission.network_layer import IPPacket, Precedence
|
||||
from primaite.simulator.network.transmission.transport_layer import TCPHeader, Port
|
||||
|
||||
|
||||
def test_installing_database():
|
||||
db = DatabaseService(
|
||||
name="SQL-database",
|
||||
health_state_actual=SoftwareHealthState.GOOD,
|
||||
health_state_visible=SoftwareHealthState.GOOD,
|
||||
criticality=SoftwareCriticality.MEDIUM,
|
||||
port=Port.SQL_SERVER,
|
||||
operating_state=ServiceOperatingState.RUNNING,
|
||||
def test_database_query_across_the_network():
|
||||
"""Tests DB query across the network returns HTTP status 200 and date."""
|
||||
network = arcd_uc2_network()
|
||||
|
||||
client_1: Computer = network.get_node_by_hostname("client_1")
|
||||
|
||||
client_1.arp.send_arp_request(IPv4Address("192.168.1.14"))
|
||||
|
||||
dst_mac_address = client_1.arp.get_arp_cache_mac_address(IPv4Address("192.168.1.14"))
|
||||
|
||||
outbound_nic = client_1.arp.get_arp_cache_nic(IPv4Address("192.168.1.14"))
|
||||
client_1.ping("192.168.1.14")
|
||||
|
||||
|
||||
frame = Frame(
|
||||
ethernet=EthernetHeader(
|
||||
src_mac_addr=client_1.ethernet_port[1].mac_address,
|
||||
dst_mac_addr=dst_mac_address
|
||||
),
|
||||
ip=IPPacket(
|
||||
src_ip_address=client_1.ethernet_port[1].ip_address,
|
||||
dst_ip_address=IPv4Address("192.168.1.14"),
|
||||
precedence=Precedence.FLASH
|
||||
),
|
||||
tcp=TCPHeader(
|
||||
src_port=Port.POSTGRES_SERVER,
|
||||
dst_port=Port.POSTGRES_SERVER
|
||||
),
|
||||
payload="SELECT * FROM user;"
|
||||
)
|
||||
|
||||
node = Node(hostname="db-server")
|
||||
outbound_nic.send_frame(frame)
|
||||
|
||||
node.install_service(db)
|
||||
client_1_last_payload = outbound_nic.pcap.read()[-1]["payload"]
|
||||
|
||||
assert db in node
|
||||
|
||||
file_exists = False
|
||||
for folder in node.file_system.folders.values():
|
||||
for file in folder.files.values():
|
||||
if file.name == "db_primary_store":
|
||||
file_exists = True
|
||||
break
|
||||
if file_exists:
|
||||
break
|
||||
assert file_exists
|
||||
|
||||
|
||||
def test_uninstalling_database():
|
||||
db = DatabaseService(
|
||||
name="SQL-database",
|
||||
health_state_actual=SoftwareHealthState.GOOD,
|
||||
health_state_visible=SoftwareHealthState.GOOD,
|
||||
criticality=SoftwareCriticality.MEDIUM,
|
||||
port=Port.SQL_SERVER,
|
||||
operating_state=ServiceOperatingState.RUNNING,
|
||||
)
|
||||
|
||||
node = Node(hostname="db-server")
|
||||
|
||||
node.install_service(db)
|
||||
|
||||
node.uninstall_service(db)
|
||||
|
||||
assert db not in node
|
||||
assert node.file_system.get_folder("database") is None
|
||||
assert client_1_last_payload["status_code"] == 200
|
||||
assert client_1_last_payload["data"]
|
||||
Reference in New Issue
Block a user