Yair Zaslavsky has uploaded a new change for review.

Change subject: tools: Handling add first/removing last domain (#858769)
......................................................................

tools: Handling add first/removing last domain (#858769)

https://bugzilla.redhat.com/858769

This patch fixes issues with adding first/removing last domain
and changing the value of option AdUserPassword

Change-Id: I4fcfc9cf68131e80a481d8d1962f3afc1c30ae7f
Signed-off-by: Yair Zaslavsky <yzasl...@redhat.com>
---
M 
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/kerberos/ConfigurationProvider.java
M 
backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/EngineConfigLogic.java
M 
backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/entity/ConfigKeyFactory.java
M 
backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/entity/helper/CompositePasswordValueHelper.java
M 
backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/entity/helper/PasswordValueHelper.java
5 files changed, 37 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/78/8178/1

diff --git 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/kerberos/ConfigurationProvider.java
 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/kerberos/ConfigurationProvider.java
index 7a6196e..bb81445 100644
--- 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/kerberos/ConfigurationProvider.java
+++ 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/kerberos/ConfigurationProvider.java
@@ -10,8 +10,10 @@
 
 import java.io.BufferedWriter;
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.PrintWriter;
 import java.util.EnumMap;
 
 import org.apache.log4j.Logger;
@@ -94,18 +96,21 @@
         File passFile = null;
 
         try {
-            passFile = createPassFile(entry.getDomainsConfigurationEntry());
-            String executeCmd = engineConfigExecutable + " -s "
-                    + enumValue.name() + ((passedAsValue) ? "=" + 
entry.getDomainsConfigurationEntry() :
-                        " --admin-pass-file " + passFile.getAbsolutePath())
-                        + " -p " + engineConfigProperties;
-
-            Process engineConfigProcess = 
Runtime.getRuntime().exec(executeCmd);
+            StringBuilder executeCmd = new 
StringBuilder(engineConfigExecutable);
+            executeCmd.append(" -s ").append(enumValue.name());
+            if (passedAsValue) {
+                executeCmd.append("=" + entry.getDomainsConfigurationEntry());
+            } else {
+                passFile = 
createPassFile(entry.getDomainsConfigurationEntry());
+                executeCmd.append(" --admin-pass-file " + 
passFile.getAbsolutePath());
+            }
+            executeCmd.append(" -p " + engineConfigProperties);
+            Process engineConfigProcess = 
Runtime.getRuntime().exec(executeCmd.toString());
 
             int retVal = engineConfigProcess.waitFor();
             if (retVal != 0) {
                 throw new 
ManageDomainsResult(ManageDomainsResultEnum.FAILED_SETTING_CONFIGURATION_VALUE_FOR_OPTION,
-                        enumValue.name() + " - execute command: " + 
executeCmd);
+                        enumValue.name() + " - execute command: " + 
executeCmd.toString());
             }
         } catch (Throwable e) {
             throw new 
ManageDomainsResult(ManageDomainsResultEnum.FAILED_SETTING_CONFIGURATION_VALUE_FOR_OPTION_WITH_DETAILS,
diff --git 
a/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/EngineConfigLogic.java
 
b/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/EngineConfigLogic.java
index 05a1e8d..c2e43eb 100644
--- 
a/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/EngineConfigLogic.java
+++ 
b/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/EngineConfigLogic.java
@@ -2,9 +2,11 @@
 
 import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.io.PrintWriter;
 import java.net.ConnectException;
 import java.security.InvalidParameterException;
 import java.sql.SQLException;
@@ -145,6 +147,11 @@
     }
 
     public static String getPassFromFile(String passFile) throws IOException {
+        File f = new File(passFile);
+        if (!f.exists())
+        {
+            return StringUtils.EMPTY;
+        }
         FileReader input = new FileReader(passFile);
         BufferedReader br = new BufferedReader(input);
         String pass = br.readLine();
@@ -153,6 +160,9 @@
             br.close();
         } catch (Exception e) {
             // Ignore
+        }
+        if (pass == null) {
+            return StringUtils.EMPTY;
         }
         return pass;
     }
@@ -315,7 +325,7 @@
         if (version == null) {
             version = startVersionDialog(key);
         }
-
+        
         boolean sucessUpdate = persist(key, value, version);
         if (!sucessUpdate) {
             log.debug("setValue: error setting " + key + "'s value. No such 
entry"
@@ -324,7 +334,7 @@
                     + (version == null ? "" : " with version " + version) + 
".");
         }
     }
