Skip to content

Commit

Permalink
clean up cache.db
Browse files Browse the repository at this point in the history
  • Loading branch information
subbyte committed Jul 25, 2024
1 parent 7cff882 commit 0af883b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
2 changes: 2 additions & 0 deletions packages/kestrel_core/src/kestrel/cache/sql.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import os
from copy import copy
from tempfile import mkstemp
from typing import Any, Iterable, Mapping, MutableMapping, Optional
Expand Down Expand Up @@ -71,6 +72,7 @@ def __init__(

def __del__(self):
self.connection.close()
os.remove(self.db_path)

def __getitem__(self, instruction_id: UUID) -> DataFrame:
return read_sql(self.cache_catalog[instruction_id], self.connection)
Expand Down
6 changes: 0 additions & 6 deletions packages/kestrel_core/tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ class Gateway(SqlCache):
def schemes():
return ["gateway"]

extra_db = []
with Session() as session:
stmt1 = """
procs = NEW process [ {"name": "cmd.exe", "pid": 123}
Expand All @@ -236,7 +235,6 @@ def schemes():
session.irgraph.get_nodes_by_type_and_attributes(Construct, {"interface": CACHE_INTERFACE_IDENTIFIER})[0].interface = "datalake"

new_cache = SqlCache()
extra_db.append(new_cache.db_path)
session.interface_manager.interfaces.append(new_cache)
stmt2 = """
nt = NEW network [ {"pid": 123, "source": "192.168.1.1", "destination": "1.1.1.1"}
Expand All @@ -249,7 +247,6 @@ def schemes():
session.irgraph.get_nodes_by_type_and_attributes(Construct, {"interface": CACHE_INTERFACE_IDENTIFIER})[0].interface = "gateway"

new_cache = SqlCache()
extra_db.append(new_cache.db_path)
session.interface_manager.interfaces.append(new_cache)
stmt3 = """
domain = NEW domain [ {"ip": "1.1.1.1", "domain": "cloudflare.com"}
Expand Down Expand Up @@ -307,9 +304,6 @@ def schemes():
df_ref = DataFrame([{"ip": "1.1.1.2", "domain": "xyz.cloudflare.com"}])
assert df_ref.equals(df_res)

for db_file in extra_db:
os.remove(db_file)


def test_apply_on_construct():
hf = """
Expand Down

0 comments on commit 0af883b

Please sign in to comment.