Received: from eggs.gnu.org ([2001:4830:134:3::10]:53755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkZRy-0004WH-7Z for qemu-devel@nongnu.org; Thu, 15 Sep 2016 12:23:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bkZRv-0000ct-Tw for qemu-devel@nongnu.org; Thu, 15 Sep 2016 12:23:46 -0400 References: <1471625435-6190-1-git-send-email-kwolf@redhat.com> <1471625435-6190-11-git-send-email-kwolf@redhat.com> <32842c09-6dce-b68b-d95e-de3813099faa@redhat.com> <87mvj9cf4q.fsf@oc4731375738.ibm.com> From: Eric Blake Message-ID: <29a13248-76b4-73a0-5544-67c7fb4378b0@redhat.com> Date: Thu, 15 Sep 2016 11:23:35 -0500 MIME-Version: 1.0 In-Reply-To: <87mvj9cf4q.fsf@oc4731375738.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="NSn1wq8Xb6Gv5FQvNoSBVqs7aRT0RQbFf" Subject: Re: [Qemu-devel] [PATCH 10/10] qemu-iotests/118: Test media change with qdev name List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Sascha Silbe , Kevin Wolf , qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --NSn1wq8Xb6Gv5FQvNoSBVqs7aRT0RQbFf From: Eric Blake To: Sascha Silbe , Kevin Wolf , qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com Message-ID: <29a13248-76b4-73a0-5544-67c7fb4378b0@redhat.com> Subject: Re: [Qemu-devel] [PATCH 10/10] qemu-iotests/118: Test media change with qdev name References: <1471625435-6190-1-git-send-email-kwolf@redhat.com> <1471625435-6190-11-git-send-email-kwolf@redhat.com> <32842c09-6dce-b68b-d95e-de3813099faa@redhat.com> <87mvj9cf4q.fsf@oc4731375738.ibm.com> In-Reply-To: <87mvj9cf4q.fsf@oc4731375738.ibm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 09/15/2016 11:16 AM, Sascha Silbe wrote: >>> + if self.device_name is not None: >>> + result =3D self.vm.qmp('blockdev-change-medium', >>> + id=3Dself.device_name, filename=3Dn= ew_img, >>> + format=3Diotests.imgfmt) >>> + else: >>> + result =3D self.vm.qmp('blockdev-change-medium', >>> + device=3D'drive0', filename=3Dnew_i= mg, >>> + format=3Diotests.imgfmt) >> >> I'm not enough of a python guru to know if there is any way to compres= s >> this to a shorter format (I do know, however, that the lack of an >> obvious ?: operator in python can indeed result in verbose if/else >> clauses compared to other languages). >=20 > Actually there is a direct equivalent of "?:" (which unfortunately isn'= t > in C11) in Python: "or". So you can use: >=20 > result =3D self.vm.qmp('blockdev-change-medium', > id=3Dself.device_name or 'drive0', filenam= e=3Dnew_img, Not what we want. We want to use a different parameter, based on the overall condition (so it is NOT as simple as a conditional assignment to the 'id' parameter, but an actual swap between whether we have the 'id' or the 'device' parameter). It's not obvious whether: result =3D foo(id=3Dself.device_name, device=3D'drive0' if not self.device_name else None) would have the same semantics as: if self.device_name: result =3D foo(id=3Dself.device_name) else result =3D foo(device=3D'drive0') and even if it does have the same semantics, it's not obvious if there's a shorter way to write it. So we end up with verbose duplication of all the remaining parameters. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --NSn1wq8Xb6Gv5FQvNoSBVqs7aRT0RQbFf Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJX2ssHAAoJEKeha0olJ0Nq76MH+wTxahM4mu8jRxxnNzS/5edw RDB5NLLrUaakpagwKRazASqfDE+LSqrnQ4Z2eLoNJy8KzFd2hAvlHHnp6W6KVVt8 vFxmMhFI2O3FCBONxdq1Nz4jGxrOz7iFlXl0nTEOc8pBGn50safu99es7l5uPx9n WwXPz4vQecQ9xK7i8N9HgpNQsjZZ9sT8MIpr1ECR1X3XQ7L9TVXoOjpbrkIb50FS Q0NBKWeoXBfKiTMIK5Uzpyl0GjaOFlissI2obr26KWjBXK77A7tM19Dz8Hl294Cp hQfO5QTXDeLtNvEoBgPTX1biohMSEAwy9ZkIHRrHXztpjODhdhX4Ceg6TCxTlpw= =T+hu -----END PGP SIGNATURE----- --NSn1wq8Xb6Gv5FQvNoSBVqs7aRT0RQbFf--