Search in sources :

Example 1 with VifDriver

use of com.cloud.agent.resource.kvm.vif.VifDriver in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResource method getVifDriverClass.

protected VifDriver getVifDriverClass(final String vifDriverClassName, final Map<String, Object> params) throws ConfigurationException {
    final VifDriver vifDriver;
    try {
        final Class<?> clazz = Class.forName(vifDriverClassName);
        vifDriver = (VifDriver) clazz.newInstance();
        vifDriver.configure(params);
    } catch (final ClassNotFoundException e) {
        throw new ConfigurationException("Unable to find class for libvirt.vif.driver " + e);
    } catch (final InstantiationException e) {
        throw new ConfigurationException("Unable to instantiate class for libvirt.vif.driver " + e);
    } catch (final IllegalAccessException e) {
        throw new ConfigurationException("Unable to instantiate class for libvirt.vif.driver " + e);
    }
    return vifDriver;
}
Also used : ConfigurationException(javax.naming.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) VifDriver(com.cloud.agent.resource.kvm.vif.VifDriver)

Example 2 with VifDriver

use of com.cloud.agent.resource.kvm.vif.VifDriver in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testPrepareForMigrationCommandLibvirtException.

@Test
public void testPrepareForMigrationCommandLibvirtException() {
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final VirtualMachineTO vm = Mockito.mock(VirtualMachineTO.class);
    final KvmStoragePoolManager storagePoolManager = Mockito.mock(KvmStoragePoolManager.class);
    final NicTO nicTO = Mockito.mock(NicTO.class);
    final VifDriver vifDriver = Mockito.mock(VifDriver.class);
    final PrepareForMigrationCommand command = new PrepareForMigrationCommand(vm);
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(vm.getName())).thenThrow(LibvirtException.class);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    when(vm.getNics()).thenReturn(new NicTO[] { nicTO });
    when(nicTO.getType()).thenReturn(TrafficType.Guest);
    when(this.libvirtComputingResource.getVifDriver(nicTO.getType())).thenReturn(vifDriver);
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolManager);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vm.getName());
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(vm, times(1)).getNics();
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) LibvirtException(org.libvirt.LibvirtException) PrepareForMigrationCommand(com.cloud.legacymodel.communication.command.PrepareForMigrationCommand) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) VirtualMachineTO(com.cloud.legacymodel.to.VirtualMachineTO) VifDriver(com.cloud.agent.resource.kvm.vif.VifDriver) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) NicTO(com.cloud.legacymodel.to.NicTO) Test(org.junit.Test)

Example 3 with VifDriver

use of com.cloud.agent.resource.kvm.vif.VifDriver in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testUnPlugNicCommandMatchMack.

@Test
public void testUnPlugNicCommandMatchMack() {
    final NicTO nic = Mockito.mock(NicTO.class);
    final String instanceName = "Test";
    final UnPlugNicCommand command = new UnPlugNicCommand(nic, instanceName);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final Connect conn = Mockito.mock(Connect.class);
    final Domain vm = Mockito.mock(Domain.class);
    final InterfaceDef interfaceDef = Mockito.mock(InterfaceDef.class);
    final List<InterfaceDef> nics = new ArrayList<>();
    final InterfaceDef intDef = Mockito.mock(InterfaceDef.class);
    nics.add(intDef);
    final VifDriver vifDriver = Mockito.mock(VifDriver.class);
    final List<VifDriver> drivers = new ArrayList<>();
    drivers.add(vifDriver);
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    when(this.libvirtComputingResource.getInterfaces(conn, command.getVmName())).thenReturn(nics);
    when(intDef.getDevName()).thenReturn("eth0");
    when(intDef.getBrName()).thenReturn("br0");
    when(intDef.getMacAddress()).thenReturn("00:00:00:00");
    when(nic.getMac()).thenReturn("00:00:00:00");
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenReturn(conn);
        when(this.libvirtComputingResource.getDomain(conn, instanceName)).thenReturn(vm);
        when(interfaceDef.toString()).thenReturn("Interface");
        final String interfaceDefStr = interfaceDef.toString();
        doNothing().when(vm).detachDevice(interfaceDefStr);
        when(this.libvirtComputingResource.getAllVifDrivers()).thenReturn(drivers);
        doNothing().when(vifDriver).unplug(intDef);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
        verify(this.libvirtComputingResource, times(1)).getDomain(conn, instanceName);
        verify(this.libvirtComputingResource, times(1)).getAllVifDrivers();
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) ArrayList(java.util.ArrayList) VifDriver(com.cloud.agent.resource.kvm.vif.VifDriver) UnPlugNicCommand(com.cloud.legacymodel.communication.command.UnPlugNicCommand) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) InterfaceDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.InterfaceDef) Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) Domain(org.libvirt.Domain) NicTO(com.cloud.legacymodel.to.NicTO) Test(org.junit.Test)

Example 4 with VifDriver

use of com.cloud.agent.resource.kvm.vif.VifDriver in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testUnPlugNicCommandNoNics.

