diff --git a/build/build-tests.xml b/build/build-tests.xml
index 544a496c69a..fa375479a7a 100755
--- a/build/build-tests.xml
+++ b/build/build-tests.xml
@@ -132,6 +132,8 @@
+
+
diff --git a/test/conf/demo/commandstype.properties b/test/conf/demo/commandstype.properties
new file mode 100644
index 00000000000..6d70b267356
--- /dev/null
+++ b/test/conf/demo/commandstype.properties
@@ -0,0 +1,4 @@
+deployVirtualMachine=async
+listPublicIpAddresses=sync
+associateIPAddress=sync
+createPortForwardingRule=async
\ No newline at end of file
diff --git a/test/conf/demo/setup.properties b/test/conf/demo/setup.properties
new file mode 100644
index 00000000000..e6802e343a5
--- /dev/null
+++ b/test/conf/demo/setup.properties
@@ -0,0 +1,9 @@
+hostname=localhost
+apikey=p62of2UV0INfl9Jyg-vl90nAnhPMg9vioiHc5QBcx4DyeUl_OZLEWxMVzqtdzmLlgIoMz5yNmrSUy0z1bdIOHA
+secretkey=UZeggpLS1n5XqzQ-CDGJt04Vk8i3kwF-Q7FGy0whGf_awy_rWTqt4Ui3cEJNEPLu5gt9m34kZNVOl5wptauaEg
+account=admin
+domainId=1
+serviceOfferingId=1
+networkId=204
+templateId=5
+zoneId==1
\ No newline at end of file
diff --git a/test/src/com/cloud/test/demo/Demo.java b/test/src/com/cloud/test/demo/Demo.java
new file mode 100644
index 00000000000..1545d7c7e45
--- /dev/null
+++ b/test/src/com/cloud/test/demo/Demo.java
@@ -0,0 +1,211 @@
+// Copyright 2012 Citrix Systems, Inc. Licensed under the
+// Apache License, Version 2.0 (the "License"); you may not use this
+// file except in compliance with the License. Citrix Systems, Inc.
+// reserves all rights not expressly granted by 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.
+//
+// Automatically generated by addcopyright.py at 04/03/2012
+package com.cloud.test.demo;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Properties;
+
+import com.cloud.test.utils.UtilsForTest;
+import com.cloud.utils.PropertiesUtil;
+import com.trilead.ssh2.ChannelCondition;
+import com.trilead.ssh2.Connection;
+import com.trilead.ssh2.Session;
+
+/**
+ * @author Alena Prokharchyk
+ */
+public class Demo {
+ private static HashMap _apiCommands = new HashMap();
+ private static Properties properties = new Properties();
+
+ public static void main(String[] args){
+ //read properties files
+ readCommandsType();
+ readDeployConfig();
+ String publicIp = createDeployment();
+ //setup httpd on the user vms
+ //setupHttpd(publicIp, "password");
+
+ System.out.println("\nURL is " + "http://" + publicIp + "/cloudcom-faq.html");
+ }
+
+ private static void readCommandsType() {
+ Properties preProcessedCommands = new Properties();
+ String configFile = "../conf/demo/commandstype.properties";
+ File commandsFile = PropertiesUtil.findConfigFile(configFile);
+ try {
+ if (commandsFile != null) {
+ preProcessedCommands.load(new FileInputStream(commandsFile));
+ for (Object key : preProcessedCommands.keySet()) {
+ String strKey = (String)key;
+ String asyncParams = (String)preProcessedCommands.getProperty(strKey);
+ boolean isAsync = false;
+ if (String.valueOf(asyncParams).equalsIgnoreCase("async")) {
+ isAsync=true;
+ }
+ _apiCommands.put(strKey, isAsync);
+ }
+ }
+ } catch (FileNotFoundException fnfex) {
+ System.exit(1);
+ } catch (IOException ex) {
+ System.out.println("ERROR: Error reading properites file " + configFile);
+ System.exit(1);
+ } finally {
+ if (commandsFile == null) {
+ System.out.println("ERROR: Unable to find properites file " + configFile);
+ }
+ }
+ }
+
+ private static void readDeployConfig() {
+ String configFile = "../conf/demo/setup.properties";
+ File commandsFile = PropertiesUtil.findConfigFile(configFile);
+ try {
+ if (commandsFile != null) {
+ properties.load(new FileInputStream(commandsFile));
+ }
+ } catch (FileNotFoundException fnfex) {
+ System.exit(1);
+ } catch (IOException ex) {
+ System.out.println("ERROR: Error reading properites file " + configFile);
+ System.exit(1);
+ } finally {
+ if (commandsFile == null) {
+ System.out.println("ERROR: Unable to find properites file " + configFile);
+ }
+ }
+ }
+
+ private static void setupHttpd(String host, String password) {
+ if (host == null) {
+ System.out.println("Did not receive a host back from test, ignoring ssh test");
+ System.exit(1);
+ }
+
+ if (password == null) {
+ System.out.println("Did not receive a password back from test, ignoring ssh test");
+ System.exit(1);
+ }
+
+ try {
+ System.out.println("Sleeping for 1 min before trying to ssh into linux host ");
+ //Thread.sleep(60000);
+ System.out.println("Attempting to SSH into linux host " + host);
+
+ Connection conn = new Connection(host);
+ conn.connect(null, 60000, 60000);
+
+ System.out.println("User root ssHed successfully into linux host " + host);
+
+ boolean isAuthenticated = conn.authenticateWithPassword("root", password);
+
+ if (isAuthenticated == false) {
+ System.out.println("ERROR: Authentication failed for root with password" + password);
+ System.exit(1);
+ }
+
+ boolean success = false;
+ String linuxCommand = "yum install httpd -y && service httpd start && service iptables stop && cd /var/www/html && wget cloud.com";
+
+ Session sess = conn.openSession();
+ System.out.println("User root executing : " + linuxCommand);
+ sess.execCommand(linuxCommand);
+
+ InputStream stdout = sess.getStdout();
+ InputStream stderr = sess.getStderr();
+
+ byte[] buffer = new byte[8192];
+ while (true) {
+ if ((stdout.available() == 0) && (stderr.available() == 0)) {
+ int conditions = sess.waitForCondition(ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA | ChannelCondition.EOF, 120000);
+
+ if ((conditions & ChannelCondition.TIMEOUT) != 0) {
+ System.out.println("ERROR: Timeout while waiting for data from peer.");
+ System.exit(1);
+ }
+
+ if ((conditions & ChannelCondition.EOF) != 0) {
+ if ((conditions & (ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA)) == 0) {
+ break;
+ }
+ }
+ }
+
+ while (stdout.available() > 0) {
+ success = true;
+ int len = stdout.read(buffer);
+ if (len > 0)
+ System.out.println(new String(buffer, 0, len));
+ }
+
+ while (stderr.available() > 0) {
+ /* int len = */stderr.read(buffer);
+ }
+ }
+
+ sess.close();
+ conn.close();
+
+ if (!success) {
+ System.out.println("ERROR: SSH Linux Network test failed: unable to setup httpd");
+ System.exit(1);
+ }
+ } catch (Exception e) {
+ System.out.println("ERROR: SSH Linux Network test fail with error " + e.getMessage());
+ System.exit(1);
+ }
+ System.out.println("Httpd is setup succesfully on the user vm");
+ }
+
+ public static String createDeployment() {
+ //1) deployVm
+ String urlToSign = "command=deployVirtualMachine&serviceOfferingId=" + properties.getProperty("serviceOfferingId") +
+ "&networkId=" + properties.getProperty("networkId") +
+ "&templateId=" + properties.getProperty("templateId") + "&zoneId=" + properties.getProperty("zoneId");
+ String url = UtilsForTest.signUrl(urlToSign, properties.getProperty("apikey"),
+ properties.getProperty("secretkey"));
+ System.out.println("http://" + properties.getProperty("hostname") + ":8080/client/api?" + url);
+ long vmId=3;
+
+ //2) List public IP address - source nat
+ urlToSign = "command=listPublicIpAddresses&zoneId=" + properties.getProperty("zoneId");
+ url = UtilsForTest.signUrl(urlToSign, properties.getProperty("apikey"),
+ properties.getProperty("secretkey"));
+ System.out.println("http://" + properties.getProperty("hostname") + ":8080/client/api?" + url);
+ long ipId=67;
+
+ //3) create portForwarding rules for port 22 and 80
+ urlToSign = "command=createPortForwardingRule&privateport=22&publicport=22&protocol=tcp&ipaddressid=" + ipId +
+ "&virtualmachineid=" + vmId;
+ url = UtilsForTest.signUrl(urlToSign, properties.getProperty("apikey"),
+ properties.getProperty("secretkey"));
+ System.out.println("http://" + properties.getProperty("hostname") + ":8080/client/api?" + url);
+
+ urlToSign = "command=createPortForwardingRule&privateport=80&publicport=80&protocol=tcp&ipaddressid=" + ipId +
+ "&virtualmachineid=" + vmId;
+ url = UtilsForTest.signUrl(urlToSign, properties.getProperty("apikey"),
+ properties.getProperty("secretkey"));
+ System.out.println("http://" + properties.getProperty("hostname") + ":8080/client/api?" + url);
+
+
+ return "10.223.153.76";
+ }
+
+}
+
diff --git a/test/src/com/cloud/test/utils/UtilsForTest.java b/test/src/com/cloud/test/utils/UtilsForTest.java
index 4c09b118fc0..90901da6e7a 100644
--- a/test/src/com/cloud/test/utils/UtilsForTest.java
+++ b/test/src/com/cloud/test/utils/UtilsForTest.java
@@ -14,12 +14,17 @@ package com.cloud.test.utils;
import java.io.InputStream;
import java.math.BigInteger;
+import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.TreeMap;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
@@ -228,6 +233,61 @@ public class UtilsForTest {
ex.printStackTrace();
}
return null;
+ }
+
+ public static String signUrl(String url, String apiKey, String secretKey) {
+
+ //sorted map (sort by key)
+ TreeMap param = new TreeMap();
+
+ String temp = "";
+ param.put("apikey", apiKey);
+
+ //1) Parse the URL and put all parameters to sorted map
+ StringTokenizer str1 = new StringTokenizer (url, "&");
+ while(str1.hasMoreTokens()) {
+ String newEl = str1.nextToken();
+ StringTokenizer str2 = new StringTokenizer(newEl, "=");
+ String name = str2.nextToken();
+ String value= str2.nextToken();
+ param.put(name, value);
+ }
+
+ //2) URL encode parameters' values
+ Set> c = param.entrySet();
+ Iterator> it = c.iterator();
+ while (it.hasNext()) {
+ Map.Entry me = (Map.Entry)it.next();
+ String key = (String) me.getKey();
+ String value = (String) me.getValue();
+ try {
+ temp = temp + key + "=" + URLEncoder.encode(value, "UTF-8") + "&";
+ } catch (Exception ex) {
+ System.out.println("Unable to set parameter " + value + " for the command " + param.get("command"));
+ System.exit(1);
+ }
+
+ }
+ temp = temp.substring(0, temp.length()-1 );
+
+ //3) Lower case the request
+ String requestToSign = temp.toLowerCase();
+
+ //4) Generate the signature
+ String signature = UtilsForTest.signRequest(requestToSign, secretKey);
+
+ //5) Encode the signature
+ String encodedSignature = "";
+ try {
+ encodedSignature = URLEncoder.encode(signature, "UTF-8");
+ } catch (Exception ex) {
+ System.out.println(ex);
+ System.exit(1);
+ }
+
+ //6) append the signature to the url
+ url = temp + "&signature=" + encodedSignature;
+ return url;
}
}