Search in sources :

Example 1 with NetworkRulesSystemVmCommand

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();
}
Also used : UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) TrafficType(com.cloud.network.Networks.TrafficType) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) Type(com.cloud.vm.VirtualMachine.Type) StoragePoolType(com.cloud.storage.Storage.StoragePoolType) BootloaderType(com.cloud.template.VirtualMachineTemplate.BootloaderType) GuestType(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.GuestDef.GuestType) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) LibvirtException(org.libvirt.LibvirtException) NetworkRulesSystemVmCommand(com.cloud.agent.api.NetworkRulesSystemVmCommand) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with NetworkRulesSystemVmCommand

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());
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) Connection(com.xensource.xenapi.Connection) NetworkRulesSystemVmCommand(com.cloud.agent.api.NetworkRulesSystemVmCommand) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with NetworkRulesSystemVmCommand

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());
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) Connection(com.xensource.xenapi.Connection) NetworkRulesSystemVmCommand(com.cloud.agent.api.NetworkRulesSystemVmCommand) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with NetworkRulesSystemVmCommand

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());
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) Connection(com.xensource.xenapi.Connection) NetworkRulesSystemVmCommand(com.cloud.agent.api.NetworkRulesSystemVmCommand) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with NetworkRulesSystemVmCommand

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);
    }
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Commands(com.cloud.agent.manager.Commands) NetworkRulesSystemVmCommand(com.cloud.agent.api.NetworkRulesSystemVmCommand) ArrayList(java.util.ArrayList)

Aggregations

NetworkRulesSystemVmCommand (com.cloud.agent.api.NetworkRulesSystemVmCommand)6 Answer (com.cloud.agent.api.Answer)5 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)5 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 RebootAnswer (com.cloud.agent.api.RebootAnswer)3 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)3 Connection (com.xensource.xenapi.Connection)3 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)2 UnsupportedAnswer (com.cloud.agent.api.UnsupportedAnswer)2 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)2 GuestType (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.GuestDef.GuestType)2 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)2 LibvirtUtilitiesHelper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper)2 TrafficType (com.cloud.network.Networks.TrafficType)2 StoragePoolType (com.cloud.storage.Storage.StoragePoolType)2 BootloaderType (com.cloud.template.VirtualMachineTemplate.BootloaderType)2 Type (com.cloud.vm.VirtualMachine.Type)2 LibvirtException (org.libvirt.LibvirtException)2 Commands (com.cloud.agent.manager.Commands)1