Skip to content

Commit b449351

Browse files
committed
CLOUDSTACK-9491: incorrect parsing of device list to find ethernet index of plugged NIC
In VmwareResource, findRouterEthDeviceIndex() method find ethernet interface index given the mac address. This method is used, once a nic is plugged to determine ethernet interface. "/proc/sys/net/ipv4/conf" from the VR and looped through the devices to find the right ethernet interface. However current logic read it once, and loops through the device list. Its observerd device may not show up '/proc/sys/net/ipv4/conf' immediatly once NIC is plugged in the VM from vCenter.Fix ensured, while waiting for 15 sec in the loop, read the latest content from /proc/sys/net/ipv4/conf, so that right device list is processed.
1 parent fcee71f commit b449351

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -831,18 +831,19 @@ private int findRouterEthDeviceIndex(String domrName, String routerIp, String ma
831831
VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
832832

833833
s_logger.info("findRouterEthDeviceIndex. mac: " + mac);
834-
835-
// TODO : this is a temporary very inefficient solution, will refactor it later
836-
Pair<Boolean, String> result = SshHelper.sshExecute(routerIp, DefaultDomRSshPort, "root", mgr.getSystemVMKeyFile(), null, "ls /proc/sys/net/ipv4/conf");
834+
ArrayList<String> skipInterfaces = new ArrayList<String>(Arrays.asList("all", "default", "lo"));
837835

838836
// when we dynamically plug in a new NIC into virtual router, it may take time to show up in guest OS
839837
// we use a waiting loop here as a workaround to synchronize activities in systems
840838
long startTick = System.currentTimeMillis();
841839
while (System.currentTimeMillis() - startTick < 15000) {
840+
841+
// TODO : this is a temporary very inefficient solution, will refactor it later
842+
Pair<Boolean, String> result = SshHelper.sshExecute(routerIp, DefaultDomRSshPort, "root", mgr.getSystemVMKeyFile(), null, "ls /proc/sys/net/ipv4/conf");
842843
if (result.first()) {
843844
String[] tokens = result.second().split("\\s+");
844845
for (String token : tokens) {
845-
if (!("all".equalsIgnoreCase(token) || "default".equalsIgnoreCase(token) || "lo".equalsIgnoreCase(token))) {
846+
if (!(skipInterfaces.contains(token))) {
846847
String cmd = String.format("ip address show %s | grep link/ether | sed -e 's/^[ \t]*//' | cut -d' ' -f2", token);
847848

848849
if (s_logger.isDebugEnabled())
@@ -853,8 +854,11 @@ private int findRouterEthDeviceIndex(String domrName, String routerIp, String ma
853854
if (s_logger.isDebugEnabled())
854855
s_logger.debug("result: " + result2.first() + ", output: " + result2.second());
855856

856-
if (result2.first() && result2.second().trim().equalsIgnoreCase(mac.trim()))
857+
if (result2.first() && result2.second().trim().equalsIgnoreCase(mac.trim())) {
857858
return Integer.parseInt(token.substring(3));
859+
} else {
860+
skipInterfaces.add(token);
861+
}
858862
}
859863
}
860864
}

0 commit comments

Comments
 (0)