mirror of https://github.com/apache/cloudstack.git
server: set correct gateway when update vm nic on shared networks (#5105)
This PR fixes the issue that nic has wrong gateway after updating vm nic. Steps to reproduce the issue (1) create shared network (in advanced zone or advanced zone with sg) (2) create new shared network (with same startip/endip/netmask, but different gateway). (3) create a vm in new network (4) stop vm and update vm nic ip address Expected result: The vm has correct gateway and netmask (of second network) Actual result: The vm has wrong gateway and netmask (of first network)
This commit is contained in:
parent
326e03bc9c
commit
46a3032178
|
|
@ -1728,7 +1728,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
throw new InvalidParameterValueException("Allocating ip to guest nic " + nicVO.getUuid() + " failed, please choose another ip");
|
||||
}
|
||||
|
||||
final IPAddressVO newIp = _ipAddressDao.findByIpAndDcId(dc.getId(), ipaddr);
|
||||
final IPAddressVO newIp = _ipAddressDao.findByIpAndSourceNetworkId(network.getId(), ipaddr);
|
||||
final Vlan vlan = _vlanDao.findById(newIp.getVlanId());
|
||||
nicVO.setIPv4Gateway(vlan.getVlanGateway());
|
||||
nicVO.setIPv4Netmask(vlan.getVlanNetmask());
|
||||
|
|
|
|||
|
|
@ -604,6 +604,7 @@ public class UserVmManagerTest {
|
|||
|
||||
NicVO nic = new NicVO("nic", 1L, 2L, VirtualMachine.Type.User);
|
||||
when(_nicDao.findById(anyLong())).thenReturn(nic);
|
||||
nic.setIPv4Address("10.10.10.9");
|
||||
when(_vmDao.findById(anyLong())).thenReturn(_vmMock);
|
||||
when(_networkDao.findById(anyLong())).thenReturn(_networkMock);
|
||||
doReturn(9L).when(_networkMock).getNetworkOfferingId();
|
||||
|
|
@ -630,9 +631,9 @@ public class UserVmManagerTest {
|
|||
when(vlan.getVlanNetmask()).thenReturn("255.255.255.0");
|
||||
|
||||
when(_ipAddrMgr.allocatePublicIpForGuestNic(Mockito.eq(_networkMock), nullable(Long.class), Mockito.eq(_accountMock), anyString())).thenReturn("10.10.10.10");
|
||||
lenient().when(_ipAddressDao.findByIpAndSourceNetworkId(anyLong(), anyString())).thenReturn(null);
|
||||
when(_ipAddressDao.findByIpAndSourceNetworkId(anyLong(), eq("10.10.10.10"))).thenReturn(newIp);
|
||||
when(_ipAddressDao.findByIpAndSourceNetworkId(anyLong(), eq("10.10.10.9"))).thenReturn(null);
|
||||
when(_nicDao.persist(any(NicVO.class))).thenReturn(nic);
|
||||
when(_ipAddressDao.findByIpAndDcId(anyLong(), anyString())).thenReturn(newIp);
|
||||
when(_vlanDao.findById(anyLong())).thenReturn(vlan);
|
||||
|
||||
Account caller = new AccountVO("testaccount", 1, "networkdomain", (short)0, UUID.randomUUID().toString());
|
||||
|
|
|
|||
Loading…
Reference in New Issue