Search in sources :

Example 11 with BigSwitchBcfApiException

use of com.cloud.network.bigswitch.BigSwitchBcfApiException in project cloudstack by apache.

the class BigSwitchBcfResourceTest method testSyncTopologyRetryOnce.

@Test
public void testSyncTopologyRetryOnce() throws ConfigurationException, BigSwitchBcfApiException {
    _resource.configure("BigSwitchBcfResource", _parameters);
    _resource.setTopology(new TopologyData());
    when(_bigswitchBcfApi.syncTopology((TopologyData) any())).thenThrow(new BigSwitchBcfApiException()).thenReturn(UUID.randomUUID().toString());
    BcfAnswer ans = (BcfAnswer) _resource.executeRequest(new SyncBcfTopologyCommand(true, false));
    assertTrue(ans.getResult());
}
Also used : BcfAnswer(com.cloud.agent.api.BcfAnswer) BigSwitchBcfApiException(com.cloud.network.bigswitch.BigSwitchBcfApiException) TopologyData(com.cloud.network.bigswitch.TopologyData) SyncBcfTopologyCommand(com.cloud.agent.api.SyncBcfTopologyCommand) Test(org.junit.Test)

Example 12 with BigSwitchBcfApiException

use of com.cloud.network.bigswitch.BigSwitchBcfApiException in project cloudstack by apache.

the class BigSwitchBcfResourceTest method testDeleteAttachmentRetryOnce.

@Test
public void testDeleteAttachmentRetryOnce() throws ConfigurationException, BigSwitchBcfApiException {
    _resource.configure("BigSwitchBcfResource", _parameters);
    when(_bigswitchBcfApi.deleteAttachment((String) any(), (String) any(), (String) any())).thenThrow(new BigSwitchBcfApiException()).thenReturn(UUID.randomUUID().toString());
    BcfAnswer ans = (BcfAnswer) _resource.executeRequest(new DeleteBcfAttachmentCommand("networkId", "portid", "tenantid"));
    assertTrue(ans.getResult());
}
Also used : BcfAnswer(com.cloud.agent.api.BcfAnswer) DeleteBcfAttachmentCommand(com.cloud.agent.api.DeleteBcfAttachmentCommand) BigSwitchBcfApiException(com.cloud.network.bigswitch.BigSwitchBcfApiException) Test(org.junit.Test)

Example 13 with BigSwitchBcfApiException

use of com.cloud.network.bigswitch.BigSwitchBcfApiException in project cloudstack by apache.

the class BigSwitchBcfResourceTest method testCreateStaticNatRetryOnce.

@Test
public void testCreateStaticNatRetryOnce() throws ConfigurationException, BigSwitchBcfApiException {
    _resource.configure("BigSwitchBcfResource", _parameters);
    when(_bigswitchBcfApi.createFloatingIp((String) any(), (FloatingIpData) any())).thenThrow(new BigSwitchBcfApiException()).thenReturn(UUID.randomUUID().toString());
    CreateBcfStaticNatCommand cmd = new CreateBcfStaticNatCommand("tenantid", "networkid", "192.168.0.10", "10.4.4.100", "90:b1:1c:49:d8:56");
    BcfAnswer ans = (BcfAnswer) _resource.executeRequest(cmd);
    assertTrue(ans.getResult());
}
Also used : BcfAnswer(com.cloud.agent.api.BcfAnswer) BigSwitchBcfApiException(com.cloud.network.bigswitch.BigSwitchBcfApiException) FloatingIpData(com.cloud.network.bigswitch.FloatingIpData) CreateBcfStaticNatCommand(com.cloud.agent.api.CreateBcfStaticNatCommand) Test(org.junit.Test)

Example 14 with BigSwitchBcfApiException

use of com.cloud.network.bigswitch.BigSwitchBcfApiException in project cloudstack by apache.

the class BigSwitchBcfResourceTest method testCreateSourceNatApiException.

