Search in sources :

Example 1 with VirtualArrayCreateParam

use of com.emc.storageos.model.varray.VirtualArrayCreateParam in project coprhd-controller by CoprHD.

the class ComputeVirtualPoolTest method testComputeVirtualPoolCrud.

// @Test
// public void testComputeVirtualPoolGet() throws Exception {
// 
// // long timestamp = System.currentTimeMillis();
// 
// System.out.println("-Running testComputeVirtualPoolGet");
// 
// ComputeVirtualPoolList cvpResp = rSys.path("/compute/vpools")
// .get(ComputeVirtualPoolList.class);
// List<NamedRelatedResourceRep> cvpList = cvpResp.getComputeVirtualPool();
// Assert.assertTrue(cvpList.size() > 0);
// 
// }
@Test
public void testComputeVirtualPoolCrud() throws Exception {
    long timestamp = System.currentTimeMillis();
    System.out.println("-Running testComputeVirtualPool");
    // Create vArray (neighborhood) for test
    VirtualArrayCreateParam neighborhoodParam = new VirtualArrayCreateParam();
    neighborhoodParam.setLabel("nb1-temp" + String.valueOf(timestamp));
    // VirtualArrayRestRep n1 =
    // rSys.path("/vdc/varrays").header(RequestProcessingUtils.AUTH_TOKEN_HEADER,
    // _rootToken).post(VirtualArrayRestRep.class, neighborhoodParam);
    VirtualArrayRestRep n1 = rSys.path("/vdc/varrays").post(VirtualArrayRestRep.class, neighborhoodParam);
    Assert.assertNotNull(n1.getId());
    System.out.println("-Newly created vArray id - " + n1.getId().toString());
    // Create Compute Virtual Pool
    ComputeVirtualPoolCreateParam createParams = new ComputeVirtualPoolCreateParam();
    createParams.setDescription("VCP created by Unit Test");
    createParams.setName("VCP-Unit-Test-1");
    createParams.setSystemType("Cisco_UCSM");
    createParams.setMinCpuSpeed(2500);
    createParams.setMaxCpuSpeed(8000);
    createParams.setMinTotalCores(1);
    Integer newMaxCores = 8;
    createParams.setMaxTotalCores(newMaxCores);
    Set<String> vArrays = new HashSet<String>();
    vArrays.add(n1.getId().toString());
    createParams.setVarrays(vArrays);
    ComputeVirtualPoolRestRep cvpCreateResp = rSys.path("/compute/vpools").post(ComputeVirtualPoolRestRep.class, createParams);
    URI newId = cvpCreateResp.getId();
    Assert.assertNotNull(newId);
    System.out.println("-Newly created Compute Virtual Pool id - " + newId.toString());
    System.out.println("---max cores - " + cvpCreateResp.getMaxTotalCores());
    Assert.assertTrue(cvpCreateResp.getMaxTotalCores() == newMaxCores);
    // Get list of virtual pools
    ComputeVirtualPoolList cvpResp = rSys.path("/compute/vpools").get(ComputeVirtualPoolList.class);
    List<NamedRelatedResourceRep> cvpList = cvpResp.getComputeVirtualPool();
    Assert.assertTrue(!cvpList.isEmpty());
    // Get details of newly created Compute Virtual Pool
    ComputeVirtualPoolRestRep cvpGetResp = rSys.path("/compute/vpools/" + newId.toString()).get(ComputeVirtualPoolRestRep.class);
    Assert.assertNotNull(cvpGetResp.getId());
    System.out.println("id - " + cvpGetResp.getId().toString());
    System.out.println("name - " + cvpGetResp.getName());
    System.out.println("description - " + cvpGetResp.getDescription());
    List<RelatedResourceRep> vArrayResp = cvpGetResp.getVirtualArrays();
    Assert.assertTrue(!vArrayResp.isEmpty());
    // Get Matching Compute Elements
    ClientResponse ceResp = rSys.path("/compute/vpools/" + newId.toString() + "/matched-compute-elements").get(ClientResponse.class);
    // List<ComputeElementRestRep> ceList = ceResp.getList();
    Assert.assertTrue(ceResp.getStatus() == 200);
    // Update CVP
    System.out.println("- Updating - " + newId.toString());
    ComputeVirtualPoolUpdateParam updParams = new ComputeVirtualPoolUpdateParam();
    Integer updMaxCores = 4;
    updParams.setMaxTotalCores(updMaxCores);
    ComputeVirtualPoolRestRep updateResp = rSys.path("/compute/vpools/" + newId.toString()).put(ComputeVirtualPoolRestRep.class, updParams);
    System.out.println("---max cores - " + updateResp.getMaxTotalCores());
    Assert.assertTrue(updateResp.getMaxTotalCores() == updMaxCores);
    // Delete CVP
    ClientResponse delCvpResp = rSys.path("/compute/vpools/" + newId.toString() + "/deactivate").post(ClientResponse.class);
    Assert.assertTrue(delCvpResp != null);
    Assert.assertTrue(delCvpResp.getStatus() == 200);
    // Delete vArray
    ClientResponse deleteResp = rSys.path("/vdc/varrays/" + n1.getId().toString() + "/deactivate").post(ClientResponse.class);
    Assert.assertTrue(deleteResp != null);
    Assert.assertTrue(deleteResp.getStatus() == 200);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) RelatedResourceRep(com.emc.storageos.model.RelatedResourceRep) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) VirtualArrayCreateParam(com.emc.storageos.model.varray.VirtualArrayCreateParam) ComputeVirtualPoolList(com.emc.storageos.model.vpool.ComputeVirtualPoolList) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) URI(java.net.URI) ComputeVirtualPoolUpdateParam(com.emc.storageos.model.vpool.ComputeVirtualPoolUpdateParam) ComputeVirtualPoolRestRep(com.emc.storageos.model.vpool.ComputeVirtualPoolRestRep) VirtualArrayRestRep(com.emc.storageos.model.varray.VirtualArrayRestRep) ComputeVirtualPoolCreateParam(com.emc.storageos.model.vpool.ComputeVirtualPoolCreateParam) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with VirtualArrayCreateParam

