Roy Golan has uploaded a new change for review.
Change subject: core: Fix broken backward compatibility of os ids
......................................................................
core: Fix broken backward compatibility of os ids
This fix is about maintaining oss backward compatibility mappings of
old os names to the current IDs.
Vm Import/Export is using the os unique name instead of the os ID in the
OVF and since all unique names streamlined with the REST API
representation they all are not identified and fallback ID 0 - "other"
pre-osinfo exports would write the OS Windows8 while the new name is
windows_8 and so on
Solution:
Added a backward compatibility section to osinfo-default.properties
# Since Unassigned is removed we translate is to other so
backwardCompatibility.Unasigned = 0
backwardCompatibility.Other = 0
# represents the current id of old Windows8 os
backwardCompatibilty.Windows8 = 20
Bug-Url: https://bugzilla.redhat.com/1006340
Change-Id: I77c51a3bd0f4f0c264e8f895f40fd4d2bf4d689c
Signed-off-by: Roy Golan <[email protected]>
---
M
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepositoryImpl.java
M
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java
M packaging/conf/osinfo-defaults.properties
3 files changed, 57 insertions(+), 8 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/74/19774/1
diff --git
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepositoryImpl.java
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepositoryImpl.java
index 1642a1b..60adb6d 100644
---
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepositoryImpl.java
+++
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepositoryImpl.java
@@ -19,6 +19,7 @@
INSTANCE;
private static final String OS_ROOT_NODE = "/os/";
+ private static final String BACKWARD_COMPATIBILITY_ROOT_NODE =
"/backwardCompatibility";
/**
* the configuration tree holding all the os data.
*/
@@ -29,16 +30,18 @@
* db is 8 and the unique name is "rhel6"
*/
private Map<Integer, String> idToUnameLookup;
+ private Map<String, Integer> backwardCompatibleNamesToIds;
public void init(MapBackedPreferences preferences) {
INSTANCE.preferences = preferences;
emptyNode = preferences.node("emptyNode");
buildIdToUnameLookup();
+ buildBackCompatMapping();
}
private void buildIdToUnameLookup() {
try {
- String[] uniqueNames = preferences.node("/os").childrenNames();
+ String[] uniqueNames =
preferences.node(OS_ROOT_NODE).childrenNames();
idToUnameLookup = new HashMap<Integer, String>(uniqueNames.length);
for (String uniqueName : Arrays.asList(uniqueNames)) {
Preferences idNode = getKeyNode(uniqueName, "id", null);
@@ -48,6 +51,20 @@
}
} catch (BackingStoreException e) {
throw new RuntimeException("Failed to initialize Os Repository due
to " + e);
+ }
+ }
+
+ private void buildBackCompatMapping() {
+ try {
+ String[] entries =
preferences.node(BACKWARD_COMPATIBILITY_ROOT_NODE).childrenNames();
+ backwardCompatibleNamesToIds = new HashMap<String,
Integer>(entries.length);
+ for (String oldOsName : Arrays.asList(entries)) {
+ if (preferences.nodeExists(oldOsName)) {
+ backwardCompatibleNamesToIds.put(oldOsName,
preferences.node(oldOsName).getInt(oldOsName, 0));
+ }
+ }
+ } catch (BackingStoreException e) {
+ throw new RuntimeException("Failed to initialize Os Repository
Backward Compatibility mappings due to " + e);
}
}
@@ -190,6 +207,11 @@
return entry.getKey();
}
}
+
+ if (getBackwardCompatibleNamesToIds().containsKey(uniqueOsName)) {
+ return getBackwardCompatibleNamesToIds().get(uniqueOsName);
+ }
+
return 0;
}
@@ -303,4 +325,8 @@
public boolean isSingleQxlDeviceEnabled(int osId) {
return isLinux(osId);
}
+
+ public Map<String, Integer> getBackwardCompatibleNamesToIds() {
+ return backwardCompatibleNamesToIds;
+ }
}
diff --git
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java
index cb2569e..f23de6b 100644
---
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java
+++
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java
@@ -13,11 +13,10 @@
import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType;
import org.ovirt.engine.core.common.businessentities.UsbPolicy;
import org.ovirt.engine.core.common.businessentities.VM;
-import org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType;
import org.ovirt.engine.core.common.businessentities.VmDevice;
+import org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType;
import org.ovirt.engine.core.common.businessentities.VmStatic;
import
org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface;
-import org.ovirt.engine.core.common.osinfo.OsRepository;
import org.ovirt.engine.core.common.utils.VmDeviceCommonUtils;
import org.ovirt.engine.core.compat.Guid;
import org.ovirt.engine.core.compat.backendcompat.XmlDocument;
@@ -44,10 +43,6 @@
_vm.getStaticData().setId(new
Guid(section.Attributes.get("ovf:id").getValue()));
XmlNode node = section.SelectSingleNode("Description");
if (node != null) {
- // backward compatibility code - os id of type Other is now 0 .
"Unassigned" is removed but its Id is in use
- if
(node.InnerText.equals(String.valueOf(OsRepository.OLD_OTHER_ID))) {
- node.InnerText = String.valueOf(OsRepository.DEFAULT_OS);
- }
_vm.getStaticData().setOsId(osRepository.getOsIdByUniqueName(node.InnerText));
}
}
diff --git a/packaging/conf/osinfo-defaults.properties
b/packaging/conf/osinfo-defaults.properties
index e56160b..220cbce 100644
--- a/packaging/conf/osinfo-defaults.properties
+++ b/packaging/conf/osinfo-defaults.properties
@@ -225,4 +225,32 @@
os.ubuntu_13_10.id.value = 1255
os.ubuntu_13_10.name.value = Ubuntu Saucy Salamander
-os.ubuntu_13_10.derivedFrom.value = ubuntu_13_04
\ No newline at end of file
+os.ubuntu_13_10.derivedFrom.value = ubuntu_13_04
+
+
+# Backward Compatibility Section
+# Keep a mapping of the old os unique names to new od IDs
+# in order to support correct imports of pre-osinfo VMs
+backwardCompatibily.Unassigned = 0
+backwardCompatibily.Other = 0
+backwardCompatibily.OtherLinux = 5
+backwardCompatibily.REHL3 = 9
+backwardCompatibily.RHEL3x64 = 15
+backwardCompatibily.RHEL4 = 8
+backwardCompatibily.RHEL4x64 = 14
+backwardCompatibily.RHEL5 = 7
+backwardCompatibily.RHEL5x64 = 13
+backwardCompatibily.RHEL6 = 18
+backwardCompatibily.RHEL6x64 = 19
+backwardCompatibily.WindowsXP = 1
+backwardCompatibily.Windows2003 = 3
+backwardCompatibily.Windows2008 = 4
+backwardCompatibily.Windows2003x64 = 10
+backwardCompatibily.Windows7 = 11
+backwardCompatibily.Windows7x64 = 12
+backwardCompatibily.Windows2008x64 = 16
+backwardCompatibily.Windows2008R2x64 = 17
+backwardCompatibily.Windows8 = 20
+backwardCompatibily.Windows8x64 = 21
+backwardCompatibily.Windows2012x64 = 23
+
--
To view, visit http://gerrit.ovirt.org/19774
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I77c51a3bd0f4f0c264e8f895f40fd4d2bf4d689c
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