mirror of https://github.com/cirruslabs/tart.git
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
This commit is contained in:
parent
637a2387e7
commit
f68297097e
|
|
@ -3,3 +3,4 @@ testcontainers
|
|||
requests
|
||||
bitmath
|
||||
pytest-dependency
|
||||
paramiko
|
||||
|
|
|
|||
|
|
@ -7,10 +7,9 @@ class Tart:
|
|||
def __init__(self):
|
||||
self.tmp_dir = tempfile.TemporaryDirectory(dir=os.environ.get("CIRRUS_WORKING_DIR"))
|
||||
|
||||
# Link to the users IPSW cache to make things faster
|
||||
src = os.path.join(os.path.expanduser("~"), ".tart", "cache", "IPSWs")
|
||||
dst = os.path.join(self.tmp_dir.name, "cache", "IPSWs")
|
||||
os.makedirs(os.path.join(self.tmp_dir.name, "cache"))
|
||||
# Link to the users cache to make things faster
|
||||
src = os.path.join(os.path.expanduser("~"), ".tart", "cache")
|
||||
dst = os.path.join(self.tmp_dir.name, "cache")
|
||||
os.symlink(src, dst)
|
||||
|
||||
def __enter__(self):
|
||||
|
|
@ -31,3 +30,9 @@ class Tart:
|
|||
completed_process.check_returncode()
|
||||
|
||||
return completed_process.stdout.decode("utf-8"), completed_process.stderr.decode("utf-8")
|
||||
|
||||
def run_async(self, args) -> subprocess.Popen:
|
||||
env = os.environ.copy()
|
||||
env.update({"TART_HOME": self.tmp_dir.name})
|
||||
|
||||
return subprocess.Popen(["tart"] + args, env=env)
|
||||
|
|
|
|||
|
|
@ -6,5 +6,5 @@ def test_clone(tart):
|
|||
tart.run(["clone", "debian", "ubuntu"])
|
||||
|
||||
# Ensure that we have now 2 VMs
|
||||
stdout, _, = tart.run(["list", "--quiet"])
|
||||
stdout, _, = tart.run(["list", "--source", "local", "--quiet"])
|
||||
assert stdout == "debian\nubuntu\n"
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ def test_create_macos(tart):
|
|||
tart.run(["create", "--from-ipsw", "latest", "macos-vm"])
|
||||
|
||||
# Ensure that the VM was created
|
||||
stdout, _ = tart.run(["list", "--quiet"])
|
||||
stdout, _ = tart.run(["list", "--source", "local", "--quiet"])
|
||||
assert stdout == "macos-vm\n"
|
||||
|
||||
|
||||
|
|
@ -12,5 +12,5 @@ def test_create_linux(tart):
|
|||
tart.run(["create", "--linux", "linux-vm"])
|
||||
|
||||
# Ensure that the VM was created
|
||||
stdout, _ = tart.run(["list", "--quiet"])
|
||||
stdout, _ = tart.run(["list", "--source", "local", "--quiet"])
|
||||
assert stdout == "linux-vm\n"
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@ def test_delete(tart):
|
|||
tart.run(["create", "--linux", "debian"])
|
||||
|
||||
# Ensure that the VM exists
|
||||
stdout, _, = tart.run(["list", "--quiet"])
|
||||
stdout, _, = tart.run(["list", "--source", "local", "--quiet"])
|
||||
assert stdout == "debian\n"
|
||||
|
||||
# Delete the VM
|
||||
tart.run(["delete", "debian"])
|
||||
|
||||
# Ensure that the VM was removed
|
||||
stdout, _, = tart.run(["list", "--quiet"])
|
||||
stdout, _, = tart.run(["list", "--source", "local", "--quiet"])
|
||||
assert stdout == ""
|
||||
|
|
|
|||
|
|
@ -6,5 +6,5 @@ def test_rename(tart):
|
|||
tart.run(["rename", "debian", "ubuntu"])
|
||||
|
||||
# Ensure that the VM is now named "ubuntu"
|
||||
stdout, _, = tart.run(["list", "--quiet"])
|
||||
stdout, _, = tart.run(["list", "--source", "local", "--quiet"])
|
||||
assert stdout == "ubuntu\n"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
import uuid
|
||||
|
||||
from paramiko.client import SSHClient, AutoAddPolicy
|
||||
|
||||
|
||||
def test_run(tart):
|
||||
vm_name = f"integration-test-run-{uuid.uuid4()}"
|
||||
|
||||
# Instantiate a VM with admin:admin SSH access
|
||||
tart.run(["clone", "ghcr.io/cirruslabs/macos-ventura-base:latest", vm_name])
|
||||
|
||||
# Run the VM asynchronously
|
||||
tart_run_process = tart.run_async(["run", vm_name])
|
||||
|
||||
# Obtain the VM's IP
|
||||
stdout, _ = tart.run(["ip", vm_name, "--wait", "120"])
|
||||
ip = stdout.strip()
|
||||
|
||||
# Connect to the VM over SSH and shutdown it
|
||||
client = SSHClient()
|
||||
client.set_missing_host_key_policy(AutoAddPolicy)
|
||||
client.connect(ip, username="admin", password="admin")
|
||||
client.exec_command("sudo shutdown -h now")
|
||||
|
||||
# Wait for the "tart run" to finish successfully
|
||||
tart_run_process.wait()
|
||||
assert tart_run_process.returncode == 0
|
||||
|
||||
# Delete the VM
|
||||
_, _ = tart.run(["delete", vm_name])
|
||||
Loading…
Reference in New Issue