@Test
public void testUnPlugNicCommandNoNics() {
    final NicTO nic = Mockito.mock(NicTO.class);
    final String instanceName = "Test";
    final UnPlugNicCommand command = new UnPlugNicCommand(nic, instanceName);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final Connect conn = Mockito.mock(Connect.class);
    final Domain vm = Mockito.mock(Domain.class);
    final List<InterfaceDef> nics = new ArrayList<>();
    final VifDriver vifDriver = Mockito.mock(VifDriver.class);
    final List<VifDriver> drivers = new ArrayList<>();
    drivers.add(vifDriver);
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    when(this.libvirtComputingResource.getInterfaces(conn, command.getVmName())).thenReturn(nics);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenReturn(conn);
        when(this.libvirtComputingResource.getDomain(conn, instanceName)).thenReturn(vm);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
        verify(this.libvirtComputingResource, times(1)).getDomain(conn, instanceName);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) ArrayList(java.util.ArrayList) VifDriver(com.cloud.agent.resource.kvm.vif.VifDriver) UnPlugNicCommand(com.cloud.legacymodel.communication.command.UnPlugNicCommand) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) InterfaceDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.InterfaceDef) Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) Domain(org.libvirt.Domain) NicTO(com.cloud.legacymodel.to.NicTO) Test(org.junit.Test)

Example 5 with VifDriver

use of com.cloud.agent.resource.kvm.vif.VifDriver in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testPlugNicCommandInternalError.

@Test
public void testPlugNicCommandInternalError() {
    final NicTO nic = Mockito.mock(NicTO.class);
    final String instanceName = "Test";
    final VirtualMachineType vmtype = VirtualMachineType.DomainRouter;
    final PlugNicCommand command = new PlugNicCommand(nic, instanceName, vmtype);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final Connect conn = Mockito.mock(Connect.class);
    final Domain vm = Mockito.mock(Domain.class);
    final VifDriver vifDriver = Mockito.mock(VifDriver.class);
    final List<InterfaceDef> nics = new ArrayList<>();
    final InterfaceDef intDef = Mockito.mock(InterfaceDef.class);
    nics.add(intDef);
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    when(this.libvirtComputingResource.getInterfaces(conn, command.getVmName())).thenReturn(nics);
    when(intDef.getDevName()).thenReturn("eth0");
    when(intDef.getBrName()).thenReturn("br0");
    when(intDef.getMacAddress()).thenReturn("00:00:00:00");
    when(nic.getMac()).thenReturn("00:00:00:01");
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenReturn(conn);
        when(this.libvirtComputingResource.getDomain(conn, instanceName)).thenReturn(vm);
        when(this.libvirtComputingResource.getVifDriver(nic.getType())).thenReturn(vifDriver);
        when(vifDriver.plug(nic, "Default - VirtIO capable OS (64-bit)", "")).thenThrow(InternalErrorException.class);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    } catch (final InternalErrorException e) {
        fail(e.getMessage());
    }
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
        verify(this.libvirtComputingResource, times(1)).getDomain(conn, instanceName);
        verify(this.libvirtComputingResource, times(1)).getVifDriver(nic.getType());
        verify(vifDriver, times(1)).plug(nic, "Default - VirtIO capable OS (64-bit)", "");
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    } catch (final InternalErrorException e) {
        fail(e.getMessage());
    }
}
Also used : LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) ArrayList(java.util.ArrayList) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) VifDriver(com.cloud.agent.resource.kvm.vif.VifDriver) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) InterfaceDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.InterfaceDef) Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) VirtualMachineType(com.cloud.model.enumeration.VirtualMachineType) Domain(org.libvirt.Domain) PlugNicCommand(com.cloud.legacymodel.communication.command.PlugNicCommand) UnPlugNicCommand(com.cloud.legacymodel.communication.command.UnPlugNicCommand) NicTO(com.cloud.legacymodel.to.NicTO) Test(org.junit.Test)

Aggregations

VifDriver (com.cloud.agent.resource.kvm.vif.VifDriver)13 LibvirtException (org.libvirt.LibvirtException)12 Connect (org.libvirt.Connect)11 NicTO (com.cloud.legacymodel.to.NicTO)10 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)8 LibvirtUtilitiesHelper (com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper)8 Answer (com.cloud.legacymodel.communication.answer.Answer)8 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)8 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)8 Test (org.junit.Test)8 Domain (org.libvirt.Domain)8 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)4 LibvirtVmDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef)4 InterfaceDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef.InterfaceDef)4 PrepareForMigrationCommand (com.cloud.legacymodel.communication.command.PrepareForMigrationCommand)4 UnPlugNicCommand (com.cloud.legacymodel.communication.command.UnPlugNicCommand)4 VirtualMachineTO (com.cloud.legacymodel.to.VirtualMachineTO)4 ArrayList (java.util.ArrayList)4 InternalErrorException (com.cloud.legacymodel.exceptions.InternalErrorException)3 DiskTO (com.cloud.legacymodel.to.DiskTO)3