use of com.emc.storageos.model.varray.VirtualArrayCreateParam in project coprhd-controller by CoprHD.

the class VirtualArrayUtils method create.

public static VirtualArrayRestRep create(String name, boolean autoSanZoning) {
    VirtualArrayCreateParam virtualArray = new VirtualArrayCreateParam();
    virtualArray.setLabel(name);
    virtualArray.getBlockSettings().setAutoSanZoning(autoSanZoning);
    return getViprClient().varrays().create(virtualArray);
}
Also used : VirtualArrayCreateParam(com.emc.storageos.model.varray.VirtualArrayCreateParam)

Example 3 with VirtualArrayCreateParam

use of com.emc.storageos.model.varray.VirtualArrayCreateParam in project coprhd-controller by CoprHD.

the class InternalVirtualArrayApiTest method testInternalVirtualArray.

@Test
public void testInternalVirtualArray() throws Exception {
    long timestamp = System.currentTimeMillis();
    // 1. CREATE subtenants
    String subtenant_url = "/tenants/" + _rootTenantId.toString() + "/subtenants";
    TenantCreateParam tenantParam = new TenantCreateParam();
    String subtenant_label = "subtenant" + String.valueOf(timestamp);
    tenantParam.setLabel(subtenant_label);
    tenantParam.setUserMappings(new ArrayList<UserMappingParam>());
    UserMappingParam tenantMapping = new UserMappingParam();
    // Add an domain to the mapping
    tenantMapping.setDomain("sanity.LOCAL");
    // Add an attribute scope to the mapping
    UserMappingAttributeParam tenantAttr = new UserMappingAttributeParam();
    tenantAttr.setKey("OU");
    tenantAttr.setValues(Collections.singletonList(subtenant_label));
    tenantMapping.setAttributes(Collections.singletonList(tenantAttr));
    tenantParam.getUserMappings().add(tenantMapping);
    TenantOrgRestRep subtenant = rTAdminGr.path(subtenant_url).header(RequestProcessingUtils.AUTH_TOKEN_HEADER, _rootToken).post(TenantOrgRestRep.class, tenantParam);
    Assert.assertTrue(subtenant.getName().equals(subtenant_label));
    Assert.assertEquals(1, subtenant.getUserMappings().size());
    // 2. create neighborhoods for test
    VirtualArrayCreateParam neighborhoodParam = new VirtualArrayCreateParam();
    neighborhoodParam.setLabel("nb1" + String.valueOf(timestamp));
    VirtualArrayRestRep n1 = rSys.path("/vdc/varrays").post(VirtualArrayRestRep.class, neighborhoodParam);
    Assert.assertNotNull(n1.getId());
    // 3. set protection type
    String sProtectionType = "protectionType1";
    VirtualArrayRestRep resp = _internalVarrayClient.setProtectionType(n1.getId(), sProtectionType);
    Assert.assertTrue(resp != null);
    Assert.assertTrue(resp.getId().equals(n1.getId()));
    Assert.assertTrue(resp.getObjectSettings().getProtectionType().equals(sProtectionType));
    // 4. get protection type
    String rProtectionType = _internalVarrayClient.getProtectionType(n1.getId());
    Assert.assertTrue(resp != null);
    Assert.assertTrue(rProtectionType.equals(sProtectionType));
    // 4.a get protectoin type from an not existed varray
    try {
        URI tmpvarryId = URI.create(String.format("urn:storageos:VirtualArray:%1$s:%2$s", UUID.randomUUID().toString(), "vdc1"));
        rProtectionType = _internalVarrayClient.getProtectionType(tmpvarryId);
    } catch (APIException e) {
        Assert.assertEquals(ServiceCode.API_URL_ENTITY_NOT_FOUND, e.getServiceCode());
    }
    // 5. unset protection type
    ClientResponse unsetResp = _internalVarrayClient.unsetProtectionType(n1.getId());
    Assert.assertTrue(unsetResp != null);
    Assert.assertTrue(unsetResp.getStatus() == 200);
    // 6. get protection type after unset
    rProtectionType = _internalVarrayClient.getProtectionType(n1.getId());
    Assert.assertTrue(resp != null);
    Assert.assertTrue(rProtectionType.isEmpty());
    // 7. set registered status to true
    Boolean bDeviceRegistered = true;
    VirtualArrayRestRep resp2 = _internalVarrayClient.setDeviceRegistered(n1.getId(), bDeviceRegistered);
    Assert.assertTrue(resp2 != null);
    Assert.assertTrue(resp2.getId().equals(n1.getId()));
    Assert.assertTrue(resp2.getObjectSettings().getDeviceRegistered().equals(bDeviceRegistered));
    // 8. get registered status
    Boolean rDeviceRegistered = _internalVarrayClient.getDeviceRegistered(n1.getId());
    Assert.assertTrue(resp != null);
    Assert.assertTrue(bDeviceRegistered == rDeviceRegistered);
    // 9. try to delete nh1
    ClientResponse deleteResp = rSys.path("/vdc/varrays/" + n1.getId().toString() + "/deactivate").post(ClientResponse.class);
    Assert.assertTrue(deleteResp != null);
    Assert.assertTrue(deleteResp.getStatus() == 400);
    // 9. set registered status to false
    bDeviceRegistered = false;
    VirtualArrayRestRep resp3 = _internalVarrayClient.setDeviceRegistered(n1.getId(), bDeviceRegistered);
    Assert.assertTrue(resp3 != null);
    Assert.assertTrue(resp3.getId().equals(n1.getId()));
    Assert.assertTrue(resp3.getObjectSettings().getDeviceRegistered().equals(bDeviceRegistered));
    // 10. delete nh1
    deleteResp = rSys.path("/vdc/varrays/" + n1.getId().toString() + "/deactivate").post(ClientResponse.class);
    Assert.assertTrue(deleteResp != null);
    Assert.assertTrue(deleteResp.getStatus() == 200);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) VirtualArrayCreateParam(com.emc.storageos.model.varray.VirtualArrayCreateParam) URI(java.net.URI) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) VirtualArrayRestRep(com.emc.storageos.model.varray.VirtualArrayRestRep) Test(org.junit.Test)

