[libosinfo PATCH v2] os: Add kernel-url-argument API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tree based installations will require a kernel-url-argument to be
assed. Let's provide an API to the apps to get this info from OsinfoOS.

https://gitlab.com/libosinfo/osinfo-db/issues/28

Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
 osinfo/libosinfo.syms                         |  2 +
 osinfo/osinfo_loader.c                        |  1 +
 osinfo/osinfo_os.c                            | 67 +++++++++++++++++++
 osinfo/osinfo_os.h                            |  3 +
 .../libosinfo.org/test-os-kernel-url-arg1.xml | 13 ++++
 .../libosinfo.org/test-os-kernel-url-arg2.xml | 12 ++++
 .../libosinfo.org/test-os-kernel-url-arg3.xml | 14 ++++
 tests/test-os.c                               | 36 ++++++++++
 8 files changed, 148 insertions(+)
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-kernel-url-arg1.xml
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-kernel-url-arg2.xml
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-kernel-url-arg3.xml

diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 853acf5..f8b56a7 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -577,6 +577,8 @@ LIBOSINFO_1.5.0 {
 	osinfo_install_config_get_installation_url;
 	osinfo_install_config_set_installation_url;
 
+	osinfo_os_get_kernel_url_argument;
+
 	osinfo_product_get_short_id_list;
 
 	osinfo_tree_get_os;
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index 522162f..7735357 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -1563,6 +1563,7 @@ static void osinfo_loader_os(OsinfoLoader *loader,
         { OSINFO_OS_PROP_FAMILY, G_TYPE_STRING },
         { OSINFO_OS_PROP_DISTRO, G_TYPE_STRING },
         { OSINFO_OS_PROP_RELEASE_STATUS, G_TYPE_STRING },
+        { OSINFO_OS_PROP_KERNEL_URL_ARGUMENT, G_TYPE_STRING },
         { NULL, G_TYPE_INVALID }
     };
 
diff --git a/osinfo/osinfo_os.c b/osinfo/osinfo_os.c
index e458a45..08faf4f 100644
--- a/osinfo/osinfo_os.c
+++ b/osinfo/osinfo_os.c
@@ -75,6 +75,7 @@ enum {
 
     PROP_FAMILY,
     PROP_DISTRO,
+    PROP_KERNEL_URL_ARGUMENT,
 };
 
 static void osinfo_os_finalize(GObject *object);
@@ -99,6 +100,11 @@ osinfo_os_get_property(GObject    *object,
                                 osinfo_entity_get_param_value(entity,
                                                                "distro"));
             break;
+        case PROP_KERNEL_URL_ARGUMENT:
+            g_value_set_string(value,
+                               osinfo_entity_get_param_value(entity,
+                                                             OSINFO_OS_PROP_KERNEL_URL_ARGUMENT));
+            break;
         default:
             /* We don't have any other property... */
             G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
@@ -172,6 +178,22 @@ osinfo_os_class_init(OsinfoOsClass *klass)
     g_object_class_install_property(g_klass,
                                     PROP_DISTRO,
                                     pspec);
+
+    /**
+     * OsinfoOs:kernel-url-argument:
+     *
+     * The argument to be passed to kernel command line when performing a
+     * tree based installation of this OS.
+     */
+    pspec = g_param_spec_string("kernel-url-argument",
+                                "KernelURLArgument",
+                                _("Kernel URL Argument"),
+                                NULL /* default value */,
+                                G_PARAM_READABLE |
+                                G_PARAM_STATIC_STRINGS);
+    g_object_class_install_property(g_klass,
+                                    PROP_KERNEL_URL_ARGUMENT,
+                                    pspec);
 }
 
 static void
@@ -1142,3 +1164,48 @@ void osinfo_os_add_device_driver(OsinfoOs *os, OsinfoDeviceDriver *driver)
     osinfo_list_add(OSINFO_LIST(os->priv->device_drivers),
                     OSINFO_ENTITY(driver));
 }
+
+struct GetKernelURLArgumentData {
+    const gchar *kernel_url_arg;
+};
+
+static void get_kernel_url_argument_cb(OsinfoProduct *product, gpointer user_data)
+{
+    OsinfoOs *os = OSINFO_OS(product);
+    struct GetKernelURLArgumentData *foreach_data = user_data;
+
+    g_return_if_fail(OSINFO_IS_OS(os));
+
+    if (foreach_data->kernel_url_arg != NULL)
+        return;
+
+    foreach_data->kernel_url_arg =
+            osinfo_entity_get_param_value(OSINFO_ENTITY(os),
+                                          OSINFO_OS_PROP_KERNEL_URL_ARGUMENT);
+}
+
+/**
+ * osinfo_os_get_kernel_url_argument:
+ * @os: an operating system
+ *
+ * Gets the argument expected to be passed to the kernel command line when
+ * performing a tree based installation.
+ *
+ * Returns: (transfer none): the kernel url argument, if present. Otherwise,
+ * NULL.
+ */
+const gchar *osinfo_os_get_kernel_url_argument(OsinfoOs *os)
+{
+    struct GetKernelURLArgumentData foreach_data = {
+        .kernel_url_arg = NULL
+    };
+    g_return_val_if_fail(OSINFO_IS_OS(os), NULL);
+
+    osinfo_product_foreach_related(OSINFO_PRODUCT(os),
+                                   OSINFO_PRODUCT_FOREACH_FLAG_DERIVES_FROM |
+                                   OSINFO_PRODUCT_FOREACH_FLAG_CLONES,
+                                   get_kernel_url_argument_cb,
+                                   &foreach_data);
+
+    return foreach_data.kernel_url_arg;
+}
diff --git a/osinfo/osinfo_os.h b/osinfo/osinfo_os.h
index 7c10475..6207a53 100644
--- a/osinfo/osinfo_os.h
+++ b/osinfo/osinfo_os.h
@@ -62,6 +62,7 @@ typedef struct _OsinfoOsPrivate OsinfoOsPrivate;
 #define OSINFO_OS_PROP_FAMILY                 "family"
 #define OSINFO_OS_PROP_DISTRO                 "distro"
 #define OSINFO_OS_PROP_RELEASE_STATUS         "release-status"
