Example #1
0
 private AddVmCommand<AddVmParameters> setupCanAddVmTests(final int domainSizeGB) {
   VM vm = initializeMock(domainSizeGB);
   AddVmCommand<AddVmParameters> cmd = createCommand(vm);
   cmd.poolPerDc = macPoolPerDc;
   initCommandMethods(cmd);
   doReturn(createVmTemplate()).when(cmd).getVmTemplate();
   doReturn(createStoragePool()).when(cmd).getStoragePool();
   return cmd;
 }
Example #2
0
  @Test
  public void refuseSoundDeviceOnPPC() {
    AddVmCommand<AddVmParameters> cmd = setupCanAddPpcTest();
    cmd.getParameters().setSoundDeviceEnabled(true);
    when(osRepository.isSoundDeviceEnabled(
            cmd.getParameters().getVm().getVmOsId(), cmd.getCluster().getCompatibilityVersion()))
        .thenReturn(false);

    ValidateTestUtils.runAndAssertValidateFailure(
        cmd, EngineMessage.SOUND_DEVICE_REQUESTED_ON_NOT_SUPPORTED_ARCH);
  }
Example #3
0
 @Test
 public void validateSpaceNotWithinThreshold() throws Exception {
   AddVmCommand<AddVmParameters> command = setupCanAddVmTests(0);
   doReturn(
           new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_DISK_SPACE_LOW_ON_STORAGE_DOMAIN))
       .when(storageDomainValidator)
       .isDomainWithinThresholds();
   doReturn(storageDomainValidator)
       .when(command)
       .createStorageDomainValidator(any(StorageDomain.class));
   assertFalse(command.validateSpaceRequirements());
 }
Example #4
0
 @Test
 public void validateSpaceAndThreshold() {
   AddVmCommand<AddVmParameters> command = setupCanAddVmTests(0);
   doReturn(ValidationResult.VALID).when(storageDomainValidator).isDomainWithinThresholds();
   doReturn(ValidationResult.VALID).when(storageDomainValidator).hasSpaceForNewDisks(anyList());
   doReturn(storageDomainValidator)
       .when(command)
       .createStorageDomainValidator(any(StorageDomain.class));
   assertTrue(command.validateSpaceRequirements());
   verify(storageDomainValidator, times(TOTAL_NUM_DOMAINS)).hasSpaceForNewDisks(anyList());
   verify(storageDomainValidator, never()).hasSpaceForClonedDisks(anyList());
 }
Example #5
0
 @Test
 public void canAddVm() {
   ArrayList<String> reasons = new ArrayList<>();
   final int domainSizeGB = 20;
   AddVmCommand<AddVmParameters> cmd = setupCanAddVmTests(domainSizeGB);
   cmd.postConstruct();
   doReturn(true).when(cmd).validateCustomProperties(any(VmStatic.class), anyList());
   doReturn(true).when(cmd).validateSpaceRequirements();
   assertTrue(
       "vm could not be added",
       cmd.canAddVm(reasons, Collections.singletonList(createStorageDomain(domainSizeGB))));
 }
Example #6
0
 @Test
 public void isVirtioScsiEnabledDefaultedToTrue() {
   AddVmCommand<AddVmParameters> cmd = setupCanAddVmTests(0);
   Cluster cluster = createCluster();
   doReturn(cluster).when(cmd).getCluster();
   cmd.getParameters().getVm().setClusterId(cluster.getId());
   cmd.initEffectiveCompatibilityVersion();
   when(osRepository.getDiskInterfaces(any(Integer.class), any(Version.class)))
       .thenReturn(new ArrayList<>(Collections.singletonList("VirtIO_SCSI")));
   assertTrue(
       "isVirtioScsiEnabled hasn't been defaulted to true on cluster >= 3.3.",
       cmd.isVirtioScsiEnabled());
 }
Example #7
0
  private AddVmCommand<AddVmParameters> setupCanAddPpcTest() {
    final int domainSizeGB = 20;
    AddVmCommand<AddVmParameters> cmd = setupCanAddVmTests(domainSizeGB);

    doReturn(true).when(cmd).validateSpaceRequirements();
    doReturn(true).when(cmd).buildAndCheckDestStorageDomains();
    cmd.getParameters().getVm().setClusterArch(ArchitectureType.ppc64);
    Cluster cluster = new Cluster();
    cluster.setArchitecture(ArchitectureType.ppc64);
    cluster.setCompatibilityVersion(Version.getLast());
    doReturn(cluster).when(cmd).getCluster();

    return cmd;
  }
Example #8
0
 protected void generateStorageToDisksMap(AddVmCommand<? extends AddVmParameters> command) {
   command.storageToDisksMap = new HashMap<>();
   command.storageToDisksMap.put(
       STORAGE_DOMAIN_ID_1, generateDisksList(NUM_DISKS_STORAGE_DOMAIN_1));
   command.storageToDisksMap.put(
       STORAGE_DOMAIN_ID_2, generateDisksList(NUM_DISKS_STORAGE_DOMAIN_2));
 }
