Skip to content

Commit 507ff3d

Browse files
committed
API1: Don't fail merges when default streams differ
Instead of failing the merge on a default stream conflict, we will instead treat it as having no default set. This is safe because if the module is not yet installed, then this just means its packages aren't visible and it needs to be selected explicitly. If some packages from it are already installed, then the module stream is already set, and thus changing the default won't matter. Resolves: rhbz#1666871 Signed-off-by: Stephen Gallagher <[email protected]>
1 parent b74b0f0 commit 507ff3d

File tree

4 files changed

+103
-14
lines changed

4 files changed

+103
-14
lines changed

modulemd/v1/include/modulemd-1.0/private/modulemd-private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ enum
2626

2727
#define MD_VERSION_LATEST MD_VERSION_2
2828

29+
#define DEFAULT_MERGE_CONFLICT "__merge_conflict__"
30+
2931
ModulemdModule *
3032
modulemd_module_new_from_modulestream (ModulemdModuleStream *stream);
3133

modulemd/v1/modulemd-defaults.c

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "modulemd.h"
1515
#include "modulemd-defaults.h"
1616
#include "modulemd-simpleset.h"
17+
#include "private/modulemd-private.h"
1718
#include "private/modulemd-yaml.h"
1819

1920

@@ -148,6 +149,15 @@ modulemd_defaults_peek_default_stream (ModulemdDefaults *self)
148149
{
149150
g_return_val_if_fail (self, NULL);
150151

152+
if (self->default_stream &&
153+
g_str_equal (self->default_stream, DEFAULT_MERGE_CONFLICT))
154+
{
155+
/* During an index merge, we determined that this was in conflict
156+
* with another set of ModulemdDefaults for the same module. If we
157+
* see this, treat it as no default stream when querying for it.
158+
*/
159+
return NULL;
160+
}
151161
return self->default_stream;
152162
}
153163

@@ -157,6 +167,16 @@ modulemd_defaults_dup_default_stream (ModulemdDefaults *self)
157167
{
158168
g_return_val_if_fail (self, NULL);
159169

170+
if (self->default_stream &&
171+
g_str_equal (self->default_stream, DEFAULT_MERGE_CONFLICT))
172+
{
173+
/* During an index merge, we determined that this was in conflict
174+
* with another set of ModulemdDefaults for the same module. If we
175+
* see this, treat it as no default stream when querying for it.
176+
*/
177+
return NULL;
178+
}
179+
160180
return g_strdup (self->default_stream);
161181
}
162182

