From fce8af0debc06d2a81d1a8ad0809754a74a769cc Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 4 Jun 2025 09:30:00 +0800 Subject: [PATCH] fix: add reusable extract_config for node --- src/node/nomos_node.py | 17 +++++++++++++++++ .../test_data_confidentiality.py | 15 +-------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/node/nomos_node.py b/src/node/nomos_node.py index d61fdfc..26fa2a2 100644 --- a/src/node/nomos_node.py +++ b/src/node/nomos_node.py @@ -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) diff --git a/tests/data_confidentiality/test_data_confidentiality.py b/tests/data_confidentiality/test_data_confidentiality.py index 05d5726..e7149e1 100644 --- a/tests/data_confidentiality/test_data_confidentiality.py +++ b/tests/data_confidentiality/test_data_confidentiality.py @@ -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.