Example 4 with VirtualArrayCreateParam

use of com.emc.storageos.model.varray.VirtualArrayCreateParam in project coprhd-controller by CoprHD.

the class RoleChangeTest method accessVarray.

@Test
public void accessVarray() throws Exception {
    VirtualArrayCreateParam virtualArrayCreateParam = new VirtualArrayCreateParam();
    virtualArrayCreateParam.setLabel("array_created_by_root" + new Random().nextInt());
    ClientResponse resp = rootUser.path("/vdc/varrays").header(AUTH_TOKEN_HEADER, rootToken).post(ClientResponse.class, virtualArrayCreateParam);
    Assert.assertEquals(200, resp.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) VirtualArrayCreateParam(com.emc.storageos.model.varray.VirtualArrayCreateParam) Test(org.junit.Test)

Example 5 with VirtualArrayCreateParam

use of com.emc.storageos.model.varray.VirtualArrayCreateParam in project coprhd-controller by CoprHD.

the class ApiTest method usageAclTests.

/**
 * Cos and VirtualArray acls tests
 */
public void usageAclTests() {
    TenantResponse tenantResp = rSys.path("/tenant").get(TenantResponse.class);
    rootTenantId = tenantResp.getTenant();
    String subtenant_url = "/tenants/" + rootTenantId.toString() + "/subtenants";
    TenantOrgList list = rSys.path(subtenant_url).get(TenantOrgList.class);
    Assert.assertEquals(4, list.getSubtenants().size());
    NamedRelatedResourceRep st1 = list.getSubtenants().get(0);
    NamedRelatedResourceRep st2 = list.getSubtenants().get(1);
    // create neighborhoods for test
    VirtualArrayCreateParam neighborhoodParam = new VirtualArrayCreateParam();
    neighborhoodParam.setLabel("n1");
    VirtualArrayRestRep n1 = rSys.path("/vdc/varrays").post(VirtualArrayRestRep.class, neighborhoodParam);
    Assert.assertNotNull(n1.getId());
    neighborhoodParam.setLabel("n2");
    VirtualArrayRestRep n2 = rSys.path("/vdc/varrays").post(VirtualArrayRestRep.class, neighborhoodParam);
    Assert.assertNotNull(n2.getId());
    // test open to all by default
    ClientResponse resp = rSTAdmin1.path("/vdc/varrays/" + n1.getId().toString()).get(ClientResponse.class);
    Assert.assertEquals(200, resp.getStatus());
    resp = rSTAdmin2.path("/vdc/varrays/" + n1.getId().toString()).get(ClientResponse.class);
    Assert.assertEquals(200, resp.getStatus());
    // set usage acl for st1 on n1
    String neighborAclUrl = "/vdc/varrays/%s/acl";
    ACLAssignmentChanges changes = new ACLAssignmentChanges();
    ACLEntry entry1 = new ACLEntry();
    entry1.setTenant(st1.getId().toString());
    entry1.setAces(new ArrayList<String>());
    entry1.getAces().add("USE");
    changes.setAdd(new ArrayList<ACLEntry>());
    changes.getAdd().add(entry1);
    resp = rSys.path(String.format(neighborAclUrl, n1.getId().toString())).put(ClientResponse.class, changes);
    Assert.assertEquals(200, resp.getStatus());
    VirtualArrayRestRep nRead = rSTAdmin1.path("/vdc/varrays/" + n1.getId().toString()).get(VirtualArrayRestRep.class);
    Assert.assertEquals(nRead.getId(), n1.getId());
    Assert.assertEquals(nRead.getName(), n1.getName());
    resp = rSTAdmin2.path("/vdc/varrays/" + n1.getId().toString()).get(ClientResponse.class);
    Assert.assertEquals(403, resp.getStatus());
    // set usage acl for st2 on n2
    changes = new ACLAssignmentChanges();
    ACLEntry entry2 = new ACLEntry();
    entry2.setTenant(st2.getId().toString());
    entry2.setAces(new ArrayList<String>());
    entry2.getAces().add("USE");
    changes.setAdd(new ArrayList<ACLEntry>());
    changes.getAdd().add(entry2);
    resp = rSys.path(String.format(neighborAclUrl, n2.getId().toString())).put(ClientResponse.class, changes);
    Assert.assertEquals(200, resp.getStatus());
    nRead = rSTAdmin2.path("/vdc/varrays/" + n2.getId().toString()).get(VirtualArrayRestRep.class);
    Assert.assertEquals(nRead.getId(), n2.getId());
    Assert.assertEquals(nRead.getName(), n2.getName());
    resp = rSTAdmin1.path("/vdc/varrays/" + n2.getId().toString()).get(ClientResponse.class);
    Assert.assertEquals(403, resp.getStatus());
    // negative test - invalid tenant id
    changes = new ACLAssignmentChanges();
    entry2 = new ACLEntry();
    entry2.setTenant("invalid");
    entry2.setAces(new ArrayList<String>());
    entry2.getAces().add("USE");
    changes.setAdd(new ArrayList<ACLEntry>());
    changes.getAdd().add(entry2);
    resp = rSys.path(String.format(neighborAclUrl, n2.getId().toString())).put(ClientResponse.class, changes);
    Assert.assertEquals(400, resp.getStatus());
    // negative test - missing ace
    changes = new ACLAssignmentChanges();
    entry2 = new ACLEntry();
    entry2.setTenant(st2.getId().toString());
    entry2.setAces(new ArrayList<String>());
    changes.setAdd(new ArrayList<ACLEntry>());
    changes.getAdd().add(entry2);
    resp = rSys.path(String.format(neighborAclUrl, n2.getId().toString())).put(ClientResponse.class, changes);
    Assert.assertEquals(400, resp.getStatus());
    // negative test - choice of tenant/group/subject_id (multiple present)
    changes = new ACLAssignmentChanges();
    entry2 = new ACLEntry();
    entry2.setTenant(st2.getId().toString());
    entry2.setGroup("TEST");
    entry2.setAces(new ArrayList<String>());
    entry2.getAces().add("USE");
    changes.setAdd(new ArrayList<ACLEntry>());
    changes.getAdd().add(entry2);
    resp = rSys.path(String.format(neighborAclUrl, n2.getId().toString())).put(ClientResponse.class, changes);
    Assert.assertEquals(400, resp.getStatus());
    changes = new ACLAssignmentChanges();
    entry2 = new ACLEntry();
    entry2.setTenant(st2.getId().toString());
    entry2.setSubjectId("TEST");
    entry2.setAces(new ArrayList<String>());
    entry2.getAces().add("USE");
    changes.setAdd(new ArrayList<ACLEntry>());
    changes.getAdd().add(entry2);
    resp = rSys.path(String.format(neighborAclUrl, n2.getId().toString())).put(ClientResponse.class, changes);
    Assert.assertEquals(400, resp.getStatus());
    changes = new ACLAssignmentChanges();
    entry2 = new ACLEntry();
    entry2.setTenant(st2.getId().toString());
    entry2.setGroup("TEST");
    entry2.setSubjectId("TEST");
    entry2.setAces(new ArrayList<String>());
    entry2.getAces().add("USE");
    changes.setAdd(new ArrayList<ACLEntry>());
    changes.getAdd().add(entry2);
    resp = rSys.path(String.format(neighborAclUrl, n2.getId().toString())).put(ClientResponse.class, changes);
    Assert.assertEquals(400, resp.getStatus());
    // list neighborhoods
    VirtualArrayList nList = rSTAdminGr1.path("/vdc/varrays/").get(VirtualArrayList.class);
    Assert.assertEquals(1, nList.getVirtualArrays().size());
    Assert.assertEquals(n1.getId(), nList.getVirtualArrays().get(0).getId());
    // newly created varray, accessible for all
    neighborhoodParam = new VirtualArrayCreateParam();
    neighborhoodParam.setLabel("n3");
    VirtualArrayRestRep n3 = rSys.path("/vdc/varrays").post(VirtualArrayRestRep.class, neighborhoodParam);
    Assert.assertNotNull(n3.getId());
    nList = rSTAdminGr1.path("/vdc/varrays/").get(VirtualArrayList.class);
    Assert.assertEquals(2, nList.getVirtualArrays().size());
    Assert.assertTrue(nList.getVirtualArrays().get(0).getId().equals(n1.getId()) || nList.getVirtualArrays().get(1).getId().equals(n1.getId()));
    Assert.assertTrue(nList.getVirtualArrays().get(0).getId().equals(n3.getId()) || nList.getVirtualArrays().get(1).getId().equals(n3.getId()));
    // delete nh3
    rSys.path("/vdc/varrays/" + n3.getId().toString() + "/deactivate").post();
    // create vpool
    BlockVirtualPoolParam paramCosBlock = new BlockVirtualPoolParam();
    paramCosBlock.setName("foobar-block");
    paramCosBlock.setDescription("foobar-block description");
    paramCosBlock.setProtocols(new HashSet<String>());
    paramCosBlock.getProtocols().add(StorageProtocol.Block.FC.name());
    paramCosBlock.setMaxPaths(2);
    paramCosBlock.setProvisionType("Thick");
    BlockVirtualPoolRestRep cos1 = rZAdmin.path("/block/vpools").post(BlockVirtualPoolRestRep.class, paramCosBlock);
    Assert.assertNotNull(cos1.getId());
    resp = rZAdmin.path("/block/vpools").post(ClientResponse.class, paramCosBlock);
    Assert.assertEquals(400, resp.getStatus());
    resp = rSTAdmin1.path("/block/vpools/" + cos1.getId().toString()).get(ClientResponse.class);
    Assert.assertEquals(200, resp.getStatus());
    resp = rSTAdmin2.path("/block/vpools/" + cos1.getId().toString()).get(ClientResponse.class);
    Assert.assertEquals(200, resp.getStatus());
    // negative test: assign an empty storage pool
    VirtualPoolPoolUpdateParam paramPoolUpdate = new VirtualPoolPoolUpdateParam();
    paramPoolUpdate.setStoragePoolAssignmentChanges(new StoragePoolAssignmentChanges());
    paramPoolUpdate.getStoragePoolAssignmentChanges().setAdd(new StoragePoolAssignments());
    paramPoolUpdate.getStoragePoolAssignmentChanges().getAdd().setStoragePools(new HashSet<String>());
    paramPoolUpdate.getStoragePoolAssignmentChanges().getAdd().getStoragePools().add("");
    resp = rZAdmin.path("/block/vpools/" + cos1.getId().toString() + "/assign-matched-pools/").put(ClientResponse.class, paramPoolUpdate);
    Assert.assertEquals(400, resp.getStatus());
    // Set Cos acl
    changes = new ACLAssignmentChanges();
    changes.setAdd(new ArrayList<ACLEntry>());
    changes.getAdd().add(entry1);
    resp = rSys.path(String.format(_blockCosAclUrl, cos1.getId().toString())).put(ClientResponse.class, changes);
    Assert.assertEquals(200, resp.getStatus());
    resp = rSys.path(String.format(_fileCosAclUrl, cos1.getId().toString())).get(ClientResponse.class);
    Assert.assertEquals(400, resp.getStatus());
    BlockVirtualPoolRestRep cRead = rSTAdmin1.path("/block/vpools/" + cos1.getId().toString()).get(BlockVirtualPoolRestRep.class);
    Assert.assertEquals(cRead.getId(), cos1.getId());
    Assert.assertEquals(cRead.getName(), cos1.getName());
    resp = rSTAdmin2.path("/block/vpools/" + cos1.getId().toString()).get(ClientResponse.class);
    Assert.assertEquals(403, resp.getStatus());
    // create second CoS
    paramCosBlock = new BlockVirtualPoolParam();
    paramCosBlock.setName("foobar-block2");
    paramCosBlock.setDescription("foobar-block2 description");
    paramCosBlock.setProtocols(new HashSet<String>());
    paramCosBlock.getProtocols().add(StorageProtocol.Block.FC.name());
    paramCosBlock.setProvisionType("Thick");
    BlockVirtualPoolRestRep cos2 = rZAdminGr.path("/block/vpools").post(BlockVirtualPoolRestRep.class, paramCosBlock);
    Assert.assertNotNull(cos2.getId());
    // list vpool
    VirtualPoolList cList = rSTAdminGr1.path("/block/vpools/").get(VirtualPoolList.class);
    Assert.assertEquals(2, cList.getVirtualPool().size());
    Assert.assertTrue(cList.getVirtualPool().get(0).getId().equals(cos1.getId()) || cList.getVirtualPool().get(1).getId().equals(cos1.getId()));
    Assert.assertTrue(cList.getVirtualPool().get(0).getId().equals(cos2.getId()) || cList.getVirtualPool().get(1).getId().equals(cos2.getId()));
    cList = rSTAdmin2.path("/block/vpools/").get(VirtualPoolList.class);
    Assert.assertEquals(1, cList.getVirtualPool().size());
    Assert.assertEquals(cos2.getId(), cList.getVirtualPool().get(0).getId());
    // test limits
    for (int i = 0; i < 100; i++) {
        changes = new ACLAssignmentChanges();
        entry1.setTenant(st2.getId().toString());
        changes.setAdd(new ArrayList<ACLEntry>());
        changes.getAdd().add(entry1);
        resp = rSys.path(String.format(_blockCosAclUrl, cos2.getId().toString())).put(ClientResponse.class, changes);
        Assert.assertEquals(200, resp.getStatus());
    }
    changes = new ACLAssignmentChanges();
    entry1.setTenant("tenant_invalid");
    changes.setAdd(new ArrayList<ACLEntry>());
    changes.getAdd().add(entry1);
    resp = rSys.path(String.format(_blockCosAclUrl, cos2.getId().toString())).put(ClientResponse.class, changes);
    Assert.assertEquals(400, resp.getStatus());
    // testing tags
    String cosTagUrl = "/block/vpools/%s/tags";
    TagAssignment tags = new TagAssignment();
    tags.setAdd(new StringSet());
    tags.getAdd().add("testtag1");
    resp = rSTAdmin2.path(String.format(cosTagUrl, cos1.getId())).put(ClientResponse.class, tags);
    Assert.assertEquals(403, resp.getStatus());
    Tags tagsResp = rSys.path(String.format(cosTagUrl, cos1.getId())).put(Tags.class, tags);
    Assert.assertTrue(tagsResp.getTag().equals(tags.getAdd()));
    tags.setRemove(new StringSet());
    tags.getRemove().addAll(new HashSet(tags.getAdd()));
    // invalid tag, too short
    tags.getAdd().add("t");
    resp = rSys.path(String.format(cosTagUrl, cos1.getId())).put(ClientResponse.class, tags);
    Assert.assertEquals(400, resp.getStatus());
    tags.getAdd().clear();
    // invalid tag, too long
    tags.getAdd().add("tag" + STR144);
    resp = rSys.path(String.format(cosTagUrl, cos1.getId())).put(ClientResponse.class, tags);
    Assert.assertEquals(400, resp.getStatus());
    tags.getAdd().clear();
    // tags should be trimmed
    tags.getAdd().add(" testtag  ");
    tagsResp = rSys.path(String.format(cosTagUrl, cos1.getId())).put(Tags.class, tags);
    Assert.assertTrue(tagsResp.getTag().equals(new StringSet() {

        {
            add("testtag");
        }
    }));
    resp = rSTAdmin2.path(String.format(cosTagUrl, cos1.getId())).get(ClientResponse.class);
    Assert.assertEquals(403, resp.getStatus());
    resp = rSTAdmin1.path(String.format(cosTagUrl, cos1.getId())).get(ClientResponse.class);
    Assert.assertEquals(200, resp.getStatus());
    // Test bad parameter is returned if we add an invalid varray while creating the VirtualPool
    FileVirtualPoolParam paramFileCos = new FileVirtualPoolParam();
    paramFileCos.setName("Generic File VirtualPool");
    paramFileCos.setProtocols(new HashSet<String>());
    paramFileCos.getProtocols().add(StorageProtocol.File.NFS.name());
    paramFileCos.getProtocols().add(StorageProtocol.File.CIFS.name());
    paramFileCos.setVarrays(new HashSet<String>());
    paramFileCos.getVarrays().add("IDontExist");
    resp = rZAdmin.path("/file/vpools").post(ClientResponse.class, paramFileCos);
    Assert.assertEquals(400, resp.getStatus());
    // below is vpool restricted to tenant test
    /*
         * test setup:
         * create a varray and vpool and associate the vpool with the varray
         * restrict the vpool to the tenant
         */
    String vaLabel = "va-testTenantRestrictAccess-" + Calendar.getInstance().getTime().getTime();
    String vpLabel = "vp-testTenantRestrictAccess-" + Calendar.getInstance().getTime().getTime();
    // create a varray
    VirtualArrayCreateParam vaParam = new VirtualArrayCreateParam();
    vaParam.setLabel(vaLabel);
    BlockSettings bs = new BlockSettings();
    bs.setAutoSanZoning(true);
    vaParam.setBlockSettings(bs);
    VirtualArrayRestRep va1 = rSys.path("/vdc/varrays").post(VirtualArrayRestRep.class, vaParam);
    // create a vpool associated with the varray
    BlockVirtualPoolParam vpParam = new BlockVirtualPoolParam();
    vpParam.setName(vpLabel);
    vpParam.setDescription(vpLabel);
    Set<String> vas = new HashSet<String>();
    vas.add(va1.getId().toString());
    vpParam.setVarrays(vas);
    vpParam.setProvisionType("Thin");
    Set<String> protos = new HashSet();
    protos.add("FC");
    vpParam.setProtocols(protos);
    BlockVirtualPoolRestRep vp1 = rSys.path("/block/vpools").post(BlockVirtualPoolRestRep.class, vpParam);
    // restrict the vpool to a tenant
    ACLAssignmentChanges aclChange = new ACLAssignmentChanges();
    List<ACLEntry> acls = new ArrayList<>();
    ACLEntry acl = new ACLEntry();
    acl.setTenant(subtenant2Id.toString());
    acl.setAces(new ArrayList<String>(Arrays.asList("USE")));
    acls.add(acl);
    aclChange.setAdd(acls);
    String uri = String.format("/block/vpools/%s/acl", vp1.getId());
    ACLAssignments aclAssignments = rSys.path(uri).put(ACLAssignments.class, aclChange);
    // test1: sysadmin can see vpool
    // test2: sysmonitor can see vpool
    String vpUri = String.format("/vdc/varrays/%s/vpools", va1.getId().toString());
    VirtualPoolList vpoolList = rSys.path(vpUri).get(VirtualPoolList.class);
    List<NamedRelatedVirtualPoolRep> vpools = vpoolList.getVirtualPool();
    boolean foundVpool = false;
    for (NamedRelatedVirtualPoolRep vpool : vpools) {
        if (vpool.getId().equals(vp1.getId())) {
            foundVpool = true;
            _log.info("user root can see the vpool {}", vp1.getName());
        }
    }
    Assert.assertTrue(foundVpool);
    // test3: tenant user can see vpool
    VirtualPoolList vpoolList2 = rST2User.path(vpUri).get(VirtualPoolList.class);
    List<NamedRelatedVirtualPoolRep> vpools2 = vpoolList2.getVirtualPool();
    foundVpool = false;
    for (NamedRelatedVirtualPoolRep vpool : vpools2) {
        if (vpool.getId().equals(vp1.getId())) {
            foundVpool = true;
            _log.info("user st2user can see the vpool {}", vp1.getName());
        }
    }
    Assert.assertTrue(foundVpool);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) VirtualPoolPoolUpdateParam(com.emc.storageos.model.vpool.VirtualPoolPoolUpdateParam) VirtualArrayList(com.emc.storageos.model.varray.VirtualArrayList) ArrayList(java.util.ArrayList) VirtualPoolList(com.emc.storageos.model.vpool.VirtualPoolList) NamedRelatedVirtualPoolRep(com.emc.storageos.model.vpool.NamedRelatedVirtualPoolRep) VirtualArrayRestRep(com.emc.storageos.model.varray.VirtualArrayRestRep) StringSet(com.emc.storageos.db.client.model.StringSet) VirtualArrayList(com.emc.storageos.model.varray.VirtualArrayList) BlockVirtualPoolRestRep(com.emc.storageos.model.vpool.BlockVirtualPoolRestRep) Tags(com.emc.storageos.model.search.Tags) HashSet(java.util.HashSet) StoragePoolAssignments(com.emc.storageos.model.vpool.StoragePoolAssignments) StoragePoolAssignmentChanges(com.emc.storageos.model.vpool.StoragePoolAssignmentChanges) FileVirtualPoolParam(com.emc.storageos.model.vpool.FileVirtualPoolParam) ACLAssignmentChanges(com.emc.storageos.model.auth.ACLAssignmentChanges) VirtualArrayCreateParam(com.emc.storageos.model.varray.VirtualArrayCreateParam) TagAssignment(com.emc.storageos.model.TagAssignment) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) BlockSettings(com.emc.storageos.model.varray.BlockSettings) ACLEntry(com.emc.storageos.model.auth.ACLEntry) TenantOrgList(com.emc.storageos.model.tenant.TenantOrgList) ACLAssignments(com.emc.storageos.model.auth.ACLAssignments) BlockVirtualPoolParam(com.emc.storageos.model.vpool.BlockVirtualPoolParam) TenantResponse(com.emc.storageos.model.tenant.TenantResponse)