+#define OSINFO_OS_PROP_KERNEL_URL_ARGUMENT    "kernel-url-argument"
 
 /* object */
 struct _OsinfoOs
@@ -142,4 +143,6 @@ void osinfo_os_add_install_script(OsinfoOs *os, OsinfoInstallScript *script);
 OsinfoDeviceDriverList *osinfo_os_get_device_drivers(OsinfoOs *os);
 void osinfo_os_add_device_driver(OsinfoOs *os, OsinfoDeviceDriver *driver);
 
+const gchar *osinfo_os_get_kernel_url_argument(OsinfoOs *os);
+
 #endif /* __OSINFO_OS_H__ */
diff --git a/tests/dbdata/os/libosinfo.org/test-os-kernel-url-arg1.xml b/tests/dbdata/os/libosinfo.org/test-os-kernel-url-arg1.xml
new file mode 100644
index 0000000..f3ea3ae
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-kernel-url-arg1.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+  <os id="http://libosinfo.org/test/os/kernel-url-arg1";>
+    <short-id>kernel-url-arg1</short-id>
+    <name>Kernel URL Arg 1</name>
+    <version>unknown</version>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <release-status>prerelease</release-status>
+
+    <kernel-url-argument>install</kernel-url-argument>
+  </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-kernel-url-arg2.xml b/tests/dbdata/os/libosinfo.org/test-os-kernel-url-arg2.xml
new file mode 100644
index 0000000..d97c2d8
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-kernel-url-arg2.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+  <os id="http://libosinfo.org/test/os/kernel-url-arg2";>
+    <short-id>kernel-url-arg2</short-id>
+    <name>Kernel URL Arg 2</name>
+    <version>unknown</version>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <release-status>prerelease</release-status>
+    <derives-from id="http://libosinfo.org/test/os/kernel-url-arg1"/>
+  </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-kernel-url-arg3.xml b/tests/dbdata/os/libosinfo.org/test-os-kernel-url-arg3.xml
new file mode 100644
index 0000000..932eb77
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-kernel-url-arg3.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+  <os id="http://libosinfo.org/test/os/kernel-url-arg3";>
+    <short-id>kernel-url-arg3</short-id>
+    <name>Kernel URL Arg 3</name>
+    <version>unknown</version>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <release-status>prerelease</release-status>
+    <derives-from id="http://libosinfo.org/test/os/kernel-url-arg2"/>
+
+    <kernel-url-argument>new.install</kernel-url-argument>
+  </os>
+</libosinfo>
diff --git a/tests/test-os.c b/tests/test-os.c
index fe7c2d6..84d838e 100644
--- a/tests/test-os.c
+++ b/tests/test-os.c
@@ -651,6 +651,41 @@ test_multiple_short_ids(void)
     g_object_unref(db);
 }
 
+static void
+test_kernel_url_arg(void)
+{
+    OsinfoLoader *loader;
+    OsinfoDb *db;
+    OsinfoOs *os;
+    GError *error = NULL;
+    const char *str;
+
+    loader = osinfo_loader_new();
+    osinfo_loader_process_path(loader, SRCDIR "/tests/dbdata", &error);
+    g_assert_no_error(error);
+    db = osinfo_loader_get_db(loader);
+
+    g_debug("Testing http://libosinfo.org/test/os/kernel-url-arg1\n";);
+    os = osinfo_db_get_os(db, "http://libosinfo.org/test/os/kernel-url-arg1";);
+    g_assert_nonnull(os);
+    str = osinfo_os_get_kernel_url_argument(os);
+    g_assert_cmpstr(str, ==, "install");
+
+    g_debug("Testing http://libosinfo.org/test/os/kernel-url-arg2\n";);
+    os = osinfo_db_get_os(db, "http://libosinfo.org/test/os/kernel-url-arg2";);
+    g_assert_nonnull(os);
+    str = osinfo_os_get_kernel_url_argument(os);
+    g_assert_cmpstr(str, ==, "install");
+
+    g_debug("Testing http://libosinfo.org/test/os/kernel-url-arg3\n";);
+    os = osinfo_db_get_os(db, "http://libosinfo.org/test/os/kernel-url-arg3";);
+    g_assert_nonnull(os);
+    str = osinfo_os_get_kernel_url_argument(os);
+    g_assert_cmpstr(str, ==, "new.install");
+
+    g_object_unref(loader);
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -670,6 +705,7 @@ main(int argc, char *argv[])
     g_test_add_func("/os/resources/inheritance", test_resources_inheritance);
     g_test_add_func("/os/find_install_script", test_find_install_script);
     g_test_add_func("/os/mulitple_short_ids", test_multiple_short_ids);
+    g_test_add_func("/os/kernel_url_arg", test_kernel_url_arg);
 
     /* Upfront so we don't confuse valgrind */
     osinfo_platform_get_type();
-- 
2.21.0

_______________________________________________
Libosinfo mailing list
Libosinfo@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libosinfo




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux