Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ public class ConfigDrive {
public static final String openStackConfigDriveName = "/openstack/latest/";

/**
* This is the path to iso file relative to mount point
* @return config drive iso file path
* Creates the path to ISO file relative to mount point.
* The config driver path will have the following formated: {@link #CONFIGDRIVEDIR} + / + instanceName + / + {@link #CONFIGDRIVEFILENAME}
*
* @return config drive ISO file path
*/
public static String createConfigDrivePath(final String instanceName) {
public static String createConfigDrivePath(String instanceName) {
return ConfigDrive.CONFIGDRIVEDIR + "/" + instanceName + "/" + ConfigDrive.CONFIGDRIVEFILENAME;
}

}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.apache.cloudstack.storage.configdrive;

import java.io.IOException;

import org.junit.Assert;
import org.junit.Test;

public class ConfigDriveTest {

@Test
public void testConfigDriveIsoPath() throws IOException {
Assert.assertEquals(ConfigDrive.createConfigDrivePath("i-x-y"), "configdrive/i-x-y/configdrive.iso");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import static org.mockito.Mockito.when;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand All @@ -41,12 +42,20 @@
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.storage.configdrive.ConfigDrive;
import org.apache.cloudstack.storage.configdrive.ConfigDriveBuilder;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.reflections.ReflectionUtils;

import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
Expand Down Expand Up @@ -90,6 +99,7 @@
import com.cloud.vm.dao.VMInstanceDao;
import com.google.common.collect.Maps;

@RunWith(PowerMockRunner.class)
public class ConfigDriveNetworkElementTest {

public static final String CLOUD_ID = "xx";
Expand Down Expand Up @@ -140,7 +150,7 @@ public class ConfigDriveNetworkElementTest {
@InjectMocks private final ConfigDriveNetworkElement _configDrivesNetworkElement = new ConfigDriveNetworkElement();
@InjectMocks @Spy private NetworkModelImpl _networkModel = new NetworkModelImpl();

@org.junit.Before
@Before
public void setUp() throws NoSuchFieldException, IllegalAccessException {
MockitoAnnotations.initMocks(this);

Expand Down Expand Up @@ -243,7 +253,14 @@ public void testGetCapabilities () {
}

@Test
@SuppressWarnings("unchecked")
@PrepareForTest({ConfigDriveBuilder.class})
public void testAddPasswordAndUserData() throws Exception {
PowerMockito.mockStatic(ConfigDriveBuilder.class);

Method method = ReflectionUtils.getMethods(ConfigDriveBuilder.class, ReflectionUtils.withName("buildConfigDrive")).iterator().next();
PowerMockito.when(ConfigDriveBuilder.class, method).withArguments(Mockito.anyListOf(String[].class), Mockito.anyString(), Mockito.anyString()).thenReturn("content");

final Answer answer = mock(Answer.class);
final UserVmDetailVO userVmDetailVO = mock(UserVmDetailVO.class);
when(agentManager.easySend(anyLong(), any(HandleConfigDriveIsoCommand.class))).thenReturn(answer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;

import junit.framework.TestCase;

import org.junit.Test;

import junit.framework.TestCase;
import streamer.debug.MockServer;
import streamer.debug.MockServer.Packet;

Expand Down Expand Up @@ -93,7 +92,6 @@ public void testIsMockServerCanRespond() throws Exception {

@Test
public void testIsMockServerCanUpgradeConnectionToSsl() throws Exception {

final byte[] mockClientData1 = new byte[] {0x01, 0x02, 0x03};
final byte[] mockServerData1 = new byte[] {0x03, 0x02, 0x01};

Expand Down Expand Up @@ -161,8 +159,7 @@ public void testIsMockServerCanUpgradeConnectionToSsl() throws Exception {

final SSLSocketFactory sslSocketFactory = (SSLSocketFactory)SSLSocketFactory.getDefault();
SSLSocket sslSocket = (SSLSocket)sslSocketFactory.createSocket(socket, address.getHostName(), address.getPort(), true);
//sslSocket.setEnabledCipherSuites(sslSocket.getSupportedCipherSuites());
sslSocket.setEnabledCipherSuites(new String[] { "SSL_DH_anon_WITH_3DES_EDE_CBC_SHA" });
sslSocket.setEnabledCipherSuites(sslSocket.getSupportedCipherSuites());
sslSocket.startHandshake();

InputStream is = sslSocket.getInputStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,16 +584,19 @@ public static String getTemplateOnSecStorageFilePath(String secStorageMountPoint

StringBuffer sb = new StringBuffer();
sb.append(secStorageMountPoint);
if (!secStorageMountPoint.endsWith("/"))
if (!secStorageMountPoint.endsWith("/")) {
sb.append("/");
}

sb.append(templateRelativeFolderPath);
if (!secStorageMountPoint.endsWith("/"))
if (!secStorageMountPoint.endsWith("/")) {
sb.append("/");
}

sb.append(templateName);
if (!fileExtension.startsWith("."))
if (!fileExtension.startsWith(".")) {
sb.append(".");
}
sb.append(fileExtension);

return sb.toString();
Expand Down Expand Up @@ -904,7 +907,7 @@ protected Answer copySnapshotToTemplateFromNfsToNfs(CopyCommand cmd, SnapshotObj
try {
_storage.create(destFile.getAbsolutePath(), _tmpltpp);
try ( // generate template.properties file
FileWriter writer = new FileWriter(metaFile); BufferedWriter bufferWriter = new BufferedWriter(writer);) {
FileWriter writer = new FileWriter(metaFile); BufferedWriter bufferWriter = new BufferedWriter(writer);) {
// KVM didn't change template unique name, just used the template name passed from orchestration layer, so no need
// to send template name back.
bufferWriter.write("uniquename=" + destData.getName());
Expand Down Expand Up @@ -1450,7 +1453,7 @@ String swiftDownload(SwiftTO swift, String container, String rfilename, String l
Script command = new Script("/bin/bash", s_logger);
command.add("-c");
command.add("/usr/bin/python /usr/local/cloud/systemvm/scripts/storage/secondary/swift -A " + swift.getUrl() + " -U " + swift.getAccount() + ":" + swift.getUserName()
+ " -K " + swift.getKey() + " download " + container + " " + rfilename + " -o " + lFullPath);
+ " -K " + swift.getKey() + " download " + container + " " + rfilename + " -o " + lFullPath);
OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
String result = command.execute(parser);
if (result != null) {
Expand Down Expand Up @@ -1554,7 +1557,7 @@ String[] swiftList(SwiftTO swift, String container, String rFilename) {
Script command = new Script("/bin/bash", s_logger);
command.add("-c");
command.add("/usr/bin/python /usr/local/cloud/systemvm/scripts/storage/secondary/swift -A " + swift.getUrl() + " -U " + swift.getAccount() + ":" + swift.getUserName()
+ " -K " + swift.getKey() + " list " + container + " " + rFilename);
+ " -K " + swift.getKey() + " list " + container + " " + rFilename);
OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
String result = command.execute(parser);
if (result == null && parser.getLines() != null) {
Expand All @@ -1576,7 +1579,7 @@ String swiftDelete(SwiftTO swift, String container, String object) {
Script command = new Script("/bin/bash", s_logger);
command.add("-c");
command.add("/usr/bin/python /usr/local/cloud/systemvm/scripts/storage/secondary/swift -A " + swift.getUrl() + " -U " + swift.getAccount() + ":" + swift.getUserName()
+ " -K " + swift.getKey() + " delete " + container + " " + object);
+ " -K " + swift.getKey() + " delete " + container + " " + object);
OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
String result = command.execute(parser);
if (result != null) {
Expand Down Expand Up @@ -3316,7 +3319,7 @@ public String postUpload(String uuid, String filename, long processTimeout) {
for (Processor processor : processors.values()) {
FormatInfo info = null;
try {
info = processor.process(resourcePath, null, templateName, processTimeout * 1000);
info = processor.process(resourcePath, null, templateName, processTimeout * 1000);
} catch (InternalErrorException e) {
s_logger.error("Template process exception ", e);
return e.toString();
Expand Down