Search in sources :

Example 36 with Vm

use of org.ovirt.engine.api.model.Vm in project ovirt-engine by oVirt.

the class BackendVmsResourceTest method testClone.

@Test
public void testClone() throws Exception {
    setUriInfo(addMatrixParameterExpectations(setUpBasicUriExpectations(), BackendVmsResource.CLONE, "true"));
    setUpGetPayloadExpectations(1, 2);
    setUpGetBallooningExpectations(1, 2);
    setUpGetGraphicsExpectations(1);
    setUpGetConsoleExpectations(1, 2);
    setUpGetVmOvfExpectations(2);
    setUpGetVirtioScsiExpectations(2);
    setUpGetSoundcardExpectations(1, 2);
    setUpGetRngDeviceExpectations(1, 2);
    setUpGetCertuficateExpectations(1, 2);
    setUpEntityQueryExpectations(QueryType.GetVmTemplate, GetVmTemplateParameters.class, new String[] { "Id" }, new Object[] { GUIDS[1] }, getTemplateEntity(1));
    setUpEntityQueryExpectations(QueryType.GetClusterById, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[2] }, getClusterEntity());
    setUpCreationExpectations(ActionType.AddVmFromTemplate, AddVmParameters.class, new String[] { "StorageDomainId" }, new Object[] { GUIDS[0] }, true, true, GUIDS[2], QueryType.GetVmByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[2] }, getEntity(2));
    Response response = collection.add(createModel(new DiskAttachments()));
    assertEquals(201, response.getStatus());
    assertTrue(response.getEntity() instanceof Vm);
    verifyModel((Vm) response.getEntity(), 2);
}
Also used : Response(javax.ws.rs.core.Response) Vm(org.ovirt.engine.api.model.Vm) DiskAttachments(org.ovirt.engine.api.model.DiskAttachments) Test(org.junit.Test)

Example 37 with Vm

use of org.ovirt.engine.api.model.Vm in project ovirt-engine by oVirt.

the class BackendVmsResourceTest method testAddFromConfigurationWithRegenerateTrue.

@Test
public void testAddFromConfigurationWithRegenerateTrue() throws Exception {
    setUriInfo(setUpBasicUriExpectations());
    setUpGetPayloadExpectations(1, 3);
    setUpGetBallooningExpectations(1, 3);
    setUpGetGraphicsExpectations(1);
    setUpGetCertuficateExpectations(1, 3);
    setUpGetConsoleExpectations(3);
    setUpGetVmOvfExpectations(3);
    setUpGetVirtioScsiExpectations(3);
    setUpGetSoundcardExpectations(3);
    setUpGetRngDeviceExpectations(3);
    Vm model = createModel(null);
    org.ovirt.engine.core.common.businessentities.VM returnedVM = getEntity(2);
    model.setInitialization(new Initialization());
    model.getInitialization().setRegenerateIds(Boolean.TRUE);
    model.getInitialization().setConfiguration(new Configuration());
    model.getInitialization().getConfiguration().setData("asdasdasd");
    model.getInitialization().getConfiguration().setType(org.ovirt.engine.api.model.ConfigurationType.OVF);
    setUpGetEntityExpectations(QueryType.GetVmFromConfiguration, GetVmFromConfigurationQueryParameters.class, new String[] { "VmConfiguration", "ConfigurationType" }, new Object[] { model.getInitialization().getConfiguration().getData(), ConfigurationType.OVF }, returnedVM);
    Guid newId = GUIDS[3];
    setUpCreationExpectations(ActionType.ImportVmFromConfiguration, ImportVmFromConfParameters.class, new String[] { "Vm", "ClusterId", "ImportAsNewEntity" }, new Object[] { returnedVM, Guid.createGuidFromString(model.getCluster().getId()), true }, true, true, newId, QueryType.GetVmByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { newId }, getEntityWithProvidedId(2, newId));
    Response response = collection.add(model);
    assertEquals(201, response.getStatus());
    assertTrue(response.getEntity() instanceof Vm);
    Vm queriedVm = (Vm) response.getEntity();
    assertEquals(newId.toString(), queriedVm.getId());
    queriedVm.setId(GUIDS[2].toString());
    verifyModel((Vm) response.getEntity(), 2);
}
Also used : Initialization(org.ovirt.engine.api.model.Initialization) Response(javax.ws.rs.core.Response) Configuration(org.ovirt.engine.api.model.Configuration) Vm(org.ovirt.engine.api.model.Vm) Guid(org.ovirt.engine.core.compat.Guid) Test(org.junit.Test)

