From 016d009adfa7e12b7d5c2c43b946fc93ad07aa9d Mon Sep 17 00:00:00 2001 From: Koushik Das Date: Tue, 9 Dec 2014 11:46:45 +0530 Subject: [PATCH] CLOUDSTACK-7994: Network rules are not configured in VR after out-of-band movement due to host crash The last commit 513adab51b53ba1acdea908225cfffab90ca1595 didn't fully fix it. Scenario #1 was not handled, only #2 was handled. Fixed #1 as part of this commit. 1. If VM is in stopped state in CS due to 'PowerMissing' report from old host (hostId is null) and then there is a 'PowerOn' report from new host 2. If VM is in running state in CS and there is a 'PowerOn' report from new host --- .../VirtualNetworkApplianceManagerImpl.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index f4e83ac4c38..fb39c0a2998 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -4461,16 +4461,23 @@ VirtualMachineGuru, Listener, Configurable, StateListener if (opaque != null && opaque instanceof Pair) { Pair pair = (Pair)opaque; Object first = pair.first(); Object second = pair.second(); - if (first != null && second != null && first instanceof Long && second instanceof Long) { - Long hostId = (Long)first; + // powerHostId cannot be null in case of out-of-band VM movement + if (second != null && second instanceof Long) { Long powerHostId = (Long)second; - // If VM host known to CS is different from 'PowerOn' report host, then it is out-of-band movement - if (hostId.longValue() != powerHostId.longValue()) { - s_logger.info("Schedule a router reboot task as router " + vo.getId() + " is powered-on out-of-band. we need to reboot to refresh network rules"); + Long hostId = null; + if (first != null && first instanceof Long) { + hostId = (Long)first; + } + // The following scenarios are due to out-of-band VM movement + // 1. If VM is in stopped state in CS due to 'PowerMissing' report from old host (hostId is null) and then there is a 'PowerOn' report from new host + // 2. If VM is in running state in CS and there is a 'PowerOn' report from new host + if (hostId == null || (hostId.longValue() != powerHostId.longValue())) { + s_logger.info("Schedule a router reboot task as router " + vo.getId() + " is powered-on out-of-band, need to reboot to refresh network rules"); _executor.schedule(new RebootTask(vo.getId()), 1000, TimeUnit.MICROSECONDS); } }