fix: add reusable extract_config for node

This commit is contained in:
Roman 2025-06-04 09:30:00 +08:00
parent c90974118e
commit fce8af0deb
No known key found for this signature in database
GPG Key ID: 583BDF43C238B83E
2 changed files with 18 additions and 14 deletions

View File

@ -1,4 +1,6 @@
import io
import os
import tarfile
from src.data_storage import DS
from src.libs.common import generate_log_prefix
@ -157,6 +159,21 @@ class NomosNode:
else:
logger.debug("No keyword matches found in the logs.")
def extract_config(self, target_file):
# Copy the config file from first node
stream, _stat = self.get_archive("/config.yaml")
# Join stream into bytes and load into a memory buffer
tar_bytes = io.BytesIO(b"".join(stream))
# Extract and write only the actual config file
with tarfile.open(fileobj=tar_bytes) as tar:
member = tar.getmembers()[0]
file_obj = tar.extractfile(member)
if file_obj:
with open(f"{target_file}", "wb") as f:
f.write(file_obj.read())
def send_dispersal_request(self, data):
return self._api.da_disperse_data(data)

View File

@ -57,20 +57,7 @@ class TestDataConfidentiality(StepsDataAvailability):
assert DATA_TO_DISPERSE[1] == decoded_data, "Retrieved data are not same with original data"
# Copy the config file from first node
stream, _stat = self.node2.get_archive("/config.yaml")
# Join stream into bytes and load into a memory buffer
tar_bytes = io.BytesIO(b"".join(stream))
# Extract and write only the actual text file
with tarfile.open(fileobj=tar_bytes) as tar:
member = tar.getmembers()[0]
file_obj = tar.extractfile(member)
if file_obj:
with open("./cluster_config/config.yaml", "wb") as f:
f.write(file_obj.read())
self.node2.extract_config("./cluster_config/config.yaml")
self.node2.stop()
# Change the private key -> PeerId of the nomos_node_0. This would create a stranger to existing membership list.