Example #9
0
 private <T extends AddVmParameters> void mockUninterestingMethods(AddVmCommand<T> spy) {
   doReturn(true).when(spy).isVmNameValidLength(any(VM.class));
   doReturn(false).when(spy).isVmWithSameNameExists(anyString(), any(Guid.class));
   doReturn(STORAGE_POOL_ID).when(spy).getStoragePoolId();
   doReturn(createVmTemplate()).when(spy).getVmTemplate();
   doReturn(createCluster()).when(spy).getCluster();
   doReturn(true).when(spy).areParametersLegal(anyListOf(String.class));
   doReturn(Collections.<VmNetworkInterface>emptyList()).when(spy).getVmInterfaces();
   doReturn(Collections.<DiskImageBase>emptyList()).when(spy).getVmDisks();
   doReturn(false).when(spy).isVirtioScsiControllerAttached(any(Guid.class));
   doReturn(true).when(osRepository).isSoundDeviceEnabled(any(Integer.class), any(Version.class));
   spy.setVmTemplateId(Guid.newGuid());
 }
  protected boolean validate() {
    VM vm = parentCommand.getVm();
    if (vm == null) {
      parentCommand.addCanDoActionMessage(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
      return false;
    } else {
      targetCluster = DbFacade.getInstance().getVdsGroupDao().get(targetClusterId);
      if (targetCluster == null) {
        parentCommand.addCanDoActionMessage(EngineMessage.VM_CLUSTER_IS_NOT_VALID);
        return false;
      }

      // Check that the target cluster is in the same data center.
      if (!targetCluster.getStoragePoolId().equals(vm.getStoragePoolId())) {
        parentCommand.addCanDoActionMessage(
            EngineMessage.VM_CANNOT_MOVE_TO_CLUSTER_IN_OTHER_STORAGE_POOL);
        return false;
      }

      List<VmNic> interfaces = DbFacade.getInstance().getVmNicDao().getAllForVm(vm.getId());

      Version clusterCompatibilityVersion = targetCluster.getCompatibilityVersion();
      if (!validateDestinationClusterContainsNetworks(interfaces)
          || !validateNics(interfaces, clusterCompatibilityVersion)) {
        return false;
      }

      // Check if VM static parameters are compatible for new cluster.
      boolean isCpuSocketsValid =
          AddVmCommand.checkCpuSockets(
              vm.getStaticData().getNumOfSockets(),
              vm.getStaticData().getCpuPerSocket(),
              vm.getStaticData().getThreadsPerCpu(),
              clusterCompatibilityVersion.getValue(),
              parentCommand.getReturnValue().getCanDoActionMessages());
      if (!isCpuSocketsValid) {
        return false;
      }

      // Check that the USB policy is legal
      if (!VmHandler.isUsbPolicyLegal(
          vm.getUsbPolicy(),
          vm.getOs(),
          targetCluster,
          parentCommand.getReturnValue().getCanDoActionMessages())) {
        return false;
      }

      // Check if the display type is supported
      if (!VmHandler.isGraphicsAndDisplaySupported(
          vm.getOs(),
          VmDeviceUtils.getGraphicsTypesOfEntity(vm.getId()),
          vm.getDefaultDisplayType(),
          parentCommand.getReturnValue().getCanDoActionMessages(),
          clusterCompatibilityVersion)) {
        return false;
      }

      if (VmDeviceUtils.hasVirtioScsiController(vm.getId())) {
        // Verify cluster compatibility
        if (!FeatureSupported.virtIoScsi(targetCluster.getCompatibilityVersion())) {
          return parentCommand.failCanDoAction(
              EngineMessage.VIRTIO_SCSI_INTERFACE_IS_NOT_AVAILABLE_FOR_CLUSTER_LEVEL);
        }

        // Verify OS compatibility
        if (!VmHandler.isOsTypeSupportedForVirtioScsi(
            vm.getOs(),
            targetCluster.getCompatibilityVersion(),
            parentCommand.getReturnValue().getCanDoActionMessages())) {
          return false;
        }
      }

      // A existing VM cannot be changed into a cluster without a defined architecture
      if (targetCluster.getArchitecture() == ArchitectureType.undefined) {
        return parentCommand.failCanDoAction(
            EngineMessage.ACTION_TYPE_FAILED_CLUSTER_UNDEFINED_ARCHITECTURE);
      } else if (targetCluster.getArchitecture() != vm.getClusterArch()) {
        return parentCommand.failCanDoAction(
            EngineMessage.ACTION_TYPE_FAILED_VM_CLUSTER_DIFFERENT_ARCHITECTURES);
      }
    }
    return true;
  }
Example #11
0
 @Test
 public void testPatternBasedNameFails() {
   AddVmCommand<AddVmParameters> cmd = createCommand(initializeMock(1));
   cmd.getParameters().getVm().setName("aa-??bb");
   assertFalse("Pattern-based name should not be supported for VM", cmd.validateInputs());
 }