Roy Golan has uploaded a new change for review. Change subject: core: osinfo - fail backend startup on coliding os id error ......................................................................
core: osinfo - fail backend startup on coliding os id error fail loading the backend by throwing a RuntimeException if an osinfo properties have colliding id's. e.g os.linux.id.value = 12345 os.windows.id.value = 12345 obviously wrong and should fail with logged exception "java.lang.RuntimeException: colliding os id 12345 at node /os/windows/id" Change-Id: I9f19a1d33336f020b1ff71d9bcfd06eaee45e81d Bug-Url: https://bugzilla.redhat.com/?????? Signed-off-by: Roy Golan <[email protected]> --- M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/OsRepositoryImpl.java M backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/OsRepositoryImplTest.java 2 files changed, 23 insertions(+), 1 deletion(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/73/31373/1 diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/OsRepositoryImpl.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/OsRepositoryImpl.java index f610bac..79e38bf 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/OsRepositoryImpl.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/OsRepositoryImpl.java @@ -95,7 +95,12 @@ for (String uniqueName : uniqueNames) { Preferences idNode = getKeyNode(uniqueName, "id", null); if (idNode != null) { - idToUnameLookup.put(idNode.getInt("value", 0), uniqueName); + int osId = idNode.getInt("value", 0); + if (idNode != emptyNode && idToUnameLookup.containsKey(osId)) { + throw new RuntimeException(String.format("colliding os id %s at node %s", osId, idNode.absolutePath())); + } else { + idToUnameLookup.put(osId, uniqueName); + } } } } catch (BackingStoreException e) { diff --git a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/OsRepositoryImplTest.java b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/OsRepositoryImplTest.java index 8d16db7..cab1722 100644 --- a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/OsRepositoryImplTest.java +++ b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/OsRepositoryImplTest.java @@ -9,6 +9,8 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.prefs.BackingStoreException; +import java.util.prefs.Preferences; import org.junit.Assert; @@ -17,6 +19,8 @@ import org.ovirt.engine.core.common.businessentities.DisplayType; import org.ovirt.engine.core.common.osinfo.MapBackedPreferences; import org.ovirt.engine.core.compat.Version; + +import javax.swing.text.rtf.RTFEditorKit; public class OsRepositoryImplTest { @@ -244,4 +248,17 @@ public void testHyperVWindows() throws Exception { assertTrue(OsRepositoryImpl.INSTANCE.isHypervEnabled(OsRepositoryImpl.INSTANCE.getOsIdByUniqueName("windows_7"), Version.v3_5)); } + + @Test + public void testUniqueOsIdValidation() throws BackingStoreException { + Preferences invalidNode = preferences.node("/os/ubuntu/id"); + invalidNode.put("value", "777"); + try { + OsRepositoryImpl.INSTANCE.init(preferences); + } catch (RuntimeException e) { + // expected + } + invalidNode.removeNode(); + OsRepositoryImpl.INSTANCE.init(preferences); // must pass with no exceptions + } } -- To view, visit http://gerrit.ovirt.org/31373 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9f19a1d33336f020b1ff71d9bcfd06eaee45e81d Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Roy Golan <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
