Skip to content

Commit 8486a89

Browse files
committed
Handle non-OvsFetchInterfaceAnswer in OVS tunnel manager
1 parent 27bce46 commit 8486a89

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

plugins/network-elements/ovs/src/main/java/com/cloud/network/ovs/OvsTunnelManagerImpl.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,31 @@ protected OvsTunnelInterfaceVO createInterfaceRecord(String ip,
171171
}
172172

173173
private String handleFetchInterfaceAnswer(Answer[] answers, Long hostId) {
174-
OvsFetchInterfaceAnswer ans = (OvsFetchInterfaceAnswer)answers[0];
174+
if (answers == null || answers.length == 0 || answers[0] == null) {
175+
logger.warn("No answer returned for OvsFetchInterfaceCommand from host " + hostId);
176+
return null;
177+
}
178+
179+
Answer answer = answers[0];
180+
181+
if (!(answer instanceof OvsFetchInterfaceAnswer)) {
182+
logger.warn("Expected OvsFetchInterfaceAnswer from host " + hostId +
183+
" but got " + answer.getClass().getSimpleName() +
184+
" with details: " + answer.getDetails());
185+
return null;
186+
}
187+
188+
OvsFetchInterfaceAnswer ans = (OvsFetchInterfaceAnswer) answer;
189+
175190
if (ans.getResult()) {
176-
if (ans.getIp() != null && !("".equals(ans.getIp()))) {
191+
if (ans.getIp() != null && !ans.getIp().isEmpty()) {
177192
OvsTunnelInterfaceVO ti = createInterfaceRecord(ans.getIp(),
178-
ans.getNetmask(), ans.getMac(), hostId, ans.getLabel());
193+
ans.getNetmask(), ans.getMac(), hostId, ans.getLabel());
179194
return ti.getIp();
180195
}
181196
}
182-
// Fetch interface failed!
183-
logger.warn("Unable to fetch the IP address for the GRE tunnel endpoint"
184-
+ ans.getDetails());
197+
198+
logger.warn("Unable to fetch the IP address for the GRE tunnel endpoint: " + ans.getDetails());
185199
return null;
186200
}
187201

0 commit comments

Comments
 (0)