Ori Liel has uploaded a new change for review.

Change subject: core: Improve PM Status check flows
......................................................................

core: Improve PM Status check flows

Checking Power-Management Status currently does not differentiate between 
checking
the status of an Agent and checking the status of the Host. This patch provides 
a
method for each in FenceExecutor and makes sure the correct one in invoked in 
each
particular case

Change-Id: I7155789d46b6902ff8425a723ecab1c77536f0c1
Signed-off-by: Ori Liel <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceExecutor.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceVdsBaseCommand.java
R 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetFenceAgentStatusQuery.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVdsFenceStatusQuery.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitVdsOnUpCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestartVdsCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SshSoftFencingCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/pm/PmHealthCheckManager.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/FenceExecutorTest.java
R 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetFenceAgentStatusParameters.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostModel.java
13 files changed, 143 insertions(+), 78 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/08/37508/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceExecutor.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceExecutor.java
index 1a535df..085b1ed 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceExecutor.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceExecutor.java
@@ -53,21 +53,23 @@
     }
 
     /**
-     * Use all fencing agents of this host sequentially, until one succeeds, 
to check the status of the host.
-     *
+     * Use all fencing agents of this host sequentially. If even one agent 
returns status "on", the host is up.
+     * Otherwise, the host is down.
      */
-    public VDSFenceReturnValue checkStatus() {
+    public VDSFenceReturnValue checkHostStatus() {
         VDSFenceReturnValue returnValue = null;
         VDS proxyHost = proxyLocator.findProxyHost();
         if (proxyHost == null) {
             returnValue = proxyNotFound();
         } else {
             for (FenceAgent agent : _vds.getFenceAgents()) {
-                returnValue = fence(FenceActionType.Status, agent, proxyHost);
+                returnValue = checkAgentStatus(agent, proxyHost);
                 if (returnValue.getSucceeded()) {
                     returnValue.setProxyHostUsed(proxyHost);
-                    returnValue.setFenceAgentUsed(agent);
-                    break;
+                    if (isStatusOn(returnValue)) {
+                        returnValue.setFenceAgentUsed(agent);
+                        break;
+                    }
                 }
             }
         }
@@ -75,6 +77,28 @@
             returnValue = new VDSFenceReturnValue();
             returnValue.setSucceeded(false);
             returnValue.setExceptionString("No fence-agents found for host " + 
_vds.getName());
+        }
+        return returnValue;
+    }
+
+
+    public VDSFenceReturnValue checkAgentStatus(FenceAgent agent) {
+        VDS proxyHost = proxyLocator.findProxyHost();
+        if (proxyHost == null) {
+            return proxyNotFound();
+        } else {
+            return checkAgentStatus(agent, proxyHost);
+        }
+    }
+
+
+    private VDSFenceReturnValue checkAgentStatus(FenceAgent agent, VDS 
proxyHost) {
+        VDSFenceReturnValue returnValue = null;
+        returnValue = fence(FenceActionType.Status, agent, proxyHost);
+        if (returnValue.getSucceeded()) {
+            returnValue.setProxyHostUsed(proxyHost);
+            returnValue.setFenceAgentUsed(agent);
+            // the status itself ("on"/"off") is already set in the result 
object.
         }
         return returnValue;
     }
@@ -227,6 +251,23 @@
         }
     }
 
+    public static boolean isStatusOff(VDSFenceReturnValue returnValue) {
+        return isStatusEqualTo(returnValue, "off");
+    }
+
+    public static boolean isStatusOn(VDSFenceReturnValue returnValue) {
+        return isStatusEqualTo(returnValue, "on");
+    }
+
+    private static boolean isStatusEqualTo(VDSFenceReturnValue returnValue, 
String targetStatus) {
+        boolean result = false;
+        if (returnValue != null && returnValue.getSucceeded()) {
+            FenceStatusReturnValue value = (FenceStatusReturnValue) 
returnValue.getReturnValue();
+            result = value.getStatus().equalsIgnoreCase(targetStatus);
+        }
+        return result;
+    }
+
     BackendInternal getBackend() {
         return Backend.getInstance();
     }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceVdsBaseCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceVdsBaseCommand.java
