private void mockHostValidator() {
   when(validator.nameNotEmpty()).thenReturn(ValidationResult.VALID);
   doReturn(ValidationResult.VALID).when(validator).nameLengthIsLegal();
   doReturn(ValidationResult.VALID).when(validator).hostNameIsValid();
   doReturn(ValidationResult.VALID).when(validator).nameNotUsed();
   doReturn(ValidationResult.VALID).when(validator).hostNameNotUsed();
   doReturn(ValidationResult.VALID).when(validator).portIsValid();
   when(validator.sshUserNameNotEmpty()).thenReturn(ValidationResult.VALID);
   doReturn(ValidationResult.VALID).when(validator).validateSingleHostAttachedToLocalStorage();
   doReturn(ValidationResult.VALID).when(validator).securityKeysExists();
   doReturn(ValidationResult.VALID)
       .when(validator)
       .provisioningComputeResourceValid(any(Boolean.class), any(ExternalComputeResource.class));
   doReturn(ValidationResult.VALID)
       .when(validator)
       .provisioningHostGroupValid(any(Boolean.class), any(ExternalHostGroup.class));
   doReturn(ValidationResult.VALID).when(validator).protocolIsNotXmlrpc(any(VDSGroup.class));
   when(validator.passwordNotEmpty(
           any(Boolean.class), any(AuthenticationMethod.class), any(String.class)))
       .thenReturn(ValidationResult.VALID);
   when(commandMock.getHostValidator()).thenReturn(validator);
   when(commandMock.validate(any(ValidationResult.class))).thenCallRealMethod();
 }
Example #2
0
 protected HostValidator getHostValidator() {
   return HostValidator.createInstance(getParameters().getvds());
 }
Example #3
0
  @Override
  protected boolean validate() {
    T params = getParameters();
    setClusterId(params.getVdsStaticData().getClusterId());
    params.setVdsForUniqueId(null);
    // Check if this is a valid cluster
    boolean returnValue = validateCluster();
    if (returnValue) {
      HostValidator validator = getHostValidator();
      returnValue =
          validate(validator.nameNotEmpty())
              && validate(validator.nameLengthIsLegal())
              && validate(validator.hostNameIsValid())
              && validate(validator.nameNotUsed())
              && validate(validator.hostNameNotUsed())
              && validate(validator.portIsValid())
              && validate(validator.sshUserNameNotEmpty())
              && validate(validator.validateSingleHostAttachedToLocalStorage())
              && validate(validator.securityKeysExists())
              && validate(
                  validator.provisioningComputeResourceValid(
                      params.isProvisioned(), params.getComputeResource()))
              && validate(
                  validator.provisioningHostGroupValid(
                      params.isProvisioned(), params.getHostGroup()))
              && validate(
                  validator.passwordNotEmpty(
                      params.isPending(), params.getAuthMethod(), params.getPassword()))
              && validate(
                  validator.supportsDeployingHostedEngine(
                      params.getHostedEngineDeployConfiguration()));
    }

    if (!(returnValue
        && isPowerManagementLegal(
            params.getVdsStaticData().isPmEnabled(),
            params.getFenceAgents(),
            getCluster().getCompatibilityVersion().toString())
        && canConnect(params.getvds()))) {
      return false;
    }

    if (params.getVdsStaticData().getOpenstackNetworkProviderId() != null
        && !validateNetworkProviderProperties(
            params.getVdsStaticData().getOpenstackNetworkProviderId(),
            params.getNetworkMappings())) {
      return false;
    }

    if (isGlusterSupportEnabled() && clusterHasNonInitializingServers()) {
      // allow simultaneous installation of hosts, but if a host has completed install, only
      // allow addition of another host if it can be peer probed to cluster.
      VDS upServer = getGlusterUtil().getUpServer(getClusterId());
      if (upServer == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_NO_GLUSTER_HOST_TO_PEER_PROBE);
      }
    }

    return true;
  }