Yaniv Bronhaim has uploaded a new change for review. Change subject: Validate installed host by requesting for vdsm uuid ......................................................................
Validate installed host by requesting for vdsm uuid Deploying an host requires to verify if an host has vdsm installed. The command 'vdsm-tool vdsm-id' returns vdsm uuid if vdsm exists and installed on host and it doesn't require running vdsm instance. During canDoAction of addVdsCommand we check this variable and compare it to vds table. If exists we fail the operation before starting deploy. Need to have http://gerrit.ovirt.org/#/c/14866 in vdsm side to work properly. Change-Id: I5c6c0a85daba47fabb9253963ff187a670f28ae6 Signed-off-by: Yaniv Bronhaim <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsDeploy.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java 3 files changed, 61 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/05/14905/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java index 907a321..ee70e0b 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java @@ -299,6 +299,8 @@ VDS vds = getParameters().getvds(); String vdsName = vds.getName(); String hostName = vds.getHostName(); + String hostUUID = VdsDeploy.getInstalledVdsIdIfExists( + hostName, getParameters().getRootPassword()); int maxVdsNameLength = Config.<Integer> GetValue(ConfigValues.MaxVdsNameLength); // check that vds name is not null or empty if (vdsName == null || vdsName.isEmpty()) { @@ -313,6 +315,8 @@ returnValue = failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_NAME_ALREADY_USED); } else if (getVdsDAO().getAllForHostname(hostName).size() != 0) { returnValue = failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VDS_WITH_SAME_HOST_EXIST); + } else if (hostUUID != null && getVdsDAO().getAllWithUniqueId(hostUUID).size() != 0) { + returnValue = failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VDS_WITH_SAME_UUID_EXIST); } else { returnValue = returnValue && validateSingleHostAttachedToLocalStorage(); 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 4f03e97..a7a0516 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 @@ -1,5 +1,6 @@ package org.ovirt.engine.core.bll; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -37,7 +38,9 @@ import org.ovirt.engine.core.utils.linq.Predicate; import org.ovirt.engine.core.utils.log.Log; import org.ovirt.engine.core.utils.log.LogFactory; +import org.ovirt.engine.core.utils.ssh.ConstraintByteArrayOutputStream; import org.ovirt.engine.core.utils.ssh.EngineSSHDialog; +import org.ovirt.engine.core.utils.ssh.SSHClient; import org.ovirt.engine.core.utils.ssh.SSHDialog; import org.ovirt.engine.core.utils.transaction.TransactionMethod; import org.ovirt.engine.core.utils.transaction.TransactionSupport; @@ -884,6 +887,59 @@ } } + static public String getInstalledVdsIdIfExists(String hostname, String password) { + try { + final int SSH_PORT = 22; + final String USER = "root"; + final String SUCCESS_RESULT = "RESULT=0"; + final String ERR_OUTPUT = "RESULT=1"; + final String VDSM_TOOL = "/usr/bin/vdsm-tool"; + + SSHClient client = new SSHClient(); + Integer timeout = Config.<Integer> GetValue(ConfigValues.ConnectToServerTimeoutInSeconds) * 1000; + client.setHardTimeout(timeout); + client.setSoftTimeout(timeout); + client.setHost(hostname, SSH_PORT); + client.setPassword(password); + client.setUser(USER); + client.connect(); + client.authenticate(); + ByteArrayOutputStream out = new ConstraintByteArrayOutputStream(50); + ByteArrayOutputStream err = new ConstraintByteArrayOutputStream(50); + client.executeCommand( + "TOOL=" + VDSM_TOOL + "; " + + "if [ -x $TOOL ]; then " + + "$TOOL vdsm-id ; echo RESULT=$?; " + + " else echo " + ERR_OUTPUT + "; fi", + null, + out, + err + ); + client.disconnect(); + String[] ret = new String(out.toByteArray(), "UTF-8").split("\n"); + if (ret.length > 1 && ret[1].equals(SUCCESS_RESULT)) { + return ret[0]; + } + return null; + } + catch (TimeLimitExceededException e){ + log.errorFormat( + "Timeout during getting vdsm-id from {0}", + hostname, + e + ); + return null; + } + catch(Exception e) { + log.errorFormat( + "Coudn't get vdsm-id from host {0}", + hostname, + e + ); + return null; + } + } + /** * Main method. * Execute the command and initiate the dialog. diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java index 871d56e..bba25bd 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java @@ -167,6 +167,7 @@ ACTION_TYPE_FAILED_SPECIFY_DOMAIN_IS_NOT_EXPORT_DOMAIN, ACTION_TYPE_FAILED_DETECTED_ACTIVE_VMS, ACTION_TYPE_FAILED_VDS_WITH_SAME_HOST_EXIST, + ACTION_TYPE_FAILED_VDS_WITH_SAME_UUID_EXIST, ACTION_TYPE_FAILED_ILLEGAL_MEMORY_SIZE, ACTION_TYPE_FAILED_ILLEGAL_NUM_OF_MONITORS, ACTION_TYPE_FAILED_ILLEGAL_DOMAIN_NAME, -- To view, visit http://gerrit.ovirt.org/14905 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5c6c0a85daba47fabb9253963ff187a670f28ae6 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Yaniv Bronhaim <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
