From nobody Sun Apr 28 16:04:19 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.zohomail.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 1500042727002896.5566536909641; Fri, 14 Jul 2017 07:32:07 -0700 (PDT) Received: from localhost ([::1]:38325 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW1dT-0001Sx-Mc for importer@patchew.org; Fri, 14 Jul 2017 10:32:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51811) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW1ae-0007Ks-JN for qemu-devel@nongnu.org; Fri, 14 Jul 2017 10:29:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dW1aZ-0000FK-Qj for qemu-devel@nongnu.org; Fri, 14 Jul 2017 10:29:08 -0400 Received: from mail-wm0-f54.google.com ([74.125.82.54]:36587) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dW1aZ-0000Es-Gf for qemu-devel@nongnu.org; Fri, 14 Jul 2017 10:29:03 -0400 Received: by mail-wm0-f54.google.com with SMTP id 62so22128583wmw.1 for ; Fri, 14 Jul 2017 07:29:03 -0700 (PDT) Received: from fiorina.brq.redhat.com (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id k12sm8643618wrc.10.2017.07.14.07.29.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Jul 2017 07:29:00 -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=URyjvc0TnaQXEZxzR1U1f8nwkXvjZ1ZD7nu0ZW4gBU4=; b=Avq/9FcUWZmKoGNqHy02AiTV0JwBtyx0ti3+d/9+6HElE5kJ5LZPB4yD2Z2Aj2McIu NUyBRr72ysYFdFZOyLA1hQ3VrWbQYGIAnysOM54e7FsJdM9bGBJ5qE64AV65LLE9V1Ip mrnWx+HwqycPLnknq5T/2xbP2dth+f6HG40HAicgXjnyuRTEeDJpz3H5uxQH2pZTyp7Y vfptNQ0YJe9sWw2p5562WSMHiwfyuBgDvqsbcb6RGiaqmwCCWwWCPfeM7cjYFmRz+i/A KPepPyGZQFz3lDZbA/P1aaeJnrBs2teHBGKjc3svd1oqFq95XMFHS8EqFXMkaN5VsIIG xwIg== X-Gm-Message-State: AIVw112eE6lDtbrZOV0AgCKUgRrjfeyp6KelrEUDzOjnxqGJ+dtri9Q5 JTUGilLgt64d+TBb X-Received: by 10.28.33.66 with SMTP id h63mr3239262wmh.124.1500042542267; Fri, 14 Jul 2017 07:29:02 -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: Fri, 14 Jul 2017 16:28:56 +0200 Message-Id: <0f09fb60283c05eb6d75e5d31b8ecb43a3fe2e7e.1500042528.git.tgolembi@redhat.com> 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.54 Subject: [Qemu-devel] [PATCH v8 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 | 134 ++++++++++++++++++++++++++++++++++++ qga/commands-win32.c | 188 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ qga/qapi-schema.json | 65 ++++++++++++++++++ 3 files changed, 387 insertions(+) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index d8e412275e..fdb850db2f 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,136 @@ 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 there */ + p--; + break; + } + } else if (*p =3D=3D quote) { + *p2 =3D 0; + break; + } + *(p2++) =3D *(p++); + } +} + +static GKeyFile *ga_parse_osrelease(const char *fname) +{ + gchar *content =3D NULL; + gchar *content2 =3D NULL; + GError *err =3D NULL; + GKeyFile *keys =3D g_key_file_new(); + const char *group =3D "[os-release]\n"; + + if (!g_file_get_contents(fname, &content, NULL, &err)) { + slog("failed to read '%s', error: %s", fname, err->message); + goto fail; + } + + if (!g_utf8_validate(content, -1, NULL)) { + slog("file is not utf-8 encoded: %s", fname); + goto fail; + } + content2 =3D g_strdup_printf("%s%s", group, content); + + if (!g_key_file_load_from_data(keys, content2, -1, G_KEY_FILE_NONE, + &err)) { + 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 NULL; + struct utsname kinfo =3D {0}; + + info =3D g_new0(GuestOSInfo, 1); + + if (uname(&kinfo) !=3D 0) { + error_setg_errno(errp, errno, "uname failed"); + } else { + info->has_kernel_version =3D true; + info->kernel_version =3D g_strdup(kinfo.version); + info->has_kernel_release =3D true; + info->kernel_release =3D g_strdup(kinfo.release); + info->has_machine =3D true; + info->machine =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 6f1645747b..524c71bdb4 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -1642,3 +1642,191 @@ 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=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->has_kernel_version =3D true; + info->kernel_version =3D g_strdup_printf("%lu.%lu", + os_version.dwMajorVersion, + os_version.dwMinorVersion); + info->has_kernel_release =3D true; + info->kernel_release =3D g_strdup_printf("%lu", + os_version.dwBuildNumber); + info->has_machine =3D true; + info->machine =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..90a0c8602b 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: +# * POSIX: machine field returned by uname(2) +# * Windows: one of x86, x86_64, arm, ia64 +# @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 2008" +# @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': '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 Sun Apr 28 16:04:19 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.zohomail.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 1500042641520673.8636776402341; Fri, 14 Jul 2017 07:30:41 -0700 (PDT) Received: from localhost ([::1]:38320 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW1c4-0000Pc-2Y for importer@patchew.org; Fri, 14 Jul 2017 10:30:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51820) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW1ag-0007Ov-Ra for qemu-devel@nongnu.org; Fri, 14 Jul 2017 10:29:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dW1ab-0000GH-Qj for qemu-devel@nongnu.org; Fri, 14 Jul 2017 10:29:10 -0400 Received: from mail-wm0-f49.google.com ([74.125.82.49]:35737) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dW1ab-0000Ft-KN for qemu-devel@nongnu.org; Fri, 14 Jul 2017 10:29:05 -0400 Received: by mail-wm0-f49.google.com with SMTP id w126so22193883wme.0 for ; Fri, 14 Jul 2017 07:29:05 -0700 (PDT) Received: from fiorina.brq.redhat.com (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id k12sm8643618wrc.10.2017.07.14.07.29.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Jul 2017 07:29:02 -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=MjNq1OjaxzbTBop8ojQkybEUQSYyiuDuLpyGdeMYfTo=; b=Mlt2zHIIsSYHA2PeIOhSW/f/QH5VCMckauDIVuqKtJsO+tTvhuw28lH2H4ITZRnOtG b4evwHu7vsZvNfZIZrUX20xSNUYAyUuOqW/OYRFU0y58zn0vngIcyweWZxW9dLrhLaOG 4j417XtlCBy1L63nCa7tRBndwtMe7AuCnl8A2YKMaSNLMh1mPtAbX1K26drWIkcbNIvG WtS8FjEvx3xAsIm1KReNaHtb4/jy0l9ktNnZEW3Mqo4ybIcwlRYb+pQQtlJe5JHod5vg BpgbzPxwZx9vKVolMZhigArQfmLxIDK5BkM9giGnra5mOiX2SGB7kuoSeXW5EqBHHLLL KP1A== X-Gm-Message-State: AIVw113Q9RauDhgywBWEdrXgZrd9i8tpxby0/1c3npld9RfRgAgHx0un ArzeUUmm5fDr4mwQ X-Received: by 10.28.17.78 with SMTP id 75mr3176899wmr.63.1500042544513; Fri, 14 Jul 2017 07:29:04 -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: Fri, 14 Jul 2017 16:28:57 +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.49 Subject: [Qemu-devel] [PATCH v8 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 Reviewed-by: Marc-Andr=C3=A9 Lureau --- 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 Sun Apr 28 16:04:19 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.zohomail.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 1500042639509922.3026612883284; Fri, 14 Jul 2017 07:30:39 -0700 (PDT) Received: from localhost ([::1]:38321 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW1c4-0000QB-As for importer@patchew.org; Fri, 14 Jul 2017 10:30:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51821) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW1ag-0007Ow-Rr for qemu-devel@nongnu.org; Fri, 14 Jul 2017 10:29:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dW1ad-0000HL-KF for qemu-devel@nongnu.org; Fri, 14 Jul 2017 10:29:10 -0400 Received: from mail-wm0-f49.google.com ([74.125.82.49]:38370) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dW1ad-0000Gx-Dc for qemu-devel@nongnu.org; Fri, 14 Jul 2017 10:29:07 -0400 Received: by mail-wm0-f49.google.com with SMTP id f67so24437216wmh.1 for ; Fri, 14 Jul 2017 07:29:07 -0700 (PDT) Received: from fiorina.brq.redhat.com (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id k12sm8643618wrc.10.2017.07.14.07.29.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Jul 2017 07:29:05 -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=tYQFUT7ChWezoFApGVJU/fZORkYdnrC2GqXNB9wwkj8=; b=eEbnSUbDiEqMcEeVJLq3nFVvEAK6FvpAcj71tb55ttbcv0Ad/I+Q4JEa+RcBNd9S5N kmMBySp6ZL3szdFMpQDvxJMZ9F2Nmzp2ofTiKIWBoLTFwPLnhrsrLy3sVVOEMPGqI1da 0gxZ18bunVjmpzyDLnq4cEdvzm96f/th0eHpToQAO3dyPXTY/37Y3N+BQCfOIl0dYQhn 7janM0mEq/7isE5NYYJVEydxobPeVe0mtCeCVZFZ+2PnzWH1Ys4yeJzYRamIC0FLgUUB z1K2va+MKVM1Dv/q+D1wEO1q7e285xtdxGrSC/o02ISYug4RyMiEYTPUC4NC2yn04ecX SRdQ== X-Gm-Message-State: AIVw1118IGC/XZNDAjq92LXGcsaOR1KAhDCfOcD/L+dEckGiPVezfzR/ RkK/BVkgqNYnPlWJrmnYrg== X-Received: by 10.28.111.215 with SMTP id c84mr2977615wmi.72.1500042546445; Fri, 14 Jul 2017 07:29:06 -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: Fri, 14 Jul 2017 16:28:58 +0200 Message-Id: <215c43ac1fed2d4e74caf8ade220a6769fbd5f9e.1500042528.git.tgolembi@redhat.com> 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.49 Subject: [Qemu-devel] [PATCH v8 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 Reviewed-by: Marc-Andr=C3=A9 Lureau --- qga/commands-posix.c | 13 +++++++--- tests/data/test-qga-os-release | 7 ++++++ tests/test-qga.c | 56 ++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 tests/data/test-qga-os-release diff --git a/qga/commands-posix.c b/qga/commands-posix.c index fdb850db2f..8404a68b38 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2667,6 +2667,8 @@ GuestOSInfo *qmp_guest_get_osinfo(Error **errp) { GuestOSInfo *info =3D NULL; struct utsname kinfo =3D {0}; + GKeyFile *osrelease =3D NULL; + =20 info =3D g_new0(GuestOSInfo, 1); =20 @@ -2681,9 +2683,14 @@ GuestOSInfo *qmp_guest_get_osinfo(Error **errp) info->machine =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"); + 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/data/test-qga-os-release b/tests/data/test-qga-os-release new file mode 100644 index 0000000000..70664eb6ec --- /dev/null +++ b/tests/data/test-qga-os-release @@ -0,0 +1,7 @@ +ID=3Dqemu-ga-test +NAME=3DQEMU-GA +PRETTY_NAME=3D"QEMU Guest Agent test" +VERSION=3D"Test 1" +VERSION_ID=3D1 +VARIANT=3D"Unit test \"\'\$\`\\ and \\\\ etc." +VARIANT_ID=3Dunit-test diff --git a/tests/test-qga.c b/tests/test-qga.c index 631b98639a..06783e7585 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); } =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]); + 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); =20 if (g_getenv("QGA_TEST_SIDE_EFFECTING")) { g_test_add_data_func("/qga/fsfreeze-and-thaw", &fix, --=20 2.13.1