@Test
public void testCreateSourceNatApiException() throws ConfigurationException, BigSwitchBcfApiException {
    _resource.configure("BigSwitchBcfResource", _parameters);
    doThrow(new BigSwitchBcfApiException()).when(_bigswitchBcfApi).modifyRouter((String) any(), (RouterData) any());
    UpdateBcfRouterCommand cmd = new UpdateBcfRouterCommand("tenantid");
    BcfAnswer ans = (BcfAnswer) _resource.executeRequest(cmd);
    assertFalse(ans.getResult());
    verify(_bigswitchBcfApi, times(3)).modifyRouter((String) any(), (RouterData) any());
}
Also used : BcfAnswer(com.cloud.agent.api.BcfAnswer) BigSwitchBcfApiException(com.cloud.network.bigswitch.BigSwitchBcfApiException) UpdateBcfRouterCommand(com.cloud.agent.api.UpdateBcfRouterCommand) Test(org.junit.Test)

Example 15 with BigSwitchBcfApiException

use of com.cloud.network.bigswitch.BigSwitchBcfApiException in project cloudstack by apache.

the class BigSwitchBcfResource method executeRequest.

private Answer executeRequest(UpdateBcfRouterCommand cmd, int numRetries) {
    RouterData routerData = new RouterData(cmd.getTenantId());
    List<AclData> acls = new ArrayList<AclData>();
    acls.addAll(cmd.getAcls());
    routerData.getRouter().getAcls().addAll(acls);
    routerData.getRouter().addExternalGateway(cmd.getPublicIp());
    try {
        String hash = _bigswitchBcfApi.modifyRouter(cmd.getTenantId(), routerData);
        return new BcfAnswer(cmd, true, "tenant " + cmd.getTenantId() + " router updated", hash);
    } catch (BigSwitchBcfApiException e) {
        if (e.is_topologySyncRequested()) {
            cmd.setTopologySyncRequested(true);
            return new BcfAnswer(cmd, true, "tenant " + cmd.getTenantId() + " router updated but topology sync required.");
        } else {
            if (numRetries > 0) {
                return retry(cmd, --numRetries);
            } else {
                return new BcfAnswer(cmd, e);
            }
        }
    } catch (IllegalArgumentException e1) {
        return new BcfAnswer(cmd, false, "Illegal argument in BCF router update");
    }
}
Also used : BcfAnswer(com.cloud.agent.api.BcfAnswer) BigSwitchBcfApiException(com.cloud.network.bigswitch.BigSwitchBcfApiException) AclData(com.cloud.network.bigswitch.AclData) ArrayList(java.util.ArrayList) RouterData(com.cloud.network.bigswitch.RouterData)

Aggregations

BigSwitchBcfApiException (com.cloud.network.bigswitch.BigSwitchBcfApiException)30 BcfAnswer (com.cloud.agent.api.BcfAnswer)29 Test (org.junit.Test)22 AttachmentData (com.cloud.network.bigswitch.AttachmentData)5 RouterData (com.cloud.network.bigswitch.RouterData)5 UpdateBcfRouterCommand (com.cloud.agent.api.UpdateBcfRouterCommand)4 NetworkData (com.cloud.network.bigswitch.NetworkData)3 CreateBcfAttachmentCommand (com.cloud.agent.api.CreateBcfAttachmentCommand)2 CreateBcfRouterCommand (com.cloud.agent.api.CreateBcfRouterCommand)2 CreateBcfSegmentCommand (com.cloud.agent.api.CreateBcfSegmentCommand)2 CreateBcfStaticNatCommand (com.cloud.agent.api.CreateBcfStaticNatCommand)2 DeleteBcfAttachmentCommand (com.cloud.agent.api.DeleteBcfAttachmentCommand)2 DeleteBcfSegmentCommand (com.cloud.agent.api.DeleteBcfSegmentCommand)2 DeleteBcfStaticNatCommand (com.cloud.agent.api.DeleteBcfStaticNatCommand)2 UpdateBcfAttachmentCommand (com.cloud.agent.api.UpdateBcfAttachmentCommand)2 FloatingIpData (com.cloud.network.bigswitch.FloatingIpData)2 TopologyData (com.cloud.network.bigswitch.TopologyData)2 PingCommand (com.cloud.agent.api.PingCommand)1 SyncBcfTopologyCommand (com.cloud.agent.api.SyncBcfTopologyCommand)1 AclData (com.cloud.network.bigswitch.AclData)1