Aggregations

VirtualArrayCreateParam (com.emc.storageos.model.varray.VirtualArrayCreateParam)5 ClientResponse (com.sun.jersey.api.client.ClientResponse)4 VirtualArrayRestRep (com.emc.storageos.model.varray.VirtualArrayRestRep)3 Test (org.junit.Test)3 NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)2 URI (java.net.URI)2 HashSet (java.util.HashSet)2 StringSet (com.emc.storageos.db.client.model.StringSet)1 RelatedResourceRep (com.emc.storageos.model.RelatedResourceRep)1 TagAssignment (com.emc.storageos.model.TagAssignment)1 ACLAssignmentChanges (com.emc.storageos.model.auth.ACLAssignmentChanges)1 ACLAssignments (com.emc.storageos.model.auth.ACLAssignments)1 ACLEntry (com.emc.storageos.model.auth.ACLEntry)1 Tags (com.emc.storageos.model.search.Tags)1 TenantOrgList (com.emc.storageos.model.tenant.TenantOrgList)1 TenantResponse (com.emc.storageos.model.tenant.TenantResponse)1 BlockSettings (com.emc.storageos.model.varray.BlockSettings)1 VirtualArrayList (com.emc.storageos.model.varray.VirtualArrayList)1 BlockVirtualPoolParam (com.emc.storageos.model.vpool.BlockVirtualPoolParam)1 BlockVirtualPoolRestRep (com.emc.storageos.model.vpool.BlockVirtualPoolRestRep)1