use of com.cloud.agent.api.DisassociateMacFromNetworkAnswer in project cloudstack by apache.
the class BrocadeVcsResource method executeRequest.
private Answer executeRequest(DisassociateMacFromNetworkCommand cmd, int numRetries) {
try {
String mac = macReformat64To32(cmd.getInterfaceMac());
boolean result = _brocadeVcsApi.disassociateMacFromNetwork(cmd.getNetworkId(), mac);
return new DisassociateMacFromNetworkAnswer(cmd, result, "Disassociation of mac " + cmd.getInterfaceMac() + " from network " + cmd.getNetworkId() + " done");
} catch (BrocadeVcsApiException e) {
if (numRetries > 0) {
return retry(cmd, --numRetries);
} else {
return new DisassociateMacFromNetworkAnswer(cmd, e);
}
}
}
use of com.cloud.agent.api.DisassociateMacFromNetworkAnswer in project cloudstack by apache.
the class BrocadeVcsGuestNetworkGuruTest method testDeallocate.
@Test
public void testDeallocate() {
final NetworkVO network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork");
when(network.getState()).thenReturn(State.Implementing);
when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
when(network.getDataCenterId()).thenReturn(NETWORK_ID);
final NicProfile nic = mock(NicProfile.class);
when(nic.getMacAddress()).thenReturn("macaddress");
when(nic.getReservationStrategy()).thenReturn(ReservationStrategy.Start);
final VirtualMachineProfile vmProfile = mock(VirtualMachineProfile.class);
final HostVO brocadeHost = mock(HostVO.class);
when(hostdao.findById(anyLong())).thenReturn(brocadeHost);
when(brocadeHost.getId()).thenReturn(NETWORK_ID);
when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
final List<BrocadeVcsDeviceVO> devices = new ArrayList();
devices.add(brocadeDevice);
when(vcsdao.listByPhysicalNetwork(anyLong())).thenReturn(devices);
final DisassociateMacFromNetworkAnswer answer = mock(DisassociateMacFromNetworkAnswer.class);
when(answer.getResult()).thenReturn(true);
when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
guru.deallocate(network, nic, vmProfile);
verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command) any());
}
use of com.cloud.agent.api.DisassociateMacFromNetworkAnswer in project cloudstack by apache.
the class BrocadeVcsGuestNetworkGuruTest method testDeallocateFail.
@Test
public void testDeallocateFail() {
final NetworkVO network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork");
when(network.getState()).thenReturn(State.Implementing);
when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
when(network.getDataCenterId()).thenReturn(NETWORK_ID);
final NicProfile nic = mock(NicProfile.class);
when(nic.getMacAddress()).thenReturn("macaddress");
when(nic.getReservationStrategy()).thenReturn(ReservationStrategy.Start);
final VirtualMachineProfile vmProfile = mock(VirtualMachineProfile.class);
final HostVO brocadeHost = mock(HostVO.class);
when(hostdao.findById(anyLong())).thenReturn(brocadeHost);
when(brocadeHost.getId()).thenReturn(NETWORK_ID);
when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
final List<BrocadeVcsDeviceVO> devices = mock(List.class);
when(devices.isEmpty()).thenReturn(true);
when(vcsdao.listByPhysicalNetwork(anyLong())).thenReturn(devices);
final DisassociateMacFromNetworkAnswer answer = mock(DisassociateMacFromNetworkAnswer.class);
when(answer.getResult()).thenReturn(true);
when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
guru.deallocate(network, nic, vmProfile);
verify(agentmgr, times(0)).easySend(eq(NETWORK_ID), (Command) any());
}
use of com.cloud.agent.api.DisassociateMacFromNetworkAnswer in project cloudstack by apache.
the class BrocadeVcsResourceTest method testDisassociateMacFromNetworkApi.
@Test
public void testDisassociateMacFromNetworkApi() throws ConfigurationException, BrocadeVcsApiException {
resource.configure("BrocadeVcsResource", parameters);
when(api.disassociateMacFromNetwork(NETWORK_ID, MAC_ADDRESS_32)).thenReturn(true);
final DisassociateMacFromNetworkCommand cmd = new DisassociateMacFromNetworkCommand(NETWORK_ID, MAC_ADDRESS_64);
final DisassociateMacFromNetworkAnswer answer = (DisassociateMacFromNetworkAnswer) resource.executeRequest(cmd);
assertTrue(answer.getResult());
}
use of com.cloud.agent.api.DisassociateMacFromNetworkAnswer in project cloudstack by apache.
the class BrocadeVcsResourceTest method testDisassociateMacFromNetworkApiException.
@Test
public void testDisassociateMacFromNetworkApiException() throws ConfigurationException, BrocadeVcsApiException {
resource.configure("BrocadeVcsResource", parameters);
when(api.disassociateMacFromNetwork(NETWORK_ID, MAC_ADDRESS_32)).thenThrow(new BrocadeVcsApiException());
final DisassociateMacFromNetworkCommand cmd = new DisassociateMacFromNetworkCommand(NETWORK_ID, MAC_ADDRESS_64);
final DisassociateMacFromNetworkAnswer answer = (DisassociateMacFromNetworkAnswer) resource.executeRequest(cmd);
assertFalse(answer.getResult());
}
Aggregations