Skip to content

Commit f682970

Browse files
authored
Add a simple integration test for "tart run" (#587)
* Add a simple integration test for "tart run" * Integration tests: only "tart list" local VM images
1 parent 637a238 commit f682970

File tree

7 files changed

+46
-10
lines changed

7 files changed

+46
-10
lines changed

integration-tests/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ testcontainers
33
requests
44
bitmath
55
pytest-dependency
6+
paramiko

integration-tests/tart.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ class Tart:
77
def __init__(self):
88
self.tmp_dir = tempfile.TemporaryDirectory(dir=os.environ.get("CIRRUS_WORKING_DIR"))
99

10-
# Link to the users IPSW cache to make things faster
11-
src = os.path.join(os.path.expanduser("~"), ".tart", "cache", "IPSWs")
12-
dst = os.path.join(self.tmp_dir.name, "cache", "IPSWs")
13-
os.makedirs(os.path.join(self.tmp_dir.name, "cache"))
10+
# Link to the users cache to make things faster
11+
src = os.path.join(os.path.expanduser("~"), ".tart", "cache")
12+
dst = os.path.join(self.tmp_dir.name, "cache")
1413
os.symlink(src, dst)
1514

1615
def __enter__(self):
@@ -31,3 +30,9 @@ def run(self, args):
3130
completed_process.check_returncode()
3231

3332
return completed_process.stdout.decode("utf-8"), completed_process.stderr.decode("utf-8")
33+
34+
def run_async(self, args) -> subprocess.Popen:
35+
env = os.environ.copy()
36+
env.update({"TART_HOME": self.tmp_dir.name})
37+
38+
return subprocess.Popen(["tart"] + args, env=env)

integration-tests/test_clone.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ def test_clone(tart):
66
tart.run(["clone", "debian", "ubuntu"])
77

88
# Ensure that we have now 2 VMs
9-
stdout, _, = tart.run(["list", "--quiet"])
9+
stdout, _, = tart.run(["list", "--source", "local", "--quiet"])
1010
assert stdout == "debian\nubuntu\n"

integration-tests/test_create.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ def test_create_macos(tart):
33
tart.run(["create", "--from-ipsw", "latest", "macos-vm"])
44

55
# Ensure that the VM was created
6-
stdout, _ = tart.run(["list", "--quiet"])
6+
stdout, _ = tart.run(["list", "--source", "local", "--quiet"])
77
assert stdout == "macos-vm\n"
88

99

@@ -12,5 +12,5 @@ def test_create_linux(tart):
1212
tart.run(["create", "--linux", "linux-vm"])
1313

1414
# Ensure that the VM was created
15-
stdout, _ = tart.run(["list", "--quiet"])
15+
stdout, _ = tart.run(["list", "--source", "local", "--quiet"])
1616
assert stdout == "linux-vm\n"

integration-tests/test_delete.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ def test_delete(tart):
33
tart.run(["create", "--linux", "debian"])
44

55
# Ensure that the VM exists
6-
stdout, _, = tart.run(["list", "--quiet"])
6+
stdout, _, = tart.run(["list", "--source", "local", "--quiet"])
77
assert stdout == "debian\n"
88

99
# Delete the VM
1010
tart.run(["delete", "debian"])
1111

1212
# Ensure that the VM was removed
13-
stdout, _, = tart.run(["list", "--quiet"])
13+
stdout, _, = tart.run(["list", "--source", "local", "--quiet"])
1414
assert stdout == ""

integration-tests/test_rename.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ def test_rename(tart):
66
tart.run(["rename", "debian", "ubuntu"])
77

88
# Ensure that the VM is now named "ubuntu"
9-
stdout, _, = tart.run(["list", "--quiet"])
9+
stdout, _, = tart.run(["list", "--source", "local", "--quiet"])
1010
assert stdout == "ubuntu\n"

integration-tests/test_run.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import uuid
2+
3+
from paramiko.client import SSHClient, AutoAddPolicy
4+
5+
6+
def test_run(tart):
7+
vm_name = f"integration-test-run-{uuid.uuid4()}"
8+
9+
# Instantiate a VM with admin:admin SSH access
10+
tart.run(["clone", "ghcr.io/cirruslabs/macos-ventura-base:latest", vm_name])
11+
12+
# Run the VM asynchronously
13+
tart_run_process = tart.run_async(["run", vm_name])
14+
15+
# Obtain the VM's IP
16+
stdout, _ = tart.run(["ip", vm_name, "--wait", "120"])
17+
ip = stdout.strip()
18+
19+
# Connect to the VM over SSH and shutdown it
20+
client = SSHClient()
21+
client.set_missing_host_key_policy(AutoAddPolicy)
22+
client.connect(ip, username="admin", password="admin")
23+
client.exec_command("sudo shutdown -h now")
24+
25+
# Wait for the "tart run" to finish successfully
26+
tart_run_process.wait()
27+
assert tart_run_process.returncode == 0
28+
29+
# Delete the VM
30+
_, _ = tart.run(["delete", vm_name])

0 commit comments

Comments
 (0)