Repository: jclouds-labs Updated Branches: refs/heads/master 75178c770 -> a7dd1933d
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a7dd1933/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/compute/functions/NICToAddressTest.java ---------------------------------------------------------------------- diff --git a/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/compute/functions/NICToAddressTest.java b/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/compute/functions/NICToAddressTest.java new file mode 100644 index 0000000..70d6b8b --- /dev/null +++ b/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/compute/functions/NICToAddressTest.java @@ -0,0 +1,90 @@ +/* + * 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.jclouds.cloudsigma2.compute.functions; + +import com.google.common.collect.ImmutableList; +import org.jclouds.cloudsigma2.domain.FirewallPolicy; +import org.jclouds.cloudsigma2.domain.FirewallRule; +import org.jclouds.cloudsigma2.domain.IP; +import org.jclouds.cloudsigma2.domain.IPConfiguration; +import org.jclouds.cloudsigma2.domain.IPConfigurationType; +import org.jclouds.cloudsigma2.domain.NIC; +import org.jclouds.cloudsigma2.domain.VLANInfo; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.testng.collections.Lists; + +import java.net.URI; +import java.util.List; + +import static org.testng.Assert.assertEquals; + +@Test(groups = "unit", testName = "NICToAddressTest") +public class NICToAddressTest { + + private List<NIC> input; + private List<String> expected; + + @BeforeMethod + public void setUp() throws Exception { + input = ImmutableList.of( + new NIC.Builder() + .firewallPolicy(new FirewallPolicy.Builder() + .name("firewall") + .rules(ImmutableList.of(new FirewallRule.Builder() + .sourcePort("22") + .destinationPort("123") + .sourceIp("1.2.3.4") + .destinationIp("11.22.33.44") + .build())) + .build()) + .build(), + new NIC.Builder() + .vlan(new VLANInfo.Builder() + .uuid("a21a4e59-b133-487a-ad7b-16b41ac38e9b") + .resourceUri(new URI("/api/2.0/vlans/a21a4e59-b133-487a-ad7b-16b41ac38e9b/")) + .build()) + .build(), + new NIC.Builder() + .ipV4Configuration(new IPConfiguration.Builder() + .configurationType(IPConfigurationType.STATIC) + .ip(new IP.Builder() + .uuid("1.2.3.4") + .resourceUri(new URI("api/2.0/ips/1.2.3.4/")) + .build()) + .build()) + .build(), + new NIC.Builder() + .ipV6Configuration(new IPConfiguration.Builder() + .configurationType(IPConfigurationType.STATIC) + .ip(new IP.Builder() + .uuid("2001:0db8:0000:0000:0000:ff00:0042:8329") + .resourceUri(new URI("api/2.0/ips/2001:0db8:0000:0000:0000:ff00:0042:8329/")) + .build()) + .build()) + .build()); + + expected = Lists.newArrayList(null, null, "1.2.3.4", "2001:0db8:0000:0000:0000:ff00:0042:8329"); + } + + public void testConvertNICs() { + NICToAddress function = new NICToAddress(); + for (int i = 0; i < input.size() - 1; i++) { + assertEquals(function.apply(input.get(i)), expected.get(i)); + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a7dd1933/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/compute/functions/ServerDriveToVolumeTest.java ---------------------------------------------------------------------- diff --git a/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/compute/functions/ServerDriveToVolumeTest.java b/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/compute/functions/ServerDriveToVolumeTest.java new file mode 100644 index 0000000..d2a1c31 --- /dev/null +++ b/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/compute/functions/ServerDriveToVolumeTest.java @@ -0,0 +1,79 @@ +/* + * 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.jclouds.cloudsigma2.compute.functions; + +import org.easymock.EasyMock; +import org.jclouds.cloudsigma2.CloudSigma2Api; +import org.jclouds.cloudsigma2.domain.DeviceEmulationType; +import org.jclouds.cloudsigma2.domain.Drive; +import org.jclouds.cloudsigma2.domain.DriveInfo; +import org.jclouds.cloudsigma2.domain.ServerDrive; +import org.jclouds.compute.domain.Volume; +import org.jclouds.compute.domain.VolumeBuilder; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.math.BigInteger; + +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.testng.Assert.assertEquals; + +@Test(groups = "unit", testName = "ServerDriveToVolumeTest") +public class ServerDriveToVolumeTest { + + private ServerDrive input; + private Volume expected; + + @BeforeMethod + public void setUp() throws Exception { + input = new ServerDrive.Builder() + .bootOrder(1) + .deviceChannel("0:1") + .deviceEmulationType(DeviceEmulationType.VIRTIO) + .drive(new Drive.Builder() + .uuid("f17cce62-bcc9-4e0b-a57b-a5582b05aff0") + .build()) + .build(); + + expected = new VolumeBuilder() + .id("f17cce62-bcc9-4e0b-a57b-a5582b05aff0") + .size(1024000000.f) + .durable(true) + .type(Volume.Type.NAS) + .bootDevice(true) + .build(); + } + + public void testConvertServerDrive() { + CloudSigma2Api api = EasyMock.createMock(CloudSigma2Api.class); + + DriveInfo mockDrive = new DriveInfo.Builder() + .uuid(input.getDrive().getUuid()) + .size(new BigInteger("1024000000")) + .build(); + + expect(api.getDriveInfo(input.getDrive().getUuid())).andReturn(mockDrive); + replay(api); + + ServerDriveToVolume function = new ServerDriveToVolume(api); + assertEquals(function.apply(input), expected); + + verify(api); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a7dd1933/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/compute/functions/ServerInfoToNodeMetadataTest.java ---------------------------------------------------------------------- diff --git a/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/compute/functions/ServerInfoToNodeMetadataTest.java b/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/compute/functions/ServerInfoToNodeMetadataTest.java new file mode 100644 index 0000000..a77e928 --- /dev/null +++ b/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/compute/functions/ServerInfoToNodeMetadataTest.java @@ -0,0 +1,186 @@ +/* + * 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.jclouds.cloudsigma2.compute.functions; + +import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.name.Names; +import org.easymock.EasyMock; +import org.jclouds.cloudsigma2.CloudSigma2Api; +import org.jclouds.cloudsigma2.CloudSigma2ApiMetadata; +import org.jclouds.cloudsigma2.domain.DeviceEmulationType; +import org.jclouds.cloudsigma2.domain.Drive; +import org.jclouds.cloudsigma2.domain.DriveInfo; +import org.jclouds.cloudsigma2.domain.IP; +import org.jclouds.cloudsigma2.domain.IPConfiguration; +import org.jclouds.cloudsigma2.domain.NIC; +import org.jclouds.cloudsigma2.domain.ServerDrive; +import org.jclouds.cloudsigma2.domain.ServerInfo; +import org.jclouds.cloudsigma2.domain.ServerStatus; +import org.jclouds.cloudsigma2.domain.Tag; +import org.jclouds.compute.domain.HardwareBuilder; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeMetadataBuilder; +import org.jclouds.compute.domain.Processor; +import org.jclouds.compute.domain.Volume; +import org.jclouds.compute.domain.VolumeBuilder; +import org.jclouds.compute.functions.GroupNamingConvention; +import org.jclouds.domain.Credentials; +import org.jclouds.domain.LoginCredentials; +import org.jclouds.location.suppliers.all.JustProvider; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.math.BigInteger; +import java.net.URI; +import java.util.Map; + +import static com.google.common.collect.Iterables.getOnlyElement; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.jclouds.cloudsigma2.compute.config.CloudSigma2ComputeServiceContextModule.serverStatusToNodeStatus; +import static org.testng.Assert.assertEquals; + +@Test(groups = "unit", testName = "ServerInfoToNodeMetadataTest") +public class ServerInfoToNodeMetadataTest { + + private ServerInfo input; + private NodeMetadata expected; + private Map<String, Credentials> credentialStore; + private GroupNamingConvention.Factory namingConvention; + private LoginCredentials credentials = LoginCredentials.builder().user("ubuntu").password("ubuntu").build(); + private JustProvider justProvider; + + @BeforeMethod + public void setUp() throws Exception { + CloudSigma2ApiMetadata metadata = new CloudSigma2ApiMetadata(); + justProvider = new JustProvider(metadata.getId(), Suppliers.ofInstance(URI.create(metadata + .getDefaultEndpoint().get())), ImmutableSet.<String>of()); + + input = new ServerInfo.Builder() + .uuid("a19a425f-9e92-42f6-89fb-6361203071bb") + .name("jclouds-cloudsigma-test_acc_full_server") + .cpu(1000) + .memory(new BigInteger("268435456")) + .status(ServerStatus.STOPPED) + .drives(ImmutableList.of( + new Drive.Builder() + .uuid("ae78e68c-9daa-4471-8878-0bb87fa80260") + .resourceUri(new URI("/api/2.0/drives/ae78e68c-9daa-4471-8878-0bb87fa80260/")) + .build().toServerDrive(0, "0:0", DeviceEmulationType.IDE), + new Drive.Builder() + .uuid("22826af4-d6c8-4d39-bd41-9cea86df2976") + .resourceUri(new URI("/api/2.0/drives/22826af4-d6c8-4d39-bd41-9cea86df2976/")) + .build().toServerDrive(1, "0:0", DeviceEmulationType.VIRTIO))) + .nics(ImmutableList.of(new NIC.Builder() + .ipV4Configuration(new IPConfiguration.Builder() + .ip(new IP.Builder().uuid("1.2.3.4").build()) + .build()) + .build())) + .meta(ImmutableMap.of("foo", "bar", "image_id", "image")) + .tags(ImmutableList.of(new Tag.Builder().uuid("foo").name("foo").build(), + new Tag.Builder().uuid("jclouds-cloudsigma2-s").name("jclouds-cloudsigma2-s").build(), + new Tag.Builder().uuid("jclouds-cloudsigma2").name("jclouds-cloudsigma2").build() + )) + .build(); + + expected = new NodeMetadataBuilder() + .ids("a19a425f-9e92-42f6-89fb-6361203071bb") + .name("jclouds-cloudsigma-test_acc_full_server") + .group("jclouds-cloudsigma") + .status(NodeMetadata.Status.SUSPENDED) + .location(getOnlyElement(justProvider.get())) + .imageId("image") + .hardware(new HardwareBuilder() + .ids("a19a425f-9e92-42f6-89fb-6361203071bb") + .processor(new Processor(1, 1000)) + .ram(268435456) + .volumes(ImmutableSet.of( + new VolumeBuilder() + .id("ae78e68c-9daa-4471-8878-0bb87fa80260") + .size(1024000f) + .durable(true) + .type(Volume.Type.NAS) + .bootDevice(false) + .build(), + new VolumeBuilder() + .id("22826af4-d6c8-4d39-bd41-9cea86df2976") + .size(1024000f) + .durable(true) + .type(Volume.Type.NAS) + .bootDevice(true) + .build())) + .build()) + .publicAddresses(ImmutableSet.of("1.2.3.4")) + .userMetadata(ImmutableMap.of("foo", "bar", "image_id", "image")) + .tags(ImmutableList.of("foo", "cloudsigma2-s", "cloudsigma2")) + .credentials(credentials) + .build(); + + namingConvention = Guice.createInjector(new AbstractModule() { + @Override + protected void configure() { + Names.bindProperties(binder(), new CloudSigma2ApiMetadata().getDefaultProperties()); + } + }).getInstance(GroupNamingConvention.Factory.class); + + credentialStore = ImmutableMap.of("node#a19a425f-9e92-42f6-89fb-6361203071bb", (Credentials) credentials); + } + + public void testConvertServerInfo() { + CloudSigma2Api api = EasyMock.createMock(CloudSigma2Api.class); + + for (ServerDrive drive : input.getDrives()) { + DriveInfo mockDrive = new DriveInfo.Builder() + .uuid(drive.getDriveUuid()) + .size(new BigInteger("1024000")) + .build(); + + expect(api.getDriveInfo(drive.getDriveUuid())).andReturn(mockDrive); + } + + // tags + expect(api.getTagInfo("foo")).andReturn(new Tag.Builder().name("foo").build()); + expect(api.getTagInfo("jclouds-cloudsigma2-s")).andReturn(new Tag.Builder().name("jclouds-cloudsigma2-s") + .build()); + expect(api.getTagInfo("jclouds-cloudsigma2")).andReturn(new Tag.Builder().name("jclouds-cloudsigma2").build()); + + replay(api); + + ServerInfoToNodeMetadata function = new ServerInfoToNodeMetadata(new ServerDriveToVolume(api), new NICToAddress(), + serverStatusToNodeStatus, namingConvention, credentialStore, justProvider, api); + + NodeMetadata converted = function.apply(input); + assertEquals(converted, expected); + assertEquals(converted.getName(), expected.getName()); + assertEquals(converted.getStatus(), expected.getStatus()); + assertEquals(converted.getPublicAddresses(), expected.getPublicAddresses()); + assertEquals(converted.getImageId(), expected.getImageId()); + assertEquals(converted.getHardware(), expected.getHardware()); + assertEquals(converted.getCredentials(), expected.getCredentials()); + assertEquals(converted.getGroup(), expected.getGroup()); + assertEquals(converted.getTags(), expected.getTags()); + assertEquals(converted.getUserMetadata(), expected.getUserMetadata()); + + verify(api); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a7dd1933/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/compute/functions/TemplateOptionsToStatementWithoutPublicKeyTest.java ---------------------------------------------------------------------- diff --git a/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/compute/functions/TemplateOptionsToStatementWithoutPublicKeyTest.java b/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/compute/functions/TemplateOptionsToStatementWithoutPublicKeyTest.java new file mode 100644 index 0000000..93caac0 --- /dev/null +++ b/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/compute/functions/TemplateOptionsToStatementWithoutPublicKeyTest.java @@ -0,0 +1,75 @@ +/* + * 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.jclouds.cloudsigma2.compute.functions; + +import org.jclouds.compute.options.TemplateOptions; +import org.jclouds.scriptbuilder.domain.OsFamily; +import org.jclouds.scriptbuilder.domain.Statement; +import org.jclouds.scriptbuilder.domain.StatementList; +import org.jclouds.scriptbuilder.statements.ssh.InstallRSAPrivateKey; +import org.jclouds.ssh.SshKeys; +import org.testng.annotations.Test; + +import java.util.Map; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +/** + * Unit tests for the {@link TemplateOptionsToStatementWithoutPublicKey} class. + */ +@Test(groups = "unit", testName = "TemplateOptionsToStatementWithoutPublicKeyTest") +public class TemplateOptionsToStatementWithoutPublicKeyTest { + + @Test + public void testPublicKeyDoesNotGenerateAuthorizePublicKeyStatementIfOnlyPublicKeyOptionsConfigured() { + Map<String, String> keys = SshKeys.generate(); + TemplateOptions options = TemplateOptions.Builder.authorizePublicKey(keys.get("public")); + + TemplateOptionsToStatementWithoutPublicKey function = new TemplateOptionsToStatementWithoutPublicKey(); + assertNull(function.apply(options)); + } + + @Test + public void testPublicAndRunScriptKeyDoesNotGenerateAuthorizePublicKeyStatementIfRunScriptPresent() { + Map<String, String> keys = SshKeys.generate(); + TemplateOptions options = TemplateOptions.Builder.authorizePublicKey(keys.get("public")).runScript("uptime"); + + TemplateOptionsToStatementWithoutPublicKey function = new TemplateOptionsToStatementWithoutPublicKey(); + Statement statement = function.apply(options); + + assertEquals(statement.render(OsFamily.UNIX), "uptime\n"); + } + + @Test + public void testPublicAndPrivateKeyAndRunScriptDoesNotGenerateAuthorizePublicKeyStatementIfOtherOptionsPresent() { + Map<String, String> keys = SshKeys.generate(); + TemplateOptions options = TemplateOptions.Builder.authorizePublicKey(keys.get("public")) + .installPrivateKey(keys.get("private")).runScript("uptime"); + + TemplateOptionsToStatementWithoutPublicKey function = new TemplateOptionsToStatementWithoutPublicKey(); + Statement statement = function.apply(options); + + assertTrue(statement instanceof StatementList); + StatementList statements = (StatementList) statement; + + assertEquals(statements.size(), 2); + assertEquals(statements.get(0).render(OsFamily.UNIX), "uptime\n"); + assertTrue(statements.get(1) instanceof InstallRSAPrivateKey); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a7dd1933/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/compute/options/CloudSigma2TemplateOptionsTest.java ---------------------------------------------------------------------- diff --git a/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/compute/options/CloudSigma2TemplateOptionsTest.java b/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/compute/options/CloudSigma2TemplateOptionsTest.java new file mode 100644 index 0000000..503e7ee --- /dev/null +++ b/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/compute/options/CloudSigma2TemplateOptionsTest.java @@ -0,0 +1,49 @@ +/* + * 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.jclouds.cloudsigma2.compute.options; + +import org.jclouds.cloudsigma2.domain.DeviceEmulationType; +import org.jclouds.cloudsigma2.domain.Model; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; + +@Test(groups = "unit", testName = "CloudSigma2TemplateOptionsTest") +public class CloudSigma2TemplateOptionsTest { + + public void testDefaultsToVirtIO() { + CloudSigma2TemplateOptions options = new CloudSigma2TemplateOptions(); + assertEquals(options.getDeviceEmulationType(), DeviceEmulationType.VIRTIO); + assertEquals(options.getNicModel(), Model.VIRTIO); + } + + public void testDeviceEmulationType() { + CloudSigma2TemplateOptions options = new CloudSigma2TemplateOptions.Builder() + .deviceEmulationType(DeviceEmulationType.IDE); + assertEquals(options.getDeviceEmulationType(), DeviceEmulationType.IDE); + } + + public void testNicModel() { + CloudSigma2TemplateOptions options = new CloudSigma2TemplateOptions.Builder().nicModel(Model.E1000); + assertEquals(options.getNicModel(), Model.E1000); + } + + public void testVncPassword() { + CloudSigma2TemplateOptions options = new CloudSigma2TemplateOptions.Builder().vncPassword("foo"); + assertEquals(options.getVncPassword(), "foo"); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a7dd1933/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/functions/ServerInfoToJsonTest.java ---------------------------------------------------------------------- diff --git a/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/functions/ServerInfoToJsonTest.java b/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/functions/ServerInfoToJsonTest.java index 884b05e..20b607e 100644 --- a/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/functions/ServerInfoToJsonTest.java +++ b/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/functions/ServerInfoToJsonTest.java @@ -16,12 +16,11 @@ */ package org.jclouds.cloudsigma2.functions; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Maps; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import com.google.inject.Guice; +import java.math.BigInteger; +import java.net.URI; +import java.util.ArrayList; +import java.util.Map; + import org.jclouds.cloudsigma2.domain.DeviceEmulationType; import org.jclouds.cloudsigma2.domain.Drive; import org.jclouds.cloudsigma2.domain.IPConfiguration; @@ -32,14 +31,16 @@ import org.jclouds.cloudsigma2.domain.Owner; import org.jclouds.cloudsigma2.domain.ServerDrive; import org.jclouds.cloudsigma2.domain.ServerInfo; import org.jclouds.cloudsigma2.domain.ServerStatus; +import org.jclouds.cloudsigma2.domain.Tag; import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import java.math.BigInteger; -import java.net.URI; -import java.util.ArrayList; -import java.util.Map; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Maps; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.inject.Guice; @Test(groups = "unit") public class ServerInfoToJsonTest { @@ -104,7 +105,7 @@ public class ServerInfoToJsonTest { .runtime(null) .smp(1) .status(ServerStatus.STOPPED) - .tags(ImmutableList.of("tag_uuid_1", "tag_uuid_2")) + .tags(ImmutableList.of(new Tag.Builder().name("tag_uuid_1").build(), new Tag.Builder().name("tag_uuid_2").build())) .uuid("a19a425f-9e92-42f6-89fb-6361203071bb") .vncPassword("tester") .build(); @@ -120,9 +121,16 @@ public class ServerInfoToJsonTest { expected.add("requirements", new JsonArray()); JsonArray tagsArray = new JsonArray(); - tagsArray.add(new JsonPrimitive("tag_uuid_1")); - tagsArray.add(new JsonPrimitive("tag_uuid_2")); + JsonObject tagObject1 = new JsonObject(); + tagObject1.add("resources", new JsonArray()); + tagObject1.addProperty("name", "tag_uuid_1"); + JsonObject tagObject2 = new JsonObject(); + tagObject2.add("resources", new JsonArray()); + tagObject2.addProperty("name", "tag_uuid_2"); + tagsArray.add(tagObject1); + tagsArray.add(tagObject2); expected.add("tags", tagsArray); + expected.addProperty("vnc_password", "tester"); JsonObject nicJson = new JsonObject(); @@ -140,7 +148,7 @@ public class ServerInfoToJsonTest { JsonArray drivesArray = new JsonArray(); JsonObject driveJson1 = new JsonObject(); - driveJson1.addProperty("boot_order", 0); + driveJson1.addProperty("boot_order", (Number) null); driveJson1.addProperty("dev_channel", "0:0"); driveJson1.addProperty("device", "ide"); driveJson1.addProperty("drive", "ae78e68c-9daa-4471-8878-0bb87fa80260"); http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a7dd1933/cloudsigma2/src/test/resources/drive-cloned.json ---------------------------------------------------------------------- diff --git a/cloudsigma2/src/test/resources/drive-cloned.json b/cloudsigma2/src/test/resources/drive-cloned.json new file mode 100644 index 0000000..be5b617 --- /dev/null +++ b/cloudsigma2/src/test/resources/drive-cloned.json @@ -0,0 +1,57 @@ +{ + "objects": [ + { + "affinities": [ + "ssd", + "sample" + ], + "allow_multimount": true, + "jobs": [], + "licenses": [ + { + "amount" : 1, + "license" : { + "burstable" : true, + "long_name" : "sample_longname", + "name" : "sample_name", + "resource_uri" : "/api/2.0/samples/", + "type" : "sample_type", + "user_metric" : sample + }, + "user" : { + "resource_uri": "/api/2.0/user/5b4a69a3-8e78-4c45-a8ba-8b13f0895e23/", + "uuid": "5b4a69a3-8e78-4c45-a8ba-8b13f0895e23" + } + } + ], + "media": "disk", + "meta": { + "description": "", + "install_notes": "" + }, + "mounted_on": [ + { + "uuid" : "81f911f9-5152-4328-8671-02543bafbd0e", + "resource_uri" : "/api/2.0/servers/81f911f9-5152-4328-8671-02543bafbd0e/" + }, + { + "uuid" : "19163e1a-a6d6-4e73-8087-157dd302c373", + "resource_uri" : "/api/2.0/servers/19163e1a-a6d6-4e73-8087-157dd302c373/" + } + ], + "name": "atom-sol3", + "owner": { + "resource_uri": "/api/2.0/user/5b4a69a3-8e78-4c45-a8ba-8b13f0895e23/", + "uuid": "5b4a69a3-8e78-4c45-a8ba-8b13f0895e23" + }, + "resource_uri": "/api/2.0/drives/92ca1450-417e-4cc1-983b-1015777e2591/", + "size": 12348030976, + "status": "unmounted", + "tags": [ + "tag_uuid_1", + "tag_uuid_2" + ], + "uuid": "92ca1450-417e-4cc1-983b-1015777e2591" + } + ] +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a7dd1933/cloudsigma2/src/test/resources/fwpolicies-get-single.json ---------------------------------------------------------------------- diff --git a/cloudsigma2/src/test/resources/fwpolicies-get-single.json b/cloudsigma2/src/test/resources/fwpolicies-get-single.json new file mode 100644 index 0000000..84307fb --- /dev/null +++ b/cloudsigma2/src/test/resources/fwpolicies-get-single.json @@ -0,0 +1,61 @@ +{ + "meta": {}, + "name": "My awesome policy", + "owner": { + "resource_uri": "/api/2.0/user/a2d33327-87d6-4be9-ba7e-0082d89eb21a/", + "uuid": "a2d33327-87d6-4be9-ba7e-0082d89eb21a" + }, + "resource_uri": "/api/2.0/fwpolicies/9001b532-857a-405a-8e50-54e342871e77/", + "rules": [ + { + "action": "drop", + "comment": "Drop traffic from the VM to IP address 23.0.0.0/32", + "direction": "out", "dst_ip": "23.0.0.0/32", + "dst_port": null, + "ip_proto": null, + "src_ip": null, + "src_port": null}, + { + "action": "accept", + "comment": "Allow SSH traffic to the VM from our office in Dubai", + "direction": "in", "dst_ip": null, + "dst_port": "22", + "ip_proto": "tcp", + "src_ip": "172.66.32.0/24", + "src_port": null + }, + { + "action": "drop", + "comment": "Drop all other SSH traffic to the VM", + "direction": "in", + "dst_ip": null, + "dst_port": "22", + "ip_proto": "tcp", + "src_ip": null, + "src_port": null + }, + { + "action": "drop", + "comment": "Drop all UDP traffic to the VM, not originating from 172.66.32.55", + "direction": "in", + "dst_ip": null, + "dst_port": null, + "ip_proto": "udp", + "src_ip": "!172.66.32.55/32", + "src_port": null + }, + { + "action": "drop", + "comment": "Drop any traffic, to the VM with destination port not between 1-1024", + "direction": "in", + "dst_ip": null, + "dst_port": "!1:1024", + "ip_proto": "tcp", + "src_ip": null, + "src_port": null + } + ], + "servers": [], + "tags": [], + "uuid": "9001b532-857a-405a-8e50-54e342871e77" +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a7dd1933/cloudsigma2/src/test/resources/libdrives-cloned.json ---------------------------------------------------------------------- diff --git a/cloudsigma2/src/test/resources/libdrives-cloned.json b/cloudsigma2/src/test/resources/libdrives-cloned.json new file mode 100644 index 0000000..5be4c02 --- /dev/null +++ b/cloudsigma2/src/test/resources/libdrives-cloned.json @@ -0,0 +1,34 @@ +{ + "objects": [ + { + "affinities": [], + "allow_multimount": false, + "arch": "32", + "category": [ + "general" + ], + "description": "test_description", + "favourite": true, + "image_type": "install", + "install_notes": "test_install_notes", + "jobs": [], + "licenses": [], + "media": "cdrom", + "meta": {}, + "mounted_on": [], + "name": "ZeroShell 1.3 Linux Install CD", + "os": "linux", + "owner": { + "resource_uri": "/api/2.0/user/5b4a69a3-8e78-4c45-a8ba-8b13f0895e23/", + "uuid": "5b4a69a3-8e78-4c45-a8ba-8b13f0895e23" + }, + "paid": false, + "resource_uri": "/api/2.0/libdrives/8c45d8d9-4efd-44ec-9833-8d52004b4298/", + "size": 1000000000, + "status": "unmounted", + "tags": [], + "url": "test_url", + "uuid": "8c45d8d9-4efd-44ec-9833-8d52004b4298" + } + ] +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a7dd1933/cloudsigma2/src/test/resources/server-detail-first-page.json ---------------------------------------------------------------------- diff --git a/cloudsigma2/src/test/resources/server-detail-first-page.json b/cloudsigma2/src/test/resources/server-detail-first-page.json index 275a9a2..7f4b957 100644 --- a/cloudsigma2/src/test/resources/server-detail-first-page.json +++ b/cloudsigma2/src/test/resources/server-detail-first-page.json @@ -61,8 +61,8 @@ "smp": 1, "status": "stopped", "tags": [ - "tag_uuid_1", - "tag_uuid_2" + { "uuid": "tag_uuid_1" }, + { "uuid": "tag_uuid_2" } ], "uuid": "a19a425f-9e92-42f6-89fb-6361203071bb", "vnc_password": "tester" http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a7dd1933/cloudsigma2/src/test/resources/server-detail.json ---------------------------------------------------------------------- diff --git a/cloudsigma2/src/test/resources/server-detail.json b/cloudsigma2/src/test/resources/server-detail.json index 9d8fe62..6070c8b 100644 --- a/cloudsigma2/src/test/resources/server-detail.json +++ b/cloudsigma2/src/test/resources/server-detail.json @@ -61,8 +61,8 @@ "smp": 1, "status": "stopped", "tags": [ - "tag_uuid_1", - "tag_uuid_2" + { "uuid": "tag_uuid_1" }, + { "uuid": "tag_uuid_2" } ], "uuid": "a19a425f-9e92-42f6-89fb-6361203071bb", "vnc_password": "tester" http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a7dd1933/cloudsigma2/src/test/resources/servers-single.json ---------------------------------------------------------------------- diff --git a/cloudsigma2/src/test/resources/servers-single.json b/cloudsigma2/src/test/resources/servers-single.json index cbf35da..8a7dca5 100644 --- a/cloudsigma2/src/test/resources/servers-single.json +++ b/cloudsigma2/src/test/resources/servers-single.json @@ -56,8 +56,8 @@ "smp": 1, "status": "stopped", "tags": [ - "tag_uuid_1", - "tag_uuid_2" + { "uuid": "tag_uuid_1" }, + { "uuid": "tag_uuid_2" } ], "uuid": "a19a425f-9e92-42f6-89fb-6361203071bb", "vnc_password": "tester" http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a7dd1933/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 6b91b42..1979aac 100644 --- a/pom.xml +++ b/pom.xml @@ -70,7 +70,9 @@ <module>vcloud-director</module> <module>cdmi</module> <module>cloudsigma2</module> + <module>cloudsigma2-hnl</module> <module>cloudsigma2-lvs</module> + <module>cloudsigma2-sjc</module> <module>cloudsigma2-wdc</module> <module>cloudsigma2-zrh</module> <module>digitalocean</module>