-
+    
     /**
      * Is called when it is unclear which version is desired. If only one 
version exists for the given key, assumes that
      * is the desired version, if more than one exist, prompts the user to 
choose one.
diff --git 
a/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/entity/ConfigKeyFactory.java
 
b/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/entity/ConfigKeyFactory.java
index 3201991..6a1730e 100644
--- 
a/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/entity/ConfigKeyFactory.java
+++ 
b/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/entity/ConfigKeyFactory.java
@@ -3,7 +3,6 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Map;
-
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.commons.configuration.SubnodeConfiguration;
 import org.apache.commons.lang.StringUtils;
diff --git 
a/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/entity/helper/CompositePasswordValueHelper.java
 
b/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/entity/helper/CompositePasswordValueHelper.java
index 8f6046a..ca1268f 100644
--- 
a/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/entity/helper/CompositePasswordValueHelper.java
+++ 
b/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/entity/helper/CompositePasswordValueHelper.java
@@ -1,7 +1,10 @@
 package org.ovirt.engine.core.config.entity.helper;
 
+import java.io.FileOutputStream;
+import java.io.PrintWriter;
 import java.util.StringTokenizer;
 
+import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.config.EngineConfigCLIParser;
 import org.ovirt.engine.core.config.entity.ConfigKey;
 
@@ -27,11 +30,11 @@
 
     @Override
     public String setValue(String value) throws Exception {
-        // Happens only when deleting password value
-        if (value.isEmpty()){
-            return "";
-        }
         value = pwdValueHelper.extractPasswordValue(value);
+        // Happens only when deleting password value
+        if (StringUtils.isBlank(value)) {
+            return StringUtils.EMPTY;
+        }
         return reformatKeyVal(value, ReformatType.ENCRYPT);
     }
 
diff --git 
a/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/entity/helper/PasswordValueHelper.java
 
b/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/entity/helper/PasswordValueHelper.java
index 7eb5c75..0a34e6c 100644
--- 
a/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/entity/helper/PasswordValueHelper.java
+++ 
b/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/entity/helper/PasswordValueHelper.java
@@ -21,6 +21,7 @@
     private static String keyStorePass;
     private static final Logger log = 
Logger.getLogger(PasswordValueHelper.class);
     public static final String INTERACTIVE_MODE = "Interactive";
+    public static final String ADMIN_PASS_FILE = "admin-pass-file";
     private EngineConfigCLIParser parser;
 
     static {
@@ -87,6 +88,9 @@
 
         try {
             password = extractPasswordValue(value);
+            if (StringUtils.isBlank(password)) {
+                return StringUtils.EMPTY;
+            }
             returnedValue = encrypt(password);
         } catch (Throwable e) {
             String msg = "Failed to encrypt the current value";
@@ -102,7 +106,7 @@
         if (StringUtils.isNotBlank(value) && 
value.equalsIgnoreCase(INTERACTIVE_MODE)) {
             password = EngineConfigLogic.startPasswordDialog(null);
         } else {
-            password =
+                password =
                     
EngineConfigLogic.getPassFromFile((StringUtils.isNotBlank(value)) ? value
                             : parser.getAdminPassFile());
         }


--
To view, visit http://gerrit.ovirt.org/8178
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4fcfc9cf68131e80a481d8d1962f3afc1c30ae7f
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Yair Zaslavsky <yzasl...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to