Laszlo Hornyak has uploaded a new change for review.

Change subject: engine: unit test for VdsDeploy.getEngineSSHPublicKey
......................................................................

engine: unit test for VdsDeploy.getEngineSSHPublicKey

- removed the _ prefix from method name
- added junit test for the method

Change-Id: Ie5397eece5eabf81755df93c381d9bb6934b237e
Signed-off-by: Laszlo Hornyak <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsDeploy.java
A 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/VdsDeployTest.java
A backend/manager/modules/bll/src/test/resources/engine.p12
3 files changed, 34 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/19/12719/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsDeploy.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsDeploy.java
index 974303d..c2ed771 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsDeploy.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsDeploy.java
@@ -13,13 +13,14 @@
 import java.text.SimpleDateFormat;
 import java.util.Arrays;
 import java.util.Calendar;
+import java.util.Enumeration;
 import java.util.List;
 import java.util.TimeZone;
 import java.util.concurrent.Callable;
+
 import javax.naming.TimeLimitExceededException;
 
 import org.apache.commons.lang.StringUtils;
-
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
 import org.ovirt.engine.core.common.businessentities.VDSStatus;
@@ -40,7 +41,6 @@
 import org.ovirt.engine.core.utils.ssh.SSHDialog;
 import org.ovirt.engine.core.utils.transaction.TransactionMethod;
 import org.ovirt.engine.core.utils.transaction.TransactionSupport;
-
 import org.ovirt.otopi.constants.BaseEnv;
 import org.ovirt.otopi.constants.Confirms;
 import org.ovirt.otopi.constants.CoreEnv;
@@ -197,7 +197,7 @@
      * Return the engine ssh public key to install on host.
      * @return ssh public key.
      */
-    private static String _getEngineSSHPublicKey() {
+    static String getEngineSSHPublicKey() {
         final String keystoreFile = 
Config.<String>GetValue(ConfigValues.keystoreUrl);
         final String alias = Config.<String>GetValue(ConfigValues.CertAlias);
         final char[] password = 
Config.<String>GetValue(ConfigValues.keystorePass).toCharArray();
@@ -210,6 +210,16 @@
 
             final Certificate cert = ks.getCertificate(alias);
             if (cert == null) {
+                Enumeration<String> aliases = ks.aliases();
+                log.info("Alias with name '"+alias+"' not found in 
"+keystoreFile);
+                StringBuilder aliaslist = new StringBuilder();
+                while(aliases.hasMoreElements()) {
+                    if(aliaslist.length() != 0) {
+                        aliaslist.append(", ");
+                    }
+                    aliaslist.append(aliases.nextElement());
+                }
+                log.info("aliases: " + aliaslist.toString());
                 throw new KeyStoreException(
                     String.format(
                         "Failed to find certificate store '%1$s' using alias 
'%2$s'",
@@ -341,7 +351,7 @@
         new Callable<Object>() { public Object call() throws Exception {
             _parser.cliEnvironmentSet(
                 NetEnv.SSH_KEY,
-                _getEngineSSHPublicKey().replace("\n", "")
+                getEngineSSHPublicKey().replace("\n", "")
             );
             return null;
         }},
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/VdsDeployTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/VdsDeployTest.java
new file mode 100644
index 0000000..70041ce
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/VdsDeployTest.java
@@ -0,0 +1,20 @@
+package org.ovirt.engine.core.bll;
+
+import org.junit.Assert;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.ovirt.engine.core.common.config.ConfigValues;
+import org.ovirt.engine.core.utils.MockConfigRule;
+
+public class VdsDeployTest {
+    @ClassRule
+    public static MockConfigRule configRule = new 
MockConfigRule(MockConfigRule.mockConfig(ConfigValues.keystoreUrl,
+            "src/test/resources/engine.p12"),
+            MockConfigRule.mockConfig(ConfigValues.CertAlias, "1"),
+            MockConfigRule.mockConfig(ConfigValues.keystorePass, "mypass"));
+
+    @Test
+    public void getEngineSSHPublicKey() {
+        Assert.assertNotNull(VdsDeploy.getEngineSSHPublicKey());
+    }
+}
diff --git a/backend/manager/modules/bll/src/test/resources/engine.p12 
b/backend/manager/modules/bll/src/test/resources/engine.p12
new file mode 100644
index 0000000..638926e
--- /dev/null
+++ b/backend/manager/modules/bll/src/test/resources/engine.p12
Binary files differ


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie5397eece5eabf81755df93c381d9bb6934b237e
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Laszlo Hornyak <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to