From 3a4cd0b4bcc442b050f0f665343729689704509e Mon Sep 17 00:00:00 2001 From: David Ribeiro Alves Date: Mon, 5 Mar 2012 02:28:00 +0000 Subject: [PATCH] stuck on adapter problems --- ...VirtualBoxComputeServiceContextModule.java | 3 +- .../org/jclouds/virtualbox/domain/VmSpec.java | 2 +- ...MachineFromIMachineIfNotAlreadyExists.java | 4 +- .../functions/IMachineToSshClient.java | 5 - .../virtualbox/functions/MastersCache.java | 9 +- .../virtualbox/functions/NodeCreator.java | 55 +++++++- .../BaseVirtualBoxClientLiveTest.java | 4 + ...rtualBoxComputeServiceAdapterLiveTest.java | 128 +++++++++--------- ...romIMachineIfNotAlreadyExistsLiveTest.java | 6 + .../IMachinePredicatesLiveTest.java | 112 +++++++-------- 10 files changed, 180 insertions(+), 148 deletions(-) diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java index de91ee061c..139bbf579a 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java @@ -62,6 +62,7 @@ import org.jclouds.virtualbox.domain.ExecutionType; import org.jclouds.virtualbox.domain.IsoSpec; import org.jclouds.virtualbox.domain.Master; import org.jclouds.virtualbox.domain.MasterSpec; +import org.jclouds.virtualbox.domain.NodeSpec; import org.jclouds.virtualbox.domain.YamlImage; import org.jclouds.virtualbox.functions.CloneAndRegisterMachineFromIMachineIfNotAlreadyExists; import org.jclouds.virtualbox.functions.CreateAndInstallVm; @@ -140,7 +141,7 @@ public class VirtualBoxComputeServiceContextModule extends bind(new TypeLiteral>() { }).to((Class) CreateAndInstallVm.class); // the machine cloning function - bind(new TypeLiteral>>() { + bind(new TypeLiteral>>() { }).to((Class) NodeCreator.class); bind(new TypeLiteral>() { }).to((Class) CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.class); diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/VmSpec.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/VmSpec.java index 19b4ffa3fd..2af18ab87a 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/VmSpec.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/VmSpec.java @@ -64,7 +64,7 @@ public class VmSpec { private String name; private String id; private String osTypeId = ""; - private boolean forceOverwrite; + private boolean forceOverwrite = true; private long memory; private CleanupMode cleanUpMode; diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java index 54eb49535f..b0872dea36 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java @@ -118,8 +118,8 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements IProgress progress = currentSnapshot.getMachine().cloneTo( clonedMachine, CloneMode.MachineState, options); - if (progress.getCompleted()) - logger.debug("clone done"); + progress.waitForCompletion(-1); + logger.debug("clone done"); // registering diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToSshClient.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToSshClient.java index 1b9825ddf5..e053930254 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToSshClient.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToSshClient.java @@ -19,7 +19,6 @@ package org.jclouds.virtualbox.functions; import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; import javax.annotation.Resource; import javax.inject.Named; @@ -32,9 +31,6 @@ import org.jclouds.net.IPSocket; import org.jclouds.ssh.SshClient; import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.INetworkAdapter; -import org.virtualbox_4_1.ISystemProperties; -import org.virtualbox_4_1.VirtualBoxManager; -import org.virtualbox_4_1.jaxws.ISystemPropertiesGetMaxNetworkAdapters; import com.google.common.base.Function; import com.google.common.base.Splitter; @@ -69,7 +65,6 @@ public class IMachineToSshClient implements Function { String targetPort = Iterables.get(stuff, 5); // TODO: we need a way to align the default login credentials from the iso with the // vmspec - logger.warn("PROTOCOLNUMBER: "+nameProtocolnumberAddressInboudportGuestTargetport); if ("1".equals(protocolNumber) && "22".equals(targetPort)) { client = sshClientFactory.create(new IPSocket(hostAddress, Integer.parseInt(inboundPort)), LoginCredentials.builder().user("toor").password("password").authenticateSudo(true).build()); diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/MastersCache.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/MastersCache.java index 9b6c2005f0..9d211200ac 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/MastersCache.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/MastersCache.java @@ -151,12 +151,15 @@ public class MastersCache extends AbstractLoadingCache { // try and find a master machine in vbox try { - masterMachine = manager.get().getVBox().findMachine(masterSpec.getVmSpec().getVmId()); + masterMachine = manager.get().getVBox().findMachine(vmName); } catch (VBoxException e) { - if (machineNotFoundException(e)) + if (machineNotFoundException(e)) { + // create the master machine if it can't be found masterMachine = masterCreatorAndInstaller.apply(masterSpec); - else + } + else { throw e; + } } Master master = Master.builder().machine(masterMachine).spec(masterSpec).build(); diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java index 51f7c030c9..52b647d8bd 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java @@ -19,19 +19,32 @@ package org.jclouds.virtualbox.functions; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_PREFIX; + import javax.inject.Inject; +import javax.inject.Singleton; import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials; +import org.jclouds.domain.LoginCredentials; import org.jclouds.virtualbox.domain.CloneSpec; +import org.jclouds.virtualbox.domain.ExecutionType; import org.jclouds.virtualbox.domain.Master; +import org.jclouds.virtualbox.domain.NetworkAdapter; +import org.jclouds.virtualbox.domain.NetworkInterfaceCard; +import org.jclouds.virtualbox.domain.NetworkSpec; import org.jclouds.virtualbox.domain.NodeSpec; +import org.jclouds.virtualbox.domain.VmSpec; +import org.virtualbox_4_1.CleanupMode; import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.ISession; +import org.virtualbox_4_1.NetworkAttachmentType; import org.virtualbox_4_1.VirtualBoxManager; import com.google.common.base.Function; import com.google.common.base.Supplier; +@Singleton public class NodeCreator implements Function> { private final Supplier manager; @@ -45,16 +58,46 @@ public class NodeCreator implements Function apply(NodeSpec nodeSpec) { - + Master master = nodeSpec.getMaster(); - + if (master.getMachine().getCurrentSnapshot() != null) { - ISession session = manager.get().openMachineSession(master.getMachine()); + ISession session; + try { + session = manager.get().openMachineSession(master.getMachine()); + } catch (Exception e) { + throw new RuntimeException("error opening vbox machine session: " + e.getMessage(), e); + } session.getConsole().deleteSnapshot(master.getMachine().getCurrentSnapshot().getId()); session.unlockMachine(); } - - - + String masterNameWithoutPrefix = master.getSpec().getVmSpec().getVmName().replace(VIRTUALBOX_IMAGE_PREFIX, ""); + + String cloneName = VIRTUALBOX_NODE_PREFIX + masterNameWithoutPrefix + "-" + nodeSpec.getTag() + "-" + + nodeSpec.getName(); + + VmSpec cloneVmSpec = VmSpec.builder().id(cloneName).name(cloneName).memoryMB(512).cleanUpMode(CleanupMode.Full) + .forceOverwrite(true).build(); + + NetworkAdapter networkAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.Bridged) + .build(); + + NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter) + .build(); + + NetworkSpec cloneNetworkSpec = NetworkSpec.builder().addNIC(0L, networkInterfaceCard).build(); + + CloneSpec cloneSpec = CloneSpec.builder().linked(true).master(master.getMachine()) + .network(cloneNetworkSpec).vm(cloneVmSpec).build(); + + IMachine cloned = cloner.apply(cloneSpec); + + new LaunchMachineIfNotAlreadyRunning(manager.get(), ExecutionType.GUI, "").apply(cloned); + + // TODO get credentials from somewhere else (they are also HC in IMachineToSshClient) + NodeAndInitialCredentials nodeAndInitialCredentials = new NodeAndInitialCredentials(cloned, + cloneName, LoginCredentials.builder().user("toor").password("password").authenticateSudo(true).build()); + + return nodeAndInitialCredentials; } } diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java index 3205ef2e0f..ce4c2b2bac 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java @@ -31,7 +31,9 @@ import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.functions.DefaultCredentialsFromImageOrOverridingCredentials; import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate; import org.jclouds.config.ValueOfConfigurationKeyOrNull; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.sshj.config.SshjSshClientModule; @@ -82,6 +84,8 @@ public class BaseVirtualBoxClientLiveTest extends BaseVersionedServiceLiveTest { protected String workingDir; protected String isosDir; protected Supplier host; + protected static final PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate = new PrioritizeCredentialsFromTemplate( + new DefaultCredentialsFromImageOrOverridingCredentials()); @Override protected void setupCredentials() { diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java index 82b0473a74..59c045e18f 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java @@ -19,6 +19,7 @@ package org.jclouds.virtualbox.compute; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_PREFIX; import static org.testng.Assert.assertEquals; import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials; @@ -31,85 +32,78 @@ import org.jclouds.domain.LoginCredentials; import org.jclouds.net.IPSocket; import org.jclouds.ssh.SshClient; import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest; -import org.jclouds.virtualbox.domain.VmSpec; -import org.testng.annotations.AfterClass; import org.testng.annotations.Test; import org.virtualbox_4_1.IMachine; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; @Test(groups = "live", singleThreaded = true, testName = "VirtualBoxComputeServiceAdapterLiveTest") public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClientLiveTest { - private VirtualBoxComputeServiceAdapter adapter; - private NodeAndInitialCredentials machine; + private VirtualBoxComputeServiceAdapter adapter; + private NodeAndInitialCredentials machine; - @Override - public void setupClient() { - super.setupClient(); - adapter = context.utils().injector().getInstance(VirtualBoxComputeServiceAdapter.class); - } + @Override + public void setupClient() { + super.setupClient(); + adapter = context.utils().injector().getInstance(VirtualBoxComputeServiceAdapter.class); + } - private static final PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate = new PrioritizeCredentialsFromTemplate( - new DefaultCredentialsFromImageOrOverridingCredentials()); + @Test + public void testCreateNodeWithGroupEncodedIntoNameThenStoreCredentials() { + String group = "foo"; + String name = "foo-ef4"; + String machineName = VIRTUALBOX_NODE_PREFIX + "myTestId-" + group + "-" + name; + // get the image from + Image image = Iterables.get(adapter.listImages(), 0); + System.out.println(context.getComputeService().templateBuilder()); + Template template = context.getComputeService().templateBuilder().fromImage(image).build(); + machine = adapter.createNodeWithGroupEncodedIntoName(group, name, template); + assertEquals(machine.getNode().getName(), machineName); + // is there a place for group? + // check other things, like cpu correct, mem correct, image/os is correct + // (as possible) + // TODO: what's the IP address? + // assert + // InetAddresses.isInetAddress(machine.getPrimaryBackendIpAddress()) : + // machine; + doConnectViaSsh(machine.getNode(), prioritizeCredentialsFromTemplate.apply(template, machine.getCredentials())); + } - @Test - public void testCreateNodeWithGroupEncodedIntoNameThenStoreCredentials() { - String group = "foo"; - String name = "foo-ef4"; - // get the image from - Image image = Iterables.get(adapter.listImages(),0); - System.out.println(context.getComputeService().templateBuilder()); - Template template = context.getComputeService().templateBuilder().fromImage(image).build(); - machine = adapter.createNodeWithGroupEncodedIntoName(group, name, template); - assertEquals(machine.getNode().getName(), name); - assertEquals(machine.getNodeId(), machine.getNode().getId()); - // is there a place for group? - // check other things, like cpu correct, mem correct, image/os is correct - // (as possible) - // TODO: what's the IP address? - // assert - // InetAddresses.isInetAddress(machine.getPrimaryBackendIpAddress()) : - // machine; - doConnectViaSsh(machine.getNode(), prioritizeCredentialsFromTemplate.apply(template, machine.getCredentials())); + protected void doConnectViaSsh(IMachine machine, LoginCredentials 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(); + assertEquals(1, Iterables.size(profiles)); + } - protected void doConnectViaSsh(IMachine machine, LoginCredentials 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 testListImages() { + Iterable iMageIterable = adapter.listImages(); + for (Image image : iMageIterable) { + System.out.println(image); + } + // check state; + } - @Test - public void testListHardwareProfiles() { - Iterable profiles = adapter.listHardwareProfiles(); - assertEquals(1,Iterables.size(profiles)); - } - - @Test - public void testListImages() { - Iterable iMageIterable = adapter.listImages(); - for (Image image : iMageIterable) { - System.out.println(image); - } - // check state; - } - - @Override - protected void tearDown() throws Exception { - if (machine != null) - adapter.destroyNode(machine.getNodeId() + ""); - super.tearDown(); - } + @Override + protected void tearDown() throws Exception { + if (machine != null) +// adapter.destroyNode(machine.getNodeId() + ""); + super.tearDown(); + } } diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest.java index b85d823cd4..7279df1988 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest.java @@ -26,6 +26,7 @@ import static org.testng.Assert.assertEquals; import org.jclouds.config.ValueOfConfigurationKeyOrNull; import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest; import org.jclouds.virtualbox.domain.CloneSpec; +import org.jclouds.virtualbox.domain.ExecutionType; import org.jclouds.virtualbox.domain.HardDisk; import org.jclouds.virtualbox.domain.IsoSpec; import org.jclouds.virtualbox.domain.MasterSpec; @@ -139,6 +140,11 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest exten IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists( manager, workingDir,machineUtils).apply(cloneSpec); assertEquals(clone.getName(), cloneSpec.getVmSpec().getVmName()); + + new LaunchMachineIfNotAlreadyRunning(manager.get(), ExecutionType.GUI, "").apply(clone); + + // TODO ssh into the node + } finally { for (VmSpec spec : ImmutableSet.of(cloneSpec.getVmSpec(), sourceMachineSpec.getVmSpec())) diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/IMachinePredicatesLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/IMachinePredicatesLiveTest.java index 7bb8efd845..64a005ce6b 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/IMachinePredicatesLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/IMachinePredicatesLiveTest.java @@ -55,78 +55,64 @@ import com.google.inject.Injector; @Test(groups = "live", singleThreaded = true, testName = "IMachinePredicatesLiveTest") public class IMachinePredicatesLiveTest extends BaseVirtualBoxClientLiveTest { - private String osTypeId = ""; - private String ideControllerName = "IDE Controller"; - private String cloneName; - private String vmName; - private StorageController masterStorageController; - private MasterSpec masterMachineSpec; - private CloneSpec cloneSpec; + private String osTypeId = ""; + private String ideControllerName = "IDE Controller"; + private String cloneName; + private String vmName; + private StorageController masterStorageController; + private MasterSpec masterMachineSpec; + private NetworkSpec networkSpec; + private CloneSpec cloneSpec; - @Override - @BeforeClass(groups = "live") - public void setupClient() { - super.setupClient(); - vmName = VIRTUALBOX_IMAGE_PREFIX - + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass() - .getSimpleName()); + @Override + @BeforeClass(groups = "live") + public void setupClient() { + super.setupClient(); + vmName = VIRTUALBOX_IMAGE_PREFIX + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName()); - cloneName = VIRTUALBOX_IMAGE_PREFIX - + "Clone#" - + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass() - .getSimpleName()); + cloneName = VIRTUALBOX_IMAGE_PREFIX + "Clone#" + + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName()); - HardDisk hardDisk = HardDisk.builder().diskpath(adminDisk) - .autoDelete(true).controllerPort(0).deviceSlot(1).build(); - masterStorageController = StorageController.builder() - .name(ideControllerName).bus(StorageBus.IDE) - .attachISO(0, 0, operatingSystemIso).attachHardDisk(hardDisk) - .attachISO(1, 1, guestAdditionsIso).build(); - VmSpec masterSpec = VmSpec.builder().id(vmName).name(vmName) - .memoryMB(512).osTypeId(osTypeId) - .controller(masterStorageController).forceOverwrite(true) - .cleanUpMode(CleanupMode.Full).build(); - masterMachineSpec = MasterSpec - .builder() - .iso(IsoSpec.builder().sourcePath(operatingSystemIso) - .installationScript("").build()).vm(masterSpec) - .network(NetworkSpec.builder().build()).build(); + HardDisk hardDisk = HardDisk.builder().diskpath(adminDisk).autoDelete(true).controllerPort(0).deviceSlot(1).build(); + masterStorageController = StorageController.builder().name(ideControllerName).bus(StorageBus.IDE) + .attachISO(0, 0, operatingSystemIso).attachHardDisk(hardDisk).attachISO(1, 1, guestAdditionsIso).build(); + VmSpec masterSpec = VmSpec.builder().id(vmName).name(vmName).memoryMB(512).osTypeId(osTypeId) + .controller(masterStorageController).forceOverwrite(true).cleanUpMode(CleanupMode.Full).build(); + masterMachineSpec = MasterSpec.builder() + .iso(IsoSpec.builder().sourcePath(operatingSystemIso).installationScript("").build()).vm(masterSpec) + .network(NetworkSpec.builder().build()).build(); - NetworkAdapter networkAdapter = NetworkAdapter.builder() - .networkAttachmentType(NetworkAttachmentType.Bridged).build(); - NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard - .builder().addNetworkAdapter(networkAdapter).build(); + NetworkAdapter networkAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.Bridged) + .build(); + NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter) + .build(); - NetworkSpec networkSpec = NetworkSpec.builder() - .addNIC(0L, networkInterfaceCard).build(); + this.networkSpec = NetworkSpec.builder().addNIC(0L, networkInterfaceCard).build(); - VmSpec clonedVmSpec = VmSpec.builder().id(cloneName).name(cloneName) - .memoryMB(512).cleanUpMode(CleanupMode.Full) - .forceOverwrite(true).build(); + } - cloneSpec = CloneSpec.builder().vm(clonedVmSpec).network(networkSpec) - .build(); - } + @Test + public void testLinkedClone() { - @Test - public void testLinkedClone() { + Injector injector = context.utils().injector(); + IMachine master = injector.getInstance(CreateAndRegisterMachineFromIsoIfNotAlreadyExists.class).apply( + masterMachineSpec); - Injector injector = context.utils().injector(); - IMachine master = injector.getInstance( - CreateAndRegisterMachineFromIsoIfNotAlreadyExists.class).apply( - masterMachineSpec); - IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists( - manager, workingDir, cloneSpec, true, machineUtils) - .apply(master); + VmSpec clonedVmSpec = VmSpec.builder().id(cloneName).name(cloneName).memoryMB(512).cleanUpMode(CleanupMode.Full) + .forceOverwrite(true).build(); - assertTrue(isLinkedClone().apply(clone)); - } + this.cloneSpec = CloneSpec.builder().vm(clonedVmSpec).network(networkSpec).master(master).linked(true).build(); - @BeforeMethod - @AfterMethod - void cleanUpVms() { - for (VmSpec spec : ImmutableSet.of(cloneSpec.getVmSpec(), - masterMachineSpec.getVmSpec())) - this.undoVm(spec); - } + IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(manager, workingDir, machineUtils) + .apply(cloneSpec); + + assertTrue(isLinkedClone().apply(clone)); + } + + @BeforeMethod + @AfterMethod + void cleanUpVms() { + for (VmSpec spec : ImmutableSet.of(cloneSpec.getVmSpec(), masterMachineSpec.getVmSpec())) + this.undoVm(spec); + } }