def boot_and_run(commands, timeout=1200): child = a.boot() anita.login(child) for cmd in commands: rc = anita.shell_cmd(child, cmd, timeout) if rc != 0: raise Exception("command failed") anita.shell_cmd(child, "sync; shutdown -hp now", 1200) try: a.halt() except pexpect.exceptions.EOF: pass
# Remove the /tmp entry, because it's mounted as tmpfs -s=ram%25 by default, which isn't enough disk space. """ed /etc/fstab << EOF H /\\/tmp/d wq EOF""", "echo sshd=yes >> /etc/rc.conf", "echo PermitRootLogin without-password >> /etc/ssh/sshd_config", "/etc/rc.d/sshd restart", "sync; shutdown -hp now", ] a = anita.Anita(anita.URL('https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.0/%s/' % arch), workdir="work-NetBSD-%s" % arch, disk_size="16G", memory_size="2G", persist=True) child = a.boot() anita.login(child) for cmd in commands: anita.shell_cmd(child, cmd, 3600) # Sometimes, the halt command times out, even though it has completed # successfully. try: a.halt() except: pass
import sys import anita arch = sys.argv[1] release = sys.argv[2] workdir = sys.argv[3] disk_size = sys.argv[4] commands = [ # See https://code.google.com/p/google-compute-engine/issues/detail?id=77 "echo 'ignore classless-static-routes;' >> /etc/dhclient.conf", "echo 'dhclient=YES' >> /etc/rc.conf", "sh /etc/rc.d/dhclient start", "env PKG_PATH=http://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/%s/%s/All/ pkg_add curl git zsh sudo tmux" % (arch, release) ] a = anita.Anita( anita.URL("http://ftp.netbsd.org/pub/NetBSD/NetBSD-%s/%s/" % (release, arch)), workdir = workdir, disk_size = disk_size, memory_size = "512M", persist = True) child = a.boot() anita.login(child) for cmd in commands: anita.shell_cmd(child, cmd, 3600)