From fabiano at fidencio.org Sat Dec 1 08:54:21 2018 From: fabiano at fidencio.org (=?UTF-8?q?Fabiano=20Fid=C3=AAncio?=) Date: Sat, 1 Dec 2018 09:54:21 +0100 Subject: [Libosinfo] [libosinfo PATCH] tree: cleanup non-fatal errors Message-ID: <1543654461-22447-1-git-send-email-fabiano@fidencio.org> There are errors which are not fatal and just ignored in load_keyinfo. However, as those have not been cleaned up, we could see messages like: (lt-osinfo-detect:20658): GLib-WARNING **: GError set over the top of a previous GError or uninitialized memory. This indicates a bug in someone's code. You must ensure an error is NULL before it's set. The overwriting error message was: Key file does not have key ?boot.iso? in group ?images-x86_64? In order to avoid this, let's just call g_clear_error() after an situations where an error may have been set but it can just be ignored. Signed-off-by: Fabiano Fid?ncio --- osinfo/osinfo_tree.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/osinfo/osinfo_tree.c b/osinfo/osinfo_tree.c index da01c8b..3082eab 100644 --- a/osinfo/osinfo_tree.c +++ b/osinfo/osinfo_tree.c @@ -491,26 +491,31 @@ static OsinfoTree *load_keyinfo(const gchar *location, if (!g_key_file_load_from_data(file, content, length, G_KEY_FILE_NONE, error)) goto cleanup; + g_clear_error(error); if (!(family = g_key_file_get_string(file, "general", "family", error)) && (*error && (*error)->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND && (*error)->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) goto cleanup; + g_clear_error(error); if (!(variant = g_key_file_get_string(file, "general", "variant", error)) && (*error && (*error)->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND && (*error)->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) goto cleanup; + g_clear_error(error); if (!(version = g_key_file_get_string(file, "general", "version", error)) && (*error && (*error)->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND && (*error)->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) goto cleanup; + g_clear_error(error); if (!(arch = g_key_file_get_string(file, "general", "arch", error)) && (*error && (*error)->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND && (*error)->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) goto cleanup; + g_clear_error(error); if (arch) { @@ -520,16 +525,19 @@ static OsinfoTree *load_keyinfo(const gchar *location, (*error && (*error)->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND && (*error)->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) goto cleanup; + g_clear_error(error); if (!(initrd = g_key_file_get_string(file, group, "initrd", error)) && (*error && (*error)->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND && (*error)->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) goto cleanup; + g_clear_error(error); if (!(bootiso = g_key_file_get_string(file, group, "boot.iso", error)) && (*error && (*error)->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND && (*error)->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) goto cleanup; + g_clear_error(error); } tree = osinfo_tree_new(location, arch ? arch : "i386"); -- 1.8.3.1 From fabiano at fidencio.org Sun Dec 2 15:37:56 2018 From: fabiano at fidencio.org (=?UTF-8?q?Fabiano=20Fid=C3=AAncio?=) Date: Sun, 2 Dec 2018 16:37:56 +0100 Subject: [Libosinfo] [libosinfo PATCH 0/3] A few fixes related to treeinfo and tree detection Message-ID: <1543765079-15585-1-git-send-email-fabiano@fidencio.org> The first two patches basically are fixing the load of treeinfo attributes and then adding a test to ensure we don't regress on this anymore. The last patch improves _guess_os_from_tree() in order to avoid matching any OS that doesn't have the treeinfo set. Fabiano Fid?ncio (3): loader: properly load the treeinfo attributes test-os: expand test_loader() to cover loading treeinfo db: improve _guess_os_from_tree checks osinfo/osinfo_db.c | 3 +++ osinfo/osinfo_loader.c | 8 ++++---- tests/dbdata/os/fedoraproject.org/fedora-16.xml | 9 +++++++++ tests/test-os.c | 18 ++++++++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) -- 1.8.3.1 From fabiano at fidencio.org Sun Dec 2 15:37:57 2018 From: fabiano at fidencio.org (=?UTF-8?q?Fabiano=20Fid=C3=AAncio?=) Date: Sun, 2 Dec 2018 16:37:57 +0100 Subject: [Libosinfo] [libosinfo PATCH 1/3] loader: properly load the treeinfo attributes In-Reply-To: <1543765079-15585-1-git-send-email-fabiano@fidencio.org> References: <1543765079-15585-1-git-send-email-fabiano@fidencio.org> Message-ID: <1543765079-15585-2-git-send-email-fabiano@fidencio.org> treeinfo attributes haven't been loaded properly due to the change done in ab2ab35f, changing the hardcoded 9 to sizeof("treeinfo-"). The problem here is that size("treeinfo-") is 10, causing that any comparison to fail. Let's change the sizeof("treeinfo-") to strlen("treeinfo-"). Signed-off-by: Fabiano Fid?ncio --- osinfo/osinfo_loader.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c index 030062b..b6b6bd2 100644 --- a/osinfo/osinfo_loader.c +++ b/osinfo/osinfo_loader.c @@ -1222,22 +1222,22 @@ static OsinfoTree *osinfo_loader_tree(OsinfoLoader *loader, continue; if (g_str_equal((const gchar *)nodes[i]->name, - OSINFO_TREE_PROP_TREEINFO_FAMILY + sizeof("treeinfo-"))) + OSINFO_TREE_PROP_TREEINFO_FAMILY + strlen("treeinfo-"))) osinfo_entity_set_param(OSINFO_ENTITY(tree), OSINFO_TREE_PROP_TREEINFO_FAMILY, (const gchar *)nodes[i]->children->content); else if (g_str_equal((const gchar *)nodes[i]->name, - OSINFO_TREE_PROP_TREEINFO_VARIANT + sizeof("treeinfo-"))) + OSINFO_TREE_PROP_TREEINFO_VARIANT + strlen("treeinfo-"))) osinfo_entity_set_param(OSINFO_ENTITY(tree), OSINFO_TREE_PROP_TREEINFO_VARIANT, (const gchar *)nodes[i]->children->content); else if (g_str_equal((const gchar *)nodes[i]->name, - OSINFO_TREE_PROP_TREEINFO_VERSION + sizeof("treeinfo-"))) + OSINFO_TREE_PROP_TREEINFO_VERSION + strlen("treeinfo-"))) osinfo_entity_set_param(OSINFO_ENTITY(tree), OSINFO_TREE_PROP_TREEINFO_VERSION, (const gchar *)nodes[i]->children->content); else if (g_str_equal((const gchar *)nodes[i]->name, - OSINFO_TREE_PROP_TREEINFO_ARCH + sizeof("treeinfo-"))) + OSINFO_TREE_PROP_TREEINFO_ARCH + strlen("treeinfo-"))) osinfo_entity_set_param(OSINFO_ENTITY(tree), OSINFO_TREE_PROP_TREEINFO_ARCH, (const gchar *)nodes[i]->children->content); -- 1.8.3.1 From fabiano at fidencio.org Sun Dec 2 15:37:59 2018 From: fabiano at fidencio.org (=?UTF-8?q?Fabiano=20Fid=C3=AAncio?=) Date: Sun, 2 Dec 2018 16:37:59 +0100 Subject: [Libosinfo] [libosinfo PATCH 3/3] db: improve _guess_os_from_tree checks In-Reply-To: <1543765079-15585-1-git-send-email-fabiano@fidencio.org> References: <1543765079-15585-1-git-send-email-fabiano@fidencio.org> Message-ID: <1543765079-15585-4-git-send-email-fabiano@fidencio.org> Do not check against a distro that has all the treeinfo attribute as NULL as match_regex() would just match whatever we compare to it. Signed-off-by: Fabiano Fid?ncio --- osinfo/osinfo_db.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osinfo/osinfo_db.c b/osinfo/osinfo_db.c index fa14c6d..3bdc4c8 100644 --- a/osinfo/osinfo_db.c +++ b/osinfo/osinfo_db.c @@ -763,6 +763,9 @@ OsinfoOs *osinfo_db_guess_os_from_tree(OsinfoDb *db, const gchar *os_version = osinfo_tree_get_treeinfo_version(os_tree); const gchar *os_arch = osinfo_tree_get_treeinfo_arch(os_tree); + if (os_family == NULL && os_variant == NULL && os_version == NULL && os_arch == NULL) + continue; + if (match_regex(os_family, tree_family) && match_regex(os_variant, tree_variant) && match_regex(os_version, tree_version) && -- 1.8.3.1 From fabiano at fidencio.org Sun Dec 2 15:37:58 2018 From: fabiano at fidencio.org (=?UTF-8?q?Fabiano=20Fid=C3=AAncio?=) Date: Sun, 2 Dec 2018 16:37:58 +0100 Subject: [Libosinfo] [libosinfo PATCH 2/3] test-os: expand test_loader() to cover loading treeinfo In-Reply-To: <1543765079-15585-1-git-send-email-fabiano@fidencio.org> References: <1543765079-15585-1-git-send-email-fabiano@fidencio.org> Message-ID: <1543765079-15585-3-git-send-email-fabiano@fidencio.org> Signed-off-by: Fabiano Fid?ncio --- tests/dbdata/os/fedoraproject.org/fedora-16.xml | 9 +++++++++ tests/test-os.c | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/tests/dbdata/os/fedoraproject.org/fedora-16.xml b/tests/dbdata/os/fedoraproject.org/fedora-16.xml index 88ef431..c67ce23 100644 --- a/tests/dbdata/os/fedoraproject.org/fedora-16.xml +++ b/tests/dbdata/os/fedoraproject.org/fedora-16.xml @@ -19,5 +19,14 @@ isolinux/vmlinuz isolinux/initrd.img + + + http://archive.fedoraproject.org/pub/archive/fedora/linux/releases/16/Fedora/i386/os/ + + Fedora + 16 + i386 + + diff --git a/tests/test-os.c b/tests/test-os.c index 0b586b2..1756e59 100644 --- a/tests/test-os.c +++ b/tests/test-os.c @@ -67,6 +67,8 @@ test_loader(void) OsinfoLoader *loader; OsinfoDb *db; OsinfoOs *os; + OsinfoTreeList *treelist; + OsinfoTree *tree; GError *error = NULL; const char *str; @@ -124,6 +126,20 @@ test_loader(void) "*(osinfo_entity_get_param_value_enum): should not be reached*"); g_assert_cmpint(osinfo_os_get_release_status(os), ==, OSINFO_RELEASE_STATUS_RELEASED); + os = osinfo_db_get_os(db, "http://fedoraproject.org/fedora/16"); + g_assert_nonnull(os); + str = osinfo_product_get_short_id(OSINFO_PRODUCT(os)); + g_assert_cmpstr(str, ==, "fedora16"); + treelist = osinfo_os_get_tree_list(os); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(treelist)), ==, 1); + tree = OSINFO_TREE(osinfo_list_get_nth(OSINFO_LIST(treelist), 0)); + str = osinfo_tree_get_treeinfo_family(tree); + g_assert_cmpstr(str, ==, "Fedora"); + str = osinfo_tree_get_treeinfo_version(tree); + g_assert_cmpstr(str, ==, "16"); + str = osinfo_tree_get_treeinfo_arch(tree); + g_assert_cmpstr(str, ==, "i386"); + g_object_unref(loader); } @@ -908,6 +924,8 @@ main(int argc, char *argv[]) osinfo_filter_get_type(); osinfo_resources_get_type(); osinfo_resourceslist_get_type(); + osinfo_tree_get_type(); + osinfo_treelist_get_type(); return g_test_run(); } -- 1.8.3.1 From fidencio at redhat.com Mon Dec 3 09:11:45 2018 From: fidencio at redhat.com (=?UTF-8?q?Fabiano=20Fid=C3=AAncio?=) Date: Mon, 3 Dec 2018 10:11:45 +0100 Subject: [Libosinfo] [libosinfo PATCH 0/7] install-script: Changes needed in order to add support for unattended-installation in virt-install Message-ID: <20181203091152.31307-1-fidencio@redhat.com> This patch set has been written while playing with virt-install in order to add support there to unattended installations. In the way things are nowdays we have a few issues that I'm addressing with this series: - preferred-injection-method: We have no way to let the apps decide what's the preferred injection method for the scripts. We list the methods we support and that's it. Now I've introduced a new API which actually let the apps chose what they want to use (GNOME Boxes, for instance, prefers "disk" injection-method while virt-install prefers "initrd" injection-method and the command-line generated for each of those methods *is* different); - installation-source: Once the app has decided what's the method to be used for unattended installations, they should be able to set the installation source as in "network" or "media" because there are a few differences in the scripts that would depend on that. One example is here is the kickstart files for Fedora which would only set the repos when playing with network installation, or only set the cdrom (as source) when playing with media installation. These ideas where brought up in the following thread: https://www.redhat.com/archives/libosinfo/2018-November/msg00312.html Fabiano Fid?ncio (7): entity: Add methods to deal with GFlags test-entity: Add tests for flags related methods install-script: Add _(get|set)_preferred_injection_method() test-install-script: Cover _(get|set)_preferred_injection_method() install-script: Add _{get|set}_installation_source() test-install-script: Cover _(get|set)_installation_source() tools,install-script: Add "installation-source" parameter osinfo/libosinfo.syms | 9 ++ osinfo/osinfo_entity.c | 41 ++++++ osinfo/osinfo_entity.h | 5 + osinfo/osinfo_install_script.c | 135 ++++++++++++++++++ osinfo/osinfo_install_script.h | 15 ++ .../libosinfo-test-install-script.xml | 5 + tests/test-entity.c | 40 ++++++ tests/test-install-script.c | 47 ++++++ tools/osinfo-install-script.c | 15 ++ 9 files changed, 312 insertions(+) -- 2.19.1 From fidencio at redhat.com Mon Dec 3 09:11:46 2018 From: fidencio at redhat.com (=?UTF-8?q?Fabiano=20Fid=C3=AAncio?=) Date: Mon, 3 Dec 2018 10:11:46 +0100 Subject: [Libosinfo] [libosinfo PATCH 1/7] entity: Add methods to deal with GFlags In-Reply-To: <20181203091152.31307-1-fidencio@redhat.com> References: <20181203091152.31307-1-fidencio@redhat.com> Message-ID: <20181203091152.31307-2-fidencio@redhat.com> Add osinfo_entity_get_param_value_flags() and osinfo_entity_set_param_flags() in order to deal with flags as such OsinfoInstallScriptMethods. Signed-off-by: Fabiano Fid?ncio --- osinfo/libosinfo.syms | 3 +++ osinfo/osinfo_entity.c | 41 +++++++++++++++++++++++++++++++++++++++++ osinfo/osinfo_entity.h | 5 +++++ 3 files changed, 49 insertions(+) diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms index 5396c72..365914c 100644 --- a/osinfo/libosinfo.syms +++ b/osinfo/libosinfo.syms @@ -531,6 +531,9 @@ LIBOSINFO_0.2.13 { LIBOSINFO_1.3.0 { global: + osinfo_entity_get_param_value_flags; + osinfo_entity_set_param_flags; + osinfo_error_quark; osinfo_os_add_maximum_resources; diff --git a/osinfo/osinfo_entity.c b/osinfo/osinfo_entity.c index 20b9115..563432a 100644 --- a/osinfo/osinfo_entity.c +++ b/osinfo/osinfo_entity.c @@ -221,6 +221,22 @@ void osinfo_entity_set_param_enum(OsinfoEntity *entity, const gchar *key, gint v osinfo_entity_set_param(entity, key, enum_value->value_nick); } +void osinfo_entity_set_param_flags(OsinfoEntity *entity, const gchar *key, guint value, GType flags_type) +{ + GFlagsClass *flags_class; + guint i; + + g_return_if_fail(G_TYPE_IS_FLAGS(flags_type)); + + flags_class = g_type_class_ref(flags_type); + for (i = 0; i < flags_class->n_values; i++) { + if ((flags_class->values[i].value & value) != 0) { + osinfo_entity_set_param(entity, key, flags_class->values[i].value_nick); + break; + } + } +} + /** * osinfo_entity_add_param: * @entity: an #OsinfoEntity containing the parameters @@ -401,6 +417,31 @@ gint osinfo_entity_get_param_value_enum(OsinfoEntity *entity, g_return_val_if_reached(default_value); } +guint osinfo_entity_get_param_value_flags(OsinfoEntity *entity, + const char *key, + GType flags_type, + guint default_value) +{ + const gchar *nick; + GFlagsClass *flags_class; + GFlagsValue *flags_value; + + g_return_val_if_fail(G_TYPE_IS_FLAGS(flags_type), default_value); + + nick = osinfo_entity_get_param_value(entity, key); + if (nick == NULL) + return default_value; + + flags_class = g_type_class_ref(flags_type); + flags_value = g_flags_get_value_by_nick(flags_class, nick); + g_type_class_unref(flags_class); + + if (flags_value != NULL) + return flags_value->value; + + g_return_val_if_reached(default_value); +} + /** * osinfo_entity_get_param_value_list: * @entity: an #OsinfoEntity containing the parameters diff --git a/osinfo/osinfo_entity.h b/osinfo/osinfo_entity.h index d41237b..f4ed465 100644 --- a/osinfo/osinfo_entity.h +++ b/osinfo/osinfo_entity.h @@ -79,6 +79,10 @@ gint osinfo_entity_get_param_value_enum(OsinfoEntity *entity, const char *key, GType enum_type, gint default_value); +guint osinfo_entity_get_param_value_flags(OsinfoEntity *entity, + const char *key, + GType flags_type, + guint default_value); gint64 osinfo_entity_get_param_value_int64(OsinfoEntity *entity, const gchar *key); gint64 osinfo_entity_get_param_value_int64_with_default(OsinfoEntity *entity, const gchar *key, @@ -88,6 +92,7 @@ void osinfo_entity_set_param(OsinfoEntity *entity, const gchar *key, const gchar void osinfo_entity_set_param_boolean(OsinfoEntity *entity, const gchar *key, gboolean value); void osinfo_entity_set_param_int64(OsinfoEntity *entity, const gchar *key, gint64 value); void osinfo_entity_set_param_enum(OsinfoEntity *entity, const gchar *key, gint value, GType enum_type); +void osinfo_entity_set_param_flags(OsinfoEntity *entity, const gchar *key, guint value, GType flags_type); void osinfo_entity_add_param(OsinfoEntity *entity, const gchar *key, const gchar *value); void osinfo_entity_clear_param(OsinfoEntity *entity, const gchar *key); -- 2.19.1 From fidencio at redhat.com Mon Dec 3 09:11:47 2018 From: fidencio at redhat.com (=?UTF-8?q?Fabiano=20Fid=C3=AAncio?=) Date: Mon, 3 Dec 2018 10:11:47 +0100 Subject: [Libosinfo] [libosinfo PATCH 2/7] test-entity: Add tests for flags related methods In-Reply-To: <20181203091152.31307-1-fidencio@redhat.com> References: <20181203091152.31307-1-fidencio@redhat.com> Message-ID: <20181203091152.31307-3-fidencio@redhat.com> Signed-off-by: Fabiano Fid?ncio --- tests/test-entity.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/test-entity.c b/tests/test-entity.c index e65963c..f021f9f 100644 --- a/tests/test-entity.c +++ b/tests/test-entity.c @@ -309,6 +309,45 @@ test_int64_props(void) g_object_unref(ent); } +typedef enum { + TEST_FLAGS_FOO = 1 << 0, + TEST_FLAGS_BAR = 1 << 1, +} TestFlags; + +GType test_flags_get_type (void) G_GNUC_CONST; +#define TYPE_TEST_FLAGS (test_flags_get_type ()) + +GType test_flags_get_type (void) +{ + static volatile gsize g_define_type_id__volatile = 0; + + if (g_once_init_enter (&g_define_type_id__volatile)) { + static const GFlagsValue values[] = { + { TEST_FLAGS_FOO, "TEST_FLAGS_FOO", "foo" }, + { TEST_FLAGS_BAR, "TEST_FLAGS_BAR", "bar" }, + { 0, NULL, NULL} + }; + GType g_define_type_id = + g_flags_register_static (g_intern_static_string ("TestFlags"), values); + g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); + } + + return g_define_type_id__volatile; +} + + +static void +test_flags_props(void) +{ + OsinfoEntity *ent = g_object_new(osinfo_dummy_get_type(), "id", "myentity", NULL); + + g_assert_true(osinfo_entity_get_param_value_flags(ent, "my_flag", TYPE_TEST_FLAGS, TEST_FLAGS_FOO) == TEST_FLAGS_FOO); + osinfo_entity_set_param_flags(ent, "my_flag", TEST_FLAGS_BAR, TYPE_TEST_FLAGS); + g_assert_true(osinfo_entity_get_param_value_flags(ent, "my_flag", TYPE_TEST_FLAGS, TEST_FLAGS_FOO) == TEST_FLAGS_BAR); + + g_object_unref(ent); +} + int main(int argc, char *argv[]) { @@ -321,6 +360,7 @@ main(int argc, char *argv[]) g_test_add_func("/entity/multi_props", test_multi_props); g_test_add_func("/entity/multi_props_clear", test_multi_props_clear); g_test_add_func("/entity/int64_props", test_int64_props); + g_test_add_func("/entity/flags_props", test_flags_props); /* Upfront so we don't confuse valgrind */ osinfo_dummy_get_type(); -- 2.19.1 From fidencio at redhat.com Mon Dec 3 09:11:48 2018 From: fidencio at redhat.com (=?UTF-8?q?Fabiano=20Fid=C3=AAncio?=) Date: Mon, 3 Dec 2018 10:11:48 +0100 Subject: [Libosinfo] [libosinfo PATCH 3/7] install-script: Add _(get|set)_preferred_injection_method() In-Reply-To: <20181203091152.31307-1-fidencio@redhat.com> References: <20181203091152.31307-1-fidencio@redhat.com> Message-ID: <20181203091152.31307-4-fidencio@redhat.com> Those new methods are going to be used to tell the install-scripts whether the injection-method that's going to be used is. We have to do so as the command-line may be different depending on the injection-method used, for example: - fedora using cdrom, disk or floppy: ks=hd:/(vda|sda)/fedora.ks - fedora using initrd: ks=file:/fedora.ks Signed-off-by: Fabiano Fid?ncio --- osinfo/libosinfo.syms | 3 ++ osinfo/osinfo_install_script.c | 79 ++++++++++++++++++++++++++++++++++ osinfo/osinfo_install_script.h | 4 ++ 3 files changed, 86 insertions(+) diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms index 365914c..26298df 100644 --- a/osinfo/libosinfo.syms +++ b/osinfo/libosinfo.syms @@ -536,6 +536,9 @@ LIBOSINFO_1.3.0 { osinfo_error_quark; + osinfo_install_script_get_preferred_injection_method; + osinfo_install_script_set_preferred_injection_method; + osinfo_os_add_maximum_resources; osinfo_os_get_all_device_links; osinfo_os_get_maximum_resources; diff --git a/osinfo/osinfo_install_script.c b/osinfo/osinfo_install_script.c index 016f850..10cb5f3 100644 --- a/osinfo/osinfo_install_script.c +++ b/osinfo/osinfo_install_script.c @@ -64,6 +64,7 @@ enum { PROP_PRODUCT_KEY_FORMAT, PROP_PATH_FORMAT, PROP_AVATAR_FORMAT, + PROP_PREFERRED_INJECTION_METHOD }; typedef struct _OsinfoInstallScriptGenerateData OsinfoInstallScriptGenerateData; @@ -105,6 +106,11 @@ osinfo_install_script_set_property(GObject *object, data); break; + case PROP_PREFERRED_INJECTION_METHOD: + osinfo_install_script_set_preferred_injection_method(script, + g_value_get_flags(value)); + break; + default: /* We don't have any other property... */ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); @@ -151,6 +157,11 @@ osinfo_install_script_get_property(GObject *object, osinfo_install_script_get_avatar_format(script)); break; + case PROP_PREFERRED_INJECTION_METHOD: + g_value_set_flags(value, + osinfo_install_script_get_preferred_injection_method(script)); + break; + default: /* We don't have any other property... */ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); @@ -254,6 +265,17 @@ osinfo_install_script_class_init(OsinfoInstallScriptClass *klass) PROP_AVATAR_FORMAT, pspec); + pspec = g_param_spec_flags("preferred-injection-method", + "Preferred Injection Method", + _("The preferred injection method"), + OSINFO_TYPE_INSTALL_SCRIPT_INJECTION_METHOD, + OSINFO_INSTALL_SCRIPT_INJECTION_METHOD_DISK, /* default value */ + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + g_object_class_install_property(g_klass, + PROP_PREFERRED_INJECTION_METHOD, + pspec); + g_type_class_add_private(klass, sizeof(OsinfoInstallScriptPrivate)); } @@ -1765,6 +1787,63 @@ gboolean osinfo_install_script_get_needs_internet(OsinfoInstallScript *script) FALSE); } +/** + * osinfo_install_script_set_preferred_injection_method: + * @script: the install script + * @method: one of the injection methods: + * OSINFO_INSTALL_SCRIPT_INJECTION_METHOD_CDROM, + * OSINFO_INSTALL_SCRIPT_INJECTION_METHOD_DISK, + * OSINFO_INSTALL_SCRIPT_INJECTION_METHOD_FLOPPY, + * OSINFO_INSTALL_SCRIPT_INJECTION_METHOD_INITRD, + * OSINFO_INSTALL_SCRIPT_INJECTION_METHOD_WEB + * + * Set the preferred injection method to be used with the @script + */ +void osinfo_install_script_set_preferred_injection_method(OsinfoInstallScript *script, + OsinfoInstallScriptInjectionMethod method) +{ + unsigned int supported_methods; + + supported_methods = osinfo_install_script_get_injection_methods(script); + if ((method & supported_methods) == 0) { + g_warning("The injection-method passed is not supported by the install-script"); + return; + } + + osinfo_entity_set_param_flags + (OSINFO_ENTITY(script), + OSINFO_INSTALL_SCRIPT_PROP_PREFERRED_INJECTION_METHOD, + method, + OSINFO_TYPE_INSTALL_SCRIPT_INJECTION_METHOD); +} + +/** + * osinfo_install_script_get_preferred_injection_method: + * @script: the install script + * + * Returns: the preferred injection method for the script. If none is set and + * OSINFO_INSTALL_SCRIPT_INJECTION_METHOD_DISK is supported, + * OSINFO_INSTALL_SCRIPT_INJECTION_METHOD_DISK is returned, otherwise + * OSINFO_INSTALL_SCRIPT_INJECTION_METHOD_INITRD is returned. + */ +OsinfoInstallScriptInjectionMethod +osinfo_install_script_get_preferred_injection_method(OsinfoInstallScript *script) +{ + unsigned int supported_methods; + OsinfoInstallScriptInjectionMethod default_preferred; + supported_methods = osinfo_install_script_get_injection_methods(script); + + if ((OSINFO_INSTALL_SCRIPT_INJECTION_METHOD_DISK & supported_methods) != 0) + default_preferred = OSINFO_INSTALL_SCRIPT_INJECTION_METHOD_DISK; + else + default_preferred = OSINFO_INSTALL_SCRIPT_INJECTION_METHOD_INITRD; + + return osinfo_entity_get_param_value_flags + (OSINFO_ENTITY(script), + OSINFO_INSTALL_SCRIPT_PROP_PREFERRED_INJECTION_METHOD, + OSINFO_TYPE_INSTALL_SCRIPT_INJECTION_METHOD, + default_preferred); +} /* * Local variables: diff --git a/osinfo/osinfo_install_script.h b/osinfo/osinfo_install_script.h index e07ab5e..ed634db 100644 --- a/osinfo/osinfo_install_script.h +++ b/osinfo/osinfo_install_script.h @@ -60,6 +60,7 @@ typedef struct _OsinfoInstallScriptPrivate OsinfoInstallScriptPrivate; #define OSINFO_INSTALL_SCRIPT_PROP_PRE_INSTALL_DRIVERS_SIGNING_REQ "pre-install-drivers-signing-req" #define OSINFO_INSTALL_SCRIPT_PROP_POST_INSTALL_DRIVERS_SIGNING_REQ "post-install-drivers-signing-req" #define OSINFO_INSTALL_SCRIPT_PROP_INJECTION_METHOD "injection-method" +#define OSINFO_INSTALL_SCRIPT_PROP_PREFERRED_INJECTION_METHOD "preferred-injection-method" /* object */ struct _OsinfoInstallScript @@ -255,6 +256,9 @@ unsigned int osinfo_install_script_get_injection_methods(OsinfoInstallScript *sc gboolean osinfo_install_script_get_needs_internet(OsinfoInstallScript *script); +void osinfo_install_script_set_preferred_injection_method(OsinfoInstallScript *script, + OsinfoInstallScriptInjectionMethod method); +OsinfoInstallScriptInjectionMethod osinfo_install_script_get_preferred_injection_method(OsinfoInstallScript *script); #endif /* __OSINFO_INSTALL_SCRIPT_H__ */ /* * Local variables: -- 2.19.1 From fidencio at redhat.com Mon Dec 3 09:11:49 2018 From: fidencio at redhat.com (=?UTF-8?q?Fabiano=20Fid=C3=AAncio?=) Date: Mon, 3 Dec 2018 10:11:49 +0100 Subject: [Libosinfo] [libosinfo PATCH 4/7] test-install-script: Cover _(get|set)_preferred_injection_method() In-Reply-To: <20181203091152.31307-1-fidencio@redhat.com> References: <20181203091152.31307-1-fidencio@redhat.com> Message-ID: <20181203091152.31307-5-fidencio@redhat.com> Signed-off-by: Fabiano Fid?ncio --- .../libosinfo-test-install-script.xml | 5 ++++ tests/test-install-script.c | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/tests/dbdata/install-script/example.com/libosinfo-test-install-script.xml b/tests/dbdata/install-script/example.com/libosinfo-test-install-script.xml index e3c05b7..f03da75 100644 --- a/tests/dbdata/install-script/example.com/libosinfo-test-install-script.xml +++ b/tests/dbdata/install-script/example.com/libosinfo-test-install-script.xml @@ -8,6 +8,11 @@ + cdrom + disk + floppy + initrd +