Skip to content

Commit ea771cf

Browse files
authored
router: Fixes #2719 program VR nics by device id order for VPC (#2888)
This fixes #2719 where private gateway IP might be incorrectly programmed on a guest network nic. The VR would now check ipassoc requests by mac addresses than provided nic/device id in case they are wrong. The root cause is that the device id information is lost when aggregated commands are created upon starting of a new VPC VR, without the correct device id in ip_associations json it mis-programs the VR. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent a6196b0 commit ea771cf

6 files changed

Lines changed: 36 additions & 6 deletions

File tree

api/src/com/cloud/network/NetworkProfile.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
// under the License.
1717
package com.cloud.network;
1818

19+
import java.net.URI;
20+
1921
import com.cloud.network.Networks.BroadcastDomainType;
2022
import com.cloud.network.Networks.Mode;
2123
import com.cloud.network.Networks.TrafficType;
2224

23-
import java.net.URI;
24-
2525
public class NetworkProfile implements Network {
2626
private final long id;
2727
private final String uuid;
@@ -33,6 +33,7 @@ public class NetworkProfile implements Network {
3333
private URI broadcastUri;
3434
private final State state;
3535
private boolean isRedundant;
36+
private boolean isRollingRestart = false;
3637
private final String name;
3738
private final Mode mode;
3839
private final BroadcastDomainType broadcastDomainType;
@@ -92,6 +93,7 @@ public NetworkProfile(Network network) {
9293
guruName = network.getGuruName();
9394
strechedL2Subnet = network.isStrechedL2Network();
9495
isRedundant = network.isRedundant();
96+
isRollingRestart = network.isRollingRestart();
9597
externalId = network.getExternalId();
9698
}
9799

@@ -157,7 +159,7 @@ public boolean isRedundant() {
157159

158160
@Override
159161
public boolean isRollingRestart() {
160-
return false;
162+
return isRollingRestart;
161163
}
162164

163165
@Override

engine/schema/src/com/cloud/vm/dao/NicDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
public interface NicDao extends GenericDao<NicVO, Long> {
2727
List<NicVO> listByVmId(long instanceId);
2828

29+
List<NicVO> listByVmIdOrderByDeviceId(long instanceId);
30+
2931
List<String> listIpAddressInNetwork(long networkConfigId);
3032

3133
List<NicVO> listByVmIdIncludingRemoved(long instanceId);

engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ public List<NicVO> listByVmId(long instanceId) {
118118
return listBy(sc);
119119
}
120120

121+
@Override
122+
public List<NicVO> listByVmIdOrderByDeviceId(long instanceId) {
123+
SearchCriteria<NicVO> sc = AllFieldsSearch.create();
124+
sc.setParameters("instance", instanceId);
125+
return customSearch(sc, new Filter(NicVO.class, "deviceId", true, null, null));
126+
}
127+
121128
@Override
122129
public List<NicVO> listByVmIdIncludingRemoved(long instanceId) {
123130
SearchCriteria<NicVO> sc = AllFieldsSearch.create();

server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public boolean finalizeCommandsOnStart(final Commands cmds, final VirtualMachine
316316
final List<Pair<Nic, Network>> publicNics = new ArrayList<Pair<Nic, Network>>();
317317
final Map<String, String> vlanMacAddress = new HashMap<String, String>();
318318

319-
final List<? extends Nic> routerNics = _nicDao.listByVmId(profile.getId());
319+
final List<? extends Nic> routerNics = _nicDao.listByVmIdOrderByDeviceId(profile.getId());
320320
for (final Nic routerNic : routerNics) {
321321
final Network network = _networkModel.getNetwork(routerNic.getNetworkId());
322322
if (network.getTrafficType() == TrafficType.Guest) {

systemvm/debian/opt/cloud/bin/cs_ip.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,21 @@
1616
# specific language governing permissions and limitations
1717
# under the License.
1818

19+
import os
1920
from netaddr import *
2021

2122

23+
def macdevice_map():
24+
device_map = {}
25+
for eth in os.listdir('/sys/class/net'):
26+
if not eth.startswith('eth'):
27+
continue
28+
with open('/sys/class/net/%s/address' % eth) as f:
29+
mac_address = f.read().replace('\n', '')
30+
device_map[mac_address] = eth[3:]
31+
return device_map
32+
33+
2234
def merge(dbag, ip):
2335
nic_dev_id = None
2436
for dev in dbag:
@@ -33,6 +45,11 @@ def merge(dbag, ip):
3345
ipo = IPNetwork(ip['public_ip'] + '/' + ip['netmask'])
3446
if 'nic_dev_id' in ip:
3547
nic_dev_id = ip['nic_dev_id']
48+
if 'vif_mac_address' in ip:
49+
mac_address = ip['vif_mac_address']
50+
device_map = macdevice_map()
51+
if mac_address in device_map:
52+
nic_dev_id = device_map[mac_address]
3653
ip['device'] = 'eth' + str(nic_dev_id)
3754
ip['broadcast'] = str(ipo.broadcast)
3855
ip['cidr'] = str(ipo.ip) + '/' + str(ipo.prefixlen)

utils/src/test/java/com/cloud/utils/net/NetUtilsTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
import java.util.SortedSet;
3838
import java.util.TreeSet;
3939

40-
import com.googlecode.ipv6.IPv6Network;
4140
import org.apache.log4j.Logger;
4241
import org.junit.Test;
4342

4443
import com.cloud.utils.exception.CloudRuntimeException;
4544
import com.cloud.utils.net.NetUtils.SupersetOrSubset;
4645
import com.googlecode.ipv6.IPv6Address;
46+
import com.googlecode.ipv6.IPv6Network;
4747

4848
public class NetUtilsTest {
4949

@@ -682,6 +682,8 @@ public void testIsValidPort() {
682682
@Test
683683
public void testAllIpsOfDefaultNic() {
684684
final String defaultHostIp = NetUtils.getDefaultHostIp();
685-
assertTrue(NetUtils.getAllDefaultNicIps().stream().anyMatch(defaultHostIp::contains));
685+
if (defaultHostIp != null) {
686+
assertTrue(NetUtils.getAllDefaultNicIps().stream().anyMatch(defaultHostIp::contains));
687+
}
686688
}
687689
}

0 commit comments

Comments
 (0)