From nobody Wed May 8 16:06:55 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 1499082278723834.240603103835; Mon, 3 Jul 2017 04:44:38 -0700 (PDT) Received: from localhost ([::1]:34138 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dRzmP-0007W8-Fo for importer@patchew.org; Mon, 03 Jul 2017 07:44:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51112) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dRzir-0004VH-Qv for qemu-devel@nongnu.org; Mon, 03 Jul 2017 07:41:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dRzin-0004ii-5D for qemu-devel@nongnu.org; Mon, 03 Jul 2017 07:40:57 -0400 Received: from mail-wm0-f44.google.com ([74.125.82.44]:35078) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dRzim-0004hd-QK for qemu-devel@nongnu.org; Mon, 03 Jul 2017 07:40:53 -0400 Received: by mail-wm0-f44.google.com with SMTP id w126so165639585wme.0 for ; Mon, 03 Jul 2017 04:40:52 -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 v144sm16030731wmv.27.2017.07.03.04.40.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Jul 2017 04:40:49 -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=+0mvyLFcUCkuzrrNg5+6v+Z3gWyXOEj+HFqfJLdTEZg=; b=lwizPQxh4JK39xxp/cEg6nt6x3E33yxfeeFUq+g7bSYAz4wixHP7nOTfxLVq3zmQgT 0ltzi1RTNllpRos1lG02HZ8SxT3zWKCkdpgmoMAP5nWiN16EO8vDQwhXh85ZD92fvWnV Am/rjC6jUc/eN8th1hr+ldiKcPE3P5kItRtw345BJsfIPAYQ9BApI1/7iYu1itUly9e3 iS/HKnaSMQYCOnFD1KCl4jtRqeO1OVfA02QKwrHxSr1RjsXXyzucrelDvL7nl2EBB+X7 5RcqOQVram1XSeVJdwcfIZlkEXV59jVup30oc9+f2fDbbXqdvzl01iOA6zCPSHwa0C+t O0KQ== X-Gm-Message-State: AKS2vOwLRxyFhx19iNw9WK4J3tk60GKU45cSOzi9iS0ATCNSPNebN66n oBtmNJ9yj5rt5bbU X-Received: by 10.28.236.83 with SMTP id k80mr15115178wmh.52.1499082051475; Mon, 03 Jul 2017 04:40:51 -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: Mon, 3 Jul 2017 13:40:46 +0200 Message-Id: <28c65c91c4d63f1fe3bf69e7a70494af4b72b7e1.1499082038.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.44 Subject: [Qemu-devel] [PATCH v7 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..7a933a5f12 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 there */ + 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_NONE, + &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..e471f5561b 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=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 Wed May 8 16:06:55 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 1499082155924399.7644850106368; Mon, 3 Jul 2017 04:42:35 -0700 (PDT) Received: from localhost ([::1]:34130 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dRzkP-0005Sf-JA for importer@patchew.org; Mon, 03 Jul 2017 07:42:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51115) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dRzit-0004WE-66 for qemu-devel@nongnu.org; Mon, 03 Jul 2017 07:41:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dRzio-0004jV-9x for qemu-devel@nongnu.org; Mon, 03 Jul 2017 07:40:59 -0400 Received: from mail-wm0-f42.google.com ([74.125.82.42]:37084) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dRzio-0004j2-3D for qemu-devel@nongnu.org; Mon, 03 Jul 2017 07:40:54 -0400 Received: by mail-wm0-f42.google.com with SMTP id i127so105574014wma.0 for ; Mon, 03 Jul 2017 04:40:53 -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 v144sm16030731wmv.27.2017.07.03.04.40.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Jul 2017 04:40:51 -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=b34N6ysNt61j7Fjw6EP1lBTnJrQzuswke3F0RlNlLl/P7Tsh4vQb7mpxyDRyiClfZC +8xnJdEhz6FW/LIIEx+FSRA4UvCqxqJfKczAur2pQR/WNPs2rNGi4gWtgqgkUNbrxSFr CmOYs6966ngT8phYXIa7LnmMbJqQF63+xOJq/mhER7KO9YXPc2XgXdBYRMOGpYzohc6Y bLJH3wYl0DYdFEQFihz/uzcuq6FOS0bGmg1hiifqlG/RjJBuczpzSy/RmYoLUoPQyP6/ 593CdOsCiDBNd1mPsJ79mD1AXYGWySmf08SnhWXeotZ+SZoIUWb/7kOCpF+WlqJSqNxK Wb8g== X-Gm-Message-State: AIVw111+XEeh9sGtmPL/QYvsZSxJfsOQlZ+NTAeiwvumGX6E7QOhlhaB 9WKH+ess8XB6eG5z X-Received: by 10.28.140.84 with SMTP id o81mr3829806wmd.76.1499082052881; Mon, 03 Jul 2017 04:40:52 -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: Mon, 3 Jul 2017 13:40:47 +0200 Message-Id: <217e64d171636218b61c41f1f70e72cdb40f9144.1499082038.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.42 Subject: [Qemu-devel] [PATCH v7 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 Wed May 8 16:06:55 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 1499082274638861.5490492381101; Mon, 3 Jul 2017 04:44:34 -0700 (PDT) Received: from localhost ([::1]:34137 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dRzmL-0007S0-FI for importer@patchew.org; Mon, 03 Jul 2017 07:44:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51131) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dRziu-0004Xu-TW for qemu-devel@nongnu.org; Mon, 03 Jul 2017 07:41:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dRzip-0004kM-W8 for qemu-devel@nongnu.org; Mon, 03 Jul 2017 07:41:00 -0400 Received: from mail-wm0-f45.google.com ([74.125.82.45]:37101) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dRzip-0004jt-PF for qemu-devel@nongnu.org; Mon, 03 Jul 2017 07:40:55 -0400 Received: by mail-wm0-f45.google.com with SMTP id i127so105574751wma.0 for ; Mon, 03 Jul 2017 04:40:55 -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 v144sm16030731wmv.27.2017.07.03.04.40.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Jul 2017 04:40:53 -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=L8X3FMeuCK0YB0DDzFa3RSGRUwHjuahCzArEf+sJE60=; b=FxfFRjQT2ms4q0PEGlwarQXOXAl/6W2vA6lDkPBqNjuijflg0FFm9eU6CIS4HOXut+ sHmhvmQgn5IU67TSCe/kF8DcDGT27OIKDcC5t9V/+Tso6xsFP/+mMJbNFwgkYqlOtJcC bqceo6cEeY4ObZWTzupK3A4fLrJm452cEEDovgQTOToOtLeOfwziwCHYiPD38e0cNcRi o+K+MGTXvk86N864JvqpBQ2SKRqxe1mipwshikdN6LdGL1hYITYbtDplXBiCOAHCr5mU tAJYCZEkIEY4BANs8uQ8RPKjvrJL3s/YDrpM5rXmeaTORndRqFat2eD4uYg3BGN8pKZV LPVw== X-Gm-Message-State: AKS2vOz/gv1+hW/qgN5FMUWw5DOIxSYYN/QvnhLKj9z9DINiDjolJas0 kvuMcd3RyMkANxnF X-Received: by 10.28.238.5 with SMTP id m5mr23111515wmh.86.1499082054649; Mon, 03 Jul 2017 04:40:54 -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: Mon, 3 Jul 2017 13:40:48 +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.45 Subject: [Qemu-devel] [PATCH v7 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 | 55 ++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 72 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 7a933a5f12..16b18c96ef 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/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..c151dfdc34 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -936,6 +936,59 @@ 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 +1025,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