Search in sources :

Example 1 with CreatePrivateTemplateFromSnapshotCommand

use of com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand in project CloudStack-archive by CloudStack-extras.

the class SimulatorManagerImpl method simulate.

@DB
@Override
public Answer simulate(Command cmd, String hostGuid) {
    Transaction txn = Transaction.currentTxn();
    txn.transitToUserManagedConnection(_concierge.conn());
    try {
        MockHost host = _mockHost.findByGuid(hostGuid);
        String cmdName = cmd.toString();
        int index = cmdName.lastIndexOf(".");
        if (index != -1) {
            cmdName = cmdName.substring(index + 1);
        }
        MockConfigurationVO config = _mockConfigDao.findByNameBottomUP(host.getDataCenterId(), host.getPodId(), host.getClusterId(), host.getId(), cmdName);
        SimulatorInfo info = new SimulatorInfo();
        info.setHostUuid(hostGuid);
        if (config != null) {
            Map<String, String> configParameters = config.getParameters();
            for (Map.Entry<String, String> entry : configParameters.entrySet()) {
                if (entry.getKey().equalsIgnoreCase("enabled")) {
                    info.setEnabled(Boolean.parseBoolean(entry.getValue()));
                } else if (entry.getKey().equalsIgnoreCase("timeout")) {
                    try {
                        info.setTimeout(Integer.valueOf(entry.getValue()));
                    } catch (NumberFormatException e) {
                        s_logger.debug("invalid timeout parameter: " + e.toString());
                    }
                } else if (entry.getKey().equalsIgnoreCase("wait")) {
                    try {
                        int wait = Integer.valueOf(entry.getValue());
                        Thread.sleep(wait * 1000);
                    } catch (NumberFormatException e) {
                        s_logger.debug("invalid timeout parameter: " + e.toString());
                    } catch (InterruptedException e) {
                        s_logger.debug("thread is interrupted: " + e.toString());
                    }
                }
            }
        }
        if (cmd instanceof GetHostStatsCommand) {
            return _mockAgentMgr.getHostStatistic((GetHostStatsCommand) cmd);
        } else if (cmd instanceof CheckHealthCommand) {
            return _mockAgentMgr.checkHealth((CheckHealthCommand) cmd);
        } else if (cmd instanceof PingTestCommand) {
            return _mockAgentMgr.pingTest((PingTestCommand) cmd);
        } else if (cmd instanceof MigrateCommand) {
            return _mockVmMgr.Migrate((MigrateCommand) cmd, info);
        } else if (cmd instanceof StartCommand) {
            return _mockVmMgr.startVM((StartCommand) cmd, info);
        } else if (cmd instanceof CheckSshCommand) {
            return _mockVmMgr.checkSshCommand((CheckSshCommand) cmd);
        } else if (cmd instanceof SetStaticNatRulesCommand) {
            return _mockVmMgr.SetStaticNatRules((SetStaticNatRulesCommand) cmd);
        } else if (cmd instanceof SetPortForwardingRulesCommand) {
            return _mockVmMgr.SetPortForwardingRules((SetPortForwardingRulesCommand) cmd);
        } else if (cmd instanceof NetworkUsageCommand) {
            return _mockVmMgr.getNetworkUsage((NetworkUsageCommand) cmd);
        } else if (cmd instanceof IpAssocCommand) {
            return _mockVmMgr.IpAssoc((IpAssocCommand) cmd);
        } else if (cmd instanceof LoadBalancerConfigCommand) {
            return _mockVmMgr.LoadBalancerConfig((LoadBalancerConfigCommand) cmd);
        } else if (cmd instanceof DhcpEntryCommand) {
            return _mockVmMgr.AddDhcpEntry((DhcpEntryCommand) cmd);
        } else if (cmd instanceof VmDataCommand) {
            return _mockVmMgr.setVmData((VmDataCommand) cmd);
        } else if (cmd instanceof CleanupNetworkRulesCmd) {
            return _mockVmMgr.CleanupNetworkRules((CleanupNetworkRulesCmd) cmd, info);
        } else if (cmd instanceof CheckNetworkCommand) {
            return _mockAgentMgr.checkNetworkCommand((CheckNetworkCommand) cmd);
        } else if (cmd instanceof StopCommand) {
            return _mockVmMgr.stopVM((StopCommand) cmd);
        } else if (cmd instanceof RebootCommand) {
            return _mockVmMgr.rebootVM((RebootCommand) cmd);
        } else if (cmd instanceof GetVncPortCommand) {
            return _mockVmMgr.getVncPort((GetVncPortCommand) cmd);
        } else if (cmd instanceof CheckConsoleProxyLoadCommand) {
            return _mockVmMgr.CheckConsoleProxyLoad((CheckConsoleProxyLoadCommand) cmd);
        } else if (cmd instanceof WatchConsoleProxyLoadCommand) {
            return _mockVmMgr.WatchConsoleProxyLoad((WatchConsoleProxyLoadCommand) cmd);
        } else if (cmd instanceof SecurityGroupRulesCmd) {
            return _mockVmMgr.AddSecurityGroupRules((SecurityGroupRulesCmd) cmd, info);
        } else if (cmd instanceof SavePasswordCommand) {
            return _mockVmMgr.SavePassword((SavePasswordCommand) cmd);
        } else if (cmd instanceof PrimaryStorageDownloadCommand) {
            return _mockStorageMgr.primaryStorageDownload((PrimaryStorageDownloadCommand) cmd);
        } else if (cmd instanceof CreateCommand) {
            return _mockStorageMgr.createVolume((CreateCommand) cmd);
        } else if (cmd instanceof AttachVolumeCommand) {
            return _mockStorageMgr.AttachVolume((AttachVolumeCommand) cmd);
        } else if (cmd instanceof AttachIsoCommand) {
            return _mockStorageMgr.AttachIso((AttachIsoCommand) cmd);
        } else if (cmd instanceof DeleteStoragePoolCommand) {
            return _mockStorageMgr.DeleteStoragePool((DeleteStoragePoolCommand) cmd);
        } else if (cmd instanceof ModifyStoragePoolCommand) {
            return _mockStorageMgr.ModifyStoragePool((ModifyStoragePoolCommand) cmd);
        } else if (cmd instanceof CreateStoragePoolCommand) {
            return _mockStorageMgr.CreateStoragePool((CreateStoragePoolCommand) cmd);
        } else if (cmd instanceof SecStorageSetupCommand) {
            return _mockStorageMgr.SecStorageSetup((SecStorageSetupCommand) cmd);
        } else if (cmd instanceof ListTemplateCommand) {
            return _mockStorageMgr.ListTemplates((ListTemplateCommand) cmd);
        } else if (cmd instanceof DestroyCommand) {
            return _mockStorageMgr.Destroy((DestroyCommand) cmd);
        } else if (cmd instanceof DownloadProgressCommand) {
            return _mockStorageMgr.DownloadProcess((DownloadProgressCommand) cmd);
        } else if (cmd instanceof DownloadCommand) {
            return _mockStorageMgr.Download((DownloadCommand) cmd);
        } else if (cmd instanceof GetStorageStatsCommand) {
            return _mockStorageMgr.GetStorageStats((GetStorageStatsCommand) cmd);
        } else if (cmd instanceof ManageSnapshotCommand) {
            return _mockStorageMgr.ManageSnapshot((ManageSnapshotCommand) cmd);
        } else if (cmd instanceof BackupSnapshotCommand) {
            return _mockStorageMgr.BackupSnapshot((BackupSnapshotCommand) cmd, info);
        } else if (cmd instanceof DeleteSnapshotBackupCommand) {
            return _mockStorageMgr.DeleteSnapshotBackup((DeleteSnapshotBackupCommand) cmd);
        } else if (cmd instanceof CreateVolumeFromSnapshotCommand) {
            return _mockStorageMgr.CreateVolumeFromSnapshot((CreateVolumeFromSnapshotCommand) cmd);
        } else if (cmd instanceof DeleteTemplateCommand) {
            return _mockStorageMgr.DeleteTemplate((DeleteTemplateCommand) cmd);
        } else if (cmd instanceof SecStorageVMSetupCommand) {
            return _mockStorageMgr.SecStorageVMSetup((SecStorageVMSetupCommand) cmd);
        } else if (cmd instanceof CreatePrivateTemplateFromSnapshotCommand) {
            return _mockStorageMgr.CreatePrivateTemplateFromSnapshot((CreatePrivateTemplateFromSnapshotCommand) cmd);
        } else if (cmd instanceof ComputeChecksumCommand) {
            return _mockStorageMgr.ComputeChecksum((ComputeChecksumCommand) cmd);
        } else if (cmd instanceof CreatePrivateTemplateFromVolumeCommand) {
            return _mockStorageMgr.CreatePrivateTemplateFromVolume((CreatePrivateTemplateFromVolumeCommand) cmd);
        } else if (cmd instanceof MaintainCommand) {
            return _mockAgentMgr.MaintainCommand((MaintainCommand) cmd);
        } else if (cmd instanceof GetVmStatsCommand) {
            return _mockVmMgr.getVmStats((GetVmStatsCommand) cmd);
        } else if (cmd instanceof GetDomRVersionCmd) {
            return _mockVmMgr.getDomRVersion((GetDomRVersionCmd) cmd);
        } else if (cmd instanceof ClusterSyncCommand) {
            return new Answer(cmd);
        } else if (cmd instanceof CopyVolumeCommand) {
            return _mockStorageMgr.CopyVolume((CopyVolumeCommand) cmd);
        } else {
            return Answer.createUnsupportedCommandAnswer(cmd);
        }
    } catch (Exception e) {
        s_logger.debug("Failed execute cmd: " + e.toString());
        txn.rollback();
        return new Answer(cmd, false, e.toString());
    } finally {
        txn.transitToAutoManagedConnection(Transaction.CLOUD_DB);
    }
}
Also used : GetDomRVersionCmd(com.cloud.agent.api.GetDomRVersionCmd) DhcpEntryCommand(com.cloud.agent.api.routing.DhcpEntryCommand) VmDataCommand(com.cloud.agent.api.routing.VmDataCommand) DeleteStoragePoolCommand(com.cloud.agent.api.DeleteStoragePoolCommand) ListTemplateCommand(com.cloud.agent.api.storage.ListTemplateCommand) ManageSnapshotCommand(com.cloud.agent.api.ManageSnapshotCommand) ComputeChecksumCommand(com.cloud.agent.api.ComputeChecksumCommand) MigrateCommand(com.cloud.agent.api.MigrateCommand) AttachVolumeCommand(com.cloud.agent.api.AttachVolumeCommand) SetPortForwardingRulesCommand(com.cloud.agent.api.routing.SetPortForwardingRulesCommand) CreateVolumeFromSnapshotCommand(com.cloud.agent.api.CreateVolumeFromSnapshotCommand) CheckNetworkCommand(com.cloud.agent.api.CheckNetworkCommand) PingTestCommand(com.cloud.agent.api.PingTestCommand) BackupSnapshotCommand(com.cloud.agent.api.BackupSnapshotCommand) DeleteSnapshotBackupCommand(com.cloud.agent.api.DeleteSnapshotBackupCommand) SetStaticNatRulesCommand(com.cloud.agent.api.routing.SetStaticNatRulesCommand) SecurityGroupRulesCmd(com.cloud.agent.api.SecurityGroupRulesCmd) CreateCommand(com.cloud.agent.api.storage.CreateCommand) DestroyCommand(com.cloud.agent.api.storage.DestroyCommand) SecStorageSetupCommand(com.cloud.agent.api.SecStorageSetupCommand) NetworkUsageCommand(com.cloud.agent.api.NetworkUsageCommand) AttachIsoCommand(com.cloud.agent.api.AttachIsoCommand) CleanupNetworkRulesCmd(com.cloud.agent.api.CleanupNetworkRulesCmd) GetVmStatsCommand(com.cloud.agent.api.GetVmStatsCommand) StopCommand(com.cloud.agent.api.StopCommand) Transaction(com.cloud.utils.db.Transaction) SecStorageVMSetupCommand(com.cloud.agent.api.SecStorageVMSetupCommand) Map(java.util.Map) HashMap(java.util.HashMap) MockConfigurationVO(com.cloud.simulator.MockConfigurationVO) CheckSshCommand(com.cloud.agent.api.check.CheckSshCommand) RebootCommand(com.cloud.agent.api.RebootCommand) StartCommand(com.cloud.agent.api.StartCommand) CheckConsoleProxyLoadCommand(com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand) SavePasswordCommand(com.cloud.agent.api.routing.SavePasswordCommand) PrimaryStorageDownloadCommand(com.cloud.agent.api.storage.PrimaryStorageDownloadCommand) DownloadCommand(com.cloud.agent.api.storage.DownloadCommand) PrimaryStorageDownloadCommand(com.cloud.agent.api.storage.PrimaryStorageDownloadCommand) CopyVolumeCommand(com.cloud.agent.api.storage.CopyVolumeCommand) WatchConsoleProxyLoadCommand(com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand) GetHostStatsCommand(com.cloud.agent.api.GetHostStatsCommand) DeleteTemplateCommand(com.cloud.agent.api.storage.DeleteTemplateCommand) IpAssocCommand(com.cloud.agent.api.routing.IpAssocCommand) CreatePrivateTemplateFromSnapshotCommand(com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand) ClusterSyncCommand(com.cloud.agent.api.ClusterSyncCommand) MaintainCommand(com.cloud.agent.api.MaintainCommand) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand) GetStorageStatsCommand(com.cloud.agent.api.GetStorageStatsCommand) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) DownloadProgressCommand(com.cloud.agent.api.storage.DownloadProgressCommand) Answer(com.cloud.agent.api.Answer) GetVncPortCommand(com.cloud.agent.api.GetVncPortCommand) MockHost(com.cloud.simulator.MockHost) CreatePrivateTemplateFromVolumeCommand(com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand) CreateStoragePoolCommand(com.cloud.agent.api.CreateStoragePoolCommand) CheckHealthCommand(com.cloud.agent.api.CheckHealthCommand) DB(com.cloud.utils.db.DB)

Example 2 with CreatePrivateTemplateFromSnapshotCommand

use of com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand in project cloudstack by apache.

the class VmwareSecondaryStorageResourceHandler method executeRequest.

@Override
public Answer executeRequest(Command cmd) {
    try {
        Answer answer;
        NDC.push(getCommandLogTitle(cmd));
        if (s_logger.isDebugEnabled())
            s_logger.debug("Executing " + _gson.toJson(cmd));
        if (cmd instanceof PrimaryStorageDownloadCommand) {
            answer = execute((PrimaryStorageDownloadCommand) cmd);
        } else if (cmd instanceof BackupSnapshotCommand) {
            answer = execute((BackupSnapshotCommand) cmd);
        } else if (cmd instanceof CreatePrivateTemplateFromVolumeCommand) {
            answer = execute((CreatePrivateTemplateFromVolumeCommand) cmd);
        } else if (cmd instanceof CreatePrivateTemplateFromSnapshotCommand) {
            answer = execute((CreatePrivateTemplateFromSnapshotCommand) cmd);
        } else if (cmd instanceof CopyVolumeCommand) {
            answer = execute((CopyVolumeCommand) cmd);
        } else if (cmd instanceof CreateVolumeFromSnapshotCommand) {
            answer = execute((CreateVolumeFromSnapshotCommand) cmd);
        } else if (cmd instanceof StorageSubSystemCommand) {
            answer = storageSubsystemHandler.handleStorageCommands((StorageSubSystemCommand) cmd);
        } else if (cmd instanceof CreateEntityDownloadURLCommand) {
            answer = execute((CreateEntityDownloadURLCommand) cmd);
        } else {
            answer = _resource.defaultAction(cmd);
        }
        // special handling to pass-back context info for cleanups
        if (cmd.getContextParam("execid") != null) {
            answer.setContextParam("execid", cmd.getContextParam("execid"));
        }
        if (cmd.getContextParam("checkpoint") != null) {
            answer.setContextParam("checkpoint", cmd.getContextParam("checkpoint"));
        }
        if (cmd.getContextParam("checkpoint2") != null) {
            answer.setContextParam("checkpoint2", cmd.getContextParam("checkpoint2"));
        }
        if (s_logger.isDebugEnabled())
            s_logger.debug("Command execution answer: " + _gson.toJson(answer));
        return answer;
    } finally {
        if (s_logger.isDebugEnabled())
            s_logger.debug("Done executing " + _gson.toJson(cmd));
        recycleServiceContext();
        NDC.pop();
    }
}
Also used : BackupSnapshotCommand(com.cloud.agent.api.BackupSnapshotCommand) CreateEntityDownloadURLCommand(com.cloud.agent.api.storage.CreateEntityDownloadURLCommand) Answer(com.cloud.agent.api.Answer) StorageSubSystemCommand(org.apache.cloudstack.storage.command.StorageSubSystemCommand) CreateVolumeFromSnapshotCommand(com.cloud.agent.api.CreateVolumeFromSnapshotCommand) PrimaryStorageDownloadCommand(com.cloud.agent.api.storage.PrimaryStorageDownloadCommand) CreatePrivateTemplateFromSnapshotCommand(com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand) CopyVolumeCommand(com.cloud.agent.api.storage.CopyVolumeCommand) CreatePrivateTemplateFromVolumeCommand(com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand)