Example 38 with Vm

use of org.ovirt.engine.api.model.Vm in project ovirt-engine by oVirt.

the class BackendVmsResourceTest method verifyCollection.

@Override
protected void verifyCollection(List<Vm> collection) throws Exception {
    super.verifyCollection(collection);
    List<String> populateHeader = httpHeaders.getRequestHeader(BackendResource.POPULATE);
    boolean populated = populateHeader != null ? populateHeader.contains("true") : false;
    for (Vm vm : collection) {
        assertTrue(populated ? vm.isSetConsole() : !vm.isSetConsole());
    }
}
Also used : Vm(org.ovirt.engine.api.model.Vm)

Example 39 with Vm

use of org.ovirt.engine.api.model.Vm in project ovirt-engine by oVirt.

the class BackendVmsResourceTest method testListIncludeStatistics.

@Test
public void testListIncludeStatistics() throws Exception {
    try {
        accepts.add("application/xml; detail=statistics");
        UriInfo uriInfo = setUpUriExpectations(null);
        org.ovirt.engine.core.common.businessentities.VM vm = new org.ovirt.engine.core.common.businessentities.VM();
        VmStatistics vmStatistics = new VmStatistics();
        vmStatistics.setCpuSys(0D);
        vmStatistics.setCpuUser(0D);
        vmStatistics.setElapsedTime(0D);
        vmStatistics.setUsageCpuPercent(0);
        vmStatistics.setUsageMemPercent(0);
        vmStatistics.setUsageNetworkPercent(0);
        vm.setStatisticsData(vmStatistics);
        vm.setMigrationProgressPercent(50);
        for (int i = 0; i < GUIDS.length - 1; i++) {
            setUpGetEntityExpectations(QueryType.GetVmByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[i] }, vm);
        }
        setUpGetGraphicsMultipleExpectations(3);
        setUpQueryExpectations("");
        collection.setUriInfo(uriInfo);
        List<Vm> vms = getCollection();
        assertTrue(vms.get(0).isSetStatistics());
        verifyCollection(vms);
    } finally {
        accepts.clear();
    }
}
Also used : VmStatistics(org.ovirt.engine.core.common.businessentities.VmStatistics) Vm(org.ovirt.engine.api.model.Vm) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 40 with Vm

use of org.ovirt.engine.api.model.Vm in project ovirt-engine by oVirt.

the class BackendVmsResourceTest method testAddIncompleteParameters2.

@Test
public void testAddIncompleteParameters2() throws Exception {
    Vm model = createModel(null);
    model.setTemplate(null);
    setUriInfo(setUpBasicUriExpectations());
    try {
        collection.add(model);
        fail("expected WebApplicationException on incomplete parameters");
    } catch (WebApplicationException wae) {
        verifyIncompleteException(wae, "Vm", "add", "template.id|name");
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Vm(org.ovirt.engine.api.model.Vm) Test(org.junit.Test)

Aggregations

Vm (org.ovirt.engine.api.model.Vm)145 Test (org.junit.Test)80 Response (javax.ws.rs.core.Response)26 Host (org.ovirt.engine.api.model.Host)21 WebApplicationException (javax.ws.rs.WebApplicationException)19 Guid (org.ovirt.engine.core.compat.Guid)15 Template (org.ovirt.engine.api.model.Template)11 Hosts (org.ovirt.engine.api.model.Hosts)10 Action (org.ovirt.engine.api.model.Action)9 VmPlacementPolicy (org.ovirt.engine.api.model.VmPlacementPolicy)9 Vms (org.ovirt.engine.api.model.Vms)8 RunVmOnceParams (org.ovirt.engine.core.common.action.RunVmOnceParams)8 VM (org.ovirt.engine.core.common.businessentities.VM)8 Disk (org.ovirt.engine.api.model.Disk)7 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)7 ArrayList (java.util.ArrayList)6 Nic (org.ovirt.engine.api.model.Nic)6 VmManagementParametersBase (org.ovirt.engine.core.common.action.VmManagementParametersBase)6 Configuration (org.ovirt.engine.api.model.Configuration)5 DiskAttachment (org.ovirt.engine.api.model.DiskAttachment)5