|
|
46bd62 |
From e3bfadeaac6a46966becef50302e2ad797c1977a Mon Sep 17 00:00:00 2001
|
|
|
46bd62 |
From: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
46bd62 |
Date: Thu, 19 Apr 2018 12:33:48 -0300
|
|
|
46bd62 |
Subject: [PATCH 7/7] test-qga: add test for guest-get-osinfo
|
|
|
46bd62 |
MIME-Version: 1.0
|
|
|
46bd62 |
Content-Type: text/plain; charset=UTF-8
|
|
|
46bd62 |
Content-Transfer-Encoding: 8bit
|
|
|
46bd62 |
|
|
|
46bd62 |
RH-Author: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
46bd62 |
Message-id: <4fbd9f39de7c623e464fe5a2fe36b6aa254218ac.1524139831.git.mrezanin@redhat.com>
|
|
|
46bd62 |
Patchwork-id: 79709
|
|
|
46bd62 |
O-Subject: [RHEL-7.5.z qemu-guest-agent PATCH 7/7] test-qga: add test for guest-get-osinfo
|
|
|
46bd62 |
Bugzilla: 1598210
|
|
|
46bd62 |
RH-Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
|
|
|
46bd62 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
46bd62 |
RH-Acked-by: Tomáš Golembiovský <tgolembi@redhat.com>
|
|
|
46bd62 |
|
|
|
46bd62 |
From: Tomáš Golembiovský <tgolembi@redhat.com>
|
|
|
46bd62 |
|
|
|
46bd62 |
Add test for guest-get-osinfo command.
|
|
|
46bd62 |
|
|
|
46bd62 |
Qemu-ga was modified to accept QGA_OS_RELEASE environment variable. If
|
|
|
46bd62 |
the variable is defined it is interpreted as path to the os-release file
|
|
|
46bd62 |
and it is parsed instead of the default paths.
|
|
|
46bd62 |
|
|
|
46bd62 |
Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com>
|
|
|
46bd62 |
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
|
|
|
46bd62 |
* move declarations to beginning of functions
|
|
|
46bd62 |
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
|
|
|
46bd62 |
(cherry picked from commit 339ca68bef9f30dd18e84b7d92398327e3f819a3)
|
|
|
46bd62 |
Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
|
|
|
46bd62 |
---
|
|
|
46bd62 |
qga/commands-posix.c | 13 +++++++---
|
|
|
46bd62 |
tests/data/test-qga-os-release | 7 ++++++
|
|
|
46bd62 |
tests/test-qga.c | 56 ++++++++++++++++++++++++++++++++++++++++++
|
|
|
46bd62 |
3 files changed, 72 insertions(+), 4 deletions(-)
|
|
|
46bd62 |
create mode 100644 tests/data/test-qga-os-release
|
|
|
46bd62 |
|
|
|
46bd62 |
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
|
|
|
46bd62 |
index add8a51f2b..8c38dd3f0a 100644
|
|
|
46bd62 |
--- a/qga/commands-posix.c
|
|
|
46bd62 |
+++ b/qga/commands-posix.c
|
|
|
46bd62 |
@@ -2677,7 +2677,8 @@ GuestOSInfo *qmp_guest_get_osinfo(Error **errp)
|
|
|
46bd62 |
{
|
|
|
46bd62 |
GuestOSInfo *info = NULL;
|
|
|
46bd62 |
struct utsname kinfo;
|
|
|
46bd62 |
- GKeyFile *osrelease;
|
|
|
46bd62 |
+ GKeyFile *osrelease = NULL;
|
|
|
46bd62 |
+ const char *qga_os_release = g_getenv("QGA_OS_RELEASE");
|
|
|
46bd62 |
|
|
|
46bd62 |
info = g_new0(GuestOSInfo, 1);
|
|
|
46bd62 |
|
|
|
46bd62 |
@@ -2692,9 +2693,13 @@ GuestOSInfo *qmp_guest_get_osinfo(Error **errp)
|
|
|
46bd62 |
info->machine = g_strdup(kinfo.machine);
|
|
|
46bd62 |
}
|
|
|
46bd62 |
|
|
|
46bd62 |
- osrelease = ga_parse_osrelease("/etc/os-release");
|
|
|
46bd62 |
- if (osrelease == NULL) {
|
|
|
46bd62 |
- osrelease = ga_parse_osrelease("/usr/lib/os-release");
|
|
|
46bd62 |
+ if (qga_os_release != NULL) {
|
|
|
46bd62 |
+ osrelease = ga_parse_osrelease(qga_os_release);
|
|
|
46bd62 |
+ } else {
|
|
|
46bd62 |
+ osrelease = ga_parse_osrelease("/etc/os-release");
|
|
|
46bd62 |
+ if (osrelease == NULL) {
|
|
|
46bd62 |
+ osrelease = ga_parse_osrelease("/usr/lib/os-release");
|
|
|
46bd62 |
+ }
|
|
|
46bd62 |
}
|
|
|
46bd62 |
|
|
|
46bd62 |
if (osrelease != NULL) {
|
|
|
46bd62 |
diff --git a/tests/data/test-qga-os-release b/tests/data/test-qga-os-release
|
|
|
46bd62 |
new file mode 100644
|
|
|
46bd62 |
index 0000000000..70664eb6ec
|
|
|
46bd62 |
--- /dev/null
|
|
|
46bd62 |
+++ b/tests/data/test-qga-os-release
|
|
|
46bd62 |
@@ -0,0 +1,7 @@
|
|
|
46bd62 |
+ID=qemu-ga-test
|
|
|
46bd62 |
+NAME=QEMU-GA
|
|
|
46bd62 |
+PRETTY_NAME="QEMU Guest Agent test"
|
|
|
46bd62 |
+VERSION="Test 1"
|
|
|
46bd62 |
+VERSION_ID=1
|
|
|
46bd62 |
+VARIANT="Unit test \"\'\$\`\\ and \\\\ etc."
|
|
|
46bd62 |
+VARIANT_ID=unit-test
|
|
|
46bd62 |
diff --git a/tests/test-qga.c b/tests/test-qga.c
|
|
|
46bd62 |
index ef8616f89d..3542a015a5 100644
|
|
|
46bd62 |
--- a/tests/test-qga.c
|
|
|
46bd62 |
+++ b/tests/test-qga.c
|
|
|
46bd62 |
@@ -909,6 +909,60 @@ static void test_qga_guest_exec_invalid(gconstpointer fix)
|
|
|
46bd62 |
QDECREF(ret);
|
|
|
46bd62 |
}
|
|
|
46bd62 |
|
|
|
46bd62 |
+static void test_qga_guest_get_osinfo(gconstpointer data)
|
|
|
46bd62 |
+{
|
|
|
46bd62 |
+ TestFixture fixture;
|
|
|
46bd62 |
+ const gchar *str;
|
|
|
46bd62 |
+ gchar *cwd, *env[2];
|
|
|
46bd62 |
+ QDict *ret, *val;
|
|
|
46bd62 |
+
|
|
|
46bd62 |
+ cwd = g_get_current_dir();
|
|
|
46bd62 |
+ env[0] = g_strdup_printf(
|
|
|
46bd62 |
+ "QGA_OS_RELEASE=%s%ctests%cdata%ctest-qga-os-release",
|
|
|
46bd62 |
+ cwd, G_DIR_SEPARATOR, G_DIR_SEPARATOR, G_DIR_SEPARATOR);
|
|
|
46bd62 |
+ env[1] = NULL;
|
|
|
46bd62 |
+ g_free(cwd);
|
|
|
46bd62 |
+ fixture_setup(&fixture, NULL, env);
|
|
|
46bd62 |
+
|
|
|
46bd62 |
+ ret = qmp_fd(fixture.fd, "{'execute': 'guest-get-osinfo'}");
|
|
|
46bd62 |
+ g_assert_nonnull(ret);
|
|
|
46bd62 |
+ qmp_assert_no_error(ret);
|
|
|
46bd62 |
+
|
|
|
46bd62 |
+ val = qdict_get_qdict(ret, "return");
|
|
|
46bd62 |
+
|
|
|
46bd62 |
+ str = qdict_get_try_str(val, "id");
|
|
|
46bd62 |
+ g_assert_nonnull(str);
|
|
|
46bd62 |
+ g_assert_cmpstr(str, ==, "qemu-ga-test");
|
|
|
46bd62 |
+
|
|
|
46bd62 |
+ str = qdict_get_try_str(val, "name");
|
|
|
46bd62 |
+ g_assert_nonnull(str);
|
|
|
46bd62 |
+ g_assert_cmpstr(str, ==, "QEMU-GA");
|
|
|
46bd62 |
+
|
|
|
46bd62 |
+ str = qdict_get_try_str(val, "pretty-name");
|
|
|
46bd62 |
+ g_assert_nonnull(str);
|
|
|
46bd62 |
+ g_assert_cmpstr(str, ==, "QEMU Guest Agent test");
|
|
|
46bd62 |
+
|
|
|
46bd62 |
+ str = qdict_get_try_str(val, "version");
|
|
|
46bd62 |
+ g_assert_nonnull(str);
|
|
|
46bd62 |
+ g_assert_cmpstr(str, ==, "Test 1");
|
|
|
46bd62 |
+
|
|
|
46bd62 |
+ str = qdict_get_try_str(val, "version-id");
|
|
|
46bd62 |
+ g_assert_nonnull(str);
|
|
|
46bd62 |
+ g_assert_cmpstr(str, ==, "1");
|
|
|
46bd62 |
+
|
|
|
46bd62 |
+ str = qdict_get_try_str(val, "variant");
|
|
|
46bd62 |
+ g_assert_nonnull(str);
|
|
|
46bd62 |
+ g_assert_cmpstr(str, ==, "Unit test \"'$`\\ and \\\\ etc.");
|
|
|
46bd62 |
+
|
|
|
46bd62 |
+ str = qdict_get_try_str(val, "variant-id");
|
|
|
46bd62 |
+ g_assert_nonnull(str);
|
|
|
46bd62 |
+ g_assert_cmpstr(str, ==, "unit-test");
|
|
|
46bd62 |
+
|
|
|
46bd62 |
+ QDECREF(ret);
|
|
|
46bd62 |
+ g_free(env[0]);
|
|
|
46bd62 |
+ fixture_tear_down(&fixture, NULL);
|
|
|
46bd62 |
+}
|
|
|
46bd62 |
+
|
|
|
46bd62 |
int main(int argc, char **argv)
|
|
|
46bd62 |
{
|
|
|
46bd62 |
TestFixture fix;
|
|
|
46bd62 |
@@ -943,6 +997,8 @@ int main(int argc, char **argv)
|
|
|
46bd62 |
g_test_add_data_func("/qga/guest-exec", &fix, test_qga_guest_exec);
|
|
|
46bd62 |
g_test_add_data_func("/qga/guest-exec-invalid", &fix,
|
|
|
46bd62 |
test_qga_guest_exec_invalid);
|
|
|
46bd62 |
+ g_test_add_data_func("/qga/guest-get-osinfo", &fix,
|
|
|
46bd62 |
+ test_qga_guest_get_osinfo);
|
|
|
46bd62 |
|
|
|
46bd62 |
if (g_getenv("QGA_TEST_SIDE_EFFECTING")) {
|
|
|
46bd62 |
g_test_add_data_func("/qga/fsfreeze-and-thaw", &fix,
|
|
|
46bd62 |
--
|
|
|
46bd62 |
2.13.6
|
|
|
46bd62 |
|