From patchwork Tue Jul 18 11:01:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 9848045 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DFA75602C8 for ; Tue, 18 Jul 2017 11:23:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1CDE28573 for ; Tue, 18 Jul 2017 11:23:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6B1228577; Tue, 18 Jul 2017 11:23:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4730928573 for ; Tue, 18 Jul 2017 11:23:46 +0000 (UTC) Received: from localhost ([::1]:55574 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXQbR-0000Tz-Ez for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Jul 2017 07:23:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52131) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXQGZ-0005rh-D0 for qemu-devel@nongnu.org; Tue, 18 Jul 2017 07:02:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXQGT-00032z-87 for qemu-devel@nongnu.org; Tue, 18 Jul 2017 07:02:11 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:52583) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXQGS-00032Z-UU for qemu-devel@nongnu.org; Tue, 18 Jul 2017 07:02:05 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v6IAwiEc022769 for ; Tue, 18 Jul 2017 07:02:03 -0400 Received: from e13.ny.us.ibm.com (e13.ny.us.ibm.com [129.33.205.203]) by mx0a-001b2d01.pphosted.com with ESMTP id 2bs9y7su9k-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 18 Jul 2017 07:02:03 -0400 Received: from localhost by e13.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 18 Jul 2017 07:02:01 -0400 Received: from b01cxnp22035.gho.pok.ibm.com (9.57.198.25) by e13.ny.us.ibm.com (146.89.104.200) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 18 Jul 2017 07:01:59 -0400 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v6IB1vbr17170490; Tue, 18 Jul 2017 11:01:58 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 152E1B2046; Tue, 18 Jul 2017 06:59:28 -0400 (EDT) Received: from localhost (unknown [9.80.83.16]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP id CAD80B2052; Tue, 18 Jul 2017 06:59:27 -0400 (EDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 18 Jul 2017 06:01:44 -0500 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500375704-28002-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1500375704-28002-1-git-send-email-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17071811-0008-0000-0000-00000260F24A X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007381; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000214; SDB=6.00889293; UDB=6.00444191; IPR=6.00669465; BA=6.00005478; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00016258; XFM=3.00000015; UTC=2017-07-18 11:02:00 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17071811-0009-0000-0000-0000361219AD Message-Id: <1500375704-28002-9-git-send-email-mdroth@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-07-18_04:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1706020000 definitions=main-1707180174 X-MIME-Autoconverted: from 8bit to quoted-printable by mx0a-001b2d01.pphosted.com id v6IAwiEc022769 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL v2 8/8] test-qga: add test for guest-get-osinfo X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Tomáš Golembiovský Add test for guest-get-osinfo command. Qemu-ga was modified to accept QGA_OS_RELEASE environment variable. If the variable is defined it is interpreted as path to the os-release file and it is parsed instead of the default paths. Signed-off-by: Tomáš Golembiovský Reviewed-by: Marc-André Lureau * move declarations to beginning of functions Signed-off-by: Michael Roth --- qga/commands-posix.c | 13 +++++++--- tests/data/test-qga-os-release | 7 ++++++ tests/test-qga.c | 56 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 tests/data/test-qga-os-release diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 7b3d89a..ab0c63d 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2682,7 +2682,8 @@ GuestOSInfo *qmp_guest_get_osinfo(Error **errp) { GuestOSInfo *info = NULL; struct utsname kinfo; - GKeyFile *osrelease; + GKeyFile *osrelease = NULL; + const char *qga_os_release = g_getenv("QGA_OS_RELEASE"); info = g_new0(GuestOSInfo, 1); @@ -2697,9 +2698,13 @@ GuestOSInfo *qmp_guest_get_osinfo(Error **errp) info->machine = g_strdup(kinfo.machine); } - osrelease = ga_parse_osrelease("/etc/os-release"); - if (osrelease == NULL) { - osrelease = ga_parse_osrelease("/usr/lib/os-release"); + if (qga_os_release != NULL) { + osrelease = ga_parse_osrelease(qga_os_release); + } else { + osrelease = ga_parse_osrelease("/etc/os-release"); + if (osrelease == NULL) { + osrelease = ga_parse_osrelease("/usr/lib/os-release"); + } } if (osrelease != NULL) { diff --git a/tests/data/test-qga-os-release b/tests/data/test-qga-os-release new file mode 100644 index 0000000..70664eb --- /dev/null +++ b/tests/data/test-qga-os-release @@ -0,0 +1,7 @@ +ID=qemu-ga-test +NAME=QEMU-GA +PRETTY_NAME="QEMU Guest Agent test" +VERSION="Test 1" +VERSION_ID=1 +VARIANT="Unit test \"\'\$\`\\ and \\\\ etc." +VARIANT_ID=unit-test diff --git a/tests/test-qga.c b/tests/test-qga.c index 631b986..06783e7 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -936,6 +936,60 @@ static void test_qga_guest_exec_invalid(gconstpointer fix) QDECREF(ret); } +static void test_qga_guest_get_osinfo(gconstpointer data) +{ + TestFixture fixture; + const gchar *str; + gchar *cwd, *env[2]; + QDict *ret, *val; + + cwd = g_get_current_dir(); + env[0] = g_strdup_printf( + "QGA_OS_RELEASE=%s%ctests%cdata%ctest-qga-os-release", + cwd, G_DIR_SEPARATOR, G_DIR_SEPARATOR, G_DIR_SEPARATOR); + env[1] = NULL; + g_free(cwd); + fixture_setup(&fixture, NULL, env); + + ret = qmp_fd(fixture.fd, "{'execute': 'guest-get-osinfo'}"); + g_assert_nonnull(ret); + qmp_assert_no_error(ret); + + val = qdict_get_qdict(ret, "return"); + + str = qdict_get_try_str(val, "id"); + g_assert_nonnull(str); + g_assert_cmpstr(str, ==, "qemu-ga-test"); + + str = qdict_get_try_str(val, "name"); + g_assert_nonnull(str); + g_assert_cmpstr(str, ==, "QEMU-GA"); + + str = qdict_get_try_str(val, "pretty-name"); + g_assert_nonnull(str); + g_assert_cmpstr(str, ==, "QEMU Guest Agent test"); + + str = qdict_get_try_str(val, "version"); + g_assert_nonnull(str); + g_assert_cmpstr(str, ==, "Test 1"); + + str = qdict_get_try_str(val, "version-id"); + g_assert_nonnull(str); + g_assert_cmpstr(str, ==, "1"); + + str = qdict_get_try_str(val, "variant"); + g_assert_nonnull(str); + g_assert_cmpstr(str, ==, "Unit test \"'$`\\ and \\\\ etc."); + + str = qdict_get_try_str(val, "variant-id"); + g_assert_nonnull(str); + g_assert_cmpstr(str, ==, "unit-test"); + + QDECREF(ret); + g_free(env[0]); + fixture_tear_down(&fixture, NULL); +} + int main(int argc, char **argv) { TestFixture fix; @@ -972,6 +1026,8 @@ int main(int argc, char **argv) g_test_add_data_func("/qga/guest-exec", &fix, test_qga_guest_exec); g_test_add_data_func("/qga/guest-exec-invalid", &fix, test_qga_guest_exec_invalid); + g_test_add_data_func("/qga/guest-get-osinfo", &fix, + test_qga_guest_get_osinfo); if (g_getenv("QGA_TEST_SIDE_EFFECTING")) { g_test_add_data_func("/qga/fsfreeze-and-thaw", &fix,