Example 3 with CreatePrivateTemplateFromSnapshotCommand

use of com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand in project cloudstack by apache.

the class LibvirtComputingResourceTest method testCreatePrivateTemplateFromSnapshotCommandIOException.

@SuppressWarnings("unchecked")
@Test
public void testCreatePrivateTemplateFromSnapshotCommandIOException() {
    final StoragePool pool = Mockito.mock(StoragePool.class);
    final String secondaryStoragePoolURL = "nfs:/127.0.0.1/storage/secondary";
    final Long dcId = 1l;
    final Long accountId = 1l;
    final Long volumeId = 1l;
    final String backedUpSnapshotUuid = "/run/9a0afe7c-26a7-4585-bf87-abf82ae106d9/";
    final String backedUpSnapshotName = "snap";
    final String origTemplateInstallPath = "/install/path/";
    final Long newTemplateId = 2l;
    final String templateName = "templ";
    final int wait = 0;
    final CreatePrivateTemplateFromSnapshotCommand command = new CreatePrivateTemplateFromSnapshotCommand(pool, secondaryStoragePoolURL, dcId, accountId, volumeId, backedUpSnapshotUuid, backedUpSnapshotName, origTemplateInstallPath, newTemplateId, templateName, wait);
    final String templatePath = "/template/path";
    final String localPath = "/mnt/local";
    final String tmplName = "ce97bbc1-34fe-4259-9202-74bbce2562ab";
    final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
    final KVMStoragePool secondaryPool = Mockito.mock(KVMStoragePool.class);
    final KVMStoragePool snapshotPool = Mockito.mock(KVMStoragePool.class);
    final KVMPhysicalDisk snapshot = Mockito.mock(KVMPhysicalDisk.class);
    final StorageLayer storage = Mockito.mock(StorageLayer.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final TemplateLocation location = Mockito.mock(TemplateLocation.class);
    final Processor qcow2Processor = Mockito.mock(Processor.class);
    final FormatInfo info = Mockito.mock(FormatInfo.class);
    when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    String snapshotPath = command.getSnapshotUuid();
    final int index = snapshotPath.lastIndexOf("/");
    snapshotPath = snapshotPath.substring(0, index);
    when(storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath)).thenReturn(snapshotPool);
    when(storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl())).thenReturn(secondaryPool);
    when(snapshotPool.getPhysicalDisk(command.getSnapshotName())).thenReturn(snapshot);
    when(secondaryPool.getLocalPath()).thenReturn(localPath);
    when(libvirtComputingResource.getStorage()).thenReturn(storage);
    when(libvirtComputingResource.createTmplPath()).thenReturn(templatePath);
    when(libvirtComputingResource.getCmdsTimeout()).thenReturn(1);
    final String templateFolder = command.getAccountId() + File.separator + command.getNewTemplateId();
    final String templateInstallFolder = "template/tmpl/" + templateFolder;
    final String tmplPath = secondaryPool.getLocalPath() + File.separator + templateInstallFolder;
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    when(libvirtUtilitiesHelper.buildTemplateLocation(storage, tmplPath)).thenReturn(location);
    when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(tmplName);
    try {
        when(libvirtUtilitiesHelper.buildQCOW2Processor(storage)).thenReturn(qcow2Processor);
        when(qcow2Processor.process(tmplPath, null, tmplName)).thenReturn(info);
        when(location.create(1, true, tmplName)).thenThrow(IOException.class);
    } catch (final ConfigurationException e) {
        fail(e.getMessage());
    } catch (final InternalErrorException e) {
        fail(e.getMessage());
    } catch (final IOException e) {
        fail(e.getMessage());
    }
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath);
    verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl());
}
Also used : KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) StoragePool(com.cloud.storage.StoragePool) NfsStoragePool(com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool) StorageLayer(com.cloud.storage.StorageLayer) Processor(com.cloud.storage.template.Processor) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) ConfigurationException(javax.naming.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TemplateLocation(com.cloud.storage.template.TemplateLocation) CreatePrivateTemplateFromSnapshotCommand(com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand) FormatInfo(com.cloud.storage.template.Processor.FormatInfo) Test(org.junit.Test)

Example 4 with CreatePrivateTemplateFromSnapshotCommand

use of com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand in project cloudstack by apache.

the class LibvirtComputingResourceTest method testCreatePrivateTemplateFromSnapshotCommand.

@Test
public void testCreatePrivateTemplateFromSnapshotCommand() {
    final StoragePool pool = Mockito.mock(StoragePool.class);
    final String secondaryStoragePoolURL = "nfs:/127.0.0.1/storage/secondary";
    final Long dcId = 1l;
    final Long accountId = 1l;
    final Long volumeId = 1l;
    final String backedUpSnapshotUuid = "/run/9a0afe7c-26a7-4585-bf87-abf82ae106d9/";
    final String backedUpSnapshotName = "snap";
    final String origTemplateInstallPath = "/install/path/";
    final Long newTemplateId = 2l;
    final String templateName = "templ";
    final int wait = 0;
    final CreatePrivateTemplateFromSnapshotCommand command = new CreatePrivateTemplateFromSnapshotCommand(pool, secondaryStoragePoolURL, dcId, accountId, volumeId, backedUpSnapshotUuid, backedUpSnapshotName, origTemplateInstallPath, newTemplateId, templateName, wait);
    final String templatePath = "/template/path";
    final String localPath = "/mnt/local";
    final String tmplName = "ce97bbc1-34fe-4259-9202-74bbce2562ab";
    final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
    final KVMStoragePool secondaryPool = Mockito.mock(KVMStoragePool.class);
    final KVMStoragePool snapshotPool = Mockito.mock(KVMStoragePool.class);
    final KVMPhysicalDisk snapshot = Mockito.mock(KVMPhysicalDisk.class);
    final StorageLayer storage = Mockito.mock(StorageLayer.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final TemplateLocation location = Mockito.mock(TemplateLocation.class);
    final Processor qcow2Processor = Mockito.mock(Processor.class);
    final FormatInfo info = Mockito.mock(FormatInfo.class);
    when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    String snapshotPath = command.getSnapshotUuid();
    final int index = snapshotPath.lastIndexOf("/");
    snapshotPath = snapshotPath.substring(0, index);
    when(storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath)).thenReturn(snapshotPool);
    when(storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl())).thenReturn(secondaryPool);
    when(snapshotPool.getPhysicalDisk(command.getSnapshotName())).thenReturn(snapshot);
    when(secondaryPool.getLocalPath()).thenReturn(localPath);
    when(libvirtComputingResource.getStorage()).thenReturn(storage);
    when(libvirtComputingResource.createTmplPath()).thenReturn(templatePath);
    when(libvirtComputingResource.getCmdsTimeout()).thenReturn(1);
    final String templateFolder = command.getAccountId() + File.separator + command.getNewTemplateId();
    final String templateInstallFolder = "template/tmpl/" + templateFolder;
    final String tmplPath = secondaryPool.getLocalPath() + File.separator + templateInstallFolder;
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    when(libvirtUtilitiesHelper.buildTemplateLocation(storage, tmplPath)).thenReturn(location);
    when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(tmplName);
    try {
        when(libvirtUtilitiesHelper.buildQCOW2Processor(storage)).thenReturn(qcow2Processor);
        when(qcow2Processor.process(tmplPath, null, tmplName)).thenReturn(info);
    } catch (final ConfigurationException e) {
        fail(e.getMessage());
    } catch (final InternalErrorException e) {
        fail(e.getMessage());
    }
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath);
    verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl());
}
Also used : KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) StoragePool(com.cloud.storage.StoragePool) NfsStoragePool(com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool) StorageLayer(com.cloud.storage.StorageLayer) Processor(com.cloud.storage.template.Processor) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) InternalErrorException(com.cloud.exception.InternalErrorException) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) ConfigurationException(javax.naming.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TemplateLocation(com.cloud.storage.template.TemplateLocation) CreatePrivateTemplateFromSnapshotCommand(com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand) FormatInfo(com.cloud.storage.template.Processor.FormatInfo) Test(org.junit.Test)

Example 5 with CreatePrivateTemplateFromSnapshotCommand

use of com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand in project cloudstack by apache.

the class LibvirtComputingResourceTest method testCreatePrivateTemplateFromSnapshotCommandInternalErrorException.

@SuppressWarnings("unchecked")
@Test
public void testCreatePrivateTemplateFromSnapshotCommandInternalErrorException() {
    final StoragePool pool = Mockito.mock(StoragePool.class);
    final String secondaryStoragePoolURL = "nfs:/127.0.0.1/storage/secondary";
    final Long dcId = 1l;
    final Long accountId = 1l;
    final Long volumeId = 1l;
    final String backedUpSnapshotUuid = "/run/9a0afe7c-26a7-4585-bf87-abf82ae106d9/";
    final String backedUpSnapshotName = "snap";
    final String origTemplateInstallPath = "/install/path/";
    final Long newTemplateId = 2l;
    final String templateName = "templ";
    final int wait = 0;
    final CreatePrivateTemplateFromSnapshotCommand command = new CreatePrivateTemplateFromSnapshotCommand(pool, secondaryStoragePoolURL, dcId, accountId, volumeId, backedUpSnapshotUuid, backedUpSnapshotName, origTemplateInstallPath, newTemplateId, templateName, wait);
    final String templatePath = "/template/path";
    final String localPath = "/mnt/local";
    final String tmplName = "ce97bbc1-34fe-4259-9202-74bbce2562ab";
    final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
    final KVMStoragePool secondaryPool = Mockito.mock(KVMStoragePool.class);
    final KVMStoragePool snapshotPool = Mockito.mock(KVMStoragePool.class);
    final KVMPhysicalDisk snapshot = Mockito.mock(KVMPhysicalDisk.class);
    final StorageLayer storage = Mockito.mock(StorageLayer.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final TemplateLocation location = Mockito.mock(TemplateLocation.class);
    final Processor qcow2Processor = Mockito.mock(Processor.class);
    when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    String snapshotPath = command.getSnapshotUuid();
    final int index = snapshotPath.lastIndexOf("/");
    snapshotPath = snapshotPath.substring(0, index);
    when(storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath)).thenReturn(snapshotPool);
    when(storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl())).thenReturn(secondaryPool);
    when(snapshotPool.getPhysicalDisk(command.getSnapshotName())).thenReturn(snapshot);
    when(secondaryPool.getLocalPath()).thenReturn(localPath);
    when(libvirtComputingResource.getStorage()).thenReturn(storage);
    when(libvirtComputingResource.createTmplPath()).thenReturn(templatePath);
    when(libvirtComputingResource.getCmdsTimeout()).thenReturn(1);
    final String templateFolder = command.getAccountId() + File.separator + command.getNewTemplateId();
    final String templateInstallFolder = "template/tmpl/" + templateFolder;
    final String tmplPath = secondaryPool.getLocalPath() + File.separator + templateInstallFolder;
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    when(libvirtUtilitiesHelper.buildTemplateLocation(storage, tmplPath)).thenReturn(location);
    when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(tmplName);
    try {
        when(libvirtUtilitiesHelper.buildQCOW2Processor(storage)).thenReturn(qcow2Processor);
        when(qcow2Processor.process(tmplPath, null, tmplName)).thenThrow(InternalErrorException.class);
    } catch (final ConfigurationException e) {
        fail(e.getMessage());
    } catch (final InternalErrorException e) {
        fail(e.getMessage());
    }
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath);
    verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl());
}
Also used : KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) StoragePool(com.cloud.storage.StoragePool) NfsStoragePool(com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool) StorageLayer(com.cloud.storage.StorageLayer) Processor(com.cloud.storage.template.Processor) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) InternalErrorException(com.cloud.exception.InternalErrorException) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) ConfigurationException(javax.naming.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TemplateLocation(com.cloud.storage.template.TemplateLocation) CreatePrivateTemplateFromSnapshotCommand(com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand) Test(org.junit.Test)

Aggregations

CreatePrivateTemplateFromSnapshotCommand (com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand)10 Answer (com.cloud.agent.api.Answer)9 ConfigurationException (javax.naming.ConfigurationException)7 BackupSnapshotCommand (com.cloud.agent.api.BackupSnapshotCommand)5 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)5 CreatePrivateTemplateFromVolumeCommand (com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand)5 CreateVolumeFromSnapshotCommand (com.cloud.agent.api.CreateVolumeFromSnapshotCommand)5 CopyVolumeCommand (com.cloud.agent.api.storage.CopyVolumeCommand)5 InternalErrorException (com.cloud.exception.InternalErrorException)5 NfsStoragePool (com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool)5 PrimaryStorageDownloadCommand (com.cloud.agent.api.storage.PrimaryStorageDownloadCommand)4 AttachIsoCommand (com.cloud.agent.api.AttachIsoCommand)3 CheckHealthCommand (com.cloud.agent.api.CheckHealthCommand)3 CheckNetworkCommand (com.cloud.agent.api.CheckNetworkCommand)3 CreateStoragePoolCommand (com.cloud.agent.api.CreateStoragePoolCommand)3 DeleteStoragePoolCommand (com.cloud.agent.api.DeleteStoragePoolCommand)3 GetHostStatsCommand (com.cloud.agent.api.GetHostStatsCommand)3 GetStorageStatsCommand (com.cloud.agent.api.GetStorageStatsCommand)3 GetVmStatsCommand (com.cloud.agent.api.GetVmStatsCommand)3 GetVncPortCommand (com.cloud.agent.api.GetVncPortCommand)3