index 2c39583..ff4b047 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceVdsBaseCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceVdsBaseCommand.java
@@ -279,7 +279,7 @@
         int retries = getWaitForStatusRerties();
         while (!requiredStatusReached && i <= retries) {
             log.info("Attempt {} to get host '{}' status", i, hostName);
-            VDSFenceReturnValue returnValue = executor.checkStatus();
+            VDSFenceReturnValue returnValue = executor.checkHostStatus();
             if (returnValue != null && returnValue.getSucceeded()) {
                 String status = ((FenceStatusReturnValue) 
returnValue.getReturnValue()).getStatus();
                 if (status.equalsIgnoreCase(VDSM_STATUS_UNKONWN)) {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetNewVdsFenceStatusQuery.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetFenceAgentStatusQuery.java
similarity index 82%
rename from 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetNewVdsFenceStatusQuery.java
rename to 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetFenceAgentStatusQuery.java
index 8a3ed1c..1815cdc 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetNewVdsFenceStatusQuery.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetFenceAgentStatusQuery.java
@@ -3,23 +3,23 @@
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.businessentities.FenceStatusReturnValue;
 import org.ovirt.engine.core.common.businessentities.VDS;
-import org.ovirt.engine.core.common.queries.GetNewVdsFenceStatusParameters;
+import org.ovirt.engine.core.common.queries.GetFenceAgentStatusParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSFenceReturnValue;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector;
 
-public class GetNewVdsFenceStatusQuery<P extends 
GetNewVdsFenceStatusParameters> extends FenceQueryBase<P> {
+public class GetFenceAgentStatusQuery<P extends GetFenceAgentStatusParameters> 
extends FenceQueryBase<P> {
 
     private static final String UNKNOWN = "unknown";
 
-    public GetNewVdsFenceStatusQuery(P parameters) {
+    public GetFenceAgentStatusQuery(P parameters) {
         super(parameters);
     }
 
     @Override
     protected void executeQueryCommand() {
         FenceExecutor executor = new FenceExecutor(getHost());
-        VDSFenceReturnValue result = executor.checkStatus();
+        VDSFenceReturnValue result = 
executor.checkAgentStatus(getParameters().getAgent());
         if (result.getSucceeded()) {
             getQueryReturnValue().setReturnValue(result.getReturnValue());
         } else {
@@ -32,7 +32,6 @@
         VDS vds = new VDS();
         vds.setId((Guid) ((id != null) ? id : Guid.Empty));
         vds.setStoragePoolId(getParameters().getStoragePoolId());
-        vds.getFenceAgents().add(getParameters().getAgent());
         vds.setPmProxyPreferences(getParameters().getPmProxyPreferences());
         return vds;
     }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVdsFenceStatusQuery.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVdsFenceStatusQuery.java
index b34bac0..87a0831 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVdsFenceStatusQuery.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVdsFenceStatusQuery.java
@@ -6,7 +6,6 @@
 import org.ovirt.engine.core.common.queries.VdsIdParametersBase;
 import org.ovirt.engine.core.common.vdscommands.VDSFenceReturnValue;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
-import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AlertDirector;
 
 public class GetVdsFenceStatusQuery<P extends VdsIdParametersBase> extends 
FenceQueryBase<P> {
 
@@ -22,10 +21,8 @@
     protected void executeQueryCommand() {
         VDS vds = 
DbFacade.getInstance().getVdsDao().get(getParameters().getVdsId());
         FenceExecutor executor = new FenceExecutor(vds);
-        VDSFenceReturnValue result = executor.checkStatus();
+        VDSFenceReturnValue result = executor.checkHostStatus();
         if (result.getSucceeded()) {
-            // Remove all alerts including NOT CONFIG alert
-            AlertDirector.RemoveAllVdsAlerts(getParameters().getVdsId(), true);
             getQueryReturnValue().setReturnValue(result);
         } else {
             handleError(result);
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitVdsOnUpCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitVdsOnUpCommand.java
index ae9ac38..b88b45e 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitVdsOnUpCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitVdsOnUpCommand.java
@@ -171,9 +171,8 @@
         FenceExecutor executor = new FenceExecutor(getVds());
         vdsProxyFound = new FenceProxyLocator(getVds()).isProxyHostAvailable();
         if (getVds().isPmEnabled() && vdsProxyFound) {
-            VDSFenceReturnValue returnValue = executor.checkStatus();
-            fenceSucceeded = returnValue.getSucceeded(); // potential bug here 
- if no proxy host found, this variable
-                                                         // is still 'true'
+            VDSFenceReturnValue returnValue = executor.checkHostStatus();
+            fenceSucceeded = returnValue.getSucceeded();
             fenceStatusReturnValue = (FenceStatusReturnValue) 
returnValue.getReturnValue();
         }
     }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestartVdsCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestartVdsCommand.java
index 888a0d0..2c5dcc3 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestartVdsCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestartVdsCommand.java
@@ -120,7 +120,7 @@
         final String sessionId = getParameters().getSessionId();
 
         // do not try to stop Host if Host is reported as Down via PM
-        if (isPmReportsStatusDown()) {
+        if (FenceExecutor.isStatusOff(new 
FenceExecutor(getVds()).checkHostStatus())) {
             returnValue.setSucceeded(true);
         }
         else {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SshSoftFencingCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SshSoftFencingCommand.java
index fd82d643..e93bfba 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SshSoftFencingCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SshSoftFencingCommand.java
@@ -46,7 +46,7 @@
             getReturnValue().setSucceeded(false);
             return;
         }
-        if (isPmReportsStatusDown()) {
+        if (FenceExecutor.isStatusOff(new 
FenceExecutor(getVds()).checkHostStatus())) {
             // do not try to soft-fence if Host is reported as Down via PM
             getReturnValue().setSucceeded(false);
         }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsCommand.java
index 3401b0b..03ce0e7 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsCommand.java
@@ -5,13 +5,13 @@
 
 import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.bll.context.CommandContext;
+import org.ovirt.engine.core.bll.pm.PmHealthCheckManager;
 import org.ovirt.engine.core.bll.provider.NetworkProviderValidator;
 import org.ovirt.engine.core.bll.utils.PermissionSubject;
 import org.ovirt.engine.core.bll.validator.FenceValidator;
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.VdcObjectType;
 import org.ovirt.engine.core.common.action.VdsActionParameters;
-import org.ovirt.engine.core.common.businessentities.FenceStatusReturnValue;
 import org.ovirt.engine.core.common.businessentities.FenceAgent;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VDSStatus;
@@ -20,14 +20,11 @@
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.common.locks.LockingGroup;
-import org.ovirt.engine.core.common.queries.VdcQueryType;
-import org.ovirt.engine.core.common.queries.VdsIdParametersBase;
 import org.ovirt.engine.core.common.utils.Pair;
 import org.ovirt.engine.core.common.vdscommands.AddVdsVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.RemoveVdsVDSCommandParameters;
 import 
org.ovirt.engine.core.common.vdscommands.SetVdsStatusVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
-import org.ovirt.engine.core.common.vdscommands.VDSFenceReturnValue;
 import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AlertDirector;
@@ -172,8 +169,7 @@
      */
     protected void testVdsPowerManagementStatus(VdsStatic vdsStatic) {
         if (vdsStatic.isPmEnabled()) {
-            runInternalQuery(VdcQueryType.GetVdsFenceStatus,
-                    new VdsIdParametersBase(vdsStatic.getId()));
+            
PmHealthCheckManager.getInstance().pmHealthCheck(vdsStatic.getId());
         }
     }
 
@@ -320,46 +316,11 @@
         }
     }
 
-    /**
-     * Checks if Host status is Down via its PM card (if defined)
-     * @param vds
-     *              The host to check
-     * @return
-     *              boolean
-     */
-    public boolean isPmReportsStatusDown() {
-        boolean result = false;
-        VDS vds = getVds();
-        VDSFenceReturnValue returnValue = null;
-        // Check first if Host has configured PM
-        if (vds != null && vds.isPmEnabled()) {
-            FenceExecutor executor = new FenceExecutor(vds);
-            returnValue = executor.checkStatus();
-            // !! handle failure
-            result = isHostStatusOff(returnValue);
-        }
-        if (result) {
-            runVdsCommand(VDSCommandType.SetVdsStatus,
-                            new 
SetVdsStatusVDSCommandParameters(getVds().getId(), VDSStatus.Down));
-        }
-        return result;
-    }
-
     protected boolean validateNetworkProviderProperties(Guid providerId, 
String networkMappings) {
         NetworkProviderValidator validator = new 
NetworkProviderValidator(getProviderDao().get(providerId));
         return validate(validator.providerIsSet())
                 && validate(validator.providerTypeValid())
                 && validate(validator.networkMappingsProvided(networkMappings))
                 && validate(validator.messagingBrokerProvided());
-    }
-
-    private static boolean isHostStatusOff(VDSFenceReturnValue returnValue) {
-        String OFF = "off";
-        boolean result = false;
-        if (returnValue != null) {
-            FenceStatusReturnValue value = (FenceStatusReturnValue) 
returnValue.getReturnValue();
-            result = value.getStatus().equalsIgnoreCase(OFF);
-        }
-        return result;
     }
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/pm/PmHealthCheckManager.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/pm/PmHealthCheckManager.java
index d69e7db..1f4a678 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/pm/PmHealthCheckManager.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/pm/PmHealthCheckManager.java
@@ -19,6 +19,7 @@
 import org.ovirt.engine.core.common.businessentities.VDSStatus;
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.config.ConfigValues;
+import org.ovirt.engine.core.common.vdscommands.VDSFenceReturnValue;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AlertDirector;
@@ -80,11 +81,7 @@
                     List<VDS> hosts = 
DbFacade.getInstance().getVdsDao().getAll();
                     for (VDS host : hosts) {
                         if (host.isPmEnabled()) {
-                            // check health
-                            PmHealth pmHealth = checkPMHealth(host);
-                            // handle alerts - adding or canceling as necessary
-                            handleAlerts(pmHealth);
-                            log.debug(pmHealth.toString());
+                            pmHealthCheck(host);
                         }
                     }
                     log.info("Power Management Health Check completed.");
@@ -95,6 +92,26 @@
             }
         }
     }
+
+    /**
+     * Check PM health of a host. Add/Remove alerts as necessary, and log the 
results.
+     */
+    public void pmHealthCheck(VDS host) {
+        // check health
+        PmHealth pmHealth = checkPMHealth(host);
+        // handle alerts - adding or canceling as necessary
+        handleAlerts(pmHealth);
+        log.debug(pmHealth.toString());
+    }
+
+    /**
+     * Check PM health of a host. Add/Remove alerts as necessary, and log the 
results.
+     */
+    public void pmHealthCheck(Guid hostId) {
+        VDS host = DbFacade.getInstance().getVdsDao().get(hostId);
+        pmHealthCheck(host);
+    }
+
 
     /**
      * Collect health-status info for all agents.
@@ -190,6 +207,10 @@
         }
     }
 
+    /**
+     * Checks if the agent is healthy. A healthy agent is one that returns an 
answer when queries for status, and it
+     * doesn't matter whether that answer is "on" or "off".
+     */
     private boolean isHealthy(FenceAgent agent, VDS host) {
         return new FenceExecutor(host).fence(FenceActionType.Status, 
agent).getSucceeded();
     }
@@ -242,7 +263,8 @@
             RestartVdsCommand<FenceVdsActionParameters> restartVdsCommand =
                     new RestartVdsCommand<FenceVdsActionParameters>(new
                     FenceVdsActionParameters(host.getId(), 
FenceActionType.Status));
-            if (restartVdsCommand.isPmReportsStatusDown()) {
+            VDSFenceReturnValue returnValue = new 
FenceExecutor(host).checkHostStatus();
+            if (FenceExecutor.isStatusOff(returnValue)) {
                 VdcReturnValueBase retValue = 
Backend.getInstance().runInternalAction(VdcActionType.RestartVds, 
restartVdsCommand.getParameters());
                 if (retValue!= null && retValue.getSucceeded()) {
                     log.info("Host '{}' was started successfully by PM Health 
Check Manager",
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/FenceExecutorTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/FenceExecutorTest.java
index 0821e92..0e1d56c 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/FenceExecutorTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/FenceExecutorTest.java
@@ -14,6 +14,7 @@
 import org.ovirt.engine.core.common.businessentities.AuditLog;
 import org.ovirt.engine.core.common.businessentities.FenceActionType;
 import org.ovirt.engine.core.common.businessentities.FenceAgent;
+import org.ovirt.engine.core.common.businessentities.FenceStatusReturnValue;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
 import org.ovirt.engine.core.common.businessentities.VdsSpmStatus;
@@ -177,7 +178,7 @@
     @Test
     public void checkStatus_handleProxyNotFound() {
         when(proxyLocator.findProxyHost()).thenReturn(null);
-        VDSFenceReturnValue result = executor.checkStatus();
+        VDSFenceReturnValue result = executor.checkHostStatus();
         assertFalse(result.getSucceeded());
         assertTrue(result.getExceptionString().contains("no running proxy Host 
was found"));
     }
@@ -267,14 +268,59 @@
     }
 
 
+    /**
+     * Tests that when at least one agent returns 'on', checkHostStatus() 
returns 'on'. Mocking makes the first agent
+     * return 'off'. FenceExecutor then tries the next agent, which is mocked 
to return true.
+     */
     @Test
-    public void checkStatus_success() {
+    public void checkHostStatusOn() {
         mockProxyHost();
-        mockFenceSuccess();
-        VDSFenceReturnValue result = executor.checkStatus();
+        VDSReturnValue returnValueOff = new VDSReturnValue();
+        returnValueOff.setSucceeded(true);
+        FenceStatusReturnValue statusOff = new FenceStatusReturnValue("off", 
"");
+        returnValueOff.setReturnValue(statusOff);
+        VDSReturnValue returnValueOn = new VDSReturnValue();
+        returnValueOn.setSucceeded(true);
+        FenceStatusReturnValue statusOn = new FenceStatusReturnValue("on", "");
+        returnValueOn.setReturnValue(statusOn);
+        when(vdsBrokerFrontend.RunVdsCommand(eq(VDSCommandType.FenceVds), 
any(GetDeviceListVDSCommandParameters.class))).thenReturn(returnValueOff)
+                .thenReturn(returnValueOn);
+        List<FenceAgent> agents = new LinkedList<>();
+        agents.add(createAgent());
+        agents.add(createAgent());
+        when(vds.getFenceAgents()).thenReturn(agents);
+        VDSFenceReturnValue result = executor.checkHostStatus();
         assertTrue(result.getSucceeded());
+        assertTrue(result.getReturnValue() instanceof FenceStatusReturnValue);
+        FenceStatusReturnValue status = (FenceStatusReturnValue) 
result.getReturnValue();
+        assertEquals(status.getStatus(), "on");
     }
 
+    /**
+     * Tests that when no even a single agent returns 'on', checkHostStatus() 
returns 'off'. Two agents are mocked to
+     * return status 'off'. FenceExecutor tries both of them and returns 
status=off
+     */
+    @Test
+    public void checkHostStatusOff() {
+        mockProxyHost();
+        VDSReturnValue returnValueOff = new VDSReturnValue();
+        returnValueOff.setSucceeded(true);
+        FenceStatusReturnValue statusOff = new FenceStatusReturnValue("off", 
"");
+        returnValueOff.setReturnValue(statusOff);
+        when(vdsBrokerFrontend.RunVdsCommand(eq(VDSCommandType.FenceVds), 
any(GetDeviceListVDSCommandParameters.class))).thenReturn(returnValueOff)
+                .thenReturn(returnValueOff);
+        List<FenceAgent> agents = new LinkedList<>();
+        agents.add(createAgent());
+        agents.add(createAgent());
+        when(vds.getFenceAgents()).thenReturn(agents);
+        VDSFenceReturnValue result = executor.checkHostStatus();
+        assertTrue(result.getSucceeded());
+        assertTrue(result.getReturnValue() instanceof FenceStatusReturnValue);
+        FenceStatusReturnValue status = (FenceStatusReturnValue) 
result.getReturnValue();
+        assertEquals(status.getStatus(), "off");
+    }
+
+
     private FenceAgent createAgent() {
         FenceAgent agent = new FenceAgent();
         agent.setId(FENCE_AGENT_ID);
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetNewVdsFenceStatusParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetFenceAgentStatusParameters.java
similarity index 89%
rename from 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetNewVdsFenceStatusParameters.java
rename to 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetFenceAgentStatusParameters.java
index 8229d69..90db76d 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetNewVdsFenceStatusParameters.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetFenceAgentStatusParameters.java
@@ -3,14 +3,14 @@
 import org.ovirt.engine.core.common.businessentities.FenceAgent;
 import org.ovirt.engine.core.compat.Guid;
 
-public class GetNewVdsFenceStatusParameters extends VdcQueryParametersBase {
+public class GetFenceAgentStatusParameters extends VdcQueryParametersBase {
     private static final long serialVersionUID = -3663389765505476776L;
 
     private Guid _vds_id;
     private FenceAgent agent;
     private String pmProxyPreferences;
 
-    public GetNewVdsFenceStatusParameters() {
+    public GetFenceAgentStatusParameters() {
         _storagePoolId = Guid.Empty;
     }
 
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
index f250d23..f112958 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
@@ -34,7 +34,7 @@
     GetVdsByVdsId,
     GetVdsByName,
     GetVdsFenceStatus,
-    GetNewVdsFenceStatus,
+    GetFenceAgentStatus,
     GetAgentFenceOptions,
     GetAllChildVlanInterfaces,
     GetAllSiblingVlanInterfaces,
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostModel.java
index 06ca4b8..005b4bf 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostModel.java
@@ -20,7 +20,7 @@
 import org.ovirt.engine.core.common.businessentities.VdsProtocol;
 import org.ovirt.engine.core.common.businessentities.VdsStatic;
 import org.ovirt.engine.core.common.mode.ApplicationMode;
-import org.ovirt.engine.core.common.queries.GetNewVdsFenceStatusParameters;
+import org.ovirt.engine.core.common.queries.GetFenceAgentStatusParameters;
 import org.ovirt.engine.core.common.queries.VdcQueryReturnValue;
 import org.ovirt.engine.core.common.queries.VdcQueryType;
 import org.ovirt.engine.core.compat.Guid;
@@ -1578,7 +1578,7 @@
 
         VDSGroup cluster = getCluster().getSelectedItem();
 
-        GetNewVdsFenceStatusParameters param = new 
GetNewVdsFenceStatusParameters();
+        GetFenceAgentStatusParameters param = new 
GetFenceAgentStatusParameters();
         FenceAgent agent = new FenceAgent();
         if (getHostId() != null)
         {
@@ -1596,7 +1596,7 @@
         agent.setOptionsMap(isPrimary ? getPmOptionsMap() : 
getPmSecondaryOptionsMap());
 
         param.setAgent(agent);
-        Frontend.getInstance().runQuery(VdcQueryType.GetNewVdsFenceStatus, 
param, new AsyncQuery(this, new INewAsyncCallback() {
+        Frontend.getInstance().runQuery(VdcQueryType.GetFenceAgentStatus, 
param, new AsyncQuery(this, new INewAsyncCallback() {
 
                     @Override
                     public void onSuccess(Object model, Object returnValue) {


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

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

Reply via email to