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/996055
Signed-off-by: Roy Golan <rgo...@redhat.com>
---
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, 21 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/40/34740/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 ee91e66..27a5e47 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
@@ -91,7 +91,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 47a2720..b5c451d 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;
 
@@ -18,6 +20,7 @@
 import org.ovirt.engine.core.common.osinfo.MapBackedPreferences;
 import org.ovirt.engine.core.common.utils.Pair;
 import org.ovirt.engine.core.compat.Version;
+
 
 public class OsRepositoryImplTest {
 
@@ -267,4 +270,16 @@
                         .get(new Pair<>(20, 
Version.getLast())).contains("Conroe".toLowerCase()));
     }
 
+    @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/34740
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9f19a1d33336f020b1ff71d9bcfd06eaee45e81d
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.5
Gerrit-Owner: Roy Golan <rgo...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to