mirror of https://github.com/apache/jclouds.git
roughed out test cases for vbox
This commit is contained in:
parent
72989e5482
commit
fff450fdf2
|
@ -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.<Module> of(new Log4JLoggingModule(), new SshjSshClientModule()));
|
||||
}
|
||||
|
||||
@AfterGroups(groups = "live")
|
||||
protected void tearDown() {
|
||||
if (context != null)
|
||||
context.close();
|
||||
}
|
||||
|
||||
}
|
|
@ -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.
|
||||
* <p/>
|
||||
* 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.<String> 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<String, Credentials> 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<IMachine> 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<IMachine> iMachineIterable = adapter.listImages();
|
||||
|
||||
for (IMachine iMachine : iMachineIterable) {
|
||||
Image image = iMachineToImage.apply(iMachine);
|
||||
System.out.println(image);
|
||||
}
|
||||
// check state;
|
||||
}
|
||||
|
||||
@AfterGroups(groups = "live")
|
||||
protected void tearDown() {
|
||||
if (machine != null)
|
||||
adapter.destroyNode(machine.getId() + "");
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
|
@ -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<VirtualBoxManager, IMachine, IMachine, IMachine, Host>(
|
||||
"virtualbox", endpoint, apiversion, "", identity, credential, VirtualBoxManager.class,
|
||||
VirtualBoxContextBuilder.class, ImmutableSet.<Module>of()));
|
||||
|
||||
context.getComputeService().listNodes();
|
||||
|
||||
} finally {
|
||||
if (context != null)
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue