From nobody Mon Apr 29 15:17:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498771708487908.4010560060528; Thu, 29 Jun 2017 14:28:28 -0700 (PDT) Received: from localhost ([::1]:41324 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQgzD-0004mV-36 for importer@patchew.org; Thu, 29 Jun 2017 17:28:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56148) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQgy4-0004Ch-KH for qemu-devel@nongnu.org; Thu, 29 Jun 2017 17:27:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQgxz-0000uH-UF for qemu-devel@nongnu.org; Thu, 29 Jun 2017 17:27:16 -0400 Received: from mail-wm0-f46.google.com ([74.125.82.46]:38326) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQgxz-0000ti-KS for qemu-devel@nongnu.org; Thu, 29 Jun 2017 17:27:11 -0400 Received: by mail-wm0-f46.google.com with SMTP id b184so27670539wme.1 for ; Thu, 29 Jun 2017 14:27:11 -0700 (PDT) Received: from localhost.localdomain (ip-78-45-140-98.net.upcbroadband.cz. [78.45.140.98]) by smtp.gmail.com with ESMTPSA id 21sm11395020wmo.16.2017.06.29.14.27.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Jun 2017 14:27:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p1+Q57Y2GN3cfW1yeCMj9W6cJ70FcJrC5zn5LhY7BYc=; b=CbxdOK4CYFGAri1mSIZYsBLpm5fm9ux3S/AkDwvoz8ajzCI/j/kivZ9liPbIu7yQ8o kJiBOi1m1/HlyA532UKUZYjhYiTJre+St1ubUuqLWpArRkkuMSJFSinnrsaQP6TfiY1g LiPiuA/0FE9EcU4c8BDge20sSVqRZyklxLB8O+jfMCnWhnxIKiWq552KM+Ky3uivkv3n 4XZN6zievg10F7FNaXeHf9dTm6UjhSf/vNGhCuN38EB5hv+XrvZjojZArETdPpK3giNu pjwBqmjRL3GpNBYhMMW1zuu5NrOaMl2PnzoFRA/T99lLaj2xuneIS9ZHwSEyUeDAwBYG mJ2A== X-Gm-Message-State: AKS2vOxQ1xtXezrNQW2+wmagTjAMhCP3Wl8ZTu+WtzgRxjIlBTwbou+p 963Rt9rgB38ESt5B X-Received: by 10.28.88.3 with SMTP id m3mr13243560wmb.28.1498771630466; Thu, 29 Jun 2017 14:27:10 -0700 (PDT) From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= To: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eric Blake , Michael Roth , Vinzenz 'evilissimo' Feenstra Date: Thu, 29 Jun 2017 23:27:04 +0200 Message-Id: X-Mailer: git-send-email 2.13.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.46 Subject: [Qemu-devel] [PATCH v6 1/3] qemu-ga: add guest-get-osinfo command 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: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Add a new 'guest-get-osinfo' command for reporting basic information of the guest operating system. This includes machine architecture, version and release of the kernel and several fields from os-release file if it is present (as defined in [1]). [1] https://www.freedesktop.org/software/systemd/man/os-release.html Signed-off-by: Vinzenz Feenstra Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD --- qga/commands-posix.c | 136 +++++++++++++++++++++++++++++++++++++ qga/commands-win32.c | 185 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ qga/qapi-schema.json | 65 ++++++++++++++++++ 3 files changed, 386 insertions(+) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index d8e412275e..2406518d47 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -13,6 +13,7 @@ =20 #include "qemu/osdep.h" #include +#include #include #include #include @@ -2577,3 +2578,138 @@ GuestUserList *qmp_guest_get_users(Error **err) g_hash_table_destroy(cache); return head; } + +/* Replace escaped special characters with theire real values. The replace= ment + * is done in place -- returned value is in the original string. + */ +static void ga_osrelease_replace_special(gchar *value) +{ + gchar *p, *p2, quote; + + /* Trim the string at first space or semicolon if it is not enclosed in + * single or double quotes. */ + if ((value[0] !=3D '"') || (value[0] =3D=3D '\'')) { + p =3D strchr(value, ' '); + if (p !=3D NULL) { + *p =3D 0; + } + p =3D strchr(value, ';'); + if (p !=3D NULL) { + *p =3D 0; + } + return; + } + + quote =3D value[0]; + p2 =3D value; + p =3D value+1; + while (*p !=3D 0) { + if (*p =3D=3D '\\') { + p++; + switch (*p) { + case '$': + case '\'': + case '"': + case '\\': + case '`': + break; + default: + /* Keep literal backslash followed by whatever is ther= e */ + p--; + break; + } + } else if (*p =3D=3D quote) { + *p2 =3D 0; + break; + } + *(p2++) =3D *(p++); + } +} + +static GKeyFile *ga_parse_osrelease(const char *fname) +{ + gboolean ret; + gchar *content =3D NULL; + gchar *content2 =3D NULL; + gsize len; + GError *err =3D NULL; + GKeyFile *keys =3D g_key_file_new(); + const char *group =3D "[os-release]\n"; + + ret =3D g_file_get_contents(fname, &content, &len, &err); + if (ret !=3D TRUE) { + slog("failed to read '%s', error: %s", fname, err->message); + goto fail; + } + + ret =3D g_utf8_validate(content, len, NULL); + if (ret !=3D TRUE) { + slog("file is not utf-8 encoded: %s", fname); + goto fail; + } + content2 =3D g_strdup_printf("%s%s", group, content); + len +=3D strlen(group); + + ret =3D g_key_file_load_from_data (keys, content2, len, G_KEY_FILE_NON= E, + &err); + if (ret !=3D TRUE) { + slog("failed to parse file '%s', error: %s", fname, err->message); + goto fail; + } + + g_free(content); + g_free(content2); + return keys; + +fail: + g_error_free(err); + g_free(content); + g_free(content2); + g_key_file_free(keys); + return NULL; +} + +GuestOSInfo *qmp_guest_get_osinfo(Error **errp) +{ + GuestOSInfo *info =3D g_new0(GuestOSInfo, 1); + + struct utsname kinfo =3D {0}; + if (uname(&kinfo) !=3D 0) { + error_setg_errno(errp, errno, "uname failed"); + return NULL; + } + + info->kernel_version =3D g_strdup(kinfo.version); + info->kernel_release =3D g_strdup(kinfo.release); + info->machine_hardware =3D g_strdup(kinfo.machine); + + GKeyFile *osrelease =3D ga_parse_osrelease("/etc/os-release"); + if (osrelease =3D=3D NULL) { + osrelease =3D ga_parse_osrelease("/usr/lib/os-release"); + } + + if (osrelease !=3D NULL) { + char *value; + +#define GET_FIELD(field, osfield) do { \ + value =3D g_key_file_get_value(osrelease, "os-release", osfield, NULL)= ; \ + if (value !=3D NULL) { \ + ga_osrelease_replace_special(value); \ + info->has_ ## field =3D true; \ + info->field =3D value; \ + } \ +} while (0) + GET_FIELD(id, "ID"); + GET_FIELD(name, "NAME"); + GET_FIELD(pretty_name, "PRETTY_NAME"); + GET_FIELD(version, "VERSION"); + GET_FIELD(version_id, "VERSION_ID"); + GET_FIELD(variant, "VARIANT"); + GET_FIELD(variant_id, "VARIANT_ID"); +#undef GET_FIELD + + g_key_file_free(osrelease); + } + + return info; +} diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 439d229225..a451c6e8dd 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -1639,3 +1639,188 @@ GuestUserList *qmp_guest_get_users(Error **err) return NULL; #endif } + +typedef struct _ga_matrix_lookup_t { + int major; + int minor; + char const *version; + char const *version_id; +} ga_matrix_lookup_t; + +static ga_matrix_lookup_t const WIN_VERSION_MATRIX[2][8] =3D { + { + /* Desktop editions */ + { 5, 0, "Microsoft Windows 2000", "2000"}, + { 5, 1, "Microsoft Windows XP", "xp"}, + { 6, 0, "Microsoft Windows Vista", "vista"}, + { 6, 1, "Microsoft Windows 7" "7"}, + { 6, 2, "Microsoft Windows 8", "8"}, + { 6, 3, "Microsoft Windows 8.1", "8.1"}, + {10, 0, "Microsoft Windows 10", "10"}, + { 0, 0, 0} + },{ + /* Server editions */ + { 5, 2, "Microsoft Windows Server 2003", "2003"}, + { 6, 0, "Microsoft Windows Server 2008", "2008"}, + { 6, 1, "Microsoft Windows Server 2008 R2", "2008r2"}, + { 6, 2, "Microsoft Windows Server 2012", "2012"}, + { 6, 3, "Microsoft Windows Server 2012 R2", "2012r2"}, + {10, 0, "Microsoft Windows Server 2016", "2016"}, + { 0, 0, 0}, + { 0, 0, 0} + } +}; + +static void ga_get_win_version(RTL_OSVERSIONINFOEXW *info, Error **errp) +{ + typedef NTSTATUS(WINAPI * rtl_get_version_t)( + RTL_OSVERSIONINFOEXW *os_version_info_ex); + + info->dwOSVersionInfoSize =3D sizeof(RTL_OSVERSIONINFOEXW); + + HMODULE module =3D GetModuleHandle("ntdll"); + PVOID fun =3D GetProcAddress(module, "RtlGetVersion"); + if (fun !=3D NULL) { + error_setg(errp, QERR_QGA_COMMAND_FAILED, + "Failed to get address of RtlGetVersion"); + return; + } + + rtl_get_version_t rtl_get_version =3D (rtl_get_version_t)fun; + rtl_get_version(info); + return; +} + +static char *ga_get_win_name(OSVERSIONINFOEXW const *os_version, bool id) +{ + DWORD major =3D os_version->dwMajorVersion; + DWORD minor =3D os_version->dwMinorVersion; + int tbl_idx =3D (os_version->wProductType !=3D VER_NT_WORKSTATION); + ga_matrix_lookup_t const *table =3D WIN_VERSION_MATRIX[tbl_idx]; + while (table->version !=3D NULL) { + if (major =3D=3D table->major && minor =3D=3D table->minor) { + if (id) { + return g_strdup(table->version_id); + } else { + return g_strdup(table->version); + } + } + ++table; + } + slog("failed to lookup Windows version: major=3D%lu, minor=3D%lu", + major, minor); + return g_strdup("N/A"); +} + +static char *ga_get_win_product_name(Error **errp) +{ + HKEY key =3D NULL; + DWORD size =3D 128; + char *result =3D g_malloc0(size); + LONG err =3D ERROR_SUCCESS; + + err =3D RegOpenKeyA(HKEY_LOCAL_MACHINE, + "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", + &key); + if (err !=3D ERROR_SUCCESS) { + error_setg_win32(errp, err, "failed to open registry key"); + goto fail; + } + + err =3D RegQueryValueExA(key, "ProductName", NULL, NULL, + (LPBYTE)result, &size); + if (err =3D=3D ERROR_MORE_DATA) { + slog("ProductName longer than expected (%lu bytes), retrying", + size); + g_free(result); + result =3D NULL; + if (size > 0) { + result =3D g_malloc0(size); + err =3D RegQueryValueExA(key, "ProductName", NULL, NULL, + (LPBYTE)result, &size); + } + } + if (err !=3D ERROR_SUCCESS) { + error_setg_win32(errp, err, "failed to retrive ProductName"); + goto fail; + } + + return result; + +fail: + g_free(result); + return NULL; +} + +static char *ga_get_current_arch(void) +{ + SYSTEM_INFO info; + GetNativeSystemInfo(&info); + char *result =3D NULL; + switch (info.wProcessorArchitecture) { + case PROCESSOR_ARCHITECTURE_AMD64: + result =3D g_strdup("x86_64"); + break; + case PROCESSOR_ARCHITECTURE_ARM: + result =3D g_strdup("arm"); + break; + case PROCESSOR_ARCHITECTURE_IA64: + result =3D g_strdup("ia64"); + break; + case PROCESSOR_ARCHITECTURE_INTEL: + result =3D g_strdup("x86"); + break; + case PROCESSOR_ARCHITECTURE_UNKNOWN: + default: + slog("unknown processor architecture 0x%0x", + info.wProcessorArchitecture); + result =3D g_strdup("unknown"); + break; + } + return result; +} + +GuestOSInfo *qmp_guest_get_osinfo(Error **errp) +{ + Error *local_err =3D NULL; + OSVERSIONINFOEXW os_version =3D {0}; + + ga_get_win_version(&os_version, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return NULL; + } + + bool server =3D os_version.wProductType !=3D VER_NT_WORKSTATION; + char *product_name =3D ga_get_win_product_name(&local_err); + if (product_name =3D=3D NULL) { + error_propagate(errp, local_err); + return NULL; + } + + GuestOSInfo *info =3D g_new0(GuestOSInfo, 1); + + info->kernel_version =3D g_strdup_printf("%lu.%lu", + os_version.dwMajorVersion, + os_version.dwMinorVersion); + info->kernel_release =3D g_strdup_printf("%lu", + os_version.dwBuildNumber); + info->machine_hardware =3D ga_get_current_arch(); + + info->has_id =3D true; + info->id =3D g_strdup("mswindows"); + info->has_name =3D true; + info->name =3D g_strdup("Microsoft Windows"); + info->has_pretty_name =3D true; + info->pretty_name =3D product_name; + info->has_version =3D true; + info->version =3D ga_get_win_name(&os_version, false); + info->has_version_id =3D true; + info->version_id =3D ga_get_win_name(&os_version, true); + info->has_variant =3D true; + info->variant =3D g_strdup(server ? "server" : "client"); + info->has_variant_id =3D true; + info->variant_id =3D g_strdup(server ? "server" : "client"); + + return info; +} diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index 03743ab905..3d9478c10b 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -1126,3 +1126,68 @@ ## { 'command': 'guest-get-timezone', 'returns': 'GuestTimezone' } + +## +# @GuestOSInfo: +# +# @kernel-release: +# * _POSIX:_ release field returned by uname(2) +# * _Windows:_ version number of the OS +# @kernel-version: +# * _POSIX:_ version field returned by uname(2) +# * _Windows:_ build number of the OS +# @machine-hardware: +# * _POSIX:_ machine field returned by uname(2) +# * _Windows:_ architecture of the hardware +# @id: +# * _POSIX:_ as defined by os-release(5) +# * _Windows:_ contains string "mswindows" +# @name: +# * _POSIX:_ as defined by os-release(5) +# * _Windows:_ contains string "Microsoft Windows" +# @pretty-name: +# * _POSIX:_ as defined by os-release(5) +# * _Windows:_ product name, e.g. "Microsoft Windows 10 Enterprise" +# @version: +# * _POSIX:_ as defined by os-release(5) +# * _Windows:_ long version string, e.g. "Microsoft Windows Server 200= 8" +# @version-id: +# * _POSIX:_ as defined by os-release(5) +# * _Windows:_ short version identifier, e.g. "7" or "20012r2" +# @variant: +# * _POSIX:_ as defined by os-release(5) +# * _Windows:_ contains string "server" or "client" +# @variant-id: +# * _POSIX:_ as defined by os-release(5) +# * _Windows:_ contains string "server" or "client" +# +# Notes: +# +# On POSIX systems the fields @id, @name, @pretty-name, @version, @version= -id, +# @variant and @variant-id follow the definition specified in os-release(5= ). +# Refer to the manual page for exact description of the fields. Their valu= es +# are taken from the os-release file. If the file is not present in the sy= stem, +# or the values are not present in the file, the fields are not included. +# +# On Windows the values are filled from information gathered from the syst= em. +# +# Since: 2.10 +## +{ 'struct': 'GuestOSInfo', + 'data': { + 'kernel-release': 'str', 'kernel-version': 'str', + 'machine-hardware': 'str', '*id': 'str', '*name': 'str', + '*pretty-name': 'str', '*version': 'str', '*version-id': 'str', + '*variant': 'str', '*variant-id': 'str' } } + +## +# @guest-get-osinfo: +# +# Retrieve guest operating system information +# +# Returns: @GuestOSInfo +# +# Since: 2.10 +## +{ 'command': 'guest-get-osinfo', + 'returns': 'GuestOSInfo' } --=20 2.13.1 From nobody Mon Apr 29 15:17:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149877178047941.52247821877609; Thu, 29 Jun 2017 14:29:40 -0700 (PDT) Received: from localhost ([::1]:41326 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQh0N-0006La-0C for importer@patchew.org; Thu, 29 Jun 2017 17:29:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56160) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQgy6-0004DA-RI for qemu-devel@nongnu.org; Thu, 29 Jun 2017 17:27:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQgy1-0000v2-S6 for qemu-devel@nongnu.org; Thu, 29 Jun 2017 17:27:18 -0400 Received: from mail-wm0-f50.google.com ([74.125.82.50]:37787) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQgy1-0000uh-La for qemu-devel@nongnu.org; Thu, 29 Jun 2017 17:27:13 -0400 Received: by mail-wm0-f50.google.com with SMTP id i127so27801057wma.0 for ; Thu, 29 Jun 2017 14:27:13 -0700 (PDT) Received: from localhost.localdomain (ip-78-45-140-98.net.upcbroadband.cz. [78.45.140.98]) by smtp.gmail.com with ESMTPSA id 21sm11395020wmo.16.2017.06.29.14.27.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Jun 2017 14:27:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FzrvlXqICsVGjhRMi4gOtBmZADHGRNWZWH5Q64FuglU=; b=Fc1SurmE4uxy446n54UOKlKWHl8k7+678kYLdy6AumWPo1Tz8bchX0Z0RScaO1D5xD bmhGXTIDoD39wZ37CTiVaDOaq2nE6oVLNR3NW9PHeuyospc71kXgdlspSVAEbOycAymR y9n/0P3Plh3Utif6evCVVKxJUNXfiJzbyhTv/mur/PEu2N1TZxAK+HA1SSUB31qvQx6m WNsZd1DT8DshLL8aHWgRaAPeFegeoZl4TEZWdCCF3rDtiOYFg+BlCAbKHo4IgKANx1+I Ejo9HnSxqyKpJaAd+oeMPZ1I03v6PWOsWXRAeiitLL8wNhqfbAO+b6bikaPUhEvUAGpI 2ypg== X-Gm-Message-State: AKS2vOwgx/QJ89luu7R5L0AI5fYsfDTlDvUHIhs4gAoHjlb54IZB0K4A seGpz5WZ1siCjw+C X-Received: by 10.28.24.213 with SMTP id 204mr3582846wmy.15.1498771632626; Thu, 29 Jun 2017 14:27:12 -0700 (PDT) From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= To: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eric Blake , Michael Roth , Vinzenz 'evilissimo' Feenstra Date: Thu, 29 Jun 2017 23:27:05 +0200 Message-Id: X-Mailer: git-send-email 2.13.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.50 Subject: [Qemu-devel] [PATCH v6 2/3] test-qga: pass environemnt to qemu-ga 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: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Modify fixture_setup() to pass environemnt variables to spawned qemu-ga instance. Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD --- tests/test-qga.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test-qga.c b/tests/test-qga.c index c77f241036..631b98639a 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -46,7 +46,7 @@ static void qga_watch(GPid pid, gint status, gpointer use= r_data) } =20 static void -fixture_setup(TestFixture *fixture, gconstpointer data) +fixture_setup(TestFixture *fixture, gconstpointer data, gchar **envp) { const gchar *extra_arg =3D data; GError *error =3D NULL; @@ -67,7 +67,7 @@ fixture_setup(TestFixture *fixture, gconstpointer data) g_shell_parse_argv(cmd, NULL, &argv, &error); g_assert_no_error(error); =20 - g_spawn_async(fixture->test_dir, argv, NULL, + g_spawn_async(fixture->test_dir, argv, envp, G_SPAWN_SEARCH_PATH|G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &fixture->pid, &error); g_assert_no_error(error); @@ -707,7 +707,7 @@ static void test_qga_blacklist(gconstpointer data) QDict *ret, *error; const gchar *class, *desc; =20 - fixture_setup(&fix, "-b guest-ping,guest-get-time"); + fixture_setup(&fix, "-b guest-ping,guest-get-time", NULL); =20 /* check blacklist */ ret =3D qmp_fd(fix.fd, "{'execute': 'guest-ping'}"); @@ -943,7 +943,7 @@ int main(int argc, char **argv) =20 setlocale (LC_ALL, ""); g_test_init(&argc, &argv, NULL); - fixture_setup(&fix, NULL); + fixture_setup(&fix, NULL, NULL); =20 g_test_add_data_func("/qga/sync-delimited", &fix, test_qga_sync_delimi= ted); g_test_add_data_func("/qga/sync", &fix, test_qga_sync); --=20 2.13.1 From nobody Mon Apr 29 15:17:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498771843007660.3088785408374; Thu, 29 Jun 2017 14:30:43 -0700 (PDT) Received: from localhost ([::1]:41333 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQh1M-0006x2-ME for importer@patchew.org; Thu, 29 Jun 2017 17:30:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56170) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQgy9-0004Eu-4I for qemu-devel@nongnu.org; Thu, 29 Jun 2017 17:27:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQgy4-0000w4-4c for qemu-devel@nongnu.org; Thu, 29 Jun 2017 17:27:21 -0400 Received: from mail-wm0-f53.google.com ([74.125.82.53]:37801) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQgy3-0000vc-US for qemu-devel@nongnu.org; Thu, 29 Jun 2017 17:27:16 -0400 Received: by mail-wm0-f53.google.com with SMTP id i127so27801831wma.0 for ; Thu, 29 Jun 2017 14:27:15 -0700 (PDT) Received: from localhost.localdomain (ip-78-45-140-98.net.upcbroadband.cz. [78.45.140.98]) by smtp.gmail.com with ESMTPSA id 21sm11395020wmo.16.2017.06.29.14.27.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Jun 2017 14:27:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JbdylOcHm832V6h+l5GFyqBkqi7I39Ff3bO6dI1XUzY=; b=CS20q0wKHw+V/Qxy7++gDkXEwhYPHtj97VKMn0uWK7GuaC/a+Iq0MUAVVZM9onDrMK ngKOZxgz1N0501cX6IPfBSCz+7TqwOIVC4hRel5l3ztw2K94NcOcxG88+dV5dcLaKtCF zPnx1oLM+znBxxW0ILHtFxkY41/nZ45RCKouyRRakgyY4ljqh5pVjerPf60s+c/Ip255 +dWsHa/hMtVi/ErVn3iil8MmOtzJvji+6rrilt2lDaAytILPBacpp9YQ9yNzCCETxgto wi5VWM5Ba2SyhD9mpb6ABVCSqzI+X62hQpUFSZLeRf42h+Jydi90wSSwKOSmE6kGIciH MTZw== X-Gm-Message-State: AKS2vOxFN+m+RWseWHr6Hq6nW5/wiqW+7gkslJ2NxYNPZ7CSxE2QVev3 ZtH6gzeTT2Ei346K X-Received: by 10.28.180.70 with SMTP id d67mr3586739wmf.121.1498771634871; Thu, 29 Jun 2017 14:27:14 -0700 (PDT) From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= To: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eric Blake , Michael Roth , Vinzenz 'evilissimo' Feenstra Date: Thu, 29 Jun 2017 23:27:06 +0200 Message-Id: X-Mailer: git-send-email 2.13.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.53 Subject: [Qemu-devel] [PATCH v6 3/3] 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: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 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=C3=A1=C5=A1 Golembiovsk=C3=BD --- qga/commands-posix.c | 13 ++++++++++--- tests/test-qga.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 2406518d47..f6ce8dd583 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2683,9 +2683,16 @@ GuestOSInfo *qmp_guest_get_osinfo(Error **errp) info->kernel_release =3D g_strdup(kinfo.release); info->machine_hardware =3D g_strdup(kinfo.machine); =20 - GKeyFile *osrelease =3D ga_parse_osrelease("/etc/os-release"); - if (osrelease =3D=3D NULL) { - osrelease =3D ga_parse_osrelease("/usr/lib/os-release"); + GKeyFile *osrelease =3D NULL; + + const char *qga_os_release =3D g_getenv("QGA_OS_RELEASE"); + if (qga_os_release !=3D NULL) { + osrelease =3D ga_parse_osrelease(qga_os_release); + } else { + osrelease =3D ga_parse_osrelease("/etc/os-release"); + if (osrelease =3D=3D NULL) { + osrelease =3D ga_parse_osrelease("/usr/lib/os-release"); + } } =20 if (osrelease !=3D NULL) { diff --git a/tests/test-qga.c b/tests/test-qga.c index 631b98639a..b9160708a0 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -936,6 +936,58 @@ static void test_qga_guest_exec_invalid(gconstpointer = fix) QDECREF(ret); } =20 +static void test_qga_guest_get_osinfo(gconstpointer data) +{ + TestFixture fixture; + const gchar *str; + gchar *cwd, *env[2]; + QDict *ret, *val; + + cwd =3D g_get_current_dir(); + env[0] =3D g_strdup_printf("QGA_OS_RELEASE=3D%s%ctests%cdata%ctest-qga= -os-release", + cwd, G_DIR_SEPARATOR, G_DIR_SEPARATOR, G_DIR_= SEPARATOR); + env[1] =3D NULL; + g_free(cwd); + fixture_setup(&fixture, NULL, env); + + ret =3D qmp_fd(fixture.fd, "{'execute': 'guest-get-osinfo'}"); + g_assert_nonnull(ret); + qmp_assert_no_error(ret); + + val =3D qdict_get_qdict(ret, "return"); + + str =3D qdict_get_try_str(val, "id"); + g_assert_nonnull(str); + g_assert_cmpstr(str, =3D=3D, "qemu-ga-test"); + + str =3D qdict_get_try_str(val, "name"); + g_assert_nonnull(str); + g_assert_cmpstr(str, =3D=3D, "QEMU-GA"); + + str =3D qdict_get_try_str(val, "pretty-name"); + g_assert_nonnull(str); + g_assert_cmpstr(str, =3D=3D, "QEMU Guest Agent test"); + + str =3D qdict_get_try_str(val, "version"); + g_assert_nonnull(str); + g_assert_cmpstr(str, =3D=3D, "Test 1"); + + str =3D qdict_get_try_str(val, "version-id"); + g_assert_nonnull(str); + g_assert_cmpstr(str, =3D=3D, "1"); + + str =3D qdict_get_try_str(val, "variant"); + g_assert_nonnull(str); + g_assert_cmpstr(str, =3D=3D, "Unit test \"'$`\\ and \\\\ etc."); + + str =3D qdict_get_try_str(val, "variant-id"); + g_assert_nonnull(str); + g_assert_cmpstr(str, =3D=3D, "unit-test"); + + QDECREF(ret); + g_free(env[0]); +} + int main(int argc, char **argv) { TestFixture fix; @@ -972,6 +1024,7 @@ 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); =20 if (g_getenv("QGA_TEST_SIDE_EFFECTING")) { g_test_add_data_func("/qga/fsfreeze-and-thaw", &fix, --=20 2.13.1