@@ -755,24 +775,21 @@ modulemd_defaults_merge (ModulemdDefaults *first,
755775
* Merge them as best we can.
756776
*/
757777

778+
defaults = modulemd_defaults_copy (first);
779+
758780
/* First check for incompatibilities with the streams */
759-
if (g_strcmp0 (modulemd_defaults_peek_default_stream (first),
760-
modulemd_defaults_peek_default_stream (second)))
781+
if (g_strcmp0 (first->default_stream, second->default_stream))
761782
{
762783
/* Default streams don't match and override is not set.
763784
* Return an error
764785
*/
765-
g_set_error (
766-
error,
767-
MODULEMD_DEFAULTS_ERROR,
768-
MODULEMD_DEFAULTS_ERROR_CONFLICTING_STREAMS,
769-
"Conflicting default streams when merging defaults for module %s",
770-
modulemd_defaults_peek_module_name (first));
771-
return NULL;
786+
/* They have conflicting default streams */
787+
g_info ("Module stream mismatch in merge: %s != %s",
788+
first->default_stream,
789+
second->default_stream);
790+
modulemd_defaults_set_default_stream (defaults, DEFAULT_MERGE_CONFLICT);
772791
}
773792

774-
defaults = modulemd_defaults_copy (first);
775-
776793
/* Merge the profile defaults */
777794
profile_defaults = modulemd_defaults_peek_profile_defaults (defaults);
778795

modulemd/v1/tests/test-modulemd-defaults.c

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ modulemd_defaults_test_prioritizer (DefaultsFixture *fixture,
604604
g_autofree gchar *yaml_override_path = NULL;
605605
g_autoptr (GPtrArray) base_objects = NULL;
606606
g_autoptr (GPtrArray) override_objects = NULL;
607+
g_autoptr (GPtrArray) override_nodejs_objects = NULL;
607608
g_autoptr (GPtrArray) merged_objects = NULL;
608609
g_autoptr (ModulemdPrioritizer) prioritizer = NULL;
609610
g_autoptr (GError) error = NULL;
@@ -620,6 +621,18 @@ modulemd_defaults_test_prioritizer (DefaultsFixture *fixture,
620621
g_assert_nonnull (base_objects);
621622
g_assert_cmpint (base_objects->len, ==, 7);
622623

624+
625+
yaml_override_path =
626+
g_strdup_printf ("%s/test_data/defaults/overriding-nodejs.yaml",
627+
g_getenv ("MESON_SOURCE_ROOT"));
628+
g_assert_nonnull (yaml_override_path);
629+
630+
override_nodejs_objects =
631+
modulemd_objects_from_file (yaml_override_path, &error);
632+
g_clear_pointer (&yaml_override_path, g_free);
633+
g_assert_nonnull (override_nodejs_objects);
634+
g_assert_cmpint (override_nodejs_objects->len, ==, 1);
635+
623636
yaml_override_path = g_strdup_printf (
624637
"%s/test_data/defaults/overriding.yaml", g_getenv ("MESON_SOURCE_ROOT"));
625638
g_assert_nonnull (yaml_override_path);
@@ -661,6 +674,48 @@ modulemd_defaults_test_prioritizer (DefaultsFixture *fixture,
661674
g_assert_true (result);
662675

663676

677+
/*
678+
* Test that importing the nodejs overrides at the same priority level fails.
679+
*
680+
* This YAML has a conflicting default stream which should be ignored and set
681+
* to "no default stream".
682+
*/
683+
684+
result = modulemd_prioritizer_add (
685+
prioritizer, override_nodejs_objects, prio, &error);
686+
g_assert_true (result);
687+
688+
merged_objects = modulemd_prioritizer_resolve (prioritizer, &error);
689+
g_assert_nonnull (merged_objects);
690+
g_assert_cmpint (merged_objects->len, ==, 3);
691+
692+
for (gint i = 0; i < merged_objects->len; i++)
693+
{
694+
if (MODULEMD_IS_DEFAULTS (g_ptr_array_index (merged_objects, i)))
695+
{
696+
defaults = g_ptr_array_index (merged_objects, i);
697+
if (!g_strcmp0 (modulemd_defaults_peek_module_name (defaults),
698+
"nodejs"))
699+
{
700+
g_assert_null (modulemd_defaults_peek_default_stream (defaults));
701+
}
702+
}
703+
}
704+
705+
g_clear_pointer (&merged_objects, g_ptr_array_unref);
706+
707+
708+
/* Start over and test profile conflicts */
709+
g_clear_pointer (&prioritizer, g_object_unref);
710+
prioritizer = modulemd_prioritizer_new ();
711+
result = modulemd_prioritizer_add (prioritizer, base_objects, prio, &error);
712+
if (!result)
713+
{
714+
fprintf (stderr, "Merge error: %s", error->message);
715+
}
716+
g_assert_true (result);
717+
718+
664719
/*
665720
* Test that importing the overrides at the same priority level fails.
666721
*
@@ -673,7 +728,7 @@ modulemd_defaults_test_prioritizer (DefaultsFixture *fixture,
673728
g_assert_cmpstr (
674729
g_quark_to_string (error->domain), ==, "modulemd-defaults-error-quark");
675730
g_assert_cmpint (
676-
error->code, ==, MODULEMD_DEFAULTS_ERROR_CONFLICTING_STREAMS);
731+
error->code, ==, MODULEMD_DEFAULTS_ERROR_CONFLICTING_PROFILES);
677732
g_clear_pointer (&error, g_error_free);
678733

679734
/* The object's internal state is undefined after an error, so delete it */
@@ -989,7 +1044,7 @@ modulemd_defaults_test_index_prioritizer (DefaultsFixture *fixture,
9891044
g_assert_cmpstr (
9901045
g_quark_to_string (error->domain), ==, "modulemd-defaults-error-quark");
9911046
g_assert_cmpint (
992-
error->code, ==, MODULEMD_DEFAULTS_ERROR_CONFLICTING_STREAMS);
1047+
error->code, ==, MODULEMD_DEFAULTS_ERROR_CONFLICTING_PROFILES);
9931048
g_clear_pointer (&error, g_error_free);
9941049

9951050
/* The object's internal state is undefined after an error, so delete it */
@@ -1140,6 +1195,11 @@ modulemd_regressions_issue44 (DefaultsFixture *fixture,
11401195

11411196
/* Add another almost-identical document, except with a conflicting default
11421197
* stream set.
1198+
*
1199+
* NOTE: when this was written (for issue 44 on GitHub), this was meant to be
1200+
* a hard error. As of 1.8.1 we expect this to just result in having no
1201+
* default stream for this module. This test has been slightly modified so
1202+
* that the expected result is now a pass.
11431203
*/
11441204
yaml_conflicting_path = g_strdup_printf (
11451205
"%s/test_data/defaults/issue44-2.yaml", g_getenv ("MESON_SOURCE_ROOT"));
@@ -1151,7 +1211,7 @@ modulemd_regressions_issue44 (DefaultsFixture *fixture,
11511211

11521212
result =
11531213
modulemd_prioritizer_add (prioritizer, conflicting_objects, 0, &error);
1154-
g_assert_false (result);
1214+
g_assert_true (result);
11551215
}
11561216

11571217

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
document: modulemd-defaults
3+
version: 1
4+
data:
5+
module: nodejs
6+
stream: '9.0'
7+
profiles:
8+
'6.0': [default]
9+
'8.0': [super]
10+
'9.0': [supermegaultra]

0 commit comments

Comments
 (0)