Blob Blame History Raw
From 6357a82435d328b1da23ab4995f26836427747a4 Mon Sep 17 00:00:00 2001
From: Pino Toscano <ptoscano@redhat.com>
Date: Wed, 21 Feb 2018 17:37:30 +0100
Subject: [PATCH] inspector: show the per-OS osinfo guess (RHBZ#1544842)

Output also the osinfo guess for each OS in the generated XML output;
adapt the RNG schema, and the test data to it.

(cherry picked from commit 2f8ec91fc1f3e81c8fb81d45849bc7462ee13642)
---
 inspector/expected-coreos.img.xml | 1 +
 inspector/expected-debian.img.xml | 1 +
 inspector/expected-fedora.img.xml | 1 +
 inspector/expected-ubuntu.img.xml | 1 +
 inspector/inspector.c             | 7 +++++++
 inspector/virt-inspector.rng      | 1 +
 6 files changed, 12 insertions(+)

diff --git a/inspector/expected-coreos.img.xml b/inspector/expected-coreos.img.xml
index e4a5d1134..0cdfba6e6 100644
--- a/inspector/expected-coreos.img.xml
+++ b/inspector/expected-coreos.img.xml
@@ -8,6 +8,7 @@
     <major_version>899</major_version>
     <minor_version>13</minor_version>
     <hostname>coreos.invalid</hostname>
+    <osinfo>coreos899.13</osinfo>
     <mountpoints>
       <mountpoint dev="/dev/sda5">/</mountpoint>
       <mountpoint dev="/dev/sda3">/usr</mountpoint>
diff --git a/inspector/expected-debian.img.xml b/inspector/expected-debian.img.xml
index 37ecfa049..6583dc262 100644
--- a/inspector/expected-debian.img.xml
+++ b/inspector/expected-debian.img.xml
@@ -11,6 +11,7 @@
     <package_format>deb</package_format>
     <package_management>apt</package_management>
     <hostname>debian.invalid</hostname>
+    <osinfo>debian5</osinfo>
     <mountpoints>
       <mountpoint dev="/dev/debian/root">/</mountpoint>
       <mountpoint dev="/dev/debian/usr">/usr</mountpoint>
diff --git a/inspector/expected-fedora.img.xml b/inspector/expected-fedora.img.xml
index 8d40e8cb7..df6060a73 100644
--- a/inspector/expected-fedora.img.xml
+++ b/inspector/expected-fedora.img.xml
@@ -11,6 +11,7 @@
     <package_format>rpm</package_format>
     <package_management>yum</package_management>
     <hostname>fedora.invalid</hostname>
+    <osinfo>fedora14</osinfo>
     <mountpoints>
       <mountpoint dev="/dev/VG/Root">/</mountpoint>
       <mountpoint dev="/dev/sda1">/boot</mountpoint>
diff --git a/inspector/expected-ubuntu.img.xml b/inspector/expected-ubuntu.img.xml
index c19c14cd5..4ebcd76d6 100644
--- a/inspector/expected-ubuntu.img.xml
+++ b/inspector/expected-ubuntu.img.xml
@@ -11,6 +11,7 @@
     <package_format>deb</package_format>
     <package_management>apt</package_management>
     <hostname>ubuntu.invalid</hostname>
+    <osinfo>ubuntu10.10</osinfo>
     <mountpoints>
       <mountpoint dev="/dev/sda2">/</mountpoint>
       <mountpoint dev="/dev/sda1">/boot</mountpoint>
diff --git a/inspector/inspector.c b/inspector/inspector.c
index d608b1b63..5075a8f04 100644
--- a/inspector/inspector.c
+++ b/inspector/inspector.c
@@ -443,6 +443,13 @@ output_root (xmlTextWriterPtr xo, char *root)
 					 BAD_CAST str));
   free (str);
 
+  str = guestfs_inspect_get_osinfo (g, root);
+  if (!str) exit (EXIT_FAILURE);
+  if (STRNEQ (str, "unknown"))
+    XMLERROR (-1,
+              xmlTextWriterWriteElement (xo, BAD_CAST "osinfo", BAD_CAST str));
+  free (str);
+
   output_mountpoints (xo, root);
 
   output_filesystems (xo, root);
diff --git a/inspector/virt-inspector.rng b/inspector/virt-inspector.rng
index 314785202..1e3a58af8 100644
--- a/inspector/virt-inspector.rng
+++ b/inspector/virt-inspector.rng
@@ -38,6 +38,7 @@
             <optional><ref name="ospackageformat"/></optional>
             <optional><ref name="ospackagemanagement"/></optional>
             <optional><element name="hostname"><text/></element></optional>
+            <optional><element name="osinfo"><text/></element></optional>
 
             <ref name="mountpoints"/>
             <ref name="filesystems"/>
-- 
2.20.1