[{"id":1765456,"web_url":"http://patchwork.ozlabs.org/comment/1765456/","msgid":"<87tw0dgqpv.fsf@linaro.org>","list_archive_url":null,"date":"2017-09-08T15:22:36","subject":"Re: [Qemu-devel] [PATCH v6 04/12] tests: Add vm test lib","submitter":{"id":39532,"url":"http://patchwork.ozlabs.org/api/people/39532/","name":"Alex Bennée","email":"alex.bennee@linaro.org"},"content":"Fam Zheng <famz@redhat.com> writes:\n\n> This is the common code to implement a \"VM test\" to\n>\n>   1) Download and initialize a pre-defined VM that has necessary\n>   dependencies to build QEMU and SSH access.\n>\n>   2) Archive $SRC_PATH to a .tar file.\n>\n>   3) Boot the VM, and pass the source tar file to the guest.\n>\n>   4) SSH into the VM, untar the source tarball, build from the source.\n>\n> Signed-off-by: Fam Zheng <famz@redhat.com>\n> ---\n>  tests/vm/basevm.py | 276 +++++++++++++++++++++++++++++++++++++++++++++++++++++\n>  1 file changed, 276 insertions(+)\n>  create mode 100755 tests/vm/basevm.py\n>\n> diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py\n> new file mode 100755\n> index 0000000000..9db91d61fa\n> --- /dev/null\n> +++ b/tests/vm/basevm.py\n> @@ -0,0 +1,276 @@\n> +#!/usr/bin/env python\n> +#\n> +# VM testing base class\n> +#\n> +# Copyright (C) 2017 Red Hat Inc.\n> +#\n> +# Authors:\n> +#  Fam Zheng <famz@redhat.com>\n> +#\n> +# This work is licensed under the terms of the GNU GPL, version 2.  See\n> +# the COPYING file in the top-level directory.\n> +#\n> +\n> +import os\n> +import sys\n> +import logging\n> +import time\n> +import datetime\n> +sys.path.append(os.path.join(os.path.dirname(__file__), \"..\", \"..\", \"scripts\"))\n> +from qemu import QEMUMachine\n> +import subprocess\n> +import hashlib\n> +import optparse\n> +import atexit\n> +import tempfile\n> +import shutil\n> +import multiprocessing\n> +import traceback\n> +\n> +SSH_KEY = \"\"\"\\\n> +-----BEGIN RSA PRIVATE KEY-----\n> +MIIEowIBAAKCAQEAopAuOlmLV6LVHdFBj8/eeOwI9CqguIJPp7eAQSZvOiB4Ag/R\n> +coEhl/RBbrV5Yc/SmSD4PTpJO/iM10RwliNjDb4a3I8q3sykRJu9c9PI/YsH8WN9\n> ++NH2NjKPtJIcKTu287IM5JYxyB6nDoOzILbTyJ1TDR/xH6qYEfBAyiblggdjcvhA\n> +RTf93QIn39F/xLypXvT1K2O9BJEsnJ8lEUvB2UXhKo/JTfSeZF8wPBeowaP9EONk\n> +7b+nuJOWHGg68Ji6wVi62tjwl2Szch6lxIhZBpnV7QNRKMfYHP6eIyF4pusazzZq\n> +Telsq6xI2ghecWLzb/MF5A+rklsGx2FNuJSAJwIDAQABAoIBAHHi4o/8VZNivz0x\n> +cWXn8erzKV6tUoWQvW85Lj/2RiwJvSlsnYZDkx5af1CpEE2HA/pFT8PNRqsd+MWC\n> +7AEy710cVsM4BYerBFYQaYxwzblaoojo88LSjVPw3h5Z0iLM8+IMVd36nwuc9dpE\n> +R8TecMZ1+U4Tl6BgqkK+9xToZRdPKdjS8L5MoFhGN+xY0vRbbJbGaV9Q0IHxLBkB\n> +rEBV7T1mUynneCHRUQlJQEwJmKpT8MH3IjsUXlG5YvnuuvcQJSNTaW2iDLxuOKp8\n> +cxW8+qL88zpb1D5dppoIu6rlrugN0azSq70ruFJQPc/A8GQrDKoGgRQiagxNY3u+\n> +vHZzXlECgYEA0dKO3gfkSxsDBb94sQwskMScqLhcKhztEa8kPxTx6Yqh+x8/scx3\n> +XhJyOt669P8U1v8a/2Al+s81oZzzfQSzO1Q7gEwSrgBcRMSIoRBUw9uYcy02ngb/\n> +j/ng3DGivfJztjjiSJwb46FHkJ2JR8mF2UisC6UMXk3NgFY/3vWQx78CgYEAxlcG\n> +T3hfSWSmTgKRczMJuHQOX9ULfTBIqwP5VqkkkiavzigGRirzb5lgnmuTSPTpF0LB\n> +XVPjR2M4q+7gzP0Dca3pocrvLEoxjwIKnCbYKnyyvnUoE9qHv4Kr+vDbgWpa2LXG\n> +JbLmE7tgTCIp20jOPPT4xuDvlbzQZBJ5qCQSoZkCgYEAgrotSSihlCnAOFSTXbu4\n> +CHp3IKe8xIBBNENq0eK61kcJpOxTQvOha3sSsJsU4JAM6+cFaxb8kseHIqonCj1j\n> +bhOM/uJmwQJ4el/4wGDsbxriYOBKpyq1D38gGhDS1IW6kk3erl6VAb36WJ/OaGum\n> +eTpN9vNeQWM4Jj2WjdNx4QECgYAwTdd6mU1TmZCrJRL5ZG+0nYc2rbMrnQvFoqUi\n> +BvWiJovggHzur90zy73tNzPaq9Ls2FQxf5G1vCN8NCRJqEEjeYCR59OSDMu/EXc2\n> +CnvQ9SevHOdS1oEDEjcCWZCMFzPi3XpRih1gptzQDe31uuiHjf3cqcGPzTlPdfRt\n> +D8P92QKBgC4UaBvIRwREVJsdZzpIzm224Bpe8LOmA7DeTnjlT0b3lkGiBJ36/Q0p\n> +VhYh/6cjX4/iuIs7gJbGon7B+YPB8scmOi3fj0+nkJAONue1mMfBNkba6qQTc6Y2\n> +5mEKw2/O7/JpND7ucU3OK9plcw/qnrWDgHxl0Iz95+OzUIIagxne\n> +-----END RSA PRIVATE KEY-----\n> +\"\"\"\n> +SSH_PUB_KEY = \"\"\"\\\n> +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCikC46WYtXotUd0UGPz9547Aj0KqC4gk+nt4BBJm86IHgCD9FygSGX9EFutXlhz9KZIPg9Okk7+IzXRHCWI2MNvhrcjyrezKREm71z08j9iwfxY3340fY2Mo+0khwpO7bzsgzkljHIHqcOg7MgttPInVMNH/EfqpgR8EDKJuWCB2Ny+EBFN/3dAiff0X/EvKle9PUrY70EkSycnyURS8HZReEqj8lN9J5kXzA8F6jBo/0Q42Ttv6e4k5YcaDrwmLrBWLra2PCXZLNyHqXEiFkGmdXtA1Eox9gc/p4jIXim6xrPNmpN6WyrrEjaCF5xYvNv8wXkD6uSWwbHYU24lIAn qemu-vm-key\n> +\"\"\"\n\nI'm not sure we should be embedding the keys in the script. I understand\nwe need a common key for downloaded images (although it would be better\nto post-customise the image after download with the local developer\nkeys). Perhaps ./tests/testing-keys/id_rsa[.pub]?\n\n> +\n> +class BaseVM(object):\n> +    GUEST_USER = \"qemu\"\n> +    GUEST_PASS = \"qemupass\"\n> +    ROOT_PASS = \"qemupass\"\n> +\n> +    # The script to run in the guest that builds QEMU\n> +    BUILD_SCRIPT = \"\"\n> +    # The guest name, to be overridden by subclasses\n> +    name = \"#base\"\n> +    def __init__(self, debug=False, vcpus=None):\n> +        self._guest = None\n> +        self._tmpdir = tempfile.mkdtemp(prefix=\"vm-test-\", suffix=\".tmp\", dir=\".\")\n> +        atexit.register(shutil.rmtree, self._tmpdir)\n> +\n> +        self._ssh_key_file = os.path.join(self._tmpdir, \"id_rsa\")\n> +        open(self._ssh_key_file, \"w\").write(SSH_KEY)\n> +        subprocess.check_call([\"chmod\", \"600\", self._ssh_key_file])\n> +\n> +        self._ssh_pub_key_file = os.path.join(self._tmpdir, \"id_rsa.pub\")\n> +        open(self._ssh_pub_key_file, \"w\").write(SSH_PUB_KEY)\n\nAs above, I think it would be better just to keep copies of the keys in\nthe tests directory rather than in the python source.\n\n> +\n> +        self.debug = debug\n> +        self._stderr = sys.stderr\n> +        self._devnull = open(\"/dev/null\", \"w\")\n\nYou can use os.devnull as a portable reference.\n\n> +        if self.debug:\n> +            self._stdout = sys.stdout\n> +        else:\n> +            self._stdout = self._devnull\n> +        self._args = [ \\\n> +            \"-nodefaults\", \"-m\", \"2G\",\n> +            \"-cpu\", \"host\",\n> +            \"-netdev\", \"user,id=vnet,hostfwd=:0.0.0.0:0-:22\",\n\nIt doesn't help that howstfwd is poorly documented. Are we trying to map\nan ephemeral port to the guests 22?\n\n> +            \"-device\", \"virtio-net-pci,netdev=vnet\",\n> +            \"-vnc\", \":0,to=20\",\n\nDo we need a GUI?\n\n> +            \"-serial\", \"file:%s\" % os.path.join(self._tmpdir,\n> \"serial.out\")]\n> +        if vcpus:\n> +            self._args += [\"-smp\", str(vcpus)]\n> +        if os.access(\"/dev/kvm\", os.R_OK | os.W_OK):\n> +            self._args += [\"-enable-kvm\"]\n> +        else:\n> +            logging.info(\"KVM not available, not using -enable-kvm\")\n> +        self._data_args = []\n> +\n> +    def _download_with_cache(self, url, sha256sum=None):\n> +        def check_sha256sum(fname):\n> +            if not sha256sum:\n> +                return True\n> +            checksum = subprocess.check_output([\"sha256sum\", fname]).split()[0]\n> +            return sha256sum == checksum\n> +\n> +        cache_dir = os.path.expanduser(\"~/.cache/qemu-vm/download\")\n> +        if not os.path.exists(cache_dir):\n> +            os.makedirs(cache_dir)\n> +        fname = os.path.join(cache_dir, hashlib.sha1(url).hexdigest())\n> +        if os.path.exists(fname) and check_sha256sum(fname):\n> +            return fname\n> +        logging.debug(\"Downloading %s to %s...\", url, fname)\n> +        subprocess.check_call([\"wget\", \"-c\", url, \"-O\", fname + \".download\"],\n> +                              stdout=self._stdout,\n> stderr=self._stderr)\n\nUsing wget rather than doing it internally adds a utility requirement.\nIs doing a pure python urllib2 fetch too slow for this?\n\n> +        os.rename(fname + \".download\", fname)\n> +        return fname\n> +\n> +    def _ssh_do(self, user, cmd, check, interactive=False):\n> +        ssh_cmd = [\"ssh\", \"-q\",\n> +                   \"-o\", \"StrictHostKeyChecking=no\",\n> +                   \"-o\", \"UserKnownHostsFile=/dev/null\",\n> +                   \"-o\", \"ConnectTimeout=1\",\n> +                   \"-p\", self.ssh_port, \"-i\", self._ssh_key_file]\n> +        if interactive:\n> +            ssh_cmd += ['-t']\n> +        assert not isinstance(cmd, str)\n> +        ssh_cmd += [\"%s@127.0.0.1\" % user] + list(cmd)\n> +        logging.debug(\"ssh_cmd: %s\", \" \".join(ssh_cmd))\n> +        r = subprocess.call(ssh_cmd,\n> +                            stdin=sys.stdin if interactive else self._devnull,\n> +                            stdout=sys.stdout if interactive else self._stdout,\n> +                            stderr=sys.stderr if interactive else self._stderr)\n> +        if check and r != 0:\n> +            raise Exception(\"SSH command failed: %s\" % cmd)\n> +        return r\n> +\n> +    def ssh(self, *cmd):\n> +        return self._ssh_do(self.GUEST_USER, cmd, False)\n> +\n> +    def ssh_interactive(self, *cmd):\n> +        return self._ssh_do(self.GUEST_USER, cmd, False, True)\n> +\n> +    def ssh_root(self, *cmd):\n> +        return self._ssh_do(\"root\", cmd, False)\n> +\n> +    def ssh_check(self, *cmd):\n> +        self._ssh_do(self.GUEST_USER, cmd, True)\n> +\n> +    def ssh_root_check(self, *cmd):\n> +        self._ssh_do(\"root\", cmd, True)\n> +\n> +    def build_image(self, img):\n> +        raise NotImplementedError\n> +\n> +    def add_source_dir(self, src_dir):\n> +        name = \"data-\" + hashlib.sha1(src_dir).hexdigest()[:5]\n> +        tarfile = os.path.join(self._tmpdir, name + \".tar\")\n> +        logging.debug(\"Creating archive %s for src_dir dir: %s\", tarfile, src_dir)\n> +        subprocess.check_call([\"./scripts/archive-source.sh\", tarfile],\n> +                              cwd=src_dir, stdin=self._devnull,\n> +                              stdout=self._stdout, stderr=self._stderr)\n> +        self._data_args += [\"-drive\",\n> +                            \"file=%s,if=none,id=%s,cache=writeback,format=raw\" % \\\n> +                                    (tarfile, name),\n> +                            \"-device\",\n> +                            \"virtio-blk,drive=%s,serial=%s,bootindex=1\" % (name, name)]\n> +\n> +    def boot(self, img, extra_args=[]):\n> +        args = self._args + [\n> +            \"-device\", \"VGA\",\n\nIs specifying a display device at boot time really needed (say rather\nthan further up with the rest of the machine description). Do we even\nwant a display given use ssh/serial for everything?\n\n> +            \"-drive\", \"file=%s,if=none,id=drive0,cache=writeback\" % img,\n> +            \"-device\", \"virtio-blk,drive=drive0,bootindex=0\"]\n> +        args += self._data_args + extra_args\n> +        logging.debug(\"QEMU args: %s\", \" \".join(args))\n> +        guest = QEMUMachine(binary=os.environ.get(\"QEMU\", \"qemu-system-x86_64\"),\n> +                            args=args)\n> +        guest.launch()\n> +        atexit.register(self.shutdown)\n> +        self._guest = guest\n> +        usernet_info = guest.qmp(\"human-monitor-command\",\n> +                                 command_line=\"info usernet\")\n> +        self.ssh_port = None\n> +        for l in usernet_info[\"return\"].splitlines():\n> +            fields = l.split()\n> +            if \"TCP[HOST_FORWARD]\" in fields and \"22\" in fields:\n> +                self.ssh_port = l.split()[3]\n> +        if not self.ssh_port:\n> +            raise Exception(\"Cannot find ssh port from 'info usernet':\\n%s\" % \\\n> +                            usernet_info)\n> +\n> +    def wait_ssh(self, seconds=120):\n> +        starttime = datetime.datetime.now()\n> +        guest_up = False\n> +        while (datetime.datetime.now() - starttime).total_seconds() < seconds:\n> +            if self.ssh(\"exit 0\") == 0:\n> +                guest_up = True\n> +                break\n> +            time.sleep(1)\n> +        if not guest_up:\n> +            raise Exception(\"Timeout while waiting for guest ssh\")\n> +\n> +    def shutdown(self):\n> +        self._guest.shutdown()\n> +\n> +    def wait(self):\n> +        self._guest.wait()\n> +\n> +    def qmp(self, *args, **kwargs):\n> +        return self._guest.qmp(*args, **kwargs)\n> +\n> +def parse_args(vm_name):\n> +    parser = optparse.OptionParser(description=\"\"\"\n> +    VM test utility.  Exit codes: 0 = success, 1 = command line error, 2 = environment initialization failed, 3 = test command failed\"\"\")\n> +    parser.add_option(\"--debug\", \"-D\", action=\"store_true\",\n> +                      help=\"enable debug output\")\n> +    parser.add_option(\"--image\", \"-i\", default=\"%s.img\" % vm_name,\n> +                      help=\"image file name\")\n> +    parser.add_option(\"--force\", \"-f\", action=\"store_true\",\n> +                      help=\"force build image even if image exists\")\n> +    parser.add_option(\"--jobs\", type=int, default=multiprocessing.cpu_count() / 2,\n> +                      help=\"number of virtual CPUs\")\n> +    parser.add_option(\"--build-image\", \"-b\", action=\"store_true\",\n> +                      help=\"build image\")\n> +    parser.add_option(\"--build-qemu\",\n> +                      help=\"build QEMU from source in guest\")\n> +    parser.add_option(\"--interactive\", \"-I\", action=\"store_true\",\n> +                      help=\"Interactively run command\")\n> +    parser.disable_interspersed_args()\n> +    return parser.parse_args()\n> +\n> +def main(vmcls):\n> +    try:\n> +        args, argv = parse_args(vmcls.name)\n> +        if not argv and not args.build_qemu and not args.build_image:\n> +            print \"Nothing to do?\"\n> +            return 1\n> +        if args.debug:\n> +            logging.getLogger().setLevel(logging.DEBUG)\n> +        vm = vmcls(debug=args.debug, vcpus=args.jobs)\n> +        if args.build_image:\n> +            if os.path.exists(args.image) and not args.force:\n> +                sys.stderr.writelines([\"Image file exists: %s\\n\" % args.image,\n> +                                      \"Use --force option to overwrite\\n\"])\n> +                return 1\n> +            return vm.build_image(args.image)\n> +        if args.build_qemu:\n> +            vm.add_source_dir(args.build_qemu)\n> +            cmd = [vm.BUILD_SCRIPT.format(\n> +                   configure_opts = \" \".join(argv),\n> +                   jobs=args.jobs)]\n> +        else:\n> +            cmd = argv\n> +        vm.boot(args.image + \",snapshot=on\")\n\nIf this fails it's fairly cryptic:\n\n/home/alex/lsrc/qemu/qemu.git/tests/vm/openbsd  --debug   --image \"tests/vm/openbsd.img\" --build-qemu /home/alex/lsrc/qemu/qemu.git\nDEBUG:root:Creating archive ./vm-test-fxejnB.tmp/data-2de24.tar for src_dir dir: /home/alex/lsrc/qemu/qemu.git\nDEBUG:root:QEMU args: -nodefaults -m 2G -cpu host -netdev user,id=vnet,hostfwd=:0.0.0.0:0-:22 -device virtio-net-pci,netdev=vnet -vnc :0,to=20 -serial file:./vm-test-fxejnB.tmp/serial.out -smp 4 -enable-kvm -device VGA -drive file=tests/vm/openbsd.img,snapshot=on,if=none,id=drive0,cache=writeback -device virtio-blk,drive=drive0,bootindex=0 -drive file=./vm-test-fxejnB.tmp/data-2de24.tar,if=none,id=data-2de24,cache=writeback,format=raw -device virtio-blk,drive=data-2de24,serial=data-2de24,bootindex=1\nFailed to prepare guest environment\nTraceback (most recent call last):\n  File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/basevm.py\", line 260, in main\n    vm.boot(args.image + \",snapshot=on\")\n  File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/basevm.py\", line 184, in boot\n    guest.launch()\n  File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/../../scripts/qemu.py\", line 151, in launch\n    self._post_launch()\n  File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/../../scripts/qemu.py\", line 135, in _post_launch\n    self._qmp.accept()\n  File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/../../scripts/qmp/qmp.py\", line 147, in accept\n    return self.__negotiate_capabilities()\n  File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/../../scripts/qmp/qmp.py\", line 60, in __negotiate_capabilities\n    raise QMPConnectError\nQMPConnectError\n\nI assume QEMU failed to boot and might have given us a message that\nwould be useful.\n\n\n> +        vm.wait_ssh()\n> +    except Exception as e:\n> +        if isinstance(e, SystemExit) and e.code == 0:\n> +            return 0\n> +        sys.stderr.write(\"Failed to prepare guest environment\\n\")\n> +        traceback.print_exc()\n> +        return 2\n> +\n> +    if args.interactive:\n> +        if vm.ssh_interactive(*cmd) == 0:\n> +            return 0\n> +        vm.ssh_interactive()\n> +        return 3\n> +    else:\n> +        if vm.ssh(*cmd) != 0:\n> +            return 3\n\n\n--\nAlex Bennée","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=linaro.org header.i=@linaro.org\n\theader.b=\"jc0PwtHX\"; dkim-atps=neutral"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xph0X1kPmz9s2G\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSat,  9 Sep 2017 01:23:08 +1000 (AEST)","from localhost ([::1]:45938 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dqL7a-0008GW-DH\n\tfor incoming@patchwork.ozlabs.org; Fri, 08 Sep 2017 11:23:06 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:42975)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <alex.bennee@linaro.org>) id 1dqL7E-0008Fz-PZ\n\tfor qemu-devel@nongnu.org; Fri, 08 Sep 2017 11:22:46 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <alex.bennee@linaro.org>) id 1dqL7B-0003Af-G8\n\tfor qemu-devel@nongnu.org; Fri, 08 Sep 2017 11:22:44 -0400","from mail-wr0-x22a.google.com ([2a00:1450:400c:c0c::22a]:33462)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <alex.bennee@linaro.org>)\n\tid 1dqL7B-000398-4n\n\tfor qemu-devel@nongnu.org; Fri, 08 Sep 2017 11:22:41 -0400","by mail-wr0-x22a.google.com with SMTP id a43so5314642wrc.0\n\tfor <qemu-devel@nongnu.org>; Fri, 08 Sep 2017 08:22:39 -0700 (PDT)","from zen.linaro.local ([81.128.185.34])\n\tby smtp.gmail.com with ESMTPSA id\n\ta195sm1966470wme.34.2017.09.08.08.22.37\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tFri, 08 Sep 2017 08:22:37 -0700 (PDT)","from zen (localhost [127.0.0.1])\n\tby zen.linaro.local (Postfix) with ESMTPS id D9EA93E00A6;\n\tFri,  8 Sep 2017 16:22:36 +0100 (BST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google;\n\th=references:user-agent:from:to:cc:subject:in-reply-to:date\n\t:message-id:mime-version:content-transfer-encoding;\n\tbh=o/lY8gbpj4YtqJeG6kDTlzMSpcBIRIUIHHit7NoIJBA=;\n\tb=jc0PwtHX7VEkBRojWdGPBDphMGUnUe2ZIvcDsonwfAPlW6AdYp0XQtdLHc3pIZh4HA\n\t/WEz+OXzeJaBqS5OX0MXE5uPXvRBvgbGmaOrohATYHdUosU4aP58QnCdzyGDrOvqn41Z\n\t20FIN+4r+cn6TG3cLrxewMdxZnerbnORej8TE=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:references:user-agent:from:to:cc:subject\n\t:in-reply-to:date:message-id:mime-version:content-transfer-encoding; \n\tbh=o/lY8gbpj4YtqJeG6kDTlzMSpcBIRIUIHHit7NoIJBA=;\n\tb=rB1f6V6/y6JQsI0778oZwcLiONxasKrAjQY2DyoPFV+lqUaelvRukJCq6qDCxVuTCW\n\tyCWKpBNr6qZ/dNGpdv5tou7zx5HGtUdDHQynNc8iHGRLcHjLrPN++4NjdvvzRhn9QmSZ\n\tQDcsJOkC3G0PzQtYgN4Qsb2MLMP6NsmdEbSklRik3lVmip9dwc7IjoykoVr/zYhYM4nV\n\tZVZUj8mjUA1NP3/hWblHWPVtjqHDzxeaEX0rwO4FecX1QBaha/h29fs/JhZvO0bGzeoy\n\tLEfxmJNfj2kFAEnT+BQOw9su1DNs4X6xBDNNN1W9SyufpUCIFGad2Q3h3kyQTgMVL1J7\n\tNfAw==","X-Gm-Message-State":"AHPjjUjjqwCorOKHS4+1PuXu4sN68E2P46dzrkVaOPCxefBPg1GXBhZl\n\tS0gF+SR6NJZrlGDY","X-Google-Smtp-Source":"ADKCNb5ceg4F04hvIWIvY9g9pk1D+xBgor1GrOoQCdPGcMhvG+EkIzrpuKR5wVJXkdBq+N3GMQaJug==","X-Received":"by 10.223.176.132 with SMTP id i4mr2417844wra.13.1504884158409; \n\tFri, 08 Sep 2017 08:22:38 -0700 (PDT)","References":"<20170905021201.25684-1-famz@redhat.com>\n\t<20170905021201.25684-5-famz@redhat.com>","User-agent":"mu4e 0.9.19; emacs 25.2.50.3","From":"Alex =?utf-8?q?Benn=C3=A9e?= <alex.bennee@linaro.org>","To":"Fam Zheng <famz@redhat.com>","In-reply-to":"<20170905021201.25684-5-famz@redhat.com>","Date":"Fri, 08 Sep 2017 16:22:36 +0100","Message-ID":"<87tw0dgqpv.fsf@linaro.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"8bit","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"2a00:1450:400c:c0c::22a","Subject":"Re: [Qemu-devel] [PATCH v6 04/12] tests: Add vm test lib","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org, Philippe\n\t=?utf-8?q?Mathieu-Daud=C3=A9?= <f4bug@amsat.org>,\n\tKamil Rytarowski <kamil@netbsd.org>, stefanha@redhat.com, \n\tCleber Rosa <crosa@redhat.com>, pbonzini@redhat.com","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1765659,"web_url":"http://patchwork.ozlabs.org/comment/1765659/","msgid":"<20170908232950.GD18677@lemon.lan>","list_archive_url":null,"date":"2017-09-08T23:29:56","subject":"Re: [Qemu-devel] [PATCH v6 04/12] tests: Add vm test lib","submitter":{"id":24872,"url":"http://patchwork.ozlabs.org/api/people/24872/","name":"Fam Zheng","email":"famz@redhat.com"},"content":"On Fri, 09/08 16:22, Alex Bennée wrote:\n> \n> Fam Zheng <famz@redhat.com> writes:\n> \n> > This is the common code to implement a \"VM test\" to\n> >\n> >   1) Download and initialize a pre-defined VM that has necessary\n> >   dependencies to build QEMU and SSH access.\n> >\n> >   2) Archive $SRC_PATH to a .tar file.\n> >\n> >   3) Boot the VM, and pass the source tar file to the guest.\n> >\n> >   4) SSH into the VM, untar the source tarball, build from the source.\n> >\n> > Signed-off-by: Fam Zheng <famz@redhat.com>\n> > ---\n> >  tests/vm/basevm.py | 276 +++++++++++++++++++++++++++++++++++++++++++++++++++++\n> >  1 file changed, 276 insertions(+)\n> >  create mode 100755 tests/vm/basevm.py\n> >\n> > diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py\n> > new file mode 100755\n> > index 0000000000..9db91d61fa\n> > --- /dev/null\n> > +++ b/tests/vm/basevm.py\n> > @@ -0,0 +1,276 @@\n> > +#!/usr/bin/env python\n> > +#\n> > +# VM testing base class\n> > +#\n> > +# Copyright (C) 2017 Red Hat Inc.\n> > +#\n> > +# Authors:\n> > +#  Fam Zheng <famz@redhat.com>\n> > +#\n> > +# This work is licensed under the terms of the GNU GPL, version 2.  See\n> > +# the COPYING file in the top-level directory.\n> > +#\n> > +\n> > +import os\n> > +import sys\n> > +import logging\n> > +import time\n> > +import datetime\n> > +sys.path.append(os.path.join(os.path.dirname(__file__), \"..\", \"..\", \"scripts\"))\n> > +from qemu import QEMUMachine\n> > +import subprocess\n> > +import hashlib\n> > +import optparse\n> > +import atexit\n> > +import tempfile\n> > +import shutil\n> > +import multiprocessing\n> > +import traceback\n> > +\n> > +SSH_KEY = \"\"\"\\\n> > +-----BEGIN RSA PRIVATE KEY-----\n> > +MIIEowIBAAKCAQEAopAuOlmLV6LVHdFBj8/eeOwI9CqguIJPp7eAQSZvOiB4Ag/R\n> > +coEhl/RBbrV5Yc/SmSD4PTpJO/iM10RwliNjDb4a3I8q3sykRJu9c9PI/YsH8WN9\n> > ++NH2NjKPtJIcKTu287IM5JYxyB6nDoOzILbTyJ1TDR/xH6qYEfBAyiblggdjcvhA\n> > +RTf93QIn39F/xLypXvT1K2O9BJEsnJ8lEUvB2UXhKo/JTfSeZF8wPBeowaP9EONk\n> > +7b+nuJOWHGg68Ji6wVi62tjwl2Szch6lxIhZBpnV7QNRKMfYHP6eIyF4pusazzZq\n> > +Telsq6xI2ghecWLzb/MF5A+rklsGx2FNuJSAJwIDAQABAoIBAHHi4o/8VZNivz0x\n> > +cWXn8erzKV6tUoWQvW85Lj/2RiwJvSlsnYZDkx5af1CpEE2HA/pFT8PNRqsd+MWC\n> > +7AEy710cVsM4BYerBFYQaYxwzblaoojo88LSjVPw3h5Z0iLM8+IMVd36nwuc9dpE\n> > +R8TecMZ1+U4Tl6BgqkK+9xToZRdPKdjS8L5MoFhGN+xY0vRbbJbGaV9Q0IHxLBkB\n> > +rEBV7T1mUynneCHRUQlJQEwJmKpT8MH3IjsUXlG5YvnuuvcQJSNTaW2iDLxuOKp8\n> > +cxW8+qL88zpb1D5dppoIu6rlrugN0azSq70ruFJQPc/A8GQrDKoGgRQiagxNY3u+\n> > +vHZzXlECgYEA0dKO3gfkSxsDBb94sQwskMScqLhcKhztEa8kPxTx6Yqh+x8/scx3\n> > +XhJyOt669P8U1v8a/2Al+s81oZzzfQSzO1Q7gEwSrgBcRMSIoRBUw9uYcy02ngb/\n> > +j/ng3DGivfJztjjiSJwb46FHkJ2JR8mF2UisC6UMXk3NgFY/3vWQx78CgYEAxlcG\n> > +T3hfSWSmTgKRczMJuHQOX9ULfTBIqwP5VqkkkiavzigGRirzb5lgnmuTSPTpF0LB\n> > +XVPjR2M4q+7gzP0Dca3pocrvLEoxjwIKnCbYKnyyvnUoE9qHv4Kr+vDbgWpa2LXG\n> > +JbLmE7tgTCIp20jOPPT4xuDvlbzQZBJ5qCQSoZkCgYEAgrotSSihlCnAOFSTXbu4\n> > +CHp3IKe8xIBBNENq0eK61kcJpOxTQvOha3sSsJsU4JAM6+cFaxb8kseHIqonCj1j\n> > +bhOM/uJmwQJ4el/4wGDsbxriYOBKpyq1D38gGhDS1IW6kk3erl6VAb36WJ/OaGum\n> > +eTpN9vNeQWM4Jj2WjdNx4QECgYAwTdd6mU1TmZCrJRL5ZG+0nYc2rbMrnQvFoqUi\n> > +BvWiJovggHzur90zy73tNzPaq9Ls2FQxf5G1vCN8NCRJqEEjeYCR59OSDMu/EXc2\n> > +CnvQ9SevHOdS1oEDEjcCWZCMFzPi3XpRih1gptzQDe31uuiHjf3cqcGPzTlPdfRt\n> > +D8P92QKBgC4UaBvIRwREVJsdZzpIzm224Bpe8LOmA7DeTnjlT0b3lkGiBJ36/Q0p\n> > +VhYh/6cjX4/iuIs7gJbGon7B+YPB8scmOi3fj0+nkJAONue1mMfBNkba6qQTc6Y2\n> > +5mEKw2/O7/JpND7ucU3OK9plcw/qnrWDgHxl0Iz95+OzUIIagxne\n> > +-----END RSA PRIVATE KEY-----\n> > +\"\"\"\n> > +SSH_PUB_KEY = \"\"\"\\\n> > +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCikC46WYtXotUd0UGPz9547Aj0KqC4gk+nt4BBJm86IHgCD9FygSGX9EFutXlhz9KZIPg9Okk7+IzXRHCWI2MNvhrcjyrezKREm71z08j9iwfxY3340fY2Mo+0khwpO7bzsgzkljHIHqcOg7MgttPInVMNH/EfqpgR8EDKJuWCB2Ny+EBFN/3dAiff0X/EvKle9PUrY70EkSycnyURS8HZReEqj8lN9J5kXzA8F6jBo/0Q42Ttv6e4k5YcaDrwmLrBWLra2PCXZLNyHqXEiFkGmdXtA1Eox9gc/p4jIXim6xrPNmpN6WyrrEjaCF5xYvNv8wXkD6uSWwbHYU24lIAn qemu-vm-key\n> > +\"\"\"\n> \n> I'm not sure we should be embedding the keys in the script. I understand\n> we need a common key for downloaded images (although it would be better\n> to post-customise the image after download with the local developer\n> keys). Perhaps ./tests/testing-keys/id_rsa[.pub]?\n\nWe cannot generate keys or start from local keys because it's hard to inject it\ninto the *BSD images without ssh access (chicken-and-egg problem). Adding the\nlocal keys might be a good feature, indeed.\n\n> \n> > +\n> > +class BaseVM(object):\n> > +    GUEST_USER = \"qemu\"\n> > +    GUEST_PASS = \"qemupass\"\n> > +    ROOT_PASS = \"qemupass\"\n> > +\n> > +    # The script to run in the guest that builds QEMU\n> > +    BUILD_SCRIPT = \"\"\n> > +    # The guest name, to be overridden by subclasses\n> > +    name = \"#base\"\n> > +    def __init__(self, debug=False, vcpus=None):\n> > +        self._guest = None\n> > +        self._tmpdir = tempfile.mkdtemp(prefix=\"vm-test-\", suffix=\".tmp\", dir=\".\")\n> > +        atexit.register(shutil.rmtree, self._tmpdir)\n> > +\n> > +        self._ssh_key_file = os.path.join(self._tmpdir, \"id_rsa\")\n> > +        open(self._ssh_key_file, \"w\").write(SSH_KEY)\n> > +        subprocess.check_call([\"chmod\", \"600\", self._ssh_key_file])\n> > +\n> > +        self._ssh_pub_key_file = os.path.join(self._tmpdir, \"id_rsa.pub\")\n> > +        open(self._ssh_pub_key_file, \"w\").write(SSH_PUB_KEY)\n> \n> As above, I think it would be better just to keep copies of the keys in\n> the tests directory rather than in the python source.\n> \n> > +\n> > +        self.debug = debug\n> > +        self._stderr = sys.stderr\n> > +        self._devnull = open(\"/dev/null\", \"w\")\n> \n> You can use os.devnull as a portable reference.\n\nOK.\n\n> \n> > +        if self.debug:\n> > +            self._stdout = sys.stdout\n> > +        else:\n> > +            self._stdout = self._devnull\n> > +        self._args = [ \\\n> > +            \"-nodefaults\", \"-m\", \"2G\",\n> > +            \"-cpu\", \"host\",\n> > +            \"-netdev\", \"user,id=vnet,hostfwd=:0.0.0.0:0-:22\",\n> \n> It doesn't help that howstfwd is poorly documented. Are we trying to map\n> an ephemeral port to the guests 22?\n\nYes, it is a new feature of usernet, you're right the documentation is missing.\n\n> \n> > +            \"-device\", \"virtio-net-pci,netdev=vnet\",\n> > +            \"-vnc\", \":0,to=20\",\n> \n> Do we need a GUI?\n\nI'd like to keep it, it helps when you need to diagnose.\n\n> \n> > +            \"-serial\", \"file:%s\" % os.path.join(self._tmpdir,\n> > \"serial.out\")]\n> > +        if vcpus:\n> > +            self._args += [\"-smp\", str(vcpus)]\n> > +        if os.access(\"/dev/kvm\", os.R_OK | os.W_OK):\n> > +            self._args += [\"-enable-kvm\"]\n> > +        else:\n> > +            logging.info(\"KVM not available, not using -enable-kvm\")\n> > +        self._data_args = []\n> > +\n> > +    def _download_with_cache(self, url, sha256sum=None):\n> > +        def check_sha256sum(fname):\n> > +            if not sha256sum:\n> > +                return True\n> > +            checksum = subprocess.check_output([\"sha256sum\", fname]).split()[0]\n> > +            return sha256sum == checksum\n> > +\n> > +        cache_dir = os.path.expanduser(\"~/.cache/qemu-vm/download\")\n> > +        if not os.path.exists(cache_dir):\n> > +            os.makedirs(cache_dir)\n> > +        fname = os.path.join(cache_dir, hashlib.sha1(url).hexdigest())\n> > +        if os.path.exists(fname) and check_sha256sum(fname):\n> > +            return fname\n> > +        logging.debug(\"Downloading %s to %s...\", url, fname)\n> > +        subprocess.check_call([\"wget\", \"-c\", url, \"-O\", fname + \".download\"],\n> > +                              stdout=self._stdout,\n> > stderr=self._stderr)\n> \n> Using wget rather than doing it internally adds a utility requirement.\n> Is doing a pure python urllib2 fetch too slow for this?\n\nI think \"-c\" is a good feature for downloading big files.\n\n> \n> > +        os.rename(fname + \".download\", fname)\n> > +        return fname\n> > +\n> > +    def _ssh_do(self, user, cmd, check, interactive=False):\n> > +        ssh_cmd = [\"ssh\", \"-q\",\n> > +                   \"-o\", \"StrictHostKeyChecking=no\",\n> > +                   \"-o\", \"UserKnownHostsFile=/dev/null\",\n> > +                   \"-o\", \"ConnectTimeout=1\",\n> > +                   \"-p\", self.ssh_port, \"-i\", self._ssh_key_file]\n> > +        if interactive:\n> > +            ssh_cmd += ['-t']\n> > +        assert not isinstance(cmd, str)\n> > +        ssh_cmd += [\"%s@127.0.0.1\" % user] + list(cmd)\n> > +        logging.debug(\"ssh_cmd: %s\", \" \".join(ssh_cmd))\n> > +        r = subprocess.call(ssh_cmd,\n> > +                            stdin=sys.stdin if interactive else self._devnull,\n> > +                            stdout=sys.stdout if interactive else self._stdout,\n> > +                            stderr=sys.stderr if interactive else self._stderr)\n> > +        if check and r != 0:\n> > +            raise Exception(\"SSH command failed: %s\" % cmd)\n> > +        return r\n> > +\n> > +    def ssh(self, *cmd):\n> > +        return self._ssh_do(self.GUEST_USER, cmd, False)\n> > +\n> > +    def ssh_interactive(self, *cmd):\n> > +        return self._ssh_do(self.GUEST_USER, cmd, False, True)\n> > +\n> > +    def ssh_root(self, *cmd):\n> > +        return self._ssh_do(\"root\", cmd, False)\n> > +\n> > +    def ssh_check(self, *cmd):\n> > +        self._ssh_do(self.GUEST_USER, cmd, True)\n> > +\n> > +    def ssh_root_check(self, *cmd):\n> > +        self._ssh_do(\"root\", cmd, True)\n> > +\n> > +    def build_image(self, img):\n> > +        raise NotImplementedError\n> > +\n> > +    def add_source_dir(self, src_dir):\n> > +        name = \"data-\" + hashlib.sha1(src_dir).hexdigest()[:5]\n> > +        tarfile = os.path.join(self._tmpdir, name + \".tar\")\n> > +        logging.debug(\"Creating archive %s for src_dir dir: %s\", tarfile, src_dir)\n> > +        subprocess.check_call([\"./scripts/archive-source.sh\", tarfile],\n> > +                              cwd=src_dir, stdin=self._devnull,\n> > +                              stdout=self._stdout, stderr=self._stderr)\n> > +        self._data_args += [\"-drive\",\n> > +                            \"file=%s,if=none,id=%s,cache=writeback,format=raw\" % \\\n> > +                                    (tarfile, name),\n> > +                            \"-device\",\n> > +                            \"virtio-blk,drive=%s,serial=%s,bootindex=1\" % (name, name)]\n> > +\n> > +    def boot(self, img, extra_args=[]):\n> > +        args = self._args + [\n> > +            \"-device\", \"VGA\",\n> \n> Is specifying a display device at boot time really needed (say rather\n> than further up with the rest of the machine description). Do we even\n> want a display given use ssh/serial for everything?\n\nIt makes debug easier, and also I find cloud-init or something in ubuntu\nrequires a virtual console on the display to make progress.\n\n> \n> > +            \"-drive\", \"file=%s,if=none,id=drive0,cache=writeback\" % img,\n> > +            \"-device\", \"virtio-blk,drive=drive0,bootindex=0\"]\n> > +        args += self._data_args + extra_args\n> > +        logging.debug(\"QEMU args: %s\", \" \".join(args))\n> > +        guest = QEMUMachine(binary=os.environ.get(\"QEMU\", \"qemu-system-x86_64\"),\n> > +                            args=args)\n> > +        guest.launch()\n> > +        atexit.register(self.shutdown)\n> > +        self._guest = guest\n> > +        usernet_info = guest.qmp(\"human-monitor-command\",\n> > +                                 command_line=\"info usernet\")\n> > +        self.ssh_port = None\n> > +        for l in usernet_info[\"return\"].splitlines():\n> > +            fields = l.split()\n> > +            if \"TCP[HOST_FORWARD]\" in fields and \"22\" in fields:\n> > +                self.ssh_port = l.split()[3]\n> > +        if not self.ssh_port:\n> > +            raise Exception(\"Cannot find ssh port from 'info usernet':\\n%s\" % \\\n> > +                            usernet_info)\n> > +\n> > +    def wait_ssh(self, seconds=120):\n> > +        starttime = datetime.datetime.now()\n> > +        guest_up = False\n> > +        while (datetime.datetime.now() - starttime).total_seconds() < seconds:\n> > +            if self.ssh(\"exit 0\") == 0:\n> > +                guest_up = True\n> > +                break\n> > +            time.sleep(1)\n> > +        if not guest_up:\n> > +            raise Exception(\"Timeout while waiting for guest ssh\")\n> > +\n> > +    def shutdown(self):\n> > +        self._guest.shutdown()\n> > +\n> > +    def wait(self):\n> > +        self._guest.wait()\n> > +\n> > +    def qmp(self, *args, **kwargs):\n> > +        return self._guest.qmp(*args, **kwargs)\n> > +\n> > +def parse_args(vm_name):\n> > +    parser = optparse.OptionParser(description=\"\"\"\n> > +    VM test utility.  Exit codes: 0 = success, 1 = command line error, 2 = environment initialization failed, 3 = test command failed\"\"\")\n> > +    parser.add_option(\"--debug\", \"-D\", action=\"store_true\",\n> > +                      help=\"enable debug output\")\n> > +    parser.add_option(\"--image\", \"-i\", default=\"%s.img\" % vm_name,\n> > +                      help=\"image file name\")\n> > +    parser.add_option(\"--force\", \"-f\", action=\"store_true\",\n> > +                      help=\"force build image even if image exists\")\n> > +    parser.add_option(\"--jobs\", type=int, default=multiprocessing.cpu_count() / 2,\n> > +                      help=\"number of virtual CPUs\")\n> > +    parser.add_option(\"--build-image\", \"-b\", action=\"store_true\",\n> > +                      help=\"build image\")\n> > +    parser.add_option(\"--build-qemu\",\n> > +                      help=\"build QEMU from source in guest\")\n> > +    parser.add_option(\"--interactive\", \"-I\", action=\"store_true\",\n> > +                      help=\"Interactively run command\")\n> > +    parser.disable_interspersed_args()\n> > +    return parser.parse_args()\n> > +\n> > +def main(vmcls):\n> > +    try:\n> > +        args, argv = parse_args(vmcls.name)\n> > +        if not argv and not args.build_qemu and not args.build_image:\n> > +            print \"Nothing to do?\"\n> > +            return 1\n> > +        if args.debug:\n> > +            logging.getLogger().setLevel(logging.DEBUG)\n> > +        vm = vmcls(debug=args.debug, vcpus=args.jobs)\n> > +        if args.build_image:\n> > +            if os.path.exists(args.image) and not args.force:\n> > +                sys.stderr.writelines([\"Image file exists: %s\\n\" % args.image,\n> > +                                      \"Use --force option to overwrite\\n\"])\n> > +                return 1\n> > +            return vm.build_image(args.image)\n> > +        if args.build_qemu:\n> > +            vm.add_source_dir(args.build_qemu)\n> > +            cmd = [vm.BUILD_SCRIPT.format(\n> > +                   configure_opts = \" \".join(argv),\n> > +                   jobs=args.jobs)]\n> > +        else:\n> > +            cmd = argv\n> > +        vm.boot(args.image + \",snapshot=on\")\n> \n> If this fails it's fairly cryptic:\n> \n> /home/alex/lsrc/qemu/qemu.git/tests/vm/openbsd  --debug   --image \"tests/vm/openbsd.img\" --build-qemu /home/alex/lsrc/qemu/qemu.git\n> DEBUG:root:Creating archive ./vm-test-fxejnB.tmp/data-2de24.tar for src_dir dir: /home/alex/lsrc/qemu/qemu.git\n> DEBUG:root:QEMU args: -nodefaults -m 2G -cpu host -netdev user,id=vnet,hostfwd=:0.0.0.0:0-:22 -device virtio-net-pci,netdev=vnet -vnc :0,to=20 -serial file:./vm-test-fxejnB.tmp/serial.out -smp 4 -enable-kvm -device VGA -drive file=tests/vm/openbsd.img,snapshot=on,if=none,id=drive0,cache=writeback -device virtio-blk,drive=drive0,bootindex=0 -drive file=./vm-test-fxejnB.tmp/data-2de24.tar,if=none,id=data-2de24,cache=writeback,format=raw -device virtio-blk,drive=data-2de24,serial=data-2de24,bootindex=1\n> Failed to prepare guest environment\n> Traceback (most recent call last):\n>   File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/basevm.py\", line 260, in main\n>     vm.boot(args.image + \",snapshot=on\")\n>   File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/basevm.py\", line 184, in boot\n>     guest.launch()\n>   File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/../../scripts/qemu.py\", line 151, in launch\n>     self._post_launch()\n>   File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/../../scripts/qemu.py\", line 135, in _post_launch\n>     self._qmp.accept()\n>   File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/../../scripts/qmp/qmp.py\", line 147, in accept\n>     return self.__negotiate_capabilities()\n>   File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/../../scripts/qmp/qmp.py\", line 60, in __negotiate_capabilities\n>     raise QMPConnectError\n> QMPConnectError\n> \n> I assume QEMU failed to boot and might have given us a message that\n> would be useful.\n\nIt's a separate issue of qemu.py, I didn't try to fix it here because currently\nthere are many patches touching that file on the list, there is a high chance of\nconflict.\n\nIn your case which qemu version are you using? If not master it probably is\nfailing because of the hostfwd syntax.\n\n> \n> \n> > +        vm.wait_ssh()\n> > +    except Exception as e:\n> > +        if isinstance(e, SystemExit) and e.code == 0:\n> > +            return 0\n> > +        sys.stderr.write(\"Failed to prepare guest environment\\n\")\n> > +        traceback.print_exc()\n> > +        return 2\n> > +\n> > +    if args.interactive:\n> > +        if vm.ssh_interactive(*cmd) == 0:\n> > +            return 0\n> > +        vm.ssh_interactive()\n> > +        return 3\n> > +    else:\n> > +        if vm.ssh(*cmd) != 0:\n> > +            return 3\n> \n> \n> --\n> Alex Bennée\n> \n\nThanks for the review!\n\nFam","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx07.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx07.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=famz@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xptq06Gd3z9t16\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSat,  9 Sep 2017 09:30:33 +1000 (AEST)","from localhost ([::1]:47631 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dqSjG-000554-Dc\n\tfor incoming@patchwork.ozlabs.org; Fri, 08 Sep 2017 19:30:30 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:36917)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <famz@redhat.com>) id 1dqSis-000535-DO\n\tfor qemu-devel@nongnu.org; Fri, 08 Sep 2017 19:30:08 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <famz@redhat.com>) id 1dqSio-0001Lt-86\n\tfor qemu-devel@nongnu.org; Fri, 08 Sep 2017 19:30:06 -0400","from mx1.redhat.com ([209.132.183.28]:48774)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <famz@redhat.com>) id 1dqSin-0001Kx-Ve\n\tfor qemu-devel@nongnu.org; Fri, 08 Sep 2017 19:30:02 -0400","from smtp.corp.redhat.com\n\t(int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id EC995C047B61;\n\tFri,  8 Sep 2017 23:30:00 +0000 (UTC)","from localhost (ovpn-12-27.pek2.redhat.com [10.72.12.27])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 213375D6A3;\n\tFri,  8 Sep 2017 23:29:57 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com EC995C047B61","Date":"Sat, 9 Sep 2017 07:29:56 +0800","From":"Fam Zheng <famz@redhat.com>","To":"Alex =?iso-8859-1?q?Benn=E9e?= <alex.bennee@linaro.org>","Message-ID":"<20170908232950.GD18677@lemon.lan>","References":"<20170905021201.25684-1-famz@redhat.com>\n\t<20170905021201.25684-5-famz@redhat.com>\n\t<87tw0dgqpv.fsf@linaro.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","In-Reply-To":"<87tw0dgqpv.fsf@linaro.org>","User-Agent":"Mutt/1.8.3 (2017-05-23)","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.15","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.31]);\n\tFri, 08 Sep 2017 23:30:01 +0000 (UTC)","Content-Transfer-Encoding":"quoted-printable","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"Re: [Qemu-devel] [PATCH v6 04/12] tests: Add vm test lib","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org, Philippe\n\t=?iso-8859-1?q?Mathieu-Daud=E9?= <f4bug@amsat.org>,\n\tKamil Rytarowski <kamil@netbsd.org>, stefanha@redhat.com, \n\tCleber Rosa <crosa@redhat.com>, pbonzini@redhat.com","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1765677,"web_url":"http://patchwork.ozlabs.org/comment/1765677/","msgid":"<6e624d60-c8ed-54f5-a2ca-9caf9d9c489f@amsat.org>","list_archive_url":null,"date":"2017-09-09T01:25:34","subject":"Re: [Qemu-devel] [PATCH v6 04/12] tests: Add vm test lib","submitter":{"id":70924,"url":"http://patchwork.ozlabs.org/api/people/70924/","name":"Philippe Mathieu-Daudé","email":"f4bug@amsat.org"},"content":"Hi Fam, Alex,\n\n>>\n>> If this fails it's fairly cryptic:\n>>\n>> /home/alex/lsrc/qemu/qemu.git/tests/vm/openbsd  --debug   --image \"tests/vm/openbsd.img\" --build-qemu /home/alex/lsrc/qemu/qemu.git\n>> DEBUG:root:Creating archive ./vm-test-fxejnB.tmp/data-2de24.tar for src_dir dir: /home/alex/lsrc/qemu/qemu.git\n>> DEBUG:root:QEMU args: -nodefaults -m 2G -cpu host -netdev user,id=vnet,hostfwd=:0.0.0.0:0-:22 -device virtio-net-pci,netdev=vnet -vnc :0,to=20 -serial file:./vm-test-fxejnB.tmp/serial.out -smp 4 -enable-kvm -device VGA -drive file=tests/vm/openbsd.img,snapshot=on,if=none,id=drive0,cache=writeback -device virtio-blk,drive=drive0,bootindex=0 -drive file=./vm-test-fxejnB.tmp/data-2de24.tar,if=none,id=data-2de24,cache=writeback,format=raw -device virtio-blk,drive=data-2de24,serial=data-2de24,bootindex=1\n>> Failed to prepare guest environment\n>> Traceback (most recent call last):\n>>    File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/basevm.py\", line 260, in main\n>>      vm.boot(args.image + \",snapshot=on\")\n>>    File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/basevm.py\", line 184, in boot\n>>      guest.launch()\n>>    File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/../../scripts/qemu.py\", line 151, in launch\n>>      self._post_launch()\n>>    File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/../../scripts/qemu.py\", line 135, in _post_launch\n>>      self._qmp.accept()\n>>    File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/../../scripts/qmp/qmp.py\", line 147, in accept\n>>      return self.__negotiate_capabilities()\n>>    File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/../../scripts/qmp/qmp.py\", line 60, in __negotiate_capabilities\n>>      raise QMPConnectError\n>> QMPConnectError\n>>\n>> I assume QEMU failed to boot and might have given us a message that\n>> would be useful.\n> \n> It's a separate issue of qemu.py, I didn't try to fix it here because currently\n> there are many patches touching that file on the list, there is a high chance of\n> conflict.\n> \n> In your case which qemu version are you using? If not master it probably is\n> failing because of the hostfwd syntax.\n\nvery likely.\n\none simple way to handle this could be having this script catching \nQMPConnectError and restart with older command line format,\n\nbut I prefer starting QEMU binding a QMP socket, then initialize the \noptions via QMP packets, this should be more portable, this is cleaner.\n\nalso I think we don't want to run those images with bleeding edge \nqemu-system, we want a stable QEMU to be able to compile the bleeding \nedge codebase inside a working VM.\n\nanother note: currently when a VM fails, it closes and what I've left is \nonly the last stderr.\nI'd rather see 2 modes:\n- run from some CI when only the final return value is useful, the \nstderr being extra value.\n- in user-dev mode if the build fails I'd like to have access to the \nterminal, eventually some msg like \"this build failed, you can connect \nto this VM copy/pasting the following ssh command: ... or hit ^C to \ngracefully shutdown the VM\"\nBut in this mode I'd rather mount my current workdir via a read-writable \nnetshare rather than a one-time temporary read-only tarball, so I could \nmodify my repo and just run 'make' inside the VM.\n\nRegards,\n\nPhil.","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"eVfWsjw8\"; dkim-atps=neutral"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xpxP74pVwz9sBZ\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSat,  9 Sep 2017 11:26:51 +1000 (AEST)","from localhost ([::1]:47845 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dqUXp-0003H7-Oe\n\tfor incoming@patchwork.ozlabs.org; Fri, 08 Sep 2017 21:26:49 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:55171)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <philippe.mathieu.daude@gmail.com>)\n\tid 1dqUWk-0002sp-N9\n\tfor qemu-devel@nongnu.org; Fri, 08 Sep 2017 21:25:44 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <philippe.mathieu.daude@gmail.com>)\n\tid 1dqUWh-0006e8-QR\n\tfor qemu-devel@nongnu.org; Fri, 08 Sep 2017 21:25:42 -0400","from mail-qt0-x234.google.com ([2607:f8b0:400d:c0d::234]:38877)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <philippe.mathieu.daude@gmail.com>)\n\tid 1dqUWh-0006dp-L5\n\tfor qemu-devel@nongnu.org; Fri, 08 Sep 2017 21:25:39 -0400","by mail-qt0-x234.google.com with SMTP id q8so10157241qtb.5\n\tfor <qemu-devel@nongnu.org>; Fri, 08 Sep 2017 18:25:39 -0700 (PDT)","from [192.168.1.10] ([181.93.89.178])\n\tby smtp.gmail.com with ESMTPSA id\n\tr18sm2079226qtr.91.2017.09.08.18.25.36\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tFri, 08 Sep 2017 18:25:38 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=sender:subject:to:cc:references:from:message-id:date:user-agent\n\t:mime-version:in-reply-to:content-language:content-transfer-encoding; \n\tbh=yln8ZT+lROsLymEBo8mF0wUdwCuYpSA6tWbzDbadpPM=;\n\tb=eVfWsjw87rR4gbMYlcVDgPrQrSw/GCVmMkhRbsYFI5JTuz9Vgr4VD1y+VvP6wK7/fX\n\twPPpKXkSz1UoOGrQMtNqckanM2NdpIQniA3FVovFJegKCFALLsBUoKigz/Eifb9NLCRV\n\tkFjKrNyOKAy0amrl5sxi7X3QlI0v+1vF1KLswhRn6KpYER86vJmzdys1py+FRoz9//wW\n\tJZrCO2ZWXwB86q2tkkUvF4kziPh0t40RTK9mlfdvkuICNDL7p8/gX2Y5SHBKSkd7Fuqb\n\tJkIS0eT5n40yXcoOQalL59sBLm0rDmvCl/BSFnSlYEfknLZ9P9yAXVPCHAZIQuuY+9Mt\n\tZkDQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:sender:subject:to:cc:references:from:message-id\n\t:date:user-agent:mime-version:in-reply-to:content-language\n\t:content-transfer-encoding;\n\tbh=yln8ZT+lROsLymEBo8mF0wUdwCuYpSA6tWbzDbadpPM=;\n\tb=ezodX2cAy/uKD2lKz0JVUR4e0sRDvJyQxiWlGk9H9xkd/ihZ6Q7B1BPfe7Q2HsYSIF\n\tOjOwZvu0a8gli3yMfCjdWp9cZXvy7QTSGIev20akNPKRHTVz9XOQ3kEdIViuvZ7JYtSD\n\tXk45g9IxgIlzwxb/5VS4Of47tQsWy+V3BAaZYH/TOU57LU16rSKWnHYYfxTg6TsGhnie\n\tH37R7b65udbckk13Ww9pHrg5+aEiMcjL7vqBkYKm3UnKhmMlqZTtExwOwJhtMF6Hht9t\n\tI7hrGXenf9R1gKMN50usP6Phnxzsh7xrtL2VmumPsAnVf0ti4boJdHHl5ZqI83d6qEuj\n\tFx7A==","X-Gm-Message-State":"AHPjjUiTIytZX/OfxZE23PoCSrX/2wnygiZHxkOi71ay4X1x2vefrdpD\n\tcpXr4WIoU3dvrA==","X-Google-Smtp-Source":"AOwi7QDCObv4SNHXUYKa/HQSkufHQguOviLfysHCBSrEo5LAtR0s3JTSP1pNyKbzxqqCv0IF6Mg/pQ==","X-Received":"by 10.237.62.200 with SMTP id o8mr6855696qtf.294.1504920338833; \n\tFri, 08 Sep 2017 18:25:38 -0700 (PDT)","To":"Fam Zheng <famz@redhat.com>, =?utf-8?q?Alex_Benn=C3=A9e?=\n\t<alex.bennee@linaro.org>","References":"<20170905021201.25684-1-famz@redhat.com>\n\t<20170905021201.25684-5-famz@redhat.com> <87tw0dgqpv.fsf@linaro.org>\n\t<20170908232950.GD18677@lemon.lan>","From":"=?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= <f4bug@amsat.org>","Message-ID":"<6e624d60-c8ed-54f5-a2ca-9caf9d9c489f@amsat.org>","Date":"Fri, 8 Sep 2017 22:25:34 -0300","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<20170908232950.GD18677@lemon.lan>","Content-Type":"text/plain; charset=utf-8; format=flowed","Content-Language":"en-US","Content-Transfer-Encoding":"7bit","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"2607:f8b0:400d:c0d::234","Subject":"Re: [Qemu-devel] [PATCH v6 04/12] tests: Add vm test lib","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org,\n\tKamil Rytarowski <kamil@netbsd.org>, stefanha@redhat.com,\n\tCleber Rosa <crosa@redhat.com>, pbonzini@redhat.com","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1765702,"web_url":"http://patchwork.ozlabs.org/comment/1765702/","msgid":"<20170909041036.GF18677@lemon.lan>","list_archive_url":null,"date":"2017-09-09T04:10:36","subject":"Re: [Qemu-devel] [PATCH v6 04/12] tests: Add vm test lib","submitter":{"id":24872,"url":"http://patchwork.ozlabs.org/api/people/24872/","name":"Fam Zheng","email":"famz@redhat.com"},"content":"On Fri, 09/08 22:25, Philippe Mathieu-Daudé wrote:\n> Hi Fam, Alex,\n> \n> > > \n> > > If this fails it's fairly cryptic:\n> > > \n> > > /home/alex/lsrc/qemu/qemu.git/tests/vm/openbsd  --debug   --image \"tests/vm/openbsd.img\" --build-qemu /home/alex/lsrc/qemu/qemu.git\n> > > DEBUG:root:Creating archive ./vm-test-fxejnB.tmp/data-2de24.tar for src_dir dir: /home/alex/lsrc/qemu/qemu.git\n> > > DEBUG:root:QEMU args: -nodefaults -m 2G -cpu host -netdev user,id=vnet,hostfwd=:0.0.0.0:0-:22 -device virtio-net-pci,netdev=vnet -vnc :0,to=20 -serial file:./vm-test-fxejnB.tmp/serial.out -smp 4 -enable-kvm -device VGA -drive file=tests/vm/openbsd.img,snapshot=on,if=none,id=drive0,cache=writeback -device virtio-blk,drive=drive0,bootindex=0 -drive file=./vm-test-fxejnB.tmp/data-2de24.tar,if=none,id=data-2de24,cache=writeback,format=raw -device virtio-blk,drive=data-2de24,serial=data-2de24,bootindex=1\n> > > Failed to prepare guest environment\n> > > Traceback (most recent call last):\n> > >    File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/basevm.py\", line 260, in main\n> > >      vm.boot(args.image + \",snapshot=on\")\n> > >    File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/basevm.py\", line 184, in boot\n> > >      guest.launch()\n> > >    File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/../../scripts/qemu.py\", line 151, in launch\n> > >      self._post_launch()\n> > >    File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/../../scripts/qemu.py\", line 135, in _post_launch\n> > >      self._qmp.accept()\n> > >    File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/../../scripts/qmp/qmp.py\", line 147, in accept\n> > >      return self.__negotiate_capabilities()\n> > >    File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/../../scripts/qmp/qmp.py\", line 60, in __negotiate_capabilities\n> > >      raise QMPConnectError\n> > > QMPConnectError\n> > > \n> > > I assume QEMU failed to boot and might have given us a message that\n> > > would be useful.\n> > \n> > It's a separate issue of qemu.py, I didn't try to fix it here because currently\n> > there are many patches touching that file on the list, there is a high chance of\n> > conflict.\n> > \n> > In your case which qemu version are you using? If not master it probably is\n> > failing because of the hostfwd syntax.\n> \n> very likely.\n> \n> one simple way to handle this could be having this script catching\n> QMPConnectError and restart with older command line format,\n\nThe error reporting definitely needs improving (like saying which version of\nQEMU is needed), but I'm not sure about adding fallbacks here and there are\nworth the effort, see below.\n\n> \n> but I prefer starting QEMU binding a QMP socket, then initialize the options\n> via QMP packets, this should be more portable, this is cleaner.\n\nThis is just different, but not necessarily cleaner. When you want to manually\nstart such a VM, it will be very painful. Nor does \"ps | grep | less\" etc works.\nCommand line is simpler and more user friendly in this respect.\n\n> \n> also I think we don't want to run those images with bleeding edge\n> qemu-system, we want a stable QEMU to be able to compile the bleeding edge\n> codebase inside a working VM.\n\nYou are right we are not testing that bleeding edge qemus can run the VM, but we\nneed the features of the bleeding edge qemu to write simpler test code. I think\nthis is reasonable for both CI and developers.  So unless there is an\nalternative way to do the hostfwd port allocation, I think we can live with this\nrequirement.\n\n> \n> another note: currently when a VM fails, it closes and what I've left is\n> only the last stderr.\n> I'd rather see 2 modes:\n> - run from some CI when only the final return value is useful, the stderr\n> being extra value.\n> - in user-dev mode if the build fails I'd like to have access to the\n> terminal, eventually some msg like \"this build failed, you can connect to\n> this VM copy/pasting the following ssh command: ... or hit ^C to gracefully\n> shutdown the VM\"\n> But in this mode I'd rather mount my current workdir via a read-writable\n> netshare rather than a one-time temporary read-only tarball, so I could\n> modify my repo and just run 'make' inside the VM.\n\nLike the docker tests, this is what DEBUG=1 is for.\n\nFam","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx05.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx05.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=famz@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xq12w4ntjz9s0g\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSat,  9 Sep 2017 14:11:18 +1000 (AEST)","from localhost ([::1]:48101 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dqX6w-0006xM-Qp\n\tfor incoming@patchwork.ozlabs.org; Sat, 09 Sep 2017 00:11:14 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:59763)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <famz@redhat.com>) id 1dqX6W-0006x5-AW\n\tfor qemu-devel@nongnu.org; Sat, 09 Sep 2017 00:10:49 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <famz@redhat.com>) id 1dqX6R-0005fv-Cr\n\tfor qemu-devel@nongnu.org; Sat, 09 Sep 2017 00:10:48 -0400","from mx1.redhat.com ([209.132.183.28]:47006)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <famz@redhat.com>) id 1dqX6Q-0005fK-QN\n\tfor qemu-devel@nongnu.org; Sat, 09 Sep 2017 00:10:43 -0400","from smtp.corp.redhat.com\n\t(int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id 7E00913AB2;\n\tSat,  9 Sep 2017 04:10:41 +0000 (UTC)","from localhost (ovpn-12-40.pek2.redhat.com [10.72.12.40])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id A3904614C8;\n\tSat,  9 Sep 2017 04:10:38 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 7E00913AB2","Date":"Sat, 9 Sep 2017 12:10:36 +0800","From":"Fam Zheng <famz@redhat.com>","To":"Philippe =?iso-8859-1?q?Mathieu-Daud=E9?= <f4bug@amsat.org>","Message-ID":"<20170909041036.GF18677@lemon.lan>","References":"<20170905021201.25684-1-famz@redhat.com>\n\t<20170905021201.25684-5-famz@redhat.com>\n\t<87tw0dgqpv.fsf@linaro.org> <20170908232950.GD18677@lemon.lan>\n\t<6e624d60-c8ed-54f5-a2ca-9caf9d9c489f@amsat.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","In-Reply-To":"<6e624d60-c8ed-54f5-a2ca-9caf9d9c489f@amsat.org>","User-Agent":"Mutt/1.8.3 (2017-05-23)","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.13","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.29]);\n\tSat, 09 Sep 2017 04:10:41 +0000 (UTC)","Content-Transfer-Encoding":"quoted-printable","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"Re: [Qemu-devel] [PATCH v6 04/12] tests: Add vm test lib","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org, Kamil\n\tRytarowski <kamil@netbsd.org>, stefanha@redhat.com, Cleber Rosa\n\t<crosa@redhat.com>, pbonzini@redhat.com, Alex =?iso-8859-1?q?Benn=E9e?=\n\t<alex.bennee@linaro.org>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1766213,"web_url":"http://patchwork.ozlabs.org/comment/1766213/","msgid":"<874ls9bjlm.fsf@linaro.org>","list_archive_url":null,"date":"2017-09-11T10:44:21","subject":"Re: [Qemu-devel] [PATCH v6 04/12] tests: Add vm test lib","submitter":{"id":39532,"url":"http://patchwork.ozlabs.org/api/people/39532/","name":"Alex Bennée","email":"alex.bennee@linaro.org"},"content":"Fam Zheng <famz@redhat.com> writes:\n\n> On Fri, 09/08 16:22, Alex Bennée wrote:\n>>\n>> Fam Zheng <famz@redhat.com> writes:\n>>\n>> > This is the common code to implement a \"VM test\" to\n>> >\n>> >   1) Download and initialize a pre-defined VM that has necessary\n>> >   dependencies to build QEMU and SSH access.\n>> >\n>> >   2) Archive $SRC_PATH to a .tar file.\n>> >\n>> >   3) Boot the VM, and pass the source tar file to the guest.\n>> >\n>> >   4) SSH into the VM, untar the source tarball, build from the source.\n>> >\n>> > Signed-off-by: Fam Zheng <famz@redhat.com>\n>> > ---\n>> >  tests/vm/basevm.py | 276 +++++++++++++++++++++++++++++++++++++++++++++++++++++\n>> >  1 file changed, 276 insertions(+)\n>> >  create mode 100755 tests/vm/basevm.py\n>> >\n>> > diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py\n>> > new file mode 100755\n>> > index 0000000000..9db91d61fa\n>> > --- /dev/null\n>> > +++ b/tests/vm/basevm.py\n>> > @@ -0,0 +1,276 @@\n>> > +#!/usr/bin/env python\n>> > +#\n>> > +# VM testing base class\n>> > +#\n>> > +# Copyright (C) 2017 Red Hat Inc.\n>> > +#\n>> > +# Authors:\n>> > +#  Fam Zheng <famz@redhat.com>\n>> > +#\n>> > +# This work is licensed under the terms of the GNU GPL, version 2.  See\n>> > +# the COPYING file in the top-level directory.\n>> > +#\n>> > +\n>> > +import os\n>> > +import sys\n>> > +import logging\n>> > +import time\n>> > +import datetime\n>> > +sys.path.append(os.path.join(os.path.dirname(__file__), \"..\", \"..\", \"scripts\"))\n>> > +from qemu import QEMUMachine\n>> > +import subprocess\n>> > +import hashlib\n>> > +import optparse\n>> > +import atexit\n>> > +import tempfile\n>> > +import shutil\n>> > +import multiprocessing\n>> > +import traceback\n>> > +\n>> > +SSH_KEY = \"\"\"\\\n>> > +-----BEGIN RSA PRIVATE KEY-----\n>> > +MIIEowIBAAKCAQEAopAuOlmLV6LVHdFBj8/eeOwI9CqguIJPp7eAQSZvOiB4Ag/R\n>> > +coEhl/RBbrV5Yc/SmSD4PTpJO/iM10RwliNjDb4a3I8q3sykRJu9c9PI/YsH8WN9\n>> > ++NH2NjKPtJIcKTu287IM5JYxyB6nDoOzILbTyJ1TDR/xH6qYEfBAyiblggdjcvhA\n>> > +RTf93QIn39F/xLypXvT1K2O9BJEsnJ8lEUvB2UXhKo/JTfSeZF8wPBeowaP9EONk\n>> > +7b+nuJOWHGg68Ji6wVi62tjwl2Szch6lxIhZBpnV7QNRKMfYHP6eIyF4pusazzZq\n>> > +Telsq6xI2ghecWLzb/MF5A+rklsGx2FNuJSAJwIDAQABAoIBAHHi4o/8VZNivz0x\n>> > +cWXn8erzKV6tUoWQvW85Lj/2RiwJvSlsnYZDkx5af1CpEE2HA/pFT8PNRqsd+MWC\n>> > +7AEy710cVsM4BYerBFYQaYxwzblaoojo88LSjVPw3h5Z0iLM8+IMVd36nwuc9dpE\n>> > +R8TecMZ1+U4Tl6BgqkK+9xToZRdPKdjS8L5MoFhGN+xY0vRbbJbGaV9Q0IHxLBkB\n>> > +rEBV7T1mUynneCHRUQlJQEwJmKpT8MH3IjsUXlG5YvnuuvcQJSNTaW2iDLxuOKp8\n>> > +cxW8+qL88zpb1D5dppoIu6rlrugN0azSq70ruFJQPc/A8GQrDKoGgRQiagxNY3u+\n>> > +vHZzXlECgYEA0dKO3gfkSxsDBb94sQwskMScqLhcKhztEa8kPxTx6Yqh+x8/scx3\n>> > +XhJyOt669P8U1v8a/2Al+s81oZzzfQSzO1Q7gEwSrgBcRMSIoRBUw9uYcy02ngb/\n>> > +j/ng3DGivfJztjjiSJwb46FHkJ2JR8mF2UisC6UMXk3NgFY/3vWQx78CgYEAxlcG\n>> > +T3hfSWSmTgKRczMJuHQOX9ULfTBIqwP5VqkkkiavzigGRirzb5lgnmuTSPTpF0LB\n>> > +XVPjR2M4q+7gzP0Dca3pocrvLEoxjwIKnCbYKnyyvnUoE9qHv4Kr+vDbgWpa2LXG\n>> > +JbLmE7tgTCIp20jOPPT4xuDvlbzQZBJ5qCQSoZkCgYEAgrotSSihlCnAOFSTXbu4\n>> > +CHp3IKe8xIBBNENq0eK61kcJpOxTQvOha3sSsJsU4JAM6+cFaxb8kseHIqonCj1j\n>> > +bhOM/uJmwQJ4el/4wGDsbxriYOBKpyq1D38gGhDS1IW6kk3erl6VAb36WJ/OaGum\n>> > +eTpN9vNeQWM4Jj2WjdNx4QECgYAwTdd6mU1TmZCrJRL5ZG+0nYc2rbMrnQvFoqUi\n>> > +BvWiJovggHzur90zy73tNzPaq9Ls2FQxf5G1vCN8NCRJqEEjeYCR59OSDMu/EXc2\n>> > +CnvQ9SevHOdS1oEDEjcCWZCMFzPi3XpRih1gptzQDe31uuiHjf3cqcGPzTlPdfRt\n>> > +D8P92QKBgC4UaBvIRwREVJsdZzpIzm224Bpe8LOmA7DeTnjlT0b3lkGiBJ36/Q0p\n>> > +VhYh/6cjX4/iuIs7gJbGon7B+YPB8scmOi3fj0+nkJAONue1mMfBNkba6qQTc6Y2\n>> > +5mEKw2/O7/JpND7ucU3OK9plcw/qnrWDgHxl0Iz95+OzUIIagxne\n>> > +-----END RSA PRIVATE KEY-----\n>> > +\"\"\"\n>> > +SSH_PUB_KEY = \"\"\"\\\n>> > +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCikC46WYtXotUd0UGPz9547Aj0KqC4gk+nt4BBJm86IHgCD9FygSGX9EFutXlhz9KZIPg9Okk7+IzXRHCWI2MNvhrcjyrezKREm71z08j9iwfxY3340fY2Mo+0khwpO7bzsgzkljHIHqcOg7MgttPInVMNH/EfqpgR8EDKJuWCB2Ny+EBFN/3dAiff0X/EvKle9PUrY70EkSycnyURS8HZReEqj8lN9J5kXzA8F6jBo/0Q42Ttv6e4k5YcaDrwmLrBWLra2PCXZLNyHqXEiFkGmdXtA1Eox9gc/p4jIXim6xrPNmpN6WyrrEjaCF5xYvNv8wXkD6uSWwbHYU24lIAn qemu-vm-key\n>> > +\"\"\"\n>>\n>> I'm not sure we should be embedding the keys in the script. I understand\n>> we need a common key for downloaded images (although it would be better\n>> to post-customise the image after download with the local developer\n>> keys). Perhaps ./tests/testing-keys/id_rsa[.pub]?\n>\n> We cannot generate keys or start from local keys because it's hard to inject it\n> into the *BSD images without ssh access (chicken-and-egg problem). Adding the\n> local keys might be a good feature, indeed.\n\nCan't libguestfs be used to manipulate the image without booting BSD\nitself?\n\nRegardless I still think having the key embedded in the script rather\nthan in files in the source tree is overly ugly.\n\n>\n>>\n>> > +\n>> > +class BaseVM(object):\n>> > +    GUEST_USER = \"qemu\"\n>> > +    GUEST_PASS = \"qemupass\"\n>> > +    ROOT_PASS = \"qemupass\"\n>> > +\n>> > +    # The script to run in the guest that builds QEMU\n>> > +    BUILD_SCRIPT = \"\"\n>> > +    # The guest name, to be overridden by subclasses\n>> > +    name = \"#base\"\n>> > +    def __init__(self, debug=False, vcpus=None):\n>> > +        self._guest = None\n>> > +        self._tmpdir = tempfile.mkdtemp(prefix=\"vm-test-\", suffix=\".tmp\", dir=\".\")\n>> > +        atexit.register(shutil.rmtree, self._tmpdir)\n>> > +\n>> > +        self._ssh_key_file = os.path.join(self._tmpdir, \"id_rsa\")\n>> > +        open(self._ssh_key_file, \"w\").write(SSH_KEY)\n>> > +        subprocess.check_call([\"chmod\", \"600\", self._ssh_key_file])\n>> > +\n>> > +        self._ssh_pub_key_file = os.path.join(self._tmpdir, \"id_rsa.pub\")\n>> > +        open(self._ssh_pub_key_file, \"w\").write(SSH_PUB_KEY)\n>>\n>> As above, I think it would be better just to keep copies of the keys in\n>> the tests directory rather than in the python source.\n>>\n>> > +\n>> > +        self.debug = debug\n>> > +        self._stderr = sys.stderr\n>> > +        self._devnull = open(\"/dev/null\", \"w\")\n>>\n>> You can use os.devnull as a portable reference.\n>\n> OK.\n>\n>>\n>> > +        if self.debug:\n>> > +            self._stdout = sys.stdout\n>> > +        else:\n>> > +            self._stdout = self._devnull\n>> > +        self._args = [ \\\n>> > +            \"-nodefaults\", \"-m\", \"2G\",\n>> > +            \"-cpu\", \"host\",\n>> > +            \"-netdev\", \"user,id=vnet,hostfwd=:0.0.0.0:0-:22\",\n>>\n>> It doesn't help that howstfwd is poorly documented. Are we trying to map\n>> an ephemeral port to the guests 22?\n>\n> Yes, it is a new feature of usernet, you're right the documentation is missing.\n>\n>>\n>> > +            \"-device\", \"virtio-net-pci,netdev=vnet\",\n>> > +            \"-vnc\", \":0,to=20\",\n>>\n>> Do we need a GUI?\n>\n> I'd like to keep it, it helps when you need to diagnose.\n\nAs long it runs or fails cleanly when run on a on terminal.\n\n>\n>>\n>> > +            \"-serial\", \"file:%s\" % os.path.join(self._tmpdir,\n>> > \"serial.out\")]\n>> > +        if vcpus:\n>> > +            self._args += [\"-smp\", str(vcpus)]\n>> > +        if os.access(\"/dev/kvm\", os.R_OK | os.W_OK):\n>> > +            self._args += [\"-enable-kvm\"]\n>> > +        else:\n>> > +            logging.info(\"KVM not available, not using -enable-kvm\")\n>> > +        self._data_args = []\n>> > +\n>> > +    def _download_with_cache(self, url, sha256sum=None):\n>> > +        def check_sha256sum(fname):\n>> > +            if not sha256sum:\n>> > +                return True\n>> > +            checksum = subprocess.check_output([\"sha256sum\", fname]).split()[0]\n>> > +            return sha256sum == checksum\n>> > +\n>> > +        cache_dir = os.path.expanduser(\"~/.cache/qemu-vm/download\")\n>> > +        if not os.path.exists(cache_dir):\n>> > +            os.makedirs(cache_dir)\n>> > +        fname = os.path.join(cache_dir, hashlib.sha1(url).hexdigest())\n>> > +        if os.path.exists(fname) and check_sha256sum(fname):\n>> > +            return fname\n>> > +        logging.debug(\"Downloading %s to %s...\", url, fname)\n>> > +        subprocess.check_call([\"wget\", \"-c\", url, \"-O\", fname + \".download\"],\n>> > +                              stdout=self._stdout,\n>> > stderr=self._stderr)\n>>\n>> Using wget rather than doing it internally adds a utility requirement.\n>> Is doing a pure python urllib2 fetch too slow for this?\n>\n> I think \"-c\" is a good feature for downloading big files.\n\nI guess so.\n\n>\n>>\n>> > +        os.rename(fname + \".download\", fname)\n>> > +        return fname\n>> > +\n>> > +    def _ssh_do(self, user, cmd, check, interactive=False):\n>> > +        ssh_cmd = [\"ssh\", \"-q\",\n>> > +                   \"-o\", \"StrictHostKeyChecking=no\",\n>> > +                   \"-o\", \"UserKnownHostsFile=/dev/null\",\n>> > +                   \"-o\", \"ConnectTimeout=1\",\n>> > +                   \"-p\", self.ssh_port, \"-i\", self._ssh_key_file]\n>> > +        if interactive:\n>> > +            ssh_cmd += ['-t']\n>> > +        assert not isinstance(cmd, str)\n>> > +        ssh_cmd += [\"%s@127.0.0.1\" % user] + list(cmd)\n>> > +        logging.debug(\"ssh_cmd: %s\", \" \".join(ssh_cmd))\n>> > +        r = subprocess.call(ssh_cmd,\n>> > +                            stdin=sys.stdin if interactive else self._devnull,\n>> > +                            stdout=sys.stdout if interactive else self._stdout,\n>> > +                            stderr=sys.stderr if interactive else self._stderr)\n>> > +        if check and r != 0:\n>> > +            raise Exception(\"SSH command failed: %s\" % cmd)\n>> > +        return r\n>> > +\n>> > +    def ssh(self, *cmd):\n>> > +        return self._ssh_do(self.GUEST_USER, cmd, False)\n>> > +\n>> > +    def ssh_interactive(self, *cmd):\n>> > +        return self._ssh_do(self.GUEST_USER, cmd, False, True)\n>> > +\n>> > +    def ssh_root(self, *cmd):\n>> > +        return self._ssh_do(\"root\", cmd, False)\n>> > +\n>> > +    def ssh_check(self, *cmd):\n>> > +        self._ssh_do(self.GUEST_USER, cmd, True)\n>> > +\n>> > +    def ssh_root_check(self, *cmd):\n>> > +        self._ssh_do(\"root\", cmd, True)\n>> > +\n>> > +    def build_image(self, img):\n>> > +        raise NotImplementedError\n>> > +\n>> > +    def add_source_dir(self, src_dir):\n>> > +        name = \"data-\" + hashlib.sha1(src_dir).hexdigest()[:5]\n>> > +        tarfile = os.path.join(self._tmpdir, name + \".tar\")\n>> > +        logging.debug(\"Creating archive %s for src_dir dir: %s\", tarfile, src_dir)\n>> > +        subprocess.check_call([\"./scripts/archive-source.sh\", tarfile],\n>> > +                              cwd=src_dir, stdin=self._devnull,\n>> > +                              stdout=self._stdout, stderr=self._stderr)\n>> > +        self._data_args += [\"-drive\",\n>> > +                            \"file=%s,if=none,id=%s,cache=writeback,format=raw\" % \\\n>> > +                                    (tarfile, name),\n>> > +                            \"-device\",\n>> > +                            \"virtio-blk,drive=%s,serial=%s,bootindex=1\" % (name, name)]\n>> > +\n>> > +    def boot(self, img, extra_args=[]):\n>> > +        args = self._args + [\n>> > +            \"-device\", \"VGA\",\n>>\n>> Is specifying a display device at boot time really needed (say rather\n>> than further up with the rest of the machine description). Do we even\n>> want a display given use ssh/serial for everything?\n>\n> It makes debug easier, and also I find cloud-init or something in ubuntu\n> requires a virtual console on the display to make progress.\n>\n>>\n>> > +            \"-drive\", \"file=%s,if=none,id=drive0,cache=writeback\" % img,\n>> > +            \"-device\", \"virtio-blk,drive=drive0,bootindex=0\"]\n>> > +        args += self._data_args + extra_args\n>> > +        logging.debug(\"QEMU args: %s\", \" \".join(args))\n>> > +        guest = QEMUMachine(binary=os.environ.get(\"QEMU\", \"qemu-system-x86_64\"),\n>> > +                            args=args)\n>> > +        guest.launch()\n>> > +        atexit.register(self.shutdown)\n>> > +        self._guest = guest\n>> > +        usernet_info = guest.qmp(\"human-monitor-command\",\n>> > +                                 command_line=\"info usernet\")\n>> > +        self.ssh_port = None\n>> > +        for l in usernet_info[\"return\"].splitlines():\n>> > +            fields = l.split()\n>> > +            if \"TCP[HOST_FORWARD]\" in fields and \"22\" in fields:\n>> > +                self.ssh_port = l.split()[3]\n>> > +        if not self.ssh_port:\n>> > +            raise Exception(\"Cannot find ssh port from 'info usernet':\\n%s\" % \\\n>> > +                            usernet_info)\n>> > +\n>> > +    def wait_ssh(self, seconds=120):\n>> > +        starttime = datetime.datetime.now()\n>> > +        guest_up = False\n>> > +        while (datetime.datetime.now() - starttime).total_seconds() < seconds:\n>> > +            if self.ssh(\"exit 0\") == 0:\n>> > +                guest_up = True\n>> > +                break\n>> > +            time.sleep(1)\n>> > +        if not guest_up:\n>> > +            raise Exception(\"Timeout while waiting for guest ssh\")\n>> > +\n>> > +    def shutdown(self):\n>> > +        self._guest.shutdown()\n>> > +\n>> > +    def wait(self):\n>> > +        self._guest.wait()\n>> > +\n>> > +    def qmp(self, *args, **kwargs):\n>> > +        return self._guest.qmp(*args, **kwargs)\n>> > +\n>> > +def parse_args(vm_name):\n>> > +    parser = optparse.OptionParser(description=\"\"\"\n>> > +    VM test utility.  Exit codes: 0 = success, 1 = command line error, 2 = environment initialization failed, 3 = test command failed\"\"\")\n>> > +    parser.add_option(\"--debug\", \"-D\", action=\"store_true\",\n>> > +                      help=\"enable debug output\")\n>> > +    parser.add_option(\"--image\", \"-i\", default=\"%s.img\" % vm_name,\n>> > +                      help=\"image file name\")\n>> > +    parser.add_option(\"--force\", \"-f\", action=\"store_true\",\n>> > +                      help=\"force build image even if image exists\")\n>> > +    parser.add_option(\"--jobs\", type=int, default=multiprocessing.cpu_count() / 2,\n>> > +                      help=\"number of virtual CPUs\")\n>> > +    parser.add_option(\"--build-image\", \"-b\", action=\"store_true\",\n>> > +                      help=\"build image\")\n>> > +    parser.add_option(\"--build-qemu\",\n>> > +                      help=\"build QEMU from source in guest\")\n>> > +    parser.add_option(\"--interactive\", \"-I\", action=\"store_true\",\n>> > +                      help=\"Interactively run command\")\n>> > +    parser.disable_interspersed_args()\n>> > +    return parser.parse_args()\n>> > +\n>> > +def main(vmcls):\n>> > +    try:\n>> > +        args, argv = parse_args(vmcls.name)\n>> > +        if not argv and not args.build_qemu and not args.build_image:\n>> > +            print \"Nothing to do?\"\n>> > +            return 1\n>> > +        if args.debug:\n>> > +            logging.getLogger().setLevel(logging.DEBUG)\n>> > +        vm = vmcls(debug=args.debug, vcpus=args.jobs)\n>> > +        if args.build_image:\n>> > +            if os.path.exists(args.image) and not args.force:\n>> > +                sys.stderr.writelines([\"Image file exists: %s\\n\" % args.image,\n>> > +                                      \"Use --force option to overwrite\\n\"])\n>> > +                return 1\n>> > +            return vm.build_image(args.image)\n>> > +        if args.build_qemu:\n>> > +            vm.add_source_dir(args.build_qemu)\n>> > +            cmd = [vm.BUILD_SCRIPT.format(\n>> > +                   configure_opts = \" \".join(argv),\n>> > +                   jobs=args.jobs)]\n>> > +        else:\n>> > +            cmd = argv\n>> > +        vm.boot(args.image + \",snapshot=on\")\n>>\n>> If this fails it's fairly cryptic:\n>>\n>> /home/alex/lsrc/qemu/qemu.git/tests/vm/openbsd  --debug   --image \"tests/vm/openbsd.img\" --build-qemu /home/alex/lsrc/qemu/qemu.git\n>> DEBUG:root:Creating archive ./vm-test-fxejnB.tmp/data-2de24.tar for src_dir dir: /home/alex/lsrc/qemu/qemu.git\n>> DEBUG:root:QEMU args: -nodefaults -m 2G -cpu host -netdev user,id=vnet,hostfwd=:0.0.0.0:0-:22 -device virtio-net-pci,netdev=vnet -vnc :0,to=20 -serial file:./vm-test-fxejnB.tmp/serial.out -smp 4 -enable-kvm -device VGA -drive file=tests/vm/openbsd.img,snapshot=on,if=none,id=drive0,cache=writeback -device virtio-blk,drive=drive0,bootindex=0 -drive file=./vm-test-fxejnB.tmp/data-2de24.tar,if=none,id=data-2de24,cache=writeback,format=raw -device virtio-blk,drive=data-2de24,serial=data-2de24,bootindex=1\n>> Failed to prepare guest environment\n>> Traceback (most recent call last):\n>>   File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/basevm.py\", line 260, in main\n>>     vm.boot(args.image + \",snapshot=on\")\n>>   File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/basevm.py\", line 184, in boot\n>>     guest.launch()\n>>   File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/../../scripts/qemu.py\", line 151, in launch\n>>     self._post_launch()\n>>   File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/../../scripts/qemu.py\", line 135, in _post_launch\n>>     self._qmp.accept()\n>>   File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/../../scripts/qmp/qmp.py\", line 147, in accept\n>>     return self.__negotiate_capabilities()\n>>   File \"/home/alex/lsrc/qemu/qemu.git/tests/vm/../../scripts/qmp/qmp.py\", line 60, in __negotiate_capabilities\n>>     raise QMPConnectError\n>> QMPConnectError\n>>\n>> I assume QEMU failed to boot and might have given us a message that\n>> would be useful.\n>\n> It's a separate issue of qemu.py, I didn't try to fix it here because currently\n> there are many patches touching that file on the list, there is a high chance of\n> conflict.\n>\n> In your case which qemu version are you using? If not master it probably is\n> failing because of the hostfwd syntax.\n\nNope, built on master (fcea73709b966a7ded9efa7b106ea50c7fe9025c). As I\nsay I need a cleaner error message to diagnose why it failed.\n\n>\n>>\n>>\n>> > +        vm.wait_ssh()\n>> > +    except Exception as e:\n>> > +        if isinstance(e, SystemExit) and e.code == 0:\n>> > +            return 0\n>> > +        sys.stderr.write(\"Failed to prepare guest environment\\n\")\n>> > +        traceback.print_exc()\n>> > +        return 2\n>> > +\n>> > +    if args.interactive:\n>> > +        if vm.ssh_interactive(*cmd) == 0:\n>> > +            return 0\n>> > +        vm.ssh_interactive()\n>> > +        return 3\n>> > +    else:\n>> > +        if vm.ssh(*cmd) != 0:\n>> > +            return 3\n>>\n>>\n>> --\n>> Alex Bennée\n>>\n>\n> Thanks for the review!\n>\n> Fam\n\n\n--\nAlex Bennée","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=linaro.org header.i=@linaro.org\n\theader.b=\"kpwdIYch\"; dkim-atps=neutral"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xrPhB1c8Lz9s7f\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 11 Sep 2017 20:44:58 +1000 (AEST)","from localhost ([::1]:56630 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1drMD2-0004o4-Bj\n\tfor incoming@patchwork.ozlabs.org; Mon, 11 Sep 2017 06:44:56 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:36247)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <alex.bennee@linaro.org>) id 1drMCZ-0004lt-Nd\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 06:44:30 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <alex.bennee@linaro.org>) id 1drMCW-0001kf-GX\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 06:44:27 -0400","from mail-wr0-x22a.google.com ([2a00:1450:400c:c0c::22a]:34300)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <alex.bennee@linaro.org>)\n\tid 1drMCW-0001k2-5W\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 06:44:24 -0400","by mail-wr0-x22a.google.com with SMTP id v109so13689611wrc.1\n\tfor <qemu-devel@nongnu.org>; Mon, 11 Sep 2017 03:44:24 -0700 (PDT)","from zen.linaro.local ([81.128.185.34])\n\tby smtp.gmail.com with ESMTPSA id\n\tp80sm5743337wmf.42.2017.09.11.03.44.21\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tMon, 11 Sep 2017 03:44:21 -0700 (PDT)","from zen (localhost [127.0.0.1])\n\tby zen.linaro.local (Postfix) with ESMTPS id 18E603E0142;\n\tMon, 11 Sep 2017 11:44:21 +0100 (BST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google;\n\th=references:user-agent:from:to:cc:subject:in-reply-to:date\n\t:message-id:mime-version:content-transfer-encoding;\n\tbh=Y5L2WM0Ep2j05KZqj5moMXou6BQBhG9zaS45SQSFRi0=;\n\tb=kpwdIYchmLBzPZDPlnwGoj4OWp7qXgDWqOi77u2WsFIvRbJOTmtqsxpxcowZBusXAL\n\tgMjvH6uXfhrPyps/JxUSOG0SvmI7ROfbh/UFkCGK9bn+gUFWfq+RxfBXO7j9GOg24qtj\n\tc2R2oly5Uu/VImQ9A3UULKpu/nsUpckYvBce4=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:references:user-agent:from:to:cc:subject\n\t:in-reply-to:date:message-id:mime-version:content-transfer-encoding; \n\tbh=Y5L2WM0Ep2j05KZqj5moMXou6BQBhG9zaS45SQSFRi0=;\n\tb=MomoUkFECQRqu+Ix1YOsooPfh2XmFa7t3msIUIsilMXyarYraGMeKjBPj/wUchJx3b\n\twNsTgGKxtJplJ/gdVmkzlgSLus+Yh3gU0qFdSaVMlUY0NujD+/zLK/DX65g5JQUKippE\n\tkU08XXY7WSiDNoG7QoDjQz3ksRvfdwrMUfEay+A59V3cqvFqnkWdNBxvzULixwJApjQj\n\t8gQeStlhmr+yQllDWOdUdTgnfxt8Vpi5Rg29S/M4X9H+Svy2fY4qpQpwUXtF0PxNZIl6\n\tWp1AmSWeAx50sjOy03QfnMfBqpKQ44GqNMf3/WIJ0t+eHuveE5A7mCAyq/TJj2Psrmxt\n\ttUMQ==","X-Gm-Message-State":"AHPjjUjC3RQGCYlxaIN/Me7XPX3l8FmoP89IoGduNHklV9HDoRGqNzmG\n\t+K+nwzd1CR+XkpSw","X-Google-Smtp-Source":"ADKCNb5+DpeHFWqw0qpaXkPgARhavslZYsn6peP20cDGhBJvfrnpnB+G4y1DaCnRffIQj3hDoSsbeA==","X-Received":"by 10.223.166.138 with SMTP id t10mr9136672wrc.64.1505126662761; \n\tMon, 11 Sep 2017 03:44:22 -0700 (PDT)","References":"<20170905021201.25684-1-famz@redhat.com>\n\t<20170905021201.25684-5-famz@redhat.com>\n\t<87tw0dgqpv.fsf@linaro.org> <20170908232950.GD18677@lemon.lan>","User-agent":"mu4e 0.9.19; emacs 25.2.50.3","From":"Alex =?utf-8?q?Benn=C3=A9e?= <alex.bennee@linaro.org>","To":"Fam Zheng <famz@redhat.com>","In-reply-to":"<20170908232950.GD18677@lemon.lan>","Date":"Mon, 11 Sep 2017 11:44:21 +0100","Message-ID":"<874ls9bjlm.fsf@linaro.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"8bit","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"2a00:1450:400c:c0c::22a","Subject":"Re: [Qemu-devel] [PATCH v6 04/12] tests: Add vm test lib","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org, Philippe\n\t=?utf-8?q?Mathieu-Daud=C3=A9?= <f4bug@amsat.org>,\n\tKamil Rytarowski <kamil@netbsd.org>, stefanha@redhat.com, \n\tCleber Rosa <crosa@redhat.com>, pbonzini@redhat.com","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1766631,"web_url":"http://patchwork.ozlabs.org/comment/1766631/","msgid":"<20170912001046.GF32341@lemon.lan>","list_archive_url":null,"date":"2017-09-12T00:10:46","subject":"Re: [Qemu-devel] [PATCH v6 04/12] tests: Add vm test lib","submitter":{"id":24872,"url":"http://patchwork.ozlabs.org/api/people/24872/","name":"Fam Zheng","email":"famz@redhat.com"},"content":"On Mon, 09/11 11:44, Alex Bennée wrote:\n> \n> Fam Zheng <famz@redhat.com> writes:\n> \n> > On Fri, 09/08 16:22, Alex Bennée wrote:\n> >>\n> >> Fam Zheng <famz@redhat.com> writes:\n> >>\n> >> > This is the common code to implement a \"VM test\" to\n> >> >\n> >> >   1) Download and initialize a pre-defined VM that has necessary\n> >> >   dependencies to build QEMU and SSH access.\n> >> >\n> >> >   2) Archive $SRC_PATH to a .tar file.\n> >> >\n> >> >   3) Boot the VM, and pass the source tar file to the guest.\n> >> >\n> >> >   4) SSH into the VM, untar the source tarball, build from the source.\n> >> >\n> >> > Signed-off-by: Fam Zheng <famz@redhat.com>\n> >> > ---\n> >> >  tests/vm/basevm.py | 276 +++++++++++++++++++++++++++++++++++++++++++++++++++++\n> >> >  1 file changed, 276 insertions(+)\n> >> >  create mode 100755 tests/vm/basevm.py\n> >> >\n> >> > diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py\n> >> > new file mode 100755\n> >> > index 0000000000..9db91d61fa\n> >> > --- /dev/null\n> >> > +++ b/tests/vm/basevm.py\n> >> > @@ -0,0 +1,276 @@\n> >> > +#!/usr/bin/env python\n> >> > +#\n> >> > +# VM testing base class\n> >> > +#\n> >> > +# Copyright (C) 2017 Red Hat Inc.\n> >> > +#\n> >> > +# Authors:\n> >> > +#  Fam Zheng <famz@redhat.com>\n> >> > +#\n> >> > +# This work is licensed under the terms of the GNU GPL, version 2.  See\n> >> > +# the COPYING file in the top-level directory.\n> >> > +#\n> >> > +\n> >> > +import os\n> >> > +import sys\n> >> > +import logging\n> >> > +import time\n> >> > +import datetime\n> >> > +sys.path.append(os.path.join(os.path.dirname(__file__), \"..\", \"..\", \"scripts\"))\n> >> > +from qemu import QEMUMachine\n> >> > +import subprocess\n> >> > +import hashlib\n> >> > +import optparse\n> >> > +import atexit\n> >> > +import tempfile\n> >> > +import shutil\n> >> > +import multiprocessing\n> >> > +import traceback\n> >> > +\n> >> > +SSH_KEY = \"\"\"\\\n> >> > +-----BEGIN RSA PRIVATE KEY-----\n> >> > +MIIEowIBAAKCAQEAopAuOlmLV6LVHdFBj8/eeOwI9CqguIJPp7eAQSZvOiB4Ag/R\n> >> > +coEhl/RBbrV5Yc/SmSD4PTpJO/iM10RwliNjDb4a3I8q3sykRJu9c9PI/YsH8WN9\n> >> > ++NH2NjKPtJIcKTu287IM5JYxyB6nDoOzILbTyJ1TDR/xH6qYEfBAyiblggdjcvhA\n> >> > +RTf93QIn39F/xLypXvT1K2O9BJEsnJ8lEUvB2UXhKo/JTfSeZF8wPBeowaP9EONk\n> >> > +7b+nuJOWHGg68Ji6wVi62tjwl2Szch6lxIhZBpnV7QNRKMfYHP6eIyF4pusazzZq\n> >> > +Telsq6xI2ghecWLzb/MF5A+rklsGx2FNuJSAJwIDAQABAoIBAHHi4o/8VZNivz0x\n> >> > +cWXn8erzKV6tUoWQvW85Lj/2RiwJvSlsnYZDkx5af1CpEE2HA/pFT8PNRqsd+MWC\n> >> > +7AEy710cVsM4BYerBFYQaYxwzblaoojo88LSjVPw3h5Z0iLM8+IMVd36nwuc9dpE\n> >> > +R8TecMZ1+U4Tl6BgqkK+9xToZRdPKdjS8L5MoFhGN+xY0vRbbJbGaV9Q0IHxLBkB\n> >> > +rEBV7T1mUynneCHRUQlJQEwJmKpT8MH3IjsUXlG5YvnuuvcQJSNTaW2iDLxuOKp8\n> >> > +cxW8+qL88zpb1D5dppoIu6rlrugN0azSq70ruFJQPc/A8GQrDKoGgRQiagxNY3u+\n> >> > +vHZzXlECgYEA0dKO3gfkSxsDBb94sQwskMScqLhcKhztEa8kPxTx6Yqh+x8/scx3\n> >> > +XhJyOt669P8U1v8a/2Al+s81oZzzfQSzO1Q7gEwSrgBcRMSIoRBUw9uYcy02ngb/\n> >> > +j/ng3DGivfJztjjiSJwb46FHkJ2JR8mF2UisC6UMXk3NgFY/3vWQx78CgYEAxlcG\n> >> > +T3hfSWSmTgKRczMJuHQOX9ULfTBIqwP5VqkkkiavzigGRirzb5lgnmuTSPTpF0LB\n> >> > +XVPjR2M4q+7gzP0Dca3pocrvLEoxjwIKnCbYKnyyvnUoE9qHv4Kr+vDbgWpa2LXG\n> >> > +JbLmE7tgTCIp20jOPPT4xuDvlbzQZBJ5qCQSoZkCgYEAgrotSSihlCnAOFSTXbu4\n> >> > +CHp3IKe8xIBBNENq0eK61kcJpOxTQvOha3sSsJsU4JAM6+cFaxb8kseHIqonCj1j\n> >> > +bhOM/uJmwQJ4el/4wGDsbxriYOBKpyq1D38gGhDS1IW6kk3erl6VAb36WJ/OaGum\n> >> > +eTpN9vNeQWM4Jj2WjdNx4QECgYAwTdd6mU1TmZCrJRL5ZG+0nYc2rbMrnQvFoqUi\n> >> > +BvWiJovggHzur90zy73tNzPaq9Ls2FQxf5G1vCN8NCRJqEEjeYCR59OSDMu/EXc2\n> >> > +CnvQ9SevHOdS1oEDEjcCWZCMFzPi3XpRih1gptzQDe31uuiHjf3cqcGPzTlPdfRt\n> >> > +D8P92QKBgC4UaBvIRwREVJsdZzpIzm224Bpe8LOmA7DeTnjlT0b3lkGiBJ36/Q0p\n> >> > +VhYh/6cjX4/iuIs7gJbGon7B+YPB8scmOi3fj0+nkJAONue1mMfBNkba6qQTc6Y2\n> >> > +5mEKw2/O7/JpND7ucU3OK9plcw/qnrWDgHxl0Iz95+OzUIIagxne\n> >> > +-----END RSA PRIVATE KEY-----\n> >> > +\"\"\"\n> >> > +SSH_PUB_KEY = \"\"\"\\\n> >> > +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCikC46WYtXotUd0UGPz9547Aj0KqC4gk+nt4BBJm86IHgCD9FygSGX9EFutXlhz9KZIPg9Okk7+IzXRHCWI2MNvhrcjyrezKREm71z08j9iwfxY3340fY2Mo+0khwpO7bzsgzkljHIHqcOg7MgttPInVMNH/EfqpgR8EDKJuWCB2Ny+EBFN/3dAiff0X/EvKle9PUrY70EkSycnyURS8HZReEqj8lN9J5kXzA8F6jBo/0Q42Ttv6e4k5YcaDrwmLrBWLra2PCXZLNyHqXEiFkGmdXtA1Eox9gc/p4jIXim6xrPNmpN6WyrrEjaCF5xYvNv8wXkD6uSWwbHYU24lIAn qemu-vm-key\n> >> > +\"\"\"\n> >>\n> >> I'm not sure we should be embedding the keys in the script. I understand\n> >> we need a common key for downloaded images (although it would be better\n> >> to post-customise the image after download with the local developer\n> >> keys). Perhaps ./tests/testing-keys/id_rsa[.pub]?\n> >\n> > We cannot generate keys or start from local keys because it's hard to inject it\n> > into the *BSD images without ssh access (chicken-and-egg problem). Adding the\n> > local keys might be a good feature, indeed.\n> \n> Can't libguestfs be used to manipulate the image without booting BSD\n> itself?\n\nNo, not working for BSD.\n\n> \n> Regardless I still think having the key embedded in the script rather\n> than in files in the source tree is overly ugly.\n\nOK, I can move it out.\n\n> >>\n> >> > +            \"-device\", \"virtio-net-pci,netdev=vnet\",\n> >> > +            \"-vnc\", \":0,to=20\",\n> >>\n> >> Do we need a GUI?\n> >\n> > I'd like to keep it, it helps when you need to diagnose.\n> \n> As long it runs or fails cleanly when run on a on terminal.\n\nI believe so.\n\n> > In your case which qemu version are you using? If not master it probably is\n> > failing because of the hostfwd syntax.\n> \n> Nope, built on master (fcea73709b966a7ded9efa7b106ea50c7fe9025c). As I\n> say I need a cleaner error message to diagnose why it failed.\n\nI mean the QEMU binary this script finds in $PATH: it invokes\n\"qemu-system-x86_64\" command, not the built QEMU. This is overrideable by\nsetting QEMU= env.\n\nAnyway I'll try to improve the error message.\n\nFam","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx08.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx08.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=famz@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xrlZc4yhMz9s7M\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 12 Sep 2017 10:11:20 +1000 (AEST)","from localhost ([::1]:32901 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1drYnO-0004hf-R0\n\tfor incoming@patchwork.ozlabs.org; Mon, 11 Sep 2017 20:11:18 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:60018)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <famz@redhat.com>) id 1drYn3-0004hL-Gh\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 20:10:58 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <famz@redhat.com>) id 1drYmy-00009z-EO\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 20:10:57 -0400","from mx1.redhat.com ([209.132.183.28]:48808)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <famz@redhat.com>) id 1drYmy-00009q-4k\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 20:10:52 -0400","from smtp.corp.redhat.com\n\t(int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id 44C13C0703AB;\n\tTue, 12 Sep 2017 00:10:51 +0000 (UTC)","from localhost (ovpn-12-27.pek2.redhat.com [10.72.12.27])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id BF27169FAC;\n\tTue, 12 Sep 2017 00:10:48 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 44C13C0703AB","Date":"Tue, 12 Sep 2017 08:10:46 +0800","From":"Fam Zheng <famz@redhat.com>","To":"Alex =?iso-8859-1?q?Benn=E9e?= <alex.bennee@linaro.org>","Message-ID":"<20170912001046.GF32341@lemon.lan>","References":"<20170905021201.25684-1-famz@redhat.com>\n\t<20170905021201.25684-5-famz@redhat.com>\n\t<87tw0dgqpv.fsf@linaro.org> <20170908232950.GD18677@lemon.lan>\n\t<874ls9bjlm.fsf@linaro.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","In-Reply-To":"<874ls9bjlm.fsf@linaro.org>","User-Agent":"Mutt/1.8.3 (2017-05-23)","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.11","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.32]);\n\tTue, 12 Sep 2017 00:10:51 +0000 (UTC)","Content-Transfer-Encoding":"quoted-printable","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"Re: [Qemu-devel] [PATCH v6 04/12] tests: Add vm test lib","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org, Philippe\n\t=?iso-8859-1?q?Mathieu-Daud=E9?= <f4bug@amsat.org>,\n\tKamil Rytarowski <kamil@netbsd.org>, stefanha@redhat.com, \n\tCleber Rosa <crosa@redhat.com>, pbonzini@redhat.com","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}}]