List of usage examples for javax.naming ConfigurationException getMessage
public String getMessage()
From source file:com.cloud.agent.AgentShell.java
public static void main(String[] args) { try {/*w ww . ja v a2 s. c o m*/ AgentShell shell = new AgentShell(); shell.init(args); shell.start(); } catch (ConfigurationException e) { System.out.println(e.getMessage()); } }
From source file:com.couchbase.sqoop.mapreduce.db.CouchbaseRecordReader.java
@Override public void initialize(final InputSplit splits, final TaskAttemptContext context) throws IOException, InterruptedException { try {/*from ww w . j a v a 2 s.co m*/ // if (this.client == null) { // final String user = dbConf.getUsername(); // String pass = dbConf.getPassword(); // final String url = dbConf.getUrlProperty(); // // final String passwordSecurely = new // // String(dbConfig.getConf().get(DBConfiguration.PASSWORD_PROPERTY)); // // System.out.printf("CouchbaseRecorder: Found password %s", passwordSecurely); // System.out.printf("CouchbaseRecordReader: %s", splits); // final String passwordSecurely = new String(((CouchbaseInputSplit) splits).getJob().getCredentials() // .getSecretKey(CouchbaseRecordReader.PASSWORD_SECRET_KEY)); // pass = passwordSecurely; // try { // this.client = new TapClient(Arrays.asList(new URI(url)), user, pass); // } catch (final URISyntaxException e) { // this.client.shutdown(); // } // } final MessageBuilder builder = new MessageBuilder(); if (tableName.equals("DUMP")) { builder.doDump(); builder.supportAck(); builder.specifyVbuckets(split.getVBuckets()); client.tapCustom(null, builder.getMessage()); } else if (tableName.startsWith("BACKFILL_")) { final String time = tableName.substring("BACKFILL_".length(), tableName.length()); builder.doBackfill(0); builder.supportAck(); builder.specifyVbuckets(split.getVBuckets()); final TapStream tapStream = client.tapCustom(null, builder.getMessage()); createTapStreamTimeout(tapStream, new Long(time).intValue()); } else { throw new IOException( "Table name must be \"DUMP\" or begin with " + "\"BACKFILL_\" followed by an integer."); } } catch (final ConfigurationException e) { CouchbaseRecordReader.LOG.error("Couldn't Configure Tap Stream: " + e.getMessage()); client.shutdown(); } catch (final NumberFormatException e) { CouchbaseRecordReader.LOG.error("Bad Backfill Time: " + e.getMessage() + "\n(Ex. BACKFILL_5"); client.shutdown(); } }
From source file:org.agatom.springatom.cmp.wizards.core.AbstractWizardProcessor.java
@PostConstruct private void loadStepHelperDelegate() { LOGGER.trace("loadStepHelperDelegate()"); final StepHelper[] helpers = this.getStepHelpers(); Assert.notNull(helpers, "Helpers cannot be null"); try {//ww w. j a v a 2 s. c o m this.stepHelperDelegate = StepHelperDelegate.newStepHelperDelegate(helpers); } catch (ConfigurationException e) { LOGGER.error("Failed to initialized stepHelperDelegate, configuration failed", e); throw new BeanInitializationException(e.getMessage(), Throwables.getRootCause(e)); } }
From source file:com.cloud.network.element.BigSwitchBcfElement.java
@Override @DB//from www . j a v a 2 s .c om public BigSwitchBcfDeviceVO addBigSwitchBcfDevice(AddBigSwitchBcfDeviceCmd cmd) { BigSwitchBcfDeviceVO newBcfDevice; bcfUtilsInit(); ServerResource resource = new BigSwitchBcfResource(); final String deviceName = BcfConstants.BIG_SWITCH_BCF.getName(); NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName); final Long physicalNetworkId = cmd.getPhysicalNetworkId(); final String hostname = cmd.getHost(); final String username = cmd.getUsername(); final String password = cmd.getPassword(); final Boolean nat = cmd.getNat(); PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId); if (physicalNetwork == null) { throw new InvalidParameterValueException( "Could not find phyical network with ID: " + physicalNetworkId); } long zoneId = physicalNetwork.getDataCenterId(); final PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao .findByServiceProvider(physicalNetwork.getId(), networkDevice.getNetworkServiceProvder()); if (ntwkSvcProvider == null) { throw new CloudRuntimeException("Network Service Provider: " + networkDevice.getNetworkServiceProvder() + " is not enabled in the physical network: " + physicalNetworkId + "to add this device"); } else if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) { throw new CloudRuntimeException("Network Service Provider: " + ntwkSvcProvider.getProviderName() + " is in shutdown state in the physical network: " + physicalNetworkId + "to add this device"); } ntwkSvcProvider.setFirewallServiceProvided(true); ntwkSvcProvider.setGatewayServiceProvided(true); ntwkSvcProvider.setNetworkAclServiceProvided(true); ntwkSvcProvider.setSourcenatServiceProvided(true); ntwkSvcProvider.setStaticnatServiceProvided(true); if (_bigswitchBcfDao.listByPhysicalNetwork(physicalNetworkId).size() > 1) { throw new CloudRuntimeException("At most two BCF controllers can be configured"); } DataCenterVO zone = _zoneDao.findById(physicalNetwork.getDataCenterId()); String zoneName; if (zone != null) { zoneName = zone.getName(); } else { zoneName = String.valueOf(zoneId); } Boolean natNow = _bcfUtils.isNatEnabled(); if (!nat && natNow) { throw new CloudRuntimeException( "NAT is enabled in existing controller. Enable NAT for new controller or remove existing controller first."); } else if (nat && !natNow) { throw new CloudRuntimeException( "NAT is disabled in existing controller. Disable NAT for new controller or remove existing controller first."); } Map<String, String> params = new HashMap<String, String>(); params.put("guid", UUID.randomUUID().toString()); params.put("zoneId", zoneName); params.put("physicalNetworkId", String.valueOf(physicalNetwork.getId())); params.put("name", "BigSwitch Controller - " + cmd.getHost()); params.put("hostname", cmd.getHost()); params.put("username", username); params.put("password", password); params.put("nat", nat.toString()); // FIXME What to do with multiple isolation types params.put("transportzoneisotype", physicalNetwork.getIsolationMethods().get(0).toLowerCase()); Map<String, Object> hostdetails = new HashMap<String, Object>(); hostdetails.putAll(params); try { resource.configure(cmd.getHost(), hostdetails); // store current topology in bcf resource TopologyData topo = _bcfUtils.getTopology(physicalNetwork.getId()); ((BigSwitchBcfResource) resource).setTopology(topo); final Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.L2Networking, params); if (host != null) { newBcfDevice = Transaction.execute(new TransactionCallback<BigSwitchBcfDeviceVO>() { @Override public BigSwitchBcfDeviceVO doInTransaction(TransactionStatus status) { BigSwitchBcfDeviceVO bigswitchBcfDevice = new BigSwitchBcfDeviceVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName, hostname, username, password, nat, BigSwitchBcfApi.HASH_IGNORE); _bigswitchBcfDao.persist(bigswitchBcfDevice); DetailVO detail = new DetailVO(host.getId(), "bigswitchbcfdeviceid", String.valueOf(bigswitchBcfDevice.getId())); _hostDetailsDao.persist(detail); return bigswitchBcfDevice; } }); } else { throw new CloudRuntimeException( "Failed to add BigSwitch BCF Controller Device due to internal error."); } } catch (ConfigurationException e) { throw new CloudRuntimeException(e.getMessage()); } // initial topology sync to newly added BCF controller HostVO bigswitchBcfHost = _hostDao.findById(newBcfDevice.getHostId()); _bcfUtils.syncTopologyToBcfHost(bigswitchBcfHost, nat); return newBcfDevice; }
From source file:com.cloud.network.resource.NccHttpCode.java
@Override public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { JSONObject jsonResponse = null;//from w ww .j a va 2 s . c o m try { _name = (String) params.get("name"); if (_name == null) { throw new ConfigurationException("Unable to find name in the configuration parameters"); } _zoneId = (String) params.get("zoneId"); if (_zoneId == null) { throw new ConfigurationException("Unable to find zone Id in the configuration parameters"); } _ip = (String) params.get("ip"); if (_ip == null) { throw new ConfigurationException("Unable to find IP address in the configuration parameters"); } _username = (String) params.get("username"); if (_username == null) { throw new ConfigurationException("Unable to find username in the configuration parameters"); } _password = (String) params.get("password"); if (_password == null) { throw new ConfigurationException("Unable to find password in the configuration parameters"); } _numRetries = NumbersUtil.parseInt((String) params.get("numretries"), 2); _guid = (String) params.get("guid"); if (_guid == null) { throw new ConfigurationException("Unable to find the guid in the configuration parameters"); } _deviceName = (String) params.get("deviceName"); if (_deviceName == null) { throw new ConfigurationException("Unable to find the device name in the configuration parameters"); } _nccCmdTimeout = NumbersUtil.parseLong((String) params.get("numretries"), 600000); // validate device configuration parameters login(); return true; } catch (ConfigurationException e) { throw new ConfigurationException(e.getMessage()); } catch (ExecutionException e) { s_logger.debug("Execution Exception :" + e.getMessage()); throw new ConfigurationException( "Failed to add the device. Please check the device is NCC and It is reachable from Management Server."); } }
From source file:com.cloud.hypervisor.kvm.resource.LibvirtComputingResourceTest.java
@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);/* w w w . j av a 2s.co m*/ 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()); }
From source file:com.cloud.hypervisor.kvm.resource.LibvirtComputingResourceTest.java
@SuppressWarnings("unchecked") @Test//from w w w . j ava 2s . c om 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()); }
From source file:com.cloud.hypervisor.kvm.resource.LibvirtComputingResourceTest.java
@SuppressWarnings("unchecked") @Test/*from ww w.j av a 2 s . co m*/ public void testCreatePrivateTemplateFromSnapshotCommandConfigurationException() { 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)).thenThrow(ConfigurationException.class); 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); assertFalse(answer.getResult()); verify(libvirtComputingResource, times(1)).getStoragePoolMgr(); verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath); verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl()); }
From source file:com.cloud.hypervisor.kvm.resource.LibvirtComputingResourceTest.java
@SuppressWarnings("unchecked") @Test//from w w w . ja va2s . com 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()); }