tested ip and port forwarding rules on cloudstack

This commit is contained in:
Adrian Cole 2011-02-20 19:19:03 -08:00
parent 9943169a80
commit 90d3cf4654
9 changed files with 412 additions and 43 deletions

View File

@ -0,0 +1,295 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.jclouds.cloudstack.domain;
import com.google.gson.annotations.SerializedName;
/**
*
* @author Adrian Cole
*/
public class IPForwardingRule implements Comparable<IPForwardingRule> {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private long id;
private String IPAddress;
private long IPAddressId;
private int startPort;
private String protocol;
public int endPort;
private String state;
private String virtualMachineDisplayName;
public long virtualMachineId;
private String virtualMachineName;
public Builder id(long id) {
this.id = id;
return this;
}
public Builder IPAddress(String IPAddress) {
this.IPAddress = IPAddress;
return this;
}
public Builder IPAddressId(long IPAddressId) {
this.IPAddressId = IPAddressId;
return this;
}
public Builder startPort(int startPort) {
this.startPort = startPort;
return this;
}
public Builder protocol(String protocol) {
this.protocol = protocol;
return this;
}
public Builder endPort(int endPort) {
this.endPort = endPort;
return this;
}
public Builder state(String state) {
this.state = state;
return this;
}
public Builder virtualMachineDisplayName(String virtualMachineDisplayName) {
this.virtualMachineDisplayName = virtualMachineDisplayName;
return this;
}
public Builder virtualMachineId(long virtualMachineId) {
this.virtualMachineId = virtualMachineId;
return this;
}
public Builder virtualMachineName(String virtualMachineName) {
this.virtualMachineName = virtualMachineName;
return this;
}
public IPForwardingRule build() {
return new IPForwardingRule(id, IPAddress, IPAddressId, startPort, protocol, endPort, state,
virtualMachineDisplayName, virtualMachineId, virtualMachineName);
}
}
private long id;
@SerializedName("ipaddress")
private String IPAddress;
@SerializedName("ipaddressid")
private long IPAddressId;
@SerializedName("startport")
private int startPort;
private String protocol;
@SerializedName("endport")
public int endPort;
private String state;
@SerializedName("virtualmachinedisplayname")
private String virtualMachineDisplayName;
@SerializedName("virtualmachineid")
public long virtualMachineId;
@SerializedName("virtualmachinename")
private String virtualMachineName;
// for deserializer
IPForwardingRule() {
}
public IPForwardingRule(long id, String iPAddress, long iPAddressId, int startPort, String protocol, int endPort,
String state, String virtualMachineDisplayName, long virtualMachineId, String virtualMachineName) {
this.id = id;
this.IPAddress = iPAddress;
this.IPAddressId = iPAddressId;
this.startPort = startPort;
this.protocol = protocol;
this.endPort = endPort;
this.state = state;
this.virtualMachineDisplayName = virtualMachineDisplayName;
this.virtualMachineId = virtualMachineId;
this.virtualMachineName = virtualMachineName;
}
@Override
public int compareTo(IPForwardingRule arg0) {
return new Long(id).compareTo(arg0.getId());
}
/**
*
* @return the ID of the ip forwarding rule
*/
public long getId() {
return id;
}
/**
*
* @return the public ip address for the ip forwarding rule
*/
public String getIPAddress() {
return IPAddress;
}
/**
*
* @return the public ip address id for the ip forwarding rule
*/
public long getIPAddressId() {
return IPAddressId;
}
/**
*
* @return the private port for the ip forwarding rule
*/
public int getStartPort() {
return startPort;
}
/**
*
* @return the protocol of the ip forwarding rule
*/
public String getProtocol() {
return protocol;
}
/**
*
* @return the public port for the ip forwarding rule
*/
public int getEndPort() {
return endPort;
}
/**
*
* @return the state of the rule
*/
public String getState() {
return state;
}
/**
*
* @return the VM display name for the ip forwarding rule
*/
public String getVirtualMachineDisplayName() {
return virtualMachineDisplayName;
}
/**
*
* @return the VM ID for the ip forwarding rule
*/
public long getVirtualMachineId() {
return virtualMachineId;
}
/**
*
* @return the VM name for the ip forwarding rule
*/
public String getVirtualMachineName() {
return virtualMachineName;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((IPAddress == null) ? 0 : IPAddress.hashCode());
result = prime * result + (int) (IPAddressId ^ (IPAddressId >>> 32));
result = prime * result + endPort;
result = prime * result + (int) (id ^ (id >>> 32));
result = prime * result + ((protocol == null) ? 0 : protocol.hashCode());
result = prime * result + startPort;
result = prime * result + ((state == null) ? 0 : state.hashCode());
result = prime * result + ((virtualMachineDisplayName == null) ? 0 : virtualMachineDisplayName.hashCode());
result = prime * result + (int) (virtualMachineId ^ (virtualMachineId >>> 32));
result = prime * result + ((virtualMachineName == null) ? 0 : virtualMachineName.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
IPForwardingRule other = (IPForwardingRule) obj;
if (IPAddress == null) {
if (other.IPAddress != null)
return false;
} else if (!IPAddress.equals(other.IPAddress))
return false;
if (IPAddressId != other.IPAddressId)
return false;
if (endPort != other.endPort)
return false;
if (id != other.id)
return false;
if (protocol == null) {
if (other.protocol != null)
return false;
} else if (!protocol.equals(other.protocol))
return false;
if (startPort != other.startPort)
return false;
if (state == null) {
if (other.state != null)
return false;
} else if (!state.equals(other.state))
return false;
if (virtualMachineDisplayName == null) {
if (other.virtualMachineDisplayName != null)
return false;
} else if (!virtualMachineDisplayName.equals(other.virtualMachineDisplayName))
return false;
if (virtualMachineId != other.virtualMachineId)
return false;
if (virtualMachineName == null) {
if (other.virtualMachineName != null)
return false;
} else if (!virtualMachineName.equals(other.virtualMachineName))
return false;
return true;
}
@Override
public String toString() {
return "[IPAddress=" + IPAddress + ", IPAddressId=" + IPAddressId + ", id=" + id + ", startPort=" + startPort
+ ", protocol=" + protocol + ", endPort=" + endPort + ", state=" + state
+ ", virtualMachineDisplayName=" + virtualMachineDisplayName + ", virtualMachineId=" + virtualMachineId
+ ", virtualMachineName=" + virtualMachineName + "]";
}
}

