Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

binary file via init #595

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test for binary file
  • Loading branch information
willcl-ark committed Sep 16, 2024
commit 42977129f3fb263e232e60eb5b5b96cdd5aca9a6
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -69,6 +69,7 @@ jobs:
- services_test.py
- signet_test.py
- scenarios_test.py
- binary_test.py
steps:
- uses: actions/checkout@v4
- uses: azure/setup-helm@v4.2.0
68 changes: 68 additions & 0 deletions test/binary_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python3

import json
import os
import tempfile
import time
from pathlib import Path

from test_base import TestBase

from warnet.k8s import get_default_namespace
from warnet.process import run_command


class BinaryTest(TestBase):
TEST_STRING = "Hello, World!"

def __init__(self):
super().__init__()
self.network_dir = Path(os.path.dirname(__file__)) / "data" / "small_2_node"

def run_test(self):
try:
self.setup_network()
self.test_generic_binary()
finally:
self.cleanup()

def setup_network(self):
self.log.info("Setting up network")
self.log.info(self.warnet(f"deploy {self.network_dir}"))
self.wait_for_all_tanks_status(target="running")
self.wait_for_all_edges()

def test_generic_binary(self):
self.log.info("Launching binary")
temp_file_content = f"""#!/usr/bin/env sh
echo {self.TEST_STRING}"""

with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".sh") as temp_file:
temp_file.write(temp_file_content)
temp_file_path = temp_file.name

os.chmod(temp_file_path, 0o755)
self.warnet(f"run-binary {temp_file_path}")

# Get the commander pod name
pods = run_command(f"kubectl get pods -n {get_default_namespace()} -o json")
pods = json.loads(pods)
pod_list = [item["metadata"]["name"] for item in pods["items"]]
binary_pod = next((pod for pod in pod_list if pod.startswith("binary")), None)
if binary_pod is None:
raise ValueError("No pod found starting with 'binary'")
self.log.info(f"Got pod: {binary_pod}")

def g_log():
logs = self.warnet(f"logs {binary_pod}")
return self.TEST_STRING in logs

time.sleep(5)
self.wait_for_predicate(g_log, timeout=60, interval=5)

os.unlink(temp_file_path)


if __name__ == "__main__":
test = BinaryTest()
test.run_test()
5 changes: 5 additions & 0 deletions test/data/small_2_node/network.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
nodes:
- name: tank-0000
connect:
- tank-0001
- name: tank-0001
4 changes: 4 additions & 0 deletions test/data/small_2_node/node-defaults.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
image:
repository: bitcoindevproject/bitcoin
pullPolicy: IfNotPresent
tag: "27.0"