use of com.cloud.agent.api.NetworkRulesSystemVmCommand in project cloudstack by apache.
the class LibvirtComputingResourceTest method testNetworkRulesSystemVmCommandFailure.
@SuppressWarnings("unchecked")
@Test
public void testNetworkRulesSystemVmCommandFailure() {
final String vmName = "Test";
final Type type = Type.SecondaryStorageVm;
final NetworkRulesSystemVmCommand command = new NetworkRulesSystemVmCommand(vmName, type);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenThrow(LibvirtException.class);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertFalse(answer.getResult());
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
} catch (final LibvirtException e) {
fail(e.getMessage());
}
verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
}
use of com.cloud.agent.api.NetworkRulesSystemVmCommand in project cloudstack by apache.
the class NotAValidCommand method testNetworkRulesSystemVmCommandNonUser.
@Test
public void testNetworkRulesSystemVmCommandNonUser() {
final Connection conn = Mockito.mock(Connection.class);
final NetworkRulesSystemVmCommand netRules = new NetworkRulesSystemVmCommand("Test", VirtualMachine.Type.DomainRouter);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(citrixResourceBase.getConnection()).thenReturn(conn);
when(citrixResourceBase.callHostPlugin(conn, "vmops", "default_network_rules_systemvm", "vmName", netRules.getVmName())).thenReturn("true");
final Answer answer = wrapper.execute(netRules, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
assertTrue(answer.getResult());
}
use of com.cloud.agent.api.NetworkRulesSystemVmCommand in project cloudstack by apache.
the class NotAValidCommand method testNetworkRulesSystemVmCommand.
@Test
public void testNetworkRulesSystemVmCommand() {
final Connection conn = Mockito.mock(Connection.class);
final NetworkRulesSystemVmCommand netRules = new NetworkRulesSystemVmCommand("Test", VirtualMachine.Type.User);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(citrixResourceBase.getConnection()).thenReturn(conn);
final Answer answer = wrapper.execute(netRules, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
assertTrue(answer.getResult());
}
use of com.cloud.agent.api.NetworkRulesSystemVmCommand in project cloudstack by apache.
the class NotAValidCommand method testNetworkRulesSystemVmCommandNonUserFalse.
@Test
public void testNetworkRulesSystemVmCommandNonUserFalse() {
final Connection conn = Mockito.mock(Connection.class);
final NetworkRulesSystemVmCommand netRules = new NetworkRulesSystemVmCommand("Test", VirtualMachine.Type.DomainRouter);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(citrixResourceBase.getConnection()).thenReturn(conn);
when(citrixResourceBase.callHostPlugin(conn, "vmops", "default_network_rules_systemvm", "vmName", netRules.getVmName())).thenReturn("false");
final Answer answer = wrapper.execute(netRules, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
assertFalse(answer.getResult());
}
use of com.cloud.agent.api.NetworkRulesSystemVmCommand in project cloudstack by apache.
the class SecurityGroupManagerImpl method handleVmMigrated.
protected void handleVmMigrated(VMInstanceVO vm) {
if (!isVmSecurityGroupEnabled(vm.getId())) {
return;
}
if (vm.getType() != VirtualMachine.Type.User) {
Commands cmds = null;
NetworkRulesSystemVmCommand nrc = new NetworkRulesSystemVmCommand(vm.getInstanceName(), vm.getType());
cmds = new Commands(nrc);
try {
_agentMgr.send(vm.getHostId(), cmds);
} catch (AgentUnavailableException e) {
s_logger.debug(e.toString());
} catch (OperationTimedoutException e) {
s_logger.debug(e.toString());
}
} else {
List<Long> affectedVms = new ArrayList<Long>();
affectedVms.add(vm.getId());
scheduleRulesetUpdateToHosts(affectedVms, true, null);
}
}
Aggregations