Skip to content

Commit 513adab

Browse files
committed
CLOUDSTACK-7994: Network rules are not configured in VR after out-of-band movement due to host crash
Ensure that VR is re-booted when it is moved to another host out-of-band. This is necessary to re-program all network rules
1 parent 21b0ad4 commit 513adab

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@
244244
import com.cloud.vm.dao.UserVmDao;
245245
import com.cloud.vm.dao.UserVmDetailsDao;
246246
import com.cloud.vm.dao.VMInstanceDao;
247+
247248
import org.apache.cloudstack.alert.AlertService;
248249
import org.apache.cloudstack.alert.AlertService.AlertType;
249250
import org.apache.cloudstack.api.command.admin.router.RebootRouterCmd;
@@ -266,6 +267,7 @@
266267
import javax.ejb.Local;
267268
import javax.inject.Inject;
268269
import javax.naming.ConfigurationException;
270+
269271
import java.text.ParseException;
270272
import java.text.SimpleDateFormat;
271273
import java.util.ArrayList;
@@ -4459,10 +4461,22 @@ public boolean preStateTransitionEvent(State oldState, VirtualMachine.Event even
44594461

44604462
@Override
44614463
public boolean postStateTransitionEvent(State oldState, VirtualMachine.Event event, State newState, VirtualMachine vo, boolean status, Object opaque) {
4462-
if (oldState == State.Stopped && event == VirtualMachine.Event.FollowAgentPowerOnReport && newState == State.Running) {
4464+
if (event == VirtualMachine.Event.FollowAgentPowerOnReport && newState == State.Running) {
44634465
if (vo.getType() == VirtualMachine.Type.DomainRouter) {
4464-
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");
4465-
_executor.schedule(new RebootTask(vo.getId()), 1000, TimeUnit.MICROSECONDS);
4466+
if (opaque != null && opaque instanceof Pair<?, ?>) {
4467+
Pair<?, ?> pair = (Pair<?, ?>)opaque;
4468+
Object first = pair.first();
4469+
Object second = pair.second();
4470+
if (first != null && second != null && first instanceof Long && second instanceof Long) {
4471+
Long hostId = (Long)first;
4472+
Long powerHostId = (Long)second;
4473+
// If VM host known to CS is different from 'PowerOn' report host, then it is out-of-band movement
4474+
if (hostId.longValue() != powerHostId.longValue()) {
4475+
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");
4476+
_executor.schedule(new RebootTask(vo.getId()), 1000, TimeUnit.MICROSECONDS);
4477+
}
4478+
}
4479+
}
44664480
}
44674481
}
44684482
return true;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,4 +1481,11 @@ public boolean stopRemoteAccessVpn(RemoteAccessVpn vpn, VirtualRouter router) th
14811481

14821482
return true;
14831483
}
1484+
1485+
@Override
1486+
public boolean postStateTransitionEvent(State oldState, VirtualMachine.Event event, State newState, VirtualMachine vo, boolean status, Object opaque) {
1487+
// Without this VirtualNetworkApplianceManagerImpl.postStateTransitionEvent() gets called twice as part of listeners -
1488+
// once from VpcVirtualNetworkApplianceManagerImpl and once from VirtualNetworkApplianceManagerImpl itself
1489+
return true;
1490+
}
14841491
}

0 commit comments

Comments
 (0)