Exemple #1
0
  @Test
  public void canAddVmWithVirtioScsiControllerNotSupportedOs() {
    VM vm = createVm();
    AddVmFromTemplateCommand<AddVmParameters> cmd = createVmFromTemplateCommand(vm);
    cluster = createCluster();
    vm.setClusterId(cluster.getId());

    mockStorageDomainDaoGetForStoragePool();
    mockVmTemplateDaoReturnVmTemplate();
    mockVerifyAddVM(cmd);
    mockConfig();
    mockMaxPciSlots();
    mockStorageDomainDaoGetAllStoragesForPool(20);
    mockUninterestingMethods(cmd);
    mockDisplayTypes(vm.getOs());
    mockGraphicsDevices(vm.getId());
    doReturn(true).when(cmd).checkCpuSockets();

    doReturn(cluster).when(cmd).getCluster();
    doReturn(createStoragePool()).when(cmd).getStoragePool();
    cmd.getParameters().setVirtioScsiEnabled(true);
    when(osRepository.isSoundDeviceEnabled(any(Integer.class), any(Version.class)))
        .thenReturn(true);
    when(osRepository.getArchitectureFromOS(any(Integer.class)))
        .thenReturn(ArchitectureType.x86_64);
    when(osRepository.getDiskInterfaces(any(Integer.class), any(Version.class)))
        .thenReturn(new ArrayList<>(Collections.singletonList("VirtIO")));
    mockGetAllSnapshots(cmd);

    cmd.initEffectiveCompatibilityVersion();
    ValidateTestUtils.runAndAssertValidateFailure(
        cmd, EngineMessage.ACTION_TYPE_FAILED_ILLEGAL_OS_TYPE_DOES_NOT_SUPPORT_VIRTIO_SCSI);
  }
Exemple #2
0
  @Test
  public void testStoragePoolDoesntExist() {
    final int domainSizeGB = 20;
    AddVmCommand<AddVmParameters> cmd = setupCanAddVmTests(domainSizeGB);

    doReturn(null).when(cmd).getStoragePool();

    ValidateTestUtils.runAndAssertValidateFailure(
        cmd, EngineMessage.ACTION_TYPE_FAILED_STORAGE_POOL_NOT_EXIST);
  }
Exemple #3
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);
  }
Exemple #4
0
 @Test
 public void canAddCloneVmFromSnapshotSnapshotDoesNotExist() {
   final int domainSizeGB = 15;
   final Guid sourceSnapshotId = Guid.newGuid();
   AddVmFromSnapshotCommand<AddVmFromSnapshotParameters> cmd =
       setupCanAddVmFromSnapshotTests(domainSizeGB, sourceSnapshotId);
   cmd.getVm().setName("vm1");
   mockNonInterestingMethodsForCloneVmFromSnapshot(cmd);
   ValidateTestUtils.runAndAssertValidateFailure(
       cmd, EngineMessage.ACTION_TYPE_FAILED_VM_SNAPSHOT_DOES_NOT_EXIST);
 }
Exemple #5
0
 @Test
 public void canAddCloneVmFromSnapshotNoConfiguration() {
   final int domainSizeGB = 15;
   final Guid sourceSnapshotId = Guid.newGuid();
   AddVmFromSnapshotCommand<AddVmFromSnapshotParameters> cmd =
       setupCanAddVmFromSnapshotTests(domainSizeGB, sourceSnapshotId);
   cmd.getVm().setName("vm1");
   mockNonInterestingMethodsForCloneVmFromSnapshot(cmd);
   SnapshotsValidator sv = spy(new SnapshotsValidator());
   doReturn(ValidationResult.VALID).when(sv).vmNotDuringSnapshot(any(Guid.class));
   doReturn(sv).when(cmd).createSnapshotsValidator();
   when(snapshotDao.get(sourceSnapshotId)).thenReturn(new Snapshot());
   ValidateTestUtils.runAndAssertValidateFailure(
       cmd, EngineMessage.ACTION_TYPE_FAILED_VM_SNAPSHOT_HAS_NO_CONFIGURATION);
 }
Exemple #6
0
  @Test
  public void testUnsupportedCpus() {
    // prepare a command to pass validate
    VM vm = createVm();
    vm.setVmOs(OsRepository.DEFAULT_X86_OS);
    cluster = createCluster();
    vm.setClusterId(cluster.getId());
    when(clusterDao.get(cluster.getId())).thenReturn(cluster);

    AddVmFromTemplateCommand<AddVmParameters> cmd = createVmFromTemplateCommand(vm);

    mockStorageDomainDaoGetForStoragePool();
    mockVmTemplateDaoReturnVmTemplate();
    mockVerifyAddVM(cmd);
    mockConfig();
    mockMaxPciSlots();
    mockStorageDomainDaoGetAllStoragesForPool(20);
    mockDisplayTypes(vm.getOs());
    mockUninterestingMethods(cmd);
    mockGetAllSnapshots(cmd);
    when(osRepository.getArchitectureFromOS(0)).thenReturn(ArchitectureType.x86_64);
    doReturn(createStoragePool()).when(cmd).getStoragePool();

    // prepare the mock values
    Map<Pair<Integer, Version>, Set<String>> unsupported = new HashMap<>();
    Set<String> value = new HashSet<>();
    value.add(CPU_ID);
    unsupported.put(new Pair<>(vm.getVmOsId(), cluster.getCompatibilityVersion()), value);

    when(osRepository.isCpuSupported(vm.getVmOsId(), cluster.getCompatibilityVersion(), CPU_ID))
        .thenReturn(false);
    when(osRepository.getUnsupportedCpus()).thenReturn(unsupported);

    ValidateTestUtils.runAndAssertValidateFailure(
        cmd, EngineMessage.CPU_TYPE_UNSUPPORTED_FOR_THE_GUEST_OS);
  }
Exemple #7
0
  @Test
  public void create10GBVmWith11GbAvailableAndA5GbBuffer() throws Exception {
    VM vm = createVm();
    AddVmFromTemplateCommand<AddVmParameters> cmd = createVmFromTemplateCommand(vm);

    mockStorageDomainDaoGetForStoragePool();
    mockClusterDaoReturnCluster();
    mockVmTemplateDaoReturnVmTemplate();
    mockVerifyAddVM(cmd);
    mockConfig();
    mockMaxPciSlots();

    mockOsRepository();
    mockOsRepositoryGraphics(0, Version.v4_0, new Pair<>(GraphicsType.SPICE, DisplayType.qxl));
    mockGraphicsDevices(vm.getId());

    mockStorageDomainDaoGetAllStoragesForPool(AVAILABLE_SPACE_GB);
    mockUninterestingMethods(cmd);
    mockGetAllSnapshots(cmd);
    doReturn(createStoragePool()).when(cmd).getStoragePool();

    ValidateTestUtils.runAndAssertValidateFailure(
        cmd, EngineMessage.ACTION_TYPE_FAILED_DISK_SPACE_LOW_ON_STORAGE_DOMAIN);
  }