-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #241 from bennyz/tftp-checksum
tftp: add checksum validation
- Loading branch information
Showing
6 changed files
with
126 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,37 @@ | ||
import logging | ||
import time | ||
|
||
import pytest | ||
from jumpstarter_driver_tftp.driver import FileNotFound, TftpError | ||
from jumpstarter_testing.pytest import JumpstarterTest | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class TestResource(JumpstarterTest): | ||
filter_labels = {"board": "rpi4"} | ||
|
||
@pytest.fixture() | ||
def test_tftp_upload(self, client): | ||
def setup_tftp(self, client): | ||
# Move the setup code to a fixture | ||
client.tftp.start() | ||
yield client | ||
client.tftp.stop() | ||
|
||
def test_tftp_operations(self, setup_tftp): | ||
client = setup_tftp | ||
test_file = "test.bin" | ||
|
||
# Create test file | ||
with open(test_file, "wb") as f: | ||
f.write(b"Hello from TFTP streaming test!") | ||
|
||
try: | ||
client.tftp.start() | ||
print("TFTP server started") | ||
|
||
time.sleep(1) | ||
|
||
test_file = "test.bin" | ||
with open(test_file, "wb") as f: | ||
f.write(b"Hello from TFTP streaming test!") | ||
|
||
try: | ||
client.tftp.put_local_file(test_file) | ||
print(f"Successfully uploaded {test_file}") | ||
|
||
files = client.tftp.list_files() | ||
print(f"Files in TFTP root: {files}") | ||
|
||
if test_file in files: | ||
client.tftp.delete_file(test_file) | ||
print(f"Successfully deleted {test_file}") | ||
else: | ||
print(f"Warning: {test_file} not found in TFTP root") | ||
|
||
except TftpError as e: | ||
print(f"TFTP operation failed: {e}") | ||
except FileNotFound as e: | ||
print(f"File not found: {e}") | ||
|
||
except Exception as e: | ||
print(f"Error: {e}") | ||
finally: | ||
try: | ||
client.tftp.stop() | ||
print("TFTP server stopped") | ||
except Exception as e: | ||
print(f"Error stopping server: {e}") | ||
# Test upload | ||
client.tftp.put_local_file(test_file) | ||
assert test_file in client.tftp.list_files() | ||
|
||
# Test delete | ||
client.tftp.delete_file(test_file) | ||
assert test_file not in client.tftp.list_files() | ||
|
||
except (TftpError, FileNotFound) as e: | ||
pytest.fail(f"Test failed: {e}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CHUNK_SIZE = 1024 * 1024 * 4 # 4MB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.