diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java new file mode 100644 index 0000000000..a8e1d57995 --- /dev/null +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java @@ -0,0 +1,77 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.virtualbox; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Properties; + +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.sshj.config.SshjSshClientModule; +import org.testng.annotations.AfterGroups; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeGroups; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; + +/** + * Tests behavior of {@code VirtualBoxClient} + * + * @author Adrian Cole + */ +@Test(groups = "live") +public class BaseVirtualBoxClientLiveTest { + + protected String provider = "virtualbox"; + protected String identity; + protected String credential; + protected String endpoint; + protected String apiversion; + + @BeforeClass + protected void setupCredentials() { + identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); + credential = System.getProperty("test." + provider + ".credential"); + endpoint = System.getProperty("test." + provider + ".endpoint", "http://localhost:18083/"); + apiversion = System.getProperty("test." + provider + ".apiversion", "4.1.2r73507"); + } + + protected ComputeServiceContext context; + + @BeforeGroups(groups = { "live" }) + public void setupClient() { + Properties properties = new Properties(); + properties.setProperty(provider + ".endpoint", endpoint); + properties.setProperty(provider + ".apiversion", apiversion); + context = new ComputeServiceContextFactory().createContext(provider, identity, credential, + ImmutableSet. of(new Log4JLoggingModule(), new SshjSshClientModule())); + } + + @AfterGroups(groups = "live") + protected void tearDown() { + if (context != null) + context.close(); + } + +} diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java index 9b06911288..e4d24f70b6 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java @@ -1,59 +1,127 @@ -/* - * * - * * Licensed to jclouds, Inc. (jclouds) under one or more - * * contributor license agreements. See the NOTICE file - * * distributed with this work for additional information - * * regarding copyright ownership. jclouds 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. +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.virtualbox.compute; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import java.net.URI; +import java.util.Map; + +import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.Template; +import org.jclouds.domain.Credentials; +import org.jclouds.location.suppliers.JustProvider; +import org.jclouds.net.IPSocket; +import org.jclouds.ssh.SshClient; +import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest; import org.jclouds.virtualbox.functions.IMachineToImage; +import org.testng.annotations.AfterGroups; +import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.VirtualBoxManager; -import java.net.URI; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.google.common.collect.Maps; -/** - * Tests basic functionality of the VirtualBoxComputeServiceAdapter. - *

- * Note that you need vboxwebsrv running for these tests to work. - */ -@Test(groups = "live") -public class VirtualBoxComputeServiceAdapterLiveTest { +@Test(groups = "live", singleThreaded = true, testName = "VirtualBoxComputeServiceAdapterLiveTest") +public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClientLiveTest { + private VirtualBoxComputeServiceAdapter adapter; + private IMachine machine; + + @BeforeGroups(groups = { "live" }) + public void setupClient() { + super.setupClient(); + adapter = new VirtualBoxComputeServiceAdapter(getManager(), + new JustProvider(ImmutableSet. of(), provider, URI.create(endpoint))); + } + + protected VirtualBoxManager getManager() { + return (VirtualBoxManager) context.getProviderSpecificContext().getApi(); + } @Test - public void testGetImages() throws Exception { + public void testListLocations() { + assertFalse(Iterables.isEmpty(adapter.listLocations())); + } - VirtualBoxManager virtualBoxManager = VirtualBoxManager.createInstance(""); + @Test + public void testCreateNodeWithGroupEncodedIntoNameThenStoreCredentials() { + String group = "foo"; + String name = "foo-ef4"; + Template template = context.getComputeService().templateBuilder().build(); + Map credentialStore = Maps.newLinkedHashMap(); + machine = adapter.createNodeWithGroupEncodedIntoNameThenStoreCredentials(group, name, template, credentialStore); + assertEquals(machine.getName(), name); + // is there a place for group? + // check other things, like cpu correct, mem correct, image/os is correct + // (as possible) + assert credentialStore.containsKey("node#" + machine.getId()) : "credentials to log into machine not found " + + machine; +// TODO: what's the IP address? +// assert InetAddresses.isInetAddress(machine.getPrimaryBackendIpAddress()) : machine; + doConnectViaSsh(machine, credentialStore.get("node#" + machine.getId())); + } - URI endpoint = new URI("http://localhost:18083"); - virtualBoxManager.connect(endpoint.toASCIIString(), "admin", "123456"); + protected void doConnectViaSsh(IMachine machine, Credentials creds) { + SshClient ssh = context.utils().sshFactory() + .create(new IPSocket("//TODO", 22), creds); + try { + ssh.connect(); + ExecResponse hello = ssh.exec("echo hello"); + assertEquals(hello.getOutput().trim(), "hello"); + System.err.println(ssh.exec("df -k").getOutput()); + System.err.println(ssh.exec("mount").getOutput()); + System.err.println(ssh.exec("uname -a").getOutput()); + } finally { + if (ssh != null) + ssh.disconnect(); + } + } + + @Test + public void testListHardwareProfiles() { + Iterable profiles = adapter.listHardwareProfiles(); + assertFalse(Iterables.isEmpty(profiles)); + // check state; + } + @Test + public void testListImages() { + IMachineToImage iMachineToImage = new IMachineToImage(getManager()); - VirtualBoxComputeServiceAdapter adapter = new VirtualBoxComputeServiceAdapter(virtualBoxManager); - IMachineToImage iMachineToImage = new IMachineToImage(virtualBoxManager); Iterable iMachineIterable = adapter.listImages(); - for (IMachine iMachine : iMachineIterable) { Image image = iMachineToImage.apply(iMachine); System.out.println(image); } + // check state; } -} \ No newline at end of file + + @AfterGroups(groups = "live") + protected void tearDown() { + if (machine != null) + adapter.destroyNode(machine.getId() + ""); + super.tearDown(); + } +} diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceLiveTest.java deleted file mode 100644 index e0ed5eef0d..0000000000 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceLiveTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * * - * * Licensed to jclouds, Inc. (jclouds) under one or more - * * contributor license agreements. See the NOTICE file - * * distributed with this work for additional information - * * regarding copyright ownership. jclouds 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.virtualbox.compute; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; -import org.jclouds.compute.BaseComputeServiceLiveTest; -import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; -import org.jclouds.compute.StandaloneComputeServiceContextSpec; -import org.jclouds.sshj.config.SshjSshClientModule; -import org.jclouds.virtualbox.VirtualBox; -import org.jclouds.virtualbox.VirtualBoxContextBuilder; -import org.jclouds.virtualbox.domain.Host; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.VirtualBoxManager; - -import java.util.Properties; - -import static com.google.common.base.Preconditions.checkNotNull; - -@Test(groups = "live") -public class VirtualBoxComputeServiceLiveTest extends BaseComputeServiceLiveTest { - - public VirtualBoxComputeServiceLiveTest() { - provider = "virtualbox"; - } - - @Override - protected Module getSshModule() { - return new SshjSshClientModule(); - } - - @Override - protected Properties setupRestProperties() { - Properties restProperties = new Properties(); - restProperties.setProperty("virtualbox.contextbuilder", VirtualBoxContextBuilder.class.getName()); - restProperties.setProperty("virtualbox.endpoint", "http://localhost:18083/"); - restProperties.setProperty("virtualbox.apiversion", "4.1.2r73507"); - return restProperties; - } - - @BeforeClass - protected void setupCredentials() { - identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); - credential = System.getProperty("test." + provider + ".credential"); - endpoint = System.getProperty("test." + provider + ".endpoint"); - apiversion = System.getProperty("test." + provider + ".apiversion"); - } - - @Test - public void testAndExperiment() { - ComputeServiceContext context = null; - try { - context = new ComputeServiceContextFactory() - .createContext(new StandaloneComputeServiceContextSpec( - "virtualbox", endpoint, apiversion, "", identity, credential, VirtualBoxManager.class, - VirtualBoxContextBuilder.class, ImmutableSet.of())); - - context.getComputeService().listNodes(); - - } finally { - if (context != null) - context.close(); - } - } -} diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java new file mode 100644 index 0000000000..afe953a031 --- /dev/null +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java @@ -0,0 +1,37 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.virtualbox.compute; + +import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest; +import org.testng.annotations.Test; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live", testName = "VirtualBoxExperimentLiveTest") +public class VirtualBoxExperimentLiveTest extends BaseVirtualBoxClientLiveTest{ + + @Test + public void testAndExperiment() { + context.getComputeService().listNodes(); + } + +} \ No newline at end of file