mirror of https://github.com/apache/jclouds.git
Reuse existing network for vlan IP range test if available
This commit is contained in:
parent
6192926b28
commit
225b2a3d46
|
@ -18,22 +18,30 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.cloudstack.features;
|
package org.jclouds.cloudstack.features;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import org.jclouds.cloudstack.domain.Network;
|
import org.jclouds.cloudstack.domain.Network;
|
||||||
import org.jclouds.cloudstack.domain.NetworkOffering;
|
import org.jclouds.cloudstack.domain.NetworkOffering;
|
||||||
|
import org.jclouds.cloudstack.domain.TrafficType;
|
||||||
import org.jclouds.cloudstack.domain.VlanIPRange;
|
import org.jclouds.cloudstack.domain.VlanIPRange;
|
||||||
import org.jclouds.cloudstack.domain.Zone;
|
import org.jclouds.cloudstack.domain.Zone;
|
||||||
import org.jclouds.cloudstack.options.CreateVlanIPRangeOptions;
|
import org.jclouds.cloudstack.options.CreateVlanIPRangeOptions;
|
||||||
|
import org.jclouds.cloudstack.options.ListNetworksOptions;
|
||||||
import org.jclouds.cloudstack.options.ListVlanIPRangesOptions;
|
import org.jclouds.cloudstack.options.ListVlanIPRangesOptions;
|
||||||
import org.jclouds.cloudstack.predicates.NetworkOfferingPredicates;
|
import org.jclouds.cloudstack.predicates.NetworkOfferingPredicates;
|
||||||
import org.jclouds.cloudstack.predicates.ZonePredicates;
|
import org.jclouds.cloudstack.predicates.ZonePredicates;
|
||||||
import org.testng.annotations.AfterClass;
|
import org.testng.annotations.AfterClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static com.google.common.collect.Iterables.filter;
|
||||||
import static com.google.common.collect.Iterables.find;
|
import static com.google.common.collect.Iterables.find;
|
||||||
|
import static com.google.common.collect.Iterables.getFirst;
|
||||||
|
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.zoneId;
|
||||||
import static org.testng.Assert.*;
|
import static org.testng.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,6 +53,8 @@ import static org.testng.Assert.*;
|
||||||
public class GlobalVlanClientLiveTest extends BaseCloudStackClientLiveTest {
|
public class GlobalVlanClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
|
|
||||||
private Network network;
|
private Network network;
|
||||||
|
private boolean usingExistingNetwork;
|
||||||
|
|
||||||
private VlanIPRange range;
|
private VlanIPRange range;
|
||||||
|
|
||||||
public void testListVlanIPRanges() throws Exception {
|
public void testListVlanIPRanges() throws Exception {
|
||||||
|
@ -72,10 +82,28 @@ public class GlobalVlanClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateVlanIPRange() {
|
public void testCreateVlanIPRange() {
|
||||||
Zone zone = Iterables.find(client.getZoneClient().listZones(), ZonePredicates.supportsAdvancedNetworks());
|
final Zone zone = Iterables.find(client.getZoneClient().listZones(), ZonePredicates.supportsAdvancedNetworks());
|
||||||
NetworkOffering offering = find(client.getOfferingClient().listNetworkOfferings(), NetworkOfferingPredicates.supportsGuestVirtualNetworks());
|
final NetworkOffering offering = find(client.getOfferingClient().listNetworkOfferings(),
|
||||||
|
NetworkOfferingPredicates.supportsGuestVirtualNetworks());
|
||||||
|
|
||||||
network = client.getNetworkClient().createNetworkInZone(zone.getId(), offering.getId(), "net-"+prefix, "jclouds test "+prefix);
|
Set<Network> suitableNetworks = Sets.filter(client.getNetworkClient().listNetworks(
|
||||||
|
zoneId(zone.getId()).isSystem(false).trafficType(TrafficType.GUEST)),
|
||||||
|
new Predicate<Network>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(Network network) {
|
||||||
|
return network.getNetworkOfferingId() == offering.getId();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (suitableNetworks.size() > 0) {
|
||||||
|
network = Iterables.get(suitableNetworks, 0);
|
||||||
|
usingExistingNetwork = true;
|
||||||
|
|
||||||
|
} else if (network == null) {
|
||||||
|
network = client.getNetworkClient().createNetworkInZone(zone.getId(),
|
||||||
|
offering.getId(), "net-" + prefix, "jclouds test " + prefix);
|
||||||
|
usingExistingNetwork = false;
|
||||||
|
}
|
||||||
|
|
||||||
range = globalAdminClient.getVlanClient().createVlanIPRange("172.19.1.1", "172.19.1.199", CreateVlanIPRangeOptions.Builder
|
range = globalAdminClient.getVlanClient().createVlanIPRange("172.19.1.1", "172.19.1.199", CreateVlanIPRangeOptions.Builder
|
||||||
.accountInDomain(user.getAccount(), user.getDomainId())
|
.accountInDomain(user.getAccount(), user.getDomainId())
|
||||||
|
@ -91,7 +119,7 @@ public class GlobalVlanClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
globalAdminClient.getVlanClient().deleteVlanIPRange(range.getId());
|
globalAdminClient.getVlanClient().deleteVlanIPRange(range.getId());
|
||||||
range = null;
|
range = null;
|
||||||
}
|
}
|
||||||
if (network != null) {
|
if (network != null && !usingExistingNetwork) {
|
||||||
client.getNetworkClient().deleteNetwork(network.getId());
|
client.getNetworkClient().deleteNetwork(network.getId());
|
||||||
network = null;
|
network = null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue