Search in sources :

Example 96 with Vm

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

the class BackendVmsResourceTest method testBadAddFromConfiguration.

private void testBadAddFromConfiguration(boolean valid, boolean success, String detail) throws Exception {
    Vm model = createModel(null);
    org.ovirt.engine.core.common.businessentities.VM returnedVM = getEntity(2);
    model.setInitialization(new Initialization());
    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);
    setUriInfo(setUpActionExpectations(ActionType.ImportVmFromConfiguration, ImportVmFromConfParameters.class, new String[] { "Vm", "ClusterId" }, new Object[] { returnedVM, Guid.createGuidFromString(model.getCluster().getId()) }, valid, success));
    try {
        collection.add(model);
        fail("expected WebApplicationException");
    } catch (WebApplicationException wae) {
        verifyFault(wae, detail);
    }
}
Also used : Initialization(org.ovirt.engine.api.model.Initialization) Configuration(org.ovirt.engine.api.model.Configuration) WebApplicationException(javax.ws.rs.WebApplicationException) Vm(org.ovirt.engine.api.model.Vm) ImportVmFromConfParameters(org.ovirt.engine.core.common.action.ImportVmFromConfParameters)

Example 97 with Vm

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

the class BackendVmsResourceTest method doTestCloneFromTemplateWithClonePermissions.

private void doTestCloneFromTemplateWithClonePermissions(Vm model, boolean copy) throws Exception {
    UriInfo uriInfo = setUpBasicUriExpectations();
    Map<String, String> matrixParameters = new HashMap<>();
    matrixParameters.put(BackendVmsResource.CLONE, Boolean.toString(true));
    matrixParameters.put(BackendVmsResource.CLONE_PERMISSIONS, Boolean.toString(copy));
    uriInfo = addMatrixParameterExpectations(uriInfo, matrixParameters);
    setUriInfo(uriInfo);
    setUpTemplateDisksExpectations(GUIDS[1]);
    setUpGetPayloadExpectations(1, 2);
    setUpGetBallooningExpectations(1, 2);
    setUpGetGraphicsExpectations(1);
    setUpGetCertuficateExpectations(1, 2);
    setUpGetConsoleExpectations(1, 2);
    setUpGetVmOvfExpectations(2);
    setUpGetVirtioScsiExpectations(2);
    setUpGetSoundcardExpectations(1, 2);
    setUpGetRngDeviceExpectations(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", "CopyTemplatePermissions" }, new Object[] { GUIDS[0], copy }, true, true, GUIDS[2], QueryType.GetVmByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[2] }, getEntity(2));
    Response response = collection.add(model);
    assertEquals(201, response.getStatus());
    assertTrue(response.getEntity() instanceof Vm);
    verifyModel((Vm) response.getEntity(), 2);
}
Also used : Response(javax.ws.rs.core.Response) HashMap(java.util.HashMap) Vm(org.ovirt.engine.api.model.Vm) UriInfo(javax.ws.rs.core.UriInfo)

Example 98 with Vm

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

the class BackendVmsResourceTest method testAddUploadIcon.

@Test
public void testAddUploadIcon() throws Exception {
    setUpEntityQueryExpectations(QueryType.GetVmTemplate, GetVmTemplateParameters.class, new String[] { "Id" }, new Object[] { GUIDS[1] }, getTemplateEntity(1));
    setupAddExpectations();
    setUpCreationExpectations(ActionType.AddVm, AddVmParameters.class, new String[] { "StorageDomainId", "VmLargeIcon" }, new Object[] { GUIDS[0], VmIcon.typeAndDataToDataUrl(IconTestHelpler.MEDIA_TYPE, IconTestHelpler.DATA_URL) }, true, true, GUIDS[2], QueryType.GetVmByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[2] }, getEntity(2));
    final Vm model = createModel(null);
    model.setLargeIcon(IconTestHelpler.createIconWithData());
    Response response = collection.add(model);
    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) Test(org.junit.Test)

Example 99 with Vm

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

the class BackendVmsResourceTest method testAddWithPlacementPolicySingleHostId.

@Test
public void testAddWithPlacementPolicySingleHostId() throws Exception {
    setUpAddVm();
    setUpGetConsoleExpectations(1);
    setUpCreationExpectations(ActionType.AddVm, 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));
    Vm model = createModel(null);
    model.setPlacementPolicy(new VmPlacementPolicy());
    model.getPlacementPolicy().setHosts(new Hosts());
    model.getPlacementPolicy().getHosts().getHosts().add(new Host());
    model.getPlacementPolicy().getHosts().getHosts().get(0).setId(GUIDS[1].toString());
    Response response = collection.add(model);
    assertEquals(201, response.getStatus());
    assertTrue(response.getEntity() instanceof Vm);
    verifyModel((Vm) response.getEntity(), 2);
}
Also used : Response(javax.ws.rs.core.Response) Hosts(org.ovirt.engine.api.model.Hosts) Vm(org.ovirt.engine.api.model.Vm) Host(org.ovirt.engine.api.model.Host) VmPlacementPolicy(org.ovirt.engine.api.model.VmPlacementPolicy) Test(org.junit.Test)

Example 100 with Vm

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

the class BackendVmsResourceTest method doTestAddWithClonePermissions.

private void doTestAddWithClonePermissions(Vm model, boolean copy) throws Exception {
    UriInfo uriInfo = setUpBasicUriExpectations();
    uriInfo = addMatrixParameterExpectations(uriInfo, BackendVmsResource.CLONE_PERMISSIONS, Boolean.toString(copy));
    setUriInfo(uriInfo);
    setUpGetPayloadExpectations(1, 2);
    setUpGetBallooningExpectations(1, 2);
    setUpGetGraphicsExpectations(1);
    setUpGetCertuficateExpectations(1, 2);
    setUpGetConsoleExpectations(1, 2);
    setUpGetVmOvfExpectations(2);
    setUpGetVirtioScsiExpectations(2);
    setUpGetSoundcardExpectations(1, 2);
    setUpGetRngDeviceExpectations(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.AddVm, AddVmParameters.class, new String[] { "StorageDomainId", "CopyTemplatePermissions" }, new Object[] { GUIDS[0], copy }, true, true, GUIDS[2], QueryType.GetVmByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[2] }, getEntity(2));
    Response response = collection.add(model);
    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) UriInfo(javax.ws.rs.core.UriInfo)

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