View File

@ -27,7 +27,7 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
import org.jclouds.cloudstack.domain.PortForwardingRule;
import org.jclouds.cloudstack.domain.IPForwardingRule;
import org.jclouds.cloudstack.filters.QuerySigner;
import org.jclouds.cloudstack.options.CreateIPForwardingRuleOptions;
import org.jclouds.cloudstack.options.ListIPForwardingRulesOptions;
@ -37,7 +37,6 @@ import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.Unwrap;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture;
@ -61,7 +60,7 @@ public interface NATAsyncClient {
@Unwrap(depth = 2)
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<PortForwardingRule>> listIPForwardingRules(ListIPForwardingRulesOptions... options);
ListenableFuture<Set<IPForwardingRule>> listIPForwardingRules(ListIPForwardingRulesOptions... options);
/**
* @see NATClient#getIPForwardingRule
@ -71,7 +70,7 @@ public interface NATAsyncClient {
@Unwrap(depth = 3, edgeCollection = Set.class)
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<PortForwardingRule> getIPForwardingRule(@QueryParam("id") long id);
ListenableFuture<IPForwardingRule> getIPForwardingRule(@QueryParam("id") long id);
/**
* @see NATClient#createIPForwardingRuleForVirtualMachine
@ -86,11 +85,23 @@ public interface NATAsyncClient {
CreateIPForwardingRuleOptions... options);
/**
* @see NATClient#deleteIpForwardingRule
* @see NATClient#enableStaticNATForVirtualMachine
*/
@GET
@QueryParams(keys = "command", values = "enableStaticNat")
@Unwrap
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<AsyncCreateResponse> enableStaticNATForVirtualMachine(
@QueryParam("virtualmachineid") long virtualMachineId, @QueryParam("ipaddressid") long IPAddressId);
/**
* @see NATClient#deleteIPForwardingRule
*/
@GET
@QueryParams(keys = "command", values = "deleteIpForwardingRule")
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> deleteIPForwardingRule(@QueryParam("id") long id);
@Unwrap(depth = 2)
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Long> deleteIPForwardingRule(@QueryParam("id") long id);
}

View File

@ -23,7 +23,7 @@ import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
import org.jclouds.cloudstack.domain.PortForwardingRule;
import org.jclouds.cloudstack.domain.IPForwardingRule;
import org.jclouds.cloudstack.options.CreateIPForwardingRuleOptions;
import org.jclouds.cloudstack.options.ListIPForwardingRulesOptions;
import org.jclouds.concurrent.Timeout;
@ -45,7 +45,7 @@ public interface NATClient {
* if present, how to constrain the list.
* @return IPForwardingRulees matching query, or empty set, if no IPForwardingRulees are found
*/
Set<PortForwardingRule> listIPForwardingRules(ListIPForwardingRulesOptions... options);
Set<IPForwardingRule> listIPForwardingRules(ListIPForwardingRulesOptions... options);
/**
* get a specific IPForwardingRule by id
@ -54,7 +54,7 @@ public interface NATClient {
* IPForwardingRule to get
* @return IPForwardingRule or null if not found
*/
PortForwardingRule getIPForwardingRule(long id);
IPForwardingRule getIPForwardingRule(long id);
/**
* Creates an ip forwarding rule
@ -79,5 +79,7 @@ public interface NATClient {
* @param id
* the id of the forwarding rule
*/
void deleteIPForwardingRule(long id);
Long deleteIPForwardingRule(long id);
AsyncCreateResponse enableStaticNATForVirtualMachine(long virtualMachineId, long IPAddressId);
}

View File

@ -53,11 +53,6 @@ public class AsyncJobClientLiveTest extends BaseCloudStackClientLiveTest {
assert asyncJob.getAccountId() >= 0 : asyncJob;
assert asyncJob.getCmd() != null : asyncJob;
assert asyncJob.getCreated() != null : asyncJob;
// seemingly unused fields
assert asyncJob.getInstanceId() == -1 : asyncJob;
assert asyncJob.getInstanceType() == null : asyncJob;
assert asyncJob.getResultType() == null : asyncJob;
// end
if (asyncJob.getProgress() > 0) {
assert asyncJob.getResult() == null : asyncJob;
assert asyncJob.getResultCode() == -1 : asyncJob;

View File

@ -20,6 +20,7 @@
package org.jclouds.cloudstack.features;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
@ -31,17 +32,22 @@ import org.jclouds.cloudstack.domain.VirtualMachine;
import org.jclouds.cloudstack.predicates.JobComplete;
import org.jclouds.cloudstack.predicates.VirtualMachineDestroyed;
import org.jclouds.cloudstack.predicates.VirtualMachineRunning;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.domain.Credentials;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.InetSocketAddressConnect;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Module;
/**
@ -62,17 +68,33 @@ public class BaseCloudStackClientLiveTest {
protected RetryablePredicate<Long> jobComplete;
protected RetryablePredicate<VirtualMachine> virtualMachineRunning;
protected RetryablePredicate<VirtualMachine> virtualMachineDestroyed;
protected SshClient.Factory sshFactory;
protected void setupCredentials() {
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider
+ ".identity must be set. ex. apiKey");
+ ".identity must be set. ex. apiKey");
credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider
+ ".credential must be set. ex. secretKey");
+ ".credential must be set. ex. secretKey");
endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider
+ ".endpoint must be set. ex. http://localhost:8080/client/api");
+ ".endpoint must be set. ex. http://localhost:8080/client/api");
apiversion = System.getProperty("test." + provider + ".apiversion");
}
protected void checkSSH(String address, int port) {
IPSocket socket = new IPSocket(address, port);
socketTester.apply(socket);
SshClient client = sshFactory.create(socket, new Credentials("root", "password"));
try {
client.connect();
ExecResponse exec = client.exec("echo hello");
System.out.println(exec);
assertEquals(exec.getOutput().trim(), "hello");
} finally {
if (client != null)
client.disconnect();
}
}
protected Properties setupProperties() {
Properties overrides = new Properties();
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
@ -90,9 +112,10 @@ public class BaseCloudStackClientLiveTest {
setupCredentials();
Properties overrides = setupProperties();
context = new RestContextFactory().createContext(provider, ImmutableSet.<Module> of(new Log4JLoggingModule()),
overrides);
overrides);
client = context.getApi();
sshFactory = Guice.createInjector(new JschSshClientModule()).getInstance(SshClient.Factory.class);
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 180, 1, TimeUnit.SECONDS);
jobComplete = new RetryablePredicate<Long>(new JobComplete(client), 600, 5, TimeUnit.SECONDS);
virtualMachineRunning = new RetryablePredicate<VirtualMachine>(new VirtualMachineRunning(client), 600, 5,

View File

@ -29,7 +29,10 @@ import org.jclouds.cloudstack.domain.AsyncCreateResponse;
import org.jclouds.cloudstack.domain.PortForwardingRule;
import org.jclouds.cloudstack.domain.PublicIPAddress;
import org.jclouds.cloudstack.domain.VirtualMachine;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.domain.Credentials;
import org.jclouds.net.IPSocket;
import org.jclouds.ssh.SshClient;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
@ -67,6 +70,15 @@ public class FirewallClientLiveTest extends BaseCloudStackClientLiveTest {
checkRule(rule);
IPSocket socket = new IPSocket(ip.getIPAddress(), 22);
socketTester.apply(socket);
SshClient client = sshFactory.create(socket, new Credentials("root", "password"));
try {
client.connect();
ExecResponse exec = client.exec("echo hello");
assertEquals(exec.getOutput().trim(), "hello");
} finally {
if (client != null)
client.disconnect();
}
}
@AfterGroups(groups = "live")

View File

@ -25,14 +25,12 @@ import java.lang.reflect.Method;
import org.jclouds.cloudstack.options.CreateIPForwardingRuleOptions;
import org.jclouds.cloudstack.options.ListIPForwardingRulesOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValueInSet;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
@ -68,8 +66,7 @@ public class NATAsyncClientTest extends BaseCloudStackAsyncClientTest<NATAsyncCl
HttpRequest httpRequest = processor.createRequest(method, ListIPForwardingRulesOptions.Builder
.virtualMachineId(3));
assertRequestLineEquals(
httpRequest,
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=listIpForwardingRules&virtualmachineid=3 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
@ -105,7 +102,8 @@ public class NATAsyncClientTest extends BaseCloudStackAsyncClientTest<NATAsyncCl
String.class, int.class, CreateIPForwardingRuleOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, 6, 7, "tcp", 22);
assertRequestLineEquals(httpRequest,
assertRequestLineEquals(
httpRequest,
"GET http://localhost:8080/client/api?response=json&command=createIpForwardingRule&virtualmachineid=6&protocol=tcp&ipaddressid=7&startport=22 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
@ -125,7 +123,8 @@ public class NATAsyncClientTest extends BaseCloudStackAsyncClientTest<NATAsyncCl
HttpRequest httpRequest = processor.createRequest(method, 6, 7, "tcp", 22, CreateIPForwardingRuleOptions.Builder
.endPort(22));
assertRequestLineEquals(httpRequest,
assertRequestLineEquals(
httpRequest,
"GET http://localhost:8080/client/api?response=json&command=createIpForwardingRule&virtualmachineid=6&protocol=tcp&ipaddressid=7&startport=22&endport=22 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
@ -138,18 +137,35 @@ public class NATAsyncClientTest extends BaseCloudStackAsyncClientTest<NATAsyncCl
}
public void testEnableStaticNATForVirtualMachine() throws SecurityException, NoSuchMethodException, IOException {
Method method = NATAsyncClient.class.getMethod("enableStaticNATForVirtualMachine", long.class, long.class);
HttpRequest httpRequest = processor.createRequest(method, 5, 6);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=enableStaticNat&virtualmachineid=5&ipaddressid=6 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testDeleteIPForwardingRule() throws SecurityException, NoSuchMethodException, IOException {
Method method = NATAsyncClient.class.getMethod("deleteIPForwardingRule", long.class);
HttpRequest httpRequest = processor.createRequest(method, 5);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=deleteIpForwardingRule&id=5 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);

View File

@ -26,11 +26,14 @@ import static org.testng.Assert.assertTrue;
import java.util.Set;
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
import org.jclouds.cloudstack.domain.PortForwardingRule;
import org.jclouds.cloudstack.domain.IPForwardingRule;
import org.jclouds.cloudstack.domain.PublicIPAddress;
import org.jclouds.cloudstack.domain.VirtualMachine;
import org.jclouds.cloudstack.options.ListIPForwardingRulesOptions;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.domain.Credentials;
import org.jclouds.net.IPSocket;
import org.jclouds.ssh.SshClient;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
@ -44,29 +47,43 @@ import org.testng.annotations.Test;
public class NATClientLiveTest extends BaseCloudStackClientLiveTest {
private PublicIPAddress ip = null;
private VirtualMachine vm;
private PortForwardingRule rule;
private IPForwardingRule rule;
@BeforeGroups(groups = "live")
public void setupClient() {
super.setupClient();
prefix += "rule";
prefix += "nat";
ip = AddressClientLiveTest.createPublicIPAddress(client, jobComplete);
vm = VirtualMachineClientLiveTest.createVirtualMachine(client, jobComplete, virtualMachineRunning);
}
public void testCreateIPForwardingRule() throws Exception {
// TODO check for 1-1 Nat feature
assert !ip.isStaticNAT();
client.getNATClient().enableStaticNATForVirtualMachine(vm.getId(), ip.getId());
ip = client.getAddressClient().getPublicIPAddress(ip.getId());
assert ip.isStaticNAT();
AsyncCreateResponse job = client.getNATClient().createIPForwardingRuleForVirtualMachine(vm.getId(), ip.getId(),
"tcp", 22);
assert jobComplete.apply(job.getJobId());
rule = client.getNATClient().getIPForwardingRule(job.getId());
assertEquals(rule.getIPAddressId(), ip.getId());
assertEquals(rule.getVirtualMachineId(), vm.getId());
assertEquals(rule.getPublicPort(), 22);
assertEquals(rule.getStartPort(), 22);
assertEquals(rule.getProtocol(), "tcp");
checkRule(rule);
IPSocket socket = new IPSocket(ip.getIPAddress(), 22);
socketTester.apply(socket);
SshClient client = sshFactory.create(socket, new Credentials("root", "password"));
try {
client.connect();
ExecResponse exec = client.exec("echo hello");
assertEquals(exec.getOutput().trim(), "hello");
} finally {
if (client != null)
client.disconnect();
}
}
@AfterGroups(groups = "live")
@ -84,27 +101,26 @@ public class NATClientLiveTest extends BaseCloudStackClientLiveTest {
}
public void testListIPForwardingRules() throws Exception {
Set<PortForwardingRule> response = client.getNATClient().listIPForwardingRules();
Set<IPForwardingRule> response = client.getNATClient().listIPForwardingRules();
assert null != response;
assertTrue(response.size() >= 0);
for (PortForwardingRule rule : response) {
PortForwardingRule newDetails = getOnlyElement(client.getNATClient().listIPForwardingRules(
for (IPForwardingRule rule : response) {
IPForwardingRule newDetails = getOnlyElement(client.getNATClient().listIPForwardingRules(
ListIPForwardingRulesOptions.Builder.id(rule.getId())));
assertEquals(rule.getId(), newDetails.getId());
checkRule(rule);
}
}
protected void checkRule(PortForwardingRule rule) {
protected void checkRule(IPForwardingRule rule) {
assertEquals(rule.getId(), client.getNATClient().getIPForwardingRule(rule.getId()).getId());
assert rule.getId() > 0 : rule;
assert rule.getIPAddress() != null : rule;
assert rule.getIPAddressId() > 0 : rule;
assert rule.getPrivatePort() > 0 : rule;
assert rule.getStartPort() > 0 : rule;
assert rule.getProtocol() != null : rule;
assert rule.getPublicPort() > 0 : rule;
assert rule.getEndPort() > 0 : rule;
assert rule.getState() != null : rule;
assert rule.getVirtualMachineDisplayName() != null : rule;
assert rule.getVirtualMachineId() > 0 : rule;
assert rule.getVirtualMachineName() != null : rule;

View File

@ -117,7 +117,6 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest {
public void testCreateDestroyVirtualMachine() throws Exception {
vm = createVirtualMachine(client, jobComplete, virtualMachineRunning);
assertEquals(vm.getRootDeviceType(), "NetworkFilesystem");
checkVm(vm);
}