Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CE935172BF for ; Thu, 12 Mar 2015 06:04:53 +0000 (UTC) Received: (qmail 67948 invoked by uid 500); 12 Mar 2015 06:04:53 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 67799 invoked by uid 500); 12 Mar 2015 06:04:53 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 67531 invoked by uid 99); 12 Mar 2015 06:04:53 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Mar 2015 06:04:53 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 4391FE18C8; Thu, 12 Mar 2015 06:04:53 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: bhaisaab@apache.org To: commits@cloudstack.apache.org Date: Thu, 12 Mar 2015 06:04:55 -0000 Message-Id: <84acc89e7d5444d5951a370594b044e7@git.apache.org> In-Reply-To: <66d424d35a0f46c2bd0f9dc756fe7737@git.apache.org> References: <66d424d35a0f46c2bd0f9dc756fe7737@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [03/12] git commit: updated refs/heads/master to c27c694 http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c27c6943/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/Ovm3HypervisorResourceTest.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/Ovm3HypervisorResourceTest.java b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/Ovm3HypervisorResourceTest.java new file mode 100644 index 0000000..e9c9029 --- /dev/null +++ b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/Ovm3HypervisorResourceTest.java @@ -0,0 +1,368 @@ +/******************************************************************************* + * 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 com.cloud.hypervisor.ovm3.resources; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.naming.ConfigurationException; + +import org.apache.cloudstack.storage.to.VolumeObjectTO; +import org.junit.Test; +import org.mockito.Mockito; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.ReadyCommand; +import com.cloud.agent.api.RebootCommand; +import com.cloud.agent.api.StartCommand; +import com.cloud.agent.api.StartupCommand; +import com.cloud.agent.api.StopCommand; +import com.cloud.agent.api.to.DiskTO; +import com.cloud.agent.api.to.NfsTO; +import com.cloud.agent.api.to.NicTO; +import com.cloud.agent.api.to.VirtualMachineTO; +import com.cloud.host.Host; +import com.cloud.hypervisor.ovm3.objects.CloudStackPluginTest; +import com.cloud.hypervisor.ovm3.objects.ConnectionTest; +import com.cloud.hypervisor.ovm3.objects.NetworkTest; +import com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException; +import com.cloud.hypervisor.ovm3.objects.OvmObject; +import com.cloud.hypervisor.ovm3.objects.Xen; +import com.cloud.hypervisor.ovm3.objects.XenTest; +import com.cloud.hypervisor.ovm3.objects.XmlTestResultTest; +import com.cloud.hypervisor.ovm3.resources.helpers.Ovm3Configuration; +import com.cloud.hypervisor.ovm3.resources.helpers.Ovm3ConfigurationTest; +import com.cloud.hypervisor.ovm3.support.Ovm3SupportTest; +import com.cloud.network.Networks; +import com.cloud.storage.Volume; +import com.cloud.template.VirtualMachineTemplate.BootloaderType; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachine.Type; + +public class Ovm3HypervisorResourceTest { + ConnectionTest con; + OvmObject ovmObject = new OvmObject(); + XmlTestResultTest results = new XmlTestResultTest(); + Ovm3ConfigurationTest configTest = new Ovm3ConfigurationTest(); + Ovm3HypervisorResource hypervisor = new Ovm3HypervisorResource(); + Ovm3SupportTest support = new Ovm3SupportTest(); + NetworkTest net = new NetworkTest(); + // LinuxTest linux = new LinuxTest(); + CloudStackPluginTest csp = new CloudStackPluginTest(); + XenTest xen = new XenTest(); + String currentStatus = "put"; + String vmName = "i-2-3-VM"; + + @Test + public void configureTest() throws ConfigurationException { + Ovm3Configuration config = new Ovm3Configuration(configTest.getParams()); + con = support.prepConnectionResults(); + hypervisor.setConnection(con); + results.basicBooleanTest(hypervisor.configure(config.getAgentName(), + configTest.getParams())); + } + + /* fails */ + /* + @Test(expected = CloudRuntimeException.class) + public void configureFailBaseConnectionTest() throws + ConfigurationException { + hypervisor = support.prepare(configTest.getParams()); + results.basicBooleanTest(hypervisor.configure(con.getHostName(), + configTest.getParams())); + } + */ + + @Test + public void configureControlInterfaceTest() throws ConfigurationException { + Ovm3Configuration config = new Ovm3Configuration(configTest.getParams()); + String netdef = net.getDiscoverNetwork(); + netdef = netdef.replaceAll(config.getAgentControlNetworkName(), + "thisisnotit0"); + con = support.prepConnectionResults(); + con.removeMethodResponse("discover_network"); + con.setResult(results.simpleResponseWrapWrapper(netdef)); + con.addResult(results.simpleResponseWrapWrapper(net + .getDiscoverNetwork())); + hypervisor.setConnection(con); + results.basicBooleanTest(hypervisor.configure(config.getAgentName(), + configTest.getParams())); + } + + @Test + public void startCommandTest() { + } + + @Test + public void getCurrentStatusAndConfigureTest() + throws ConfigurationException { + Ovm3Configuration config = new Ovm3Configuration(configTest.getParams()); + con = support.prepConnectionResults(); + hypervisor.setConnection(con); + results.basicBooleanTest(hypervisor.configure(config.getAgentName(), + configTest.getParams())); + assertNotNull(hypervisor.getCurrentStatus(1L)); + assertNotNull(hypervisor.getCurrentStatus(1L)); + } + + @Test + public void getCurrentStatusFailTest() throws ConfigurationException { + Ovm3Configuration config = new Ovm3Configuration(configTest.getParams()); + con = support.prepConnectionResults(); + con.setResult(results.simpleResponseWrapWrapper("fail")); + con.removeMethodResponse("echo"); + hypervisor.setConnection(con); + results.basicBooleanTest(hypervisor.configure(config.getAgentName(), + configTest.getParams())); + assertNull(hypervisor.getCurrentStatus(1L)); + } + + @Test + public void getCurrentStatusExceptionTest() throws ConfigurationException { + con = new ConnectionTest(); + hypervisor.setConnection(con); + assertNull(hypervisor.getCurrentStatus(1L)); + } + + /* gives an IOException on ssh */ + @Test + public void initializeTest() throws Exception { + Ovm3Configuration config = new Ovm3Configuration(configTest.getParams()); + con = support.prepConnectionResults(); + hypervisor.setConnection(con); + results.basicBooleanTest(hypervisor.configure(config.getAgentName(), + configTest.getParams())); + con.setIp(config.getAgentIp()); + for (StartupCommand start : hypervisor.initialize()) { + assertNotNull(start); + } + } + + private Ovm3HypervisorResource vmActionPreparation() + throws ConfigurationException { + Ovm3Configuration config = new Ovm3Configuration(configTest.getParams()); + con = support.prepConnectionResults(); + hypervisor.setConnection(con); + results.basicBooleanTest(hypervisor.configure(config.getAgentName(), + configTest.getParams())); + return hypervisor; + } + + private Boolean rebootVm(String name) throws ConfigurationException { + hypervisor = vmActionPreparation(); + con.removeMethodResponse("list_vms"); + con.addResult(xen.getMultipleVmsListXML()); + con.addResult(xen.getMultipleVmsListXML()); + RebootCommand cmd = new RebootCommand(name); + Answer ra = hypervisor.executeRequest(cmd); + return ra.getResult(); + } + + @Test + public void rebootCommandTest() throws ConfigurationException { + results.basicBooleanTest(rebootVm(vmName)); + } + + @Test + public void rebootCommandFailTest() throws ConfigurationException { + results.basicBooleanTest(rebootVm("bogus"), false); + } + + @Test + public void stopVmTest() throws ConfigurationException { + hypervisor = vmActionPreparation(); + con.removeMethodResponse("list_vms"); + con.setResult(xen.getMultipleVmsListXML()); + con.addResult(xen.getMultipleVmsListXML().replace(vmName, + vmName + "-hide")); + StopCommand cmd = new StopCommand(vmName, true, true); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult()); + } + + /* takes too long */ + /* + * @Test + * public void stopVmTestFail() throws ConfigurationException { + * stopVm(); + * con.addResult(xen.getVmListXML().replace(vmName, vmName)); + * StopCommand cmd = new StopCommand(vmName, true, true); + * StopAnswer ra = hypervisor.execute(cmd); + * results.basicBooleanTest(ra.getResult(), false); + * } + */ + + @Test + public void stopVmTreatAsStoppedTest() throws ConfigurationException { + hypervisor = vmActionPreparation(); + con.setMethodResponse("list_vms", + xen.getMultipleVmsListXML().replace(vmName, vmName + "-hide")); + StopCommand cmd = new StopCommand(vmName, true, true); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult()); + } + + @Test + public void stopVmExceptionTest() throws ConfigurationException { + hypervisor = vmActionPreparation(); + con.removeMethodResponse("list_vms"); + StopCommand cmd = new StopCommand(vmName, true, true); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult(), false); + } + + /* not relevant atm */ + public void addNicsToSpec(VirtualMachineTO vmspec, List list) { + for (String vif : list) { + String parts[] = vif.split("[,=.]+"); + addNicToSpec(vmspec, parts[1], parts[3], parts[4]); + } + } + + public void addNicToSpec(VirtualMachineTO vmspec, String mac, + String bridge, String vlan) { + ArrayList nics; + if (vmspec.getNics() != null) { + nics = new ArrayList(Arrays.asList(vmspec.getNics())); + } else { + nics = new ArrayList(); + } + NicTO nic = new NicTO(); + + nic.setType(Networks.TrafficType.Guest); + nic.setMac(mac); + nic.setDeviceId(nics.size()); + nics.add(nic); + vmspec.setNics(nics.toArray(new NicTO[nics.size()])); + } + + /* hardcoded, dirty */ + public void addDisksToSpec(VirtualMachineTO vmspec, List list) { + for (String disk : list) { + String parts[] = disk.split("[:,.]+"); + String partdeux[] = parts[1].split("/"); + String diskuuid = partdeux[partdeux.length - 1]; + String dsuuid = partdeux[3]; + String path = parts[1].replace("/" + diskuuid, ""); + addDiskToSpec(vmspec, diskuuid, dsuuid, path); + } + } + + public void addDiskToSpec(VirtualMachineTO vmspec, String uuid, + String dsuuid, String path) { + ArrayList disks; + if (vmspec.getDisks() != null) { + disks = new ArrayList(Arrays.asList(vmspec.getDisks())); + } else { + disks = new ArrayList(); + } + DiskTO disk = new DiskTO(); + VolumeObjectTO volume = new VolumeObjectTO(); + NfsTO nfsDataStore = new NfsTO(); + nfsDataStore.setUuid(dsuuid); + volume.setDataStore(nfsDataStore); + volume.setPath(path); + volume.setUuid(uuid); + disk.setData(volume); + disk.setType(Volume.Type.ROOT); + disks.add(disk); + vmspec.setDisks(disks.toArray(new DiskTO[disks.size()])); + } + + public Host getHost(String ip) { + Host host = Mockito.mock(Host.class); + Mockito.when(host.getPrivateIpAddress()).thenReturn(ip); + return host; + } + + public VirtualMachineTO createVm(String vmName) throws Ovm3ResourceException { + con = support.prepConnectionResults(); + Xen vdata = new Xen(con); + Xen.Vm vm = vdata.getVmConfig(vmName); + vdata.listVm(xen.getRepoId(), xen.getVmId()); + + // Ovm3VmGuestTypes types = new Ovm3VmGuestTypes(); + Long id = 1L; + String instanceName = vm.getVmName(); + VirtualMachine.Type type = Type.User; + int cpus = 1; // vm.getVmCpus(); + Integer speed = 0; + long minRam = vm.getVmMemory(); + long maxRam = vm.getVmMemory(); + BootloaderType bootloader = BootloaderType.PyGrub; + String os = "Oracle Enterprise Linux 6.0 (64-bit)"; + boolean enableHA = true; + boolean limitCpuUse = false; + String vncPassword = "gobbeldygoo"; + // public StartCommand(VirtualMachineTO vm, Host host, boolean + // executeInSequence) { + // ./api/src/com/cloud/agent/api/to/VirtualMachineTO.java + VirtualMachineTO vmspec = new VirtualMachineTO(id, instanceName, type, + cpus, speed, minRam, maxRam, bootloader, os, enableHA, + limitCpuUse, vncPassword); + vmspec.setBootArgs(""); + addDisksToSpec(vmspec, vm.getVmDisks()); + addNicsToSpec(vmspec, vm.getVmVifs()); + return vmspec; + } + + @Test + public void createVmTest() throws ConfigurationException, + Ovm3ResourceException { + VirtualMachineTO vmspec = createVm(vmName); + hypervisor = vmActionPreparation(); + StartCommand cmd = new StartCommand(vmspec, + getHost(hypervisor.getName()), true); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult()); + } + + @Test + public void createOtherVmTest() throws ConfigurationException, + Ovm3ResourceException { + VirtualMachineTO vmspec = createVm(vmName); + vmspec.setOs("bogus"); + hypervisor = vmActionPreparation(); + StartCommand cmd = new StartCommand(vmspec, + getHost(hypervisor.getName()), true); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult()); + } + + @Test + public void startResourceTest() { + results.basicBooleanTest(hypervisor.start()); + } + + @Test + public void stopResourceTest() { + results.basicBooleanTest(hypervisor.stop()); + } + @Test + public void readyCommandTest() throws ConfigurationException { + hypervisor = support.prepare(configTest.getParams()); + ReadyCommand ready = new ReadyCommand(); + Answer ra = hypervisor.executeRequest(ready); + results.basicBooleanTest(ra.getResult()); + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c27c6943/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/Ovm3StorageProcessorTest.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/Ovm3StorageProcessorTest.java b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/Ovm3StorageProcessorTest.java new file mode 100644 index 0000000..80586cc --- /dev/null +++ b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/Ovm3StorageProcessorTest.java @@ -0,0 +1,343 @@ +/******************************************************************************* + * 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 com.cloud.hypervisor.ovm3.resources; + +import javax.naming.ConfigurationException; + +import org.apache.cloudstack.storage.command.CopyCmdAnswer; +import org.apache.cloudstack.storage.command.CopyCommand; +import org.apache.cloudstack.storage.command.CreateObjectCommand; +import org.apache.cloudstack.storage.command.DeleteCommand; +import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; +import org.apache.cloudstack.storage.to.SnapshotObjectTO; +import org.apache.cloudstack.storage.to.TemplateObjectTO; +import org.apache.cloudstack.storage.to.VolumeObjectTO; +import org.junit.Test; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.storage.CopyVolumeCommand; +import com.cloud.agent.api.to.DiskTO; +import com.cloud.agent.api.to.NfsTO; +import com.cloud.hypervisor.ovm3.objects.ConnectionTest; +import com.cloud.hypervisor.ovm3.objects.LinuxTest; +import com.cloud.hypervisor.ovm3.objects.OvmObject; +import com.cloud.hypervisor.ovm3.objects.StoragePluginTest; +import com.cloud.hypervisor.ovm3.objects.XenTest; +import com.cloud.hypervisor.ovm3.objects.XmlTestResultTest; +import com.cloud.hypervisor.ovm3.resources.helpers.Ovm3Configuration; +import com.cloud.hypervisor.ovm3.resources.helpers.Ovm3ConfigurationTest; +import com.cloud.hypervisor.ovm3.support.Ovm3SupportTest; +import com.cloud.storage.Volume; +import com.cloud.vm.DiskProfile; + +public class Ovm3StorageProcessorTest { + ConnectionTest con = new ConnectionTest(); + OvmObject ovmObject = new OvmObject(); + XmlTestResultTest results = new XmlTestResultTest(); + Ovm3ConfigurationTest configTest = new Ovm3ConfigurationTest(); + Ovm3HypervisorResource hypervisor = new Ovm3HypervisorResource(); + Ovm3SupportTest support = new Ovm3SupportTest(); + LinuxTest linux = new LinuxTest(); + XenTest xen = new XenTest(); + StoragePluginTest storageplugin = new StoragePluginTest(); + + private ConnectionTest prepare() throws ConfigurationException { + Ovm3Configuration config = new Ovm3Configuration(configTest.getParams()); + con = support.prepConnectionResults(); + hypervisor.setConnection(con); + results.basicBooleanTest(hypervisor.configure(config.getAgentName(), + configTest.getParams())); + return con; + } + + /* these could all actually be condensed to a DiskTO */ + private TemplateObjectTO template(final String uuid, final String dsuuid, + final String storeUrl, final String path) { + TemplateObjectTO template = new TemplateObjectTO(); + NfsTO nfsDataStore = new NfsTO(); + nfsDataStore.setUuid(dsuuid); + nfsDataStore.setUrl(storeUrl); + template.setDataStore(nfsDataStore); + template.setPath(path); + template.setUuid(uuid); + return template; + } + + private VolumeObjectTO volume(final String uuid, final String dsuuid, + final String storeUrl, final String path) { + VolumeObjectTO volume = new VolumeObjectTO(); + NfsTO nfsDataStore = new NfsTO(); + nfsDataStore.setUuid(dsuuid); + nfsDataStore.setUrl(storeUrl); + volume.setDataStore(nfsDataStore); + volume.setPath(path); + volume.setUuid(uuid); + return volume; + } + + private SnapshotObjectTO snapshot(final String uuid, final String dsuuid, + final String storeUrl, final String path) { + SnapshotObjectTO volume = new SnapshotObjectTO(); + NfsTO nfsDataStore = new NfsTO(); + nfsDataStore.setUuid(dsuuid); + nfsDataStore.setUrl(storeUrl); + volume.setDataStore(nfsDataStore); + volume.setPath(path); + // volume.setUuid(uuid); + return volume; + } + + private DiskTO disk(final String uuid, final String dsuuid, + final String storeUrl, final String path, Volume.Type type) { + DiskTO disk = new DiskTO(); + disk.setType(type); + disk.setPath(""); + TemplateObjectTO template = template(uuid, dsuuid, storeUrl, path); + disk.setData(template); + return disk; + } + + /** + * Copy template from primary to primary volume + * + * @throws ConfigurationException + */ + @Test + public void copyCommandTemplateToVolumeTest() throws ConfigurationException { + con = prepare(); + String voluuid = ovmObject.newUuid(); + TemplateObjectTO src = template(ovmObject.newUuid(), + ovmObject.newUuid(), linux.getRepoId(), linux.getTemplatesDir()); + VolumeObjectTO dest = volume(voluuid, ovmObject.newUuid(), + linux.getRepoId(), linux.getVirtualDisksDir()); + CopyCommand copy = new CopyCommand(src, dest, 0, true); + CopyCmdAnswer ra = (CopyCmdAnswer) hypervisor.executeRequest(copy); + VolumeObjectTO vol = (VolumeObjectTO) ra.getNewData(); + results.basicStringTest(vol.getUuid(), voluuid); + results.basicStringTest(vol.getPath(), voluuid); + results.basicBooleanTest(ra.getResult()); + } + + /** + * Copy template from secondary to primary template + * + * @throws ConfigurationException + */ + @Test + public void copyCommandTemplateToTemplateTest() + throws ConfigurationException { + con = prepare(); + con.setMethodResponse("storage_plugin_mount", + results.simpleResponseWrapWrapper(storageplugin + .getNfsFileSystemInfo())); + /* + * because the template requires a reference to the name for the uuid... + * -sigh- + */ + String templateid = ovmObject.newUuid(); + String targetid = ovmObject.newUuid(); + String templatedir = "template/tmpl/1/11" + templateid + ".raw"; + String storeUrl = "nfs://" + linux.getRemoteHost() + "/" + + linux.getRemoteDir(); + TemplateObjectTO src = template(templateid, linux.getRepoId(), + storeUrl, templatedir); + TemplateObjectTO dest = template(targetid, + linux.getRepoId(), linux.getRepoId(), linux.getTemplatesDir()); + CopyCommand copy = new CopyCommand(src, dest, 0, true); + CopyCmdAnswer ra = (CopyCmdAnswer) hypervisor.executeRequest(copy); + TemplateObjectTO vol = (TemplateObjectTO) ra.getNewData(); + results.basicStringTest(vol.getUuid(), targetid); + results.basicStringTest(vol.getPath(), targetid); + results.basicBooleanTest(ra.getResult()); + } + + /** + * Copy template from secondary to primary template + * + * @throws ConfigurationException + */ + @Test + public void copyCommandBogusTest() throws ConfigurationException { + con = prepare(); + VolumeObjectTO src = volume(ovmObject.newUuid(), ovmObject.newUuid(), + ovmObject.newUuid(linux.getRemote()), linux.getRemote()); + VolumeObjectTO dest = volume(ovmObject.newUuid(), ovmObject.newUuid(), + linux.getRepoId(), linux.getVirtualDisksDir()); + CopyCommand copy = new CopyCommand(src, dest, 0, false); + Answer ra = hypervisor.executeRequest(copy); + results.basicBooleanTest(ra.getResult(), false); + } + + /** + * Delete an object + * + * @throws ConfigurationException + */ + @Test + public void deleteCommandTest() throws ConfigurationException { + con = prepare(); + VolumeObjectTO vol = volume(ovmObject.newUuid(), ovmObject.newUuid(), + linux.getRepoId(), linux.getVirtualDisksDir()); + DeleteCommand delete = new DeleteCommand(vol); + Answer ra = hypervisor.executeRequest(delete); + results.basicBooleanTest(ra.getResult()); + TemplateObjectTO template = template(ovmObject.newUuid(), + ovmObject.newUuid(), ovmObject.newUuid(linux.getRemote()), + linux.getRemote()); + delete = new DeleteCommand(template); + ra = hypervisor.executeRequest(delete); + results.basicBooleanTest(ra.getResult(), false); + SnapshotObjectTO snap = snapshot(ovmObject.newUuid(), + ovmObject.newUuid(), ovmObject.newUuid(linux.getRemote()), + linux.getRemote()); + delete = new DeleteCommand(snap); + ra = hypervisor.executeRequest(delete); + results.basicBooleanTest(ra.getResult(), false); + } + + public DiskProfile diskProfile() { + DiskProfile dp = new DiskProfile(1L, Volume.Type.ROOT, + xen.getVmRootDiskName(), 1, storageplugin.getFileSize(), + new String[0], false, false, 1L); + return dp; + } + + /* + * unused ? + * + * @Test + * public void createCommandTest() throws ConfigurationException { + * con = prepare(); + * DiskProfile disk = diskProfile(); + * String templateUrl = null; + * StoragePoolVO poolio = new StoragePoolVO(); + * poolio.setPath(linux.getTemplatesDir()); + * poolio.setHostAddress(linux.getRemoteHost()); + * + * CreateCommand create = new CreateCommand(disk, templateUrl, poolio , + * false); + * Answer ra = hypervisor.executeRequest(create); + * results.basicBooleanTest(ra.getResult()); + * } + */ + @Test + public void createTemplateObjectCommandTest() throws ConfigurationException { + con = prepare(); + String tempuuid = ovmObject.newUuid(); + TemplateObjectTO template = template(tempuuid, ovmObject.newUuid(), + ovmObject.newUuid(linux.getRemote()), linux.getRemote()); + template.setSize(storageplugin.getFileSize()); + String response = storageplugin.getFileCreateXml().replace( + storageplugin.getFileName(), tempuuid + ".raw"); + response = response.replace(storageplugin.getPoolUuid(), + ovmObject.deDash(linux.getRepoId())); + con.setMethodResponse("storage_plugin_create", + results.simpleResponseWrapWrapper(response)); + CreateObjectCommand create = new CreateObjectCommand(template); + Answer ra = hypervisor.executeRequest(create); + results.basicBooleanTest(ra.getResult(), false); + } + + @Test + public void createVolumeObjectCommandTest() throws ConfigurationException { + con = prepare(); + String voluuid = ovmObject.newUuid(); + VolumeObjectTO vol = volume(voluuid, linux.getRepoId(), "", + linux.getVirtualDisksDir()); + vol.setSize(storageplugin.getFileSize()); + String response = storageplugin.getFileCreateXml().replace( + storageplugin.getFileName(), voluuid + ".raw"); + response = response.replace(storageplugin.getPoolUuid(), + ovmObject.deDash(linux.getRepoId())); + con.setMethodResponse("storage_plugin_create", + results.simpleResponseWrapWrapper(response)); + CreateObjectCommand create = new CreateObjectCommand(vol); + Answer ra = hypervisor.executeRequest(create); + results.basicBooleanTest(ra.getResult()); + } + + @Test + public void createSnapshotObjectCommandTest() throws ConfigurationException { + con = prepare(); + String snapuuid = ovmObject.newUuid(); + SnapshotObjectTO snap = snapshot(snapuuid, linux.getRepoId(), "", + linux.getVirtualDisksDir()); + String response = storageplugin.getFileCreateXml().replace( + storageplugin.getFileName(), snapuuid + ".raw"); + response = response.replace(storageplugin.getPoolUuid(), + ovmObject.deDash(linux.getRepoId())); + con.setMethodResponse("storage_plugin_create", + results.simpleResponseWrapWrapper(response)); + CreateObjectCommand create = new CreateObjectCommand(snap); + Answer ra = hypervisor.executeRequest(create); + results.basicBooleanTest(ra.getResult(), false); + } + + /* + * used ? + * + * @Test + * public void isoAttachTest() throws ConfigurationException { + * con = prepare(); + * con.setMethodResponse("storage_plugin_mount", + * results.simpleResponseWrapWrapper(storageplugin.getNfsFileSystemInfo())); + * String diskid = ovmObject.newUuid(); + * String storeUrl = "nfs://" + linux.getRemoteHost() + "/" + + * linux.getIsoDir(); + * DiskTO disk = disk(diskid, ovmObject.newUuid(), storeUrl, "bla", + * Volume.Type.ISO); + * AttachCommand at = new AttachCommand((DiskTO) disk, xen.getVmName()); + * Answer ra = storage.attachIso(at); + * System.out.println(ra); + * } + */ + @Test + public void isoDettachTest() throws ConfigurationException { + con = prepare(); + + } + + @Test + public void copyVolumeCommandTest() throws ConfigurationException { + con = prepare(); + String src = linux.getVirtualDisksDir() + ovmObject.newUuid() + ".raw"; + String dst = linux.getVirtualDisksDir() + ovmObject.newUuid() + ".raw"; + StoragePoolVO poolio = new StoragePoolVO(); + CopyVolumeCommand copy = new CopyVolumeCommand(0, src, poolio, dst, + true, 0, false); + Answer ra = hypervisor.executeRequest(copy); + results.basicBooleanTest(ra.getResult()); + copy = new CopyVolumeCommand(0, src, poolio, dst, false, 0, false); + ra = hypervisor.executeRequest(copy); + results.basicBooleanTest(ra.getResult()); + } + + /* + * unused ? + * + * @Test + * public void destroyCommandTest() throws ConfigurationException { + * con = prepare(); + * DestroyCommand destroy = new DestroyCommand(support.pool, + * (Volume) volume(xen.getVmRootDiskUuid(), linux.getRepoId(), "", + * linux.getVirtualDisksDir()), + * xen.getVmName()); + * } + */ +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c27c6943/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/Ovm3VirtualRoutingResourceTest.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/Ovm3VirtualRoutingResourceTest.java b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/Ovm3VirtualRoutingResourceTest.java new file mode 100644 index 0000000..2ec4bac --- /dev/null +++ b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/Ovm3VirtualRoutingResourceTest.java @@ -0,0 +1,232 @@ +/******************************************************************************* + * 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 com.cloud.hypervisor.ovm3.resources; + +import java.util.ArrayList; +import java.util.List; + +import javax.naming.ConfigurationException; + +import org.junit.Test; + +import com.cloud.agent.api.routing.IpAssocCommand; +import com.cloud.agent.api.routing.IpAssocVpcCommand; +import com.cloud.agent.api.routing.NetworkElementCommand; +import com.cloud.agent.api.to.IpAddressTO; +import com.cloud.hypervisor.ovm3.objects.CloudStackPluginTest; +import com.cloud.hypervisor.ovm3.objects.ConnectionTest; +import com.cloud.hypervisor.ovm3.objects.LinuxTest; +import com.cloud.hypervisor.ovm3.objects.NetworkTest; +import com.cloud.hypervisor.ovm3.objects.OvmObject; +import com.cloud.hypervisor.ovm3.objects.XenTest; +import com.cloud.hypervisor.ovm3.objects.XmlTestResultTest; +import com.cloud.hypervisor.ovm3.resources.helpers.Ovm3Configuration; +import com.cloud.hypervisor.ovm3.resources.helpers.Ovm3ConfigurationTest; +import com.cloud.hypervisor.ovm3.support.Ovm3SupportTest; +import com.cloud.utils.ExecutionResult; + +public class Ovm3VirtualRoutingResourceTest { + ConnectionTest con; + OvmObject ovmObject = new OvmObject(); + XmlTestResultTest results = new XmlTestResultTest(); + Ovm3ConfigurationTest configTest = new Ovm3ConfigurationTest(); + Ovm3HypervisorResource hypervisor = new Ovm3HypervisorResource(); + Ovm3VirtualRoutingResource virtualrouting = new Ovm3VirtualRoutingResource(); + Ovm3SupportTest support = new Ovm3SupportTest(); + XenTest xen = new XenTest(); + NetworkTest net = new NetworkTest(); + LinuxTest linux = new LinuxTest(); + CloudStackPluginTest csp = new CloudStackPluginTest(); + String dom0Ip = csp.getDom0Ip(); + String domrIp = csp.getDomrIp(); + String routerip = "64.1.1.10"; + /* cheat */ + String cmd = "ls"; + String args = ""; + + @Test + public void executeInVRTest() { + con = support.prepConnectionResults(); + cmd = "/opt/cloud/bin/" + cmd; + virtualrouting.setConnection(con); + ExecutionResult result = virtualrouting.executeInVR(domrIp, cmd, args); + results.basicBooleanTest(result.isSuccess()); + } + + @Test + public void executeInVRFailTest() { + ConnectionTest con = new ConnectionTest(); + virtualrouting.setConnection(con); + ExecutionResult result = virtualrouting.executeInVR(domrIp, cmd, args); + results.basicBooleanTest(result.isSuccess(), false); + } + + @Test + public void createFileInVRTest() { + con = support.prepConnectionResults(); + virtualrouting.setConnection(con); + ExecutionResult result = virtualrouting.createFileInVR(domrIp, "/tmp", + "test", "1 2 3"); + results.basicBooleanTest(result.isSuccess()); + } + + @Test + public void createFileInVRFailTest() { + ConnectionTest con = new ConnectionTest(); + virtualrouting.setConnection(con); + ExecutionResult result = virtualrouting.createFileInVR(domrIp, "/tmp", + "test", "1 2 3"); + results.basicBooleanTest(result.isSuccess(), false); + } + + private ConnectionTest prepare() throws ConfigurationException { + Ovm3Configuration config = new Ovm3Configuration(configTest.getParams()); + con = support.prepConnectionResults(); + hypervisor.setConnection(con); + results.basicBooleanTest(hypervisor.configure(config.getAgentName(), + configTest.getParams())); + virtualrouting.setConnection(con); + return con; + } + + @Test + public void prepareVpcCommandFailTest() throws ConfigurationException { + prepare(); + IpAssocVpcCommand vpc = generateIpAssocVpcCommand(xen.getVmNicMac() + .replace("0", "A")); + results.basicBooleanTest(hypervisor.executeRequest(vpc).getResult(), + false); + } + + @Test + public void prepareVpcCommandFailHeavierTest() + throws ConfigurationException { + prepare(); + con.removeMethodResponse("list_vms"); + IpAssocVpcCommand vpc = generateIpAssocVpcCommand(xen.getVmNicMac() + .replace("0", "F")); + results.basicBooleanTest(hypervisor.executeRequest(vpc).getResult(), + false); + } + + @Test + public void prepareCommandTest() throws ConfigurationException { + prepare(); + IpAssocCommand rvm = generateIpAssocCommand(xen.getVmNicMac()); + results.basicBooleanTest(hypervisor.executeRequest(rvm).getResult()); + } + + /** + * Test is not broken, but code broke somewhere look for the mac that doesn' + "nics": [ + { + "deviceId": 2, + "networkRateMbps": 200, + "defaultNic": true, + "pxeDisable": true, + "nicUuid": "80bd3c5b-a0f0-4de5-894a-999c83210d7c", + "uuid": "eec7acd1-2845-4e46-9226-bd211bb97f28", + "ip": "192.168.1.154", + "netmask": "255.255.255.0", + "gateway": "192.168.1.1", + "mac": "06:83:0c:00:00:1e", + "dns1": "192.168.1.60", + "dns2": "192.168.1.1", + "broadcastType": "Vlan", + "type": "Public", + "broadcastUri": "vlan://0", + "isolationUri": "vlan://0", + "isSecurityGroupEnabled": false + }, + { + "com.cloud.agent.api.routing.IpAssocCommand": { + "ipAddresses": [ + { + "accountId": 2, + "publicIp": "192.168.1.154", + "sourceNat": true, + "add": true, + "oneToOneNat": false, + "firstIP": true, + "broadcastUri": "vlan://0", + "vlanGateway": "192.168.1.1", + "vlanNetmask": "255.255.255.0", + "vifMacAddress": "06:74:f6:00:00:1e", + "networkRate": 200, + "trafficType": "Public", + "newNic": false + } + * @throws ConfigurationException + */ + @Test + public void prepareCommandFailTest() throws ConfigurationException { + prepare(); + IpAssocCommand rvm = generateIpAssocCommand(xen.getVmNicMac().replace( + "0", "F")); + boolean res = hypervisor.executeRequest(rvm).getResult(); + // this should be false... + results.basicBooleanTest(res, + true); + } + + @Test + public void prepareCommandFailHeavierTest() throws ConfigurationException { + prepare(); + con.removeMethodResponse("list_vms"); + IpAssocCommand rvm = generateIpAssocCommand(xen.getVmNicMac().replace( + "0", "F")); + results.basicBooleanTest(hypervisor.executeRequest(rvm).getResult(), + false); + } + + @Test + public void prepareVpcCommandTest() throws ConfigurationException { + prepare(); + IpAssocVpcCommand vpc = generateIpAssocVpcCommand(xen.getVmNicMac()); + results.basicBooleanTest(hypervisor.executeRequest(vpc).getResult()); + } + + private IpAddressTO[] getIp(String mac) { + String br[] = xen.getVmNicBridge().split("[.]"); + List ips = new ArrayList(); + IpAddressTO ip = new IpAddressTO(1, routerip, true, true, true, "vlan://" + + br[1], "64.1.1.1", "255.255.255.0", mac, 1000, false); + ips.add(ip); + IpAddressTO[] ipArray = ips.toArray(new IpAddressTO[ips.size()]); + return ipArray; + } + + private IpAssocVpcCommand generateIpAssocVpcCommand(String mac) { + IpAssocVpcCommand cmd = new IpAssocVpcCommand(getIp(mac)); + cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, xen.getVmName()); + cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, routerip); + // assertEquals(6, cmd.getAnswersCount()); // AnswersCount is clearly + // wrong as it doesn't know enough to tell + return cmd; + } + + private IpAssocCommand generateIpAssocCommand(String mac) { + IpAssocCommand cmd = new IpAssocCommand(getIp(mac)); + cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, xen.getVmName()); + cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, routerip); + // assertEquals(6, cmd.getAnswersCount()); // AnswersCount is clearly + // wrong as it doesn't know enough to tell + return cmd; + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c27c6943/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3ConfigurationTest.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3ConfigurationTest.java b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3ConfigurationTest.java new file mode 100644 index 0000000..da0cbe2 --- /dev/null +++ b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3ConfigurationTest.java @@ -0,0 +1,112 @@ +/******************************************************************************* + * 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 com.cloud.hypervisor.ovm3.resources.helpers; + +import java.util.HashMap; +import java.util.Map; + +import javax.naming.ConfigurationException; + +import org.junit.Test; + +import com.cloud.hypervisor.ovm3.objects.XmlTestResultTest; + +public class Ovm3ConfigurationTest { + XmlTestResultTest results = new XmlTestResultTest(); + private Ovm3Configuration ovm3config; + private static Map params; + static { + params = new HashMap(); + params.put("agentusername", "oracle"); + params.put("xenserver.heartbeat.interval", "60"); + params.put("public.network.device", "xenbr0"); + params.put("private.network.device", "xenbr0"); + params.put("agentpassword", "unknown"); + params.put("secondary.storage.vm", "false"); + params.put("Hypervisor.Version", "4.1.3OVM"); + params.put("Host.OS", "Oracle VM Server"); + params.put("ipaddress", "192.168.1.64"); + params.put("ovm3pool", "true"); + params.put("password", "unknown"); + params.put("username", "root"); + params.put("pool", "a9c1219d-817d-4242-b23e-2607801c79d5"); + params.put("ismaster", "false"); + params.put("storage.network.device", "xenbr0"); + params.put("Host.OS.Version", "5.7"); + params.put("xenserver.nics.max", "7"); + params.put("agentVersion", "3.2.1-183"); + params.put("router.aggregation.command.each.timeout", "3"); + params.put("pod", "1"); + params.put("max.template.iso.size", "50"); + params.put("host", "ovm-1"); + params.put("com.cloud.network.Networks.RouterPrivateIpStrategy", + "DcGlobal"); + params.put("agentport", "8899"); + params.put("Host.OS.Kernel.Version", "2.6.39-300.22.2.el5uek"); + params.put("migratewait", "3600"); + params.put("storage.network.device1", "xenbr0"); + params.put("ovm3cluster", "false"); + params.put("ip", "192.168.1.64"); + params.put("guid", "19e5f1e7-22f4-3b6d-8d41-c82f89c65295"); + params.put("ovm3vip", "192.168.1.230"); + params.put("hasmaster", "true"); + params.put("guest.network.device", "xenbr0"); + params.put("cluster", "1"); + params.put("xenserver.heartbeat.timeout", "120"); + params.put("ovm3.heartbeat.timeout", "120"); + params.put("ovm3.heartbeat.interval", "1"); + params.put("zone", "1"); + params.put("istest", true); + } + + @Test + public void testConfigLoad() throws ConfigurationException { + params.put("pod", "1"); + ovm3config = new Ovm3Configuration(params); + results.basicStringTest(ovm3config.getAgentHostname(), "ovm-1"); + } + + @Test(expected = ConfigurationException.class) + public void testFailedParams() throws ConfigurationException { + Map par = new HashMap(params); + par.put("pod", null); + ovm3config = new Ovm3Configuration(par); + } + @Test + public void testValidatePool() throws ConfigurationException { + Map par = new HashMap(params); + par.put("cluster", "1"); + par.put("ovm3vip", "this is not an IP!"); + ovm3config = new Ovm3Configuration(par); + results.basicBooleanTest(ovm3config.getAgentInOvm3Pool(), false); + results.basicBooleanTest(ovm3config.getAgentInOvm3Cluster(), false); + results.basicStringTest(ovm3config.getOvm3PoolVip(), ""); + } + @Test + public void testAgentPort() throws ConfigurationException { + Map par = new HashMap(params); + String altPort="6333"; + par.put("agentport", altPort); + ovm3config = new Ovm3Configuration(par); + results.basicIntTest(Integer.parseInt(altPort), ovm3config.getAgentOvsAgentPort()); + } + public Map getParams() { + return params; + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c27c6943/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3GuestTypesTest.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3GuestTypesTest.java b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3GuestTypesTest.java new file mode 100644 index 0000000..436400d --- /dev/null +++ b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3GuestTypesTest.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * 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 com.cloud.hypervisor.ovm3.resources.helpers; + +import org.junit.Test; + +import com.cloud.hypervisor.ovm3.objects.XmlTestResultTest; + +public class Ovm3GuestTypesTest { + XmlTestResultTest results = new XmlTestResultTest(); + String ora = "Oracle Enterprise Linux 6.0 (64-bit)"; + Ovm3VmGuestTypes ovm3gt = new Ovm3VmGuestTypes(); + + @Test + public void testGetPvByOs() { + results.basicStringTest(ovm3gt.getOvm3GuestType(ora), "xen_pvm"); + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c27c6943/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3HypervisorNetworkTest.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3HypervisorNetworkTest.java b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3HypervisorNetworkTest.java new file mode 100644 index 0000000..64ada69 --- /dev/null +++ b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3HypervisorNetworkTest.java @@ -0,0 +1,110 @@ +package com.cloud.hypervisor.ovm3.resources.helpers; + +import java.util.ArrayList; +import java.util.List; + +import javax.naming.ConfigurationException; + +import org.junit.Test; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.CheckNetworkCommand; +import com.cloud.agent.api.PingTestCommand; +import com.cloud.hypervisor.ovm3.objects.CloudStackPluginTest; +import com.cloud.hypervisor.ovm3.objects.ConnectionTest; +import com.cloud.hypervisor.ovm3.objects.NetworkTest; +import com.cloud.hypervisor.ovm3.objects.XenTest; +import com.cloud.hypervisor.ovm3.objects.XmlTestResultTest; +import com.cloud.hypervisor.ovm3.resources.Ovm3HypervisorResource; +import com.cloud.hypervisor.ovm3.resources.Ovm3HypervisorResourceTest; +import com.cloud.hypervisor.ovm3.support.Ovm3SupportTest; +import com.cloud.network.PhysicalNetworkSetupInfo; + +public class Ovm3HypervisorNetworkTest { + ConnectionTest con = new ConnectionTest(); + Ovm3ConfigurationTest configTest = new Ovm3ConfigurationTest(); + Ovm3SupportTest support = new Ovm3SupportTest(); + Ovm3HypervisorResource hypervisor = new Ovm3HypervisorResource(); + Ovm3HypervisorResourceTest hyperTest = new Ovm3HypervisorResourceTest(); + CloudStackPluginTest csp = new CloudStackPluginTest(); + XenTest xen = new XenTest(); + NetworkTest network = new NetworkTest(); + XmlTestResultTest results = new XmlTestResultTest(); + + @Test + public void CheckNetworkCommandTest() throws ConfigurationException { + hypervisor = support.prepare(configTest.getParams()); + List setups = new ArrayList(); + PhysicalNetworkSetupInfo networkInfo = new PhysicalNetworkSetupInfo(); + setups.add(networkInfo); + CheckNetworkCommand cmd = new CheckNetworkCommand(setups); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult()); + } + @Test + public void CheckNetworkCommandGuestFailTest() throws ConfigurationException { + hypervisor = support.prepare(configTest.getParams()); + List setups = new ArrayList(); + PhysicalNetworkSetupInfo networkInfo = new PhysicalNetworkSetupInfo(); + networkInfo.setGuestNetworkName(network.getInterface() + "." + 3000); + setups.add(networkInfo); + CheckNetworkCommand cmd = new CheckNetworkCommand(setups); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult(), false); + } + @Test + public void CheckNetworkCommandPublicFailTest() throws ConfigurationException { + hypervisor = support.prepare(configTest.getParams()); + List setups = new ArrayList(); + PhysicalNetworkSetupInfo networkInfo = new PhysicalNetworkSetupInfo(); + networkInfo.setPublicNetworkName(network.getInterface() + "." + 3000); + setups.add(networkInfo); + CheckNetworkCommand cmd = new CheckNetworkCommand(setups); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult(), false); + } + @Test + public void CheckNetworkCommandPrivateFailTest() throws ConfigurationException { + hypervisor = support.prepare(configTest.getParams()); + List setups = new ArrayList(); + PhysicalNetworkSetupInfo networkInfo = new PhysicalNetworkSetupInfo(); + networkInfo.setPrivateNetworkName(network.getInterface() + "." + 3000); + setups.add(networkInfo); + CheckNetworkCommand cmd = new CheckNetworkCommand(setups); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult(), false); + } + @Test + public void CheckNetworkCommandStorageFalseTest() throws ConfigurationException { + hypervisor = support.prepare(configTest.getParams()); + List setups = new ArrayList(); + PhysicalNetworkSetupInfo networkInfo = new PhysicalNetworkSetupInfo(); + networkInfo.setStorageNetworkName(network.getInterface() + "." + 3000); + setups.add(networkInfo); + CheckNetworkCommand cmd = new CheckNetworkCommand(setups); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult()); + } + @Test + public void PingTestCommandWeDontPingRouterTest() throws ConfigurationException { + hypervisor = support.prepare(configTest.getParams()); + PingTestCommand cmd = new PingTestCommand(csp.getDom0Ip(), csp.getDomrIp()); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult(),false); + } + @Test + public void PingTestCommandComputeTest() throws ConfigurationException { + hypervisor = support.prepare(configTest.getParams()); + PingTestCommand cmd = new PingTestCommand(csp.getDom0Ip()); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult()); + } + @Test + public void PingTestCommandComputeFalseTest() throws ConfigurationException { + hypervisor = support.prepare(configTest.getParams()); + support.getConnection().setMethodResponse("ping", results.simpleResponseWrap("boolean", "0")); + PingTestCommand cmd = new PingTestCommand(csp.getDom0Ip()); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult(), false); + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c27c6943/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3HypervisorSupportTest.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3HypervisorSupportTest.java b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3HypervisorSupportTest.java new file mode 100644 index 0000000..0ba27b2 --- /dev/null +++ b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3HypervisorSupportTest.java @@ -0,0 +1,281 @@ +/******************************************************************************* + * 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 com.cloud.hypervisor.ovm3.resources.helpers; + +import static org.junit.Assert.assertNull; + +import javax.naming.ConfigurationException; + +import org.junit.Test; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.CheckHealthCommand; +import com.cloud.agent.api.CheckVirtualMachineCommand; +import com.cloud.agent.api.FenceCommand; +import com.cloud.agent.api.GetHostStatsCommand; +import com.cloud.agent.api.GetVncPortCommand; +import com.cloud.agent.api.MaintainCommand; +import com.cloud.agent.api.StartupRoutingCommand; +import com.cloud.hypervisor.ovm3.objects.ConnectionTest; +import com.cloud.hypervisor.ovm3.objects.LinuxTest; +import com.cloud.hypervisor.ovm3.objects.NetworkTest; +import com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException; +import com.cloud.hypervisor.ovm3.objects.XmlTestResultTest; +import com.cloud.hypervisor.ovm3.objects.XenTest; +import com.cloud.hypervisor.ovm3.resources.Ovm3HypervisorResource; +import com.cloud.hypervisor.ovm3.resources.Ovm3StorageProcessor; +import com.cloud.hypervisor.ovm3.resources.Ovm3VirtualRoutingResource; +import com.cloud.hypervisor.ovm3.support.Ovm3SupportTest; +import com.cloud.vm.VirtualMachine.State; + +public class Ovm3HypervisorSupportTest { + ConnectionTest con = new ConnectionTest(); + XmlTestResultTest results = new XmlTestResultTest(); + Ovm3ConfigurationTest configTest = new Ovm3ConfigurationTest(); + Ovm3HypervisorResource hypervisor = new Ovm3HypervisorResource(); + Ovm3VirtualRoutingResource virtualrouting = new Ovm3VirtualRoutingResource(); + Ovm3SupportTest support = new Ovm3SupportTest(); + Ovm3StorageProcessor storage; + Ovm3StoragePool pool; + XenTest xen = new XenTest(); + String vmName = xen.getVmName(); + String unknown = "------"; + String running = "r-----"; + String blocked = "-b----"; + String paused = "--p---"; + String shutdown = "---s--"; + String crashed = "----c-"; + String dying = "-----d"; + + /* we only want this for the xml results */ + String dom0stats = results.simpleResponseWrapWrapper("" + + "" + "rx" + + "25069761" + "" + + "" + "total" + + "4293918720" + "" + + "" + "tx" + + "37932556" + "" + + "" + "cpu" + + "2.4" + "" + "" + + "free" + + "1177550848" + "" + + ""); + + private ConnectionTest prepare() throws ConfigurationException { + Ovm3Configuration config = new Ovm3Configuration(configTest.getParams()); + con = support.prepConnectionResults(); + pool = new Ovm3StoragePool(con, config); + storage = new Ovm3StorageProcessor(con, config, pool); + hypervisor.setConnection(con); + results.basicBooleanTest(hypervisor.configure(config.getAgentName(), + configTest.getParams())); + virtualrouting.setConnection(con); + return con; + } + @Test + public void ReportedVmStatesTest() throws ConfigurationException, + Ovm3ResourceException { + Ovm3Configuration config = new Ovm3Configuration(configTest.getParams()); + con.setResult(xen.getMultipleVmsListXML()); + Ovm3HypervisorSupport hypervisor = new Ovm3HypervisorSupport(con, + config); + hypervisor.vmStateMapClear(); + + State vmState = hypervisor.getVmState(vmName); + results.basicStringTest(vmState.toString(), State.Running.toString()); + hypervisor.setVmStateStarting(vmName); + results.basicStringTest(hypervisor.getVmState(vmName).toString(), + State.Starting.toString()); + hypervisor.setVmState(vmName, State.Running); + results.basicStringTest(hypervisor.getVmState(vmName).toString(), + State.Running.toString()); + hypervisor.revmoveVmState(vmName); + assertNull(hypervisor.getVmState(vmName)); + } + + @Test + public void HypervisorVmStateTest() throws ConfigurationException, + Ovm3ResourceException { + Ovm3Configuration config = new Ovm3Configuration(configTest.getParams()); + Ovm3HypervisorSupport hypervisor = new Ovm3HypervisorSupport(con, + config); + setHypervisorVmState(hypervisor, blocked, unknown, State.Unknown); + setHypervisorVmState(hypervisor, blocked, running, State.Running); + setHypervisorVmState(hypervisor, blocked, blocked, State.Running); + setHypervisorVmState(hypervisor, blocked, paused, State.Running); + /* TODO: ehm wtf ? */ + setHypervisorVmState(hypervisor, blocked, shutdown, State.Running); + setHypervisorVmState(hypervisor, blocked, crashed, State.Error); + setHypervisorVmState(hypervisor, blocked, dying, State.Stopping); + } + + @Test + public void CombinedVmStateTest() throws ConfigurationException, + Ovm3ResourceException { + Ovm3Configuration config = new Ovm3Configuration(configTest.getParams()); + con.setResult(xen.getMultipleVmsListXML()); + Ovm3HypervisorSupport hypervisor = new Ovm3HypervisorSupport(con, + config); + hypervisor.vmStateMapClear(); + /* test starting */ + hypervisor.setVmState(vmName, State.Starting); + // System.out.println(hypervisor.getVmState(vmName)); + hypervisor.syncState(); + // System.out.println(hypervisor.getVmState(vmName)); + + // setHypervisorVmState(hypervisor, blocked, paused, State.Stopped); + + hypervisor.setVmState(vmName, State.Stopping); + hypervisor.setVmState(vmName, State.Migrating); + // setHypervisorVmState(hypervisor, blocked, running, State.Running); + hypervisor.setVmState(vmName, State.Stopped); + + // setHypervisorVmState(hypervisor, blocked, running, State.Migrating); + + } + + /** + * Sets the state, original, of the fake VM to replace. + * + * @param hypervisor + * @param original + * @param replace + * @param state + * @throws Ovm3ResourceException + */ + public void setHypervisorVmState(Ovm3HypervisorSupport hypervisor, + String original, String replace, State state) + throws Ovm3ResourceException { + String x = xen.getMultipleVmsListXML().replaceAll(original, replace); + con.setResult(x); + hypervisor.syncState(); + results.basicStringTest(hypervisor.getVmState(vmName).toString(), + state.toString()); + } + + @Test + public void getSystemVMKeyFileTest() throws ConfigurationException { + Ovm3Configuration config = new Ovm3Configuration(configTest.getParams()); + Ovm3HypervisorSupport hypervisor = new Ovm3HypervisorSupport(con, + config); + hypervisor.getSystemVMKeyFile(config.getAgentSshKeyFileName()); + } + @Test + public void getSystemVMKeyFileMissingTest() throws ConfigurationException { + Ovm3Configuration config = new Ovm3Configuration(configTest.getParams()); + Ovm3HypervisorSupport hypervisor = new Ovm3HypervisorSupport(con, + config); + hypervisor.getSystemVMKeyFile("missing"); + } + + @Test + public void checkHealthTest() throws ConfigurationException { + con = prepare(); + CheckHealthCommand cmd = new CheckHealthCommand(); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult()); + } + + @Test + public void masterCheckTest() throws ConfigurationException { + con = prepare(); + // System.out.println(hypervisor.masterCheck()); + } + + @Test + public void GetHostStatsCommandTest() throws ConfigurationException { + con = prepare(); + Ovm3Configuration config = new Ovm3Configuration(configTest.getParams()); + GetHostStatsCommand cmd = new GetHostStatsCommand(config.getCsHostGuid(), + config.getAgentName(), 1L); + con.setResult(this.dom0stats); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult()); + } + + @Test + public void GetHostStatsCommandFailTest() throws ConfigurationException { + con = prepare(); + Ovm3Configuration config = new Ovm3Configuration(configTest.getParams()); + GetHostStatsCommand cmd = new GetHostStatsCommand(config.getCsHostGuid(), + config.getAgentName(), 1L); + con.setNull(); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult(), false); + } + + @Test + public void CheckVirtualMachineCommandTest() throws ConfigurationException { + con = prepare(); + CheckVirtualMachineCommand cmd = new CheckVirtualMachineCommand(xen.getVmName()); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult()); + } + @Test + public void MaintainCommandTest() throws ConfigurationException { + con = prepare(); + MaintainCommand cmd = new MaintainCommand(); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult()); + } + @Test + public void GetVncPortCommandTest() throws ConfigurationException { + con = prepare(); + GetVncPortCommand cmd = new GetVncPortCommand(0, xen.getVmName()); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult()); + } + /* We can't fence yet... */ + @Test + public void FenceCommandTest() throws ConfigurationException { + con = prepare(); + FenceCommand cmd = new FenceCommand(); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult(), false); + } + + @Test + public void fillHostinfoTest() throws ConfigurationException { + Ovm3Configuration config = new Ovm3Configuration(configTest.getParams()); + ConnectionTest con = new ConnectionTest(); + con.setIp(config.getAgentIp()); + Ovm3HypervisorSupport hypervisor = new Ovm3HypervisorSupport(con, + config); + LinuxTest linuxTest = new LinuxTest(); + NetworkTest networkTest = new NetworkTest(); + StartupRoutingCommand srCmd = new StartupRoutingCommand(); + con.setResult(results.simpleResponseWrapWrapper(linuxTest + .getDiscoverHw())); + con.addResult(results.simpleResponseWrapWrapper(linuxTest + .getDiscoverserver())); + con.addResult(results.simpleResponseWrapWrapper(networkTest + .getDiscoverNetwork())); + hypervisor.fillHostInfo(srCmd); + } + + /* @Test(expected = CloudRuntimeException.class) + public void setupServerTest() throws ConfigurationException, IOException { + Ovm3Configuration config = new Ovm3Configuration(configTest.getParams()); + ConnectionTest con = new ConnectionTest(); + con.setIp("127.0.0.1"); + Ovm3HypervisorSupport hypervisor = new Ovm3HypervisorSupport(con, + config); + hypervisor.setupServer(config.getAgentSshKeyFileName()); + } */ +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c27c6943/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VirtualRoutingSupportTest.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VirtualRoutingSupportTest.java b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VirtualRoutingSupportTest.java new file mode 100644 index 0000000..6936b2d --- /dev/null +++ b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VirtualRoutingSupportTest.java @@ -0,0 +1,71 @@ +package com.cloud.hypervisor.ovm3.resources.helpers; + +import javax.naming.ConfigurationException; + +import org.junit.Test; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.NetworkUsageCommand; +import com.cloud.agent.api.check.CheckSshCommand; +import com.cloud.hypervisor.ovm3.objects.CloudStackPluginTest; +import com.cloud.hypervisor.ovm3.objects.ConnectionTest; +import com.cloud.hypervisor.ovm3.objects.XmlTestResultTest; +import com.cloud.hypervisor.ovm3.resources.Ovm3HypervisorResource; +import com.cloud.hypervisor.ovm3.support.Ovm3SupportTest; + +public class Ovm3VirtualRoutingSupportTest { + ConnectionTest con = new ConnectionTest(); + Ovm3ConfigurationTest configTest = new Ovm3ConfigurationTest(); + Ovm3SupportTest support = new Ovm3SupportTest(); + Ovm3HypervisorResource hypervisor = new Ovm3HypervisorResource(); + CloudStackPluginTest csp = new CloudStackPluginTest(); + XmlTestResultTest results = new XmlTestResultTest(); + + @Test + public void NetworkUsageCommandTest() throws ConfigurationException { + hypervisor = support.prepare(configTest.getParams()); + NetworkUsageCommand nuc = new NetworkUsageCommand(csp.getDomrIp(), "something", "", false); + Answer ra = hypervisor.executeRequest(nuc); + results.basicBooleanTest(ra.getResult()); + } + @Test + public void NetworkUsageVpcCommandTest() throws ConfigurationException { + hypervisor = support.prepare(configTest.getParams()); + NetworkUsageCommand nuc = new NetworkUsageCommand(csp.getDomrIp(), "something", "", true); + Answer ra = hypervisor.executeRequest(nuc); + results.basicBooleanTest(ra.getResult()); + } + @Test + public void NetworkVpcGetCommandTest() throws ConfigurationException { + NetworkVpcCommandTest("get"); + } + @Test + public void NetworkVpcCreateCommandTest() throws ConfigurationException { + NetworkVpcCommandTest("create"); + } + @Test + public void NetworkVpcResetCommandTest() throws ConfigurationException { + NetworkVpcCommandTest("reset"); + } + @Test + public void NetworkVpcVpnCommandTest() throws ConfigurationException { + NetworkVpcCommandTest("vpn"); + } + @Test + public void NetworkVpcRemoveCommandTest() throws ConfigurationException { + NetworkVpcCommandTest("remove"); + } + public void NetworkVpcCommandTest(String cmd) throws ConfigurationException { + hypervisor = support.prepare(configTest.getParams()); + NetworkUsageCommand nuc = new NetworkUsageCommand(csp.getDomrIp(), "something", cmd, true); + Answer ra = hypervisor.executeRequest(nuc); + results.basicBooleanTest(ra.getResult()); + } + @Test + public void CheckSshCommandTest() throws ConfigurationException { + hypervisor = support.prepare(configTest.getParams()); + CheckSshCommand ssh = new CheckSshCommand("name", csp.getDomrIp(), 8899); + Answer ra = hypervisor.executeRequest(ssh); + results.basicBooleanTest(ra.getResult()); + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c27c6943/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VmSupportTest.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VmSupportTest.java b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VmSupportTest.java new file mode 100644 index 0000000..e6e19f4 --- /dev/null +++ b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VmSupportTest.java @@ -0,0 +1,123 @@ +package com.cloud.hypervisor.ovm3.resources.helpers; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; +import javax.naming.ConfigurationException; +import org.junit.Test; +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.GetVmStatsCommand; +import com.cloud.agent.api.MigrateCommand; +import com.cloud.agent.api.PlugNicCommand; +import com.cloud.agent.api.PrepareForMigrationCommand; +import com.cloud.agent.api.UnPlugNicCommand; +import com.cloud.agent.api.to.NicTO; +import com.cloud.hypervisor.ovm3.objects.CloudStackPluginTest; +import com.cloud.hypervisor.ovm3.objects.ConnectionTest; +import com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException; +import com.cloud.hypervisor.ovm3.objects.XenTest; +import com.cloud.hypervisor.ovm3.objects.XmlTestResultTest; +import com.cloud.hypervisor.ovm3.resources.Ovm3HypervisorResource; +import com.cloud.hypervisor.ovm3.resources.Ovm3HypervisorResourceTest; +import com.cloud.hypervisor.ovm3.support.Ovm3SupportTest; +import com.cloud.network.Networks.TrafficType; +import com.cloud.vm.VirtualMachine; + +public class Ovm3VmSupportTest { + ConnectionTest con = new ConnectionTest(); + Ovm3ConfigurationTest configTest = new Ovm3ConfigurationTest(); + Ovm3SupportTest support = new Ovm3SupportTest(); + Ovm3HypervisorResource hypervisor = new Ovm3HypervisorResource(); + Ovm3HypervisorResourceTest hyperTest = new Ovm3HypervisorResourceTest(); + CloudStackPluginTest csp = new CloudStackPluginTest(); + XenTest xen = new XenTest(); + XmlTestResultTest results = new XmlTestResultTest(); + + private NicTO prepNic(String mac, Integer vlan, TrafficType type) throws URISyntaxException { + return prepNic(mac, vlan, type, 0); + } + private NicTO prepNic(String mac, Integer vlan, TrafficType type, Integer id) throws URISyntaxException { + URI iso = new URI("vlan://" + vlan.toString()); + NicTO nic = new NicTO(); + nic.setType(type); + /* Isolation is not what it seems.... */ + /* nic.setIsolationuri(iso); */ + nic.setBroadcastUri(iso); + nic.setMac(mac); + nic.setDeviceId(id); + return nic; + } + @Test + public void PlugNicTest() throws ConfigurationException, URISyntaxException { + hypervisor = support.prepare(configTest.getParams()); + NicTO nic = prepNic(xen.getVmNicMac(), 200, TrafficType.Guest); + PlugNicCommand plug = new PlugNicCommand(nic,xen.getVmName(), VirtualMachine.Type.User); + Answer ra = hypervisor.executeRequest(plug); + results.basicBooleanTest(ra.getResult()); + } + @Test + public void PlugNicBreakTest() throws ConfigurationException, URISyntaxException { + hypervisor = support.prepare(configTest.getParams()); + NicTO nic = prepNic(xen.getVmNicMac(), 240, TrafficType.Guest); + PlugNicCommand plug = new PlugNicCommand(nic,xen.getVmName(), VirtualMachine.Type.User); + Answer ra = hypervisor.executeRequest(plug); + results.basicBooleanTest(ra.getResult(), false); + } + @Test + public void unPlugNicTest() throws ConfigurationException, URISyntaxException { + hypervisor = support.prepare(configTest.getParams()); + NicTO nic = prepNic(xen.getVmNicMac(), 200, TrafficType.Guest); + UnPlugNicCommand plug = new UnPlugNicCommand(nic, xen.getVmName()); + Answer ra = hypervisor.executeRequest(plug); + results.basicBooleanTest(ra.getResult()); + } + @Test + public void unPlugNicBreakTest() throws ConfigurationException, URISyntaxException { + hypervisor = support.prepare(configTest.getParams()); + NicTO nic = prepNic(xen.getVmNicMac(), 240, TrafficType.Guest); + UnPlugNicCommand plug = new UnPlugNicCommand(nic, xen.getVmName()); + Answer ra = hypervisor.executeRequest(plug); + results.basicBooleanTest(ra.getResult(), false); + } + @Test + public void GetVmStatsCommandTest() throws ConfigurationException { + hypervisor = support.prepare(configTest.getParams()); + Ovm3Configuration configuration = new Ovm3Configuration(configTest.getParams()); + List vms = new ArrayList(); + vms.add(xen.getVmName()); + GetVmStatsCommand cmd = new GetVmStatsCommand(vms, configuration.getCsHostGuid(), hypervisor.getName()); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult()); + cmd = new GetVmStatsCommand(vms, configuration.getCsHostGuid(), hypervisor.getName()); + ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult()); + } + @Test + public void PrepareForMigrationCommandTest() throws ConfigurationException, Ovm3ResourceException { + hypervisor = support.prepare(configTest.getParams()); + PrepareForMigrationCommand cmd = new PrepareForMigrationCommand(hyperTest.createVm(xen.getVmName())); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult()); + } + @Test + public void MigrateCommandTest() throws ConfigurationException, Ovm3ResourceException { + Ovm3Configuration configuration = new Ovm3Configuration(configTest.getParams()); + hypervisor = support.prepare(configTest.getParams()); + MigrateCommand cmd = new MigrateCommand(xen.getVmName(), configuration.getAgentIp(), false, hyperTest.createVm(xen.getVmName()), false); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult()); + } +/* + @Test + public void AttachVolumeCommandTest() throws ConfigurationException { + hypervisor = support.prepare(configTest.getParams()); + // boolean attach, boolean managed, String vmName, StoragePoolType pooltype, + // String volumePath, String volumeName, Long volumeSize, Long deviceId, String chainInfo + AttachVolumeCommand cmd = new AttachVolumeCommand(true, false, xen.getVmName(), StoragePoolType.NetworkFilesystem, + "x", "x", 0L, 0L, "x"); + Answer ra = hypervisor.executeRequest(cmd); + results.basicBooleanTest(ra.getResult()); + } +*/ +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c27c6943/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/support/Ovm3SupportTest.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/support/Ovm3SupportTest.java b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/support/Ovm3SupportTest.java new file mode 100644 index 0000000..95d8e42 --- /dev/null +++ b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/support/Ovm3SupportTest.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * 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 com.cloud.hypervisor.ovm3.support; + +import java.util.Map; + +import javax.naming.ConfigurationException; + +import com.cloud.hypervisor.ovm3.objects.CloudStackPluginTest; +import com.cloud.hypervisor.ovm3.objects.ConnectionTest; +import com.cloud.hypervisor.ovm3.objects.LinuxTest; +import com.cloud.hypervisor.ovm3.objects.NetworkTest; +import com.cloud.hypervisor.ovm3.objects.XenTest; +import com.cloud.hypervisor.ovm3.objects.XmlTestResultTest; +import com.cloud.hypervisor.ovm3.resources.Ovm3HypervisorResource; +import com.cloud.hypervisor.ovm3.resources.Ovm3VirtualRoutingResource; +import com.cloud.hypervisor.ovm3.resources.helpers.Ovm3Configuration; +import com.cloud.hypervisor.ovm3.resources.helpers.Ovm3ConfigurationTest; + +public class Ovm3SupportTest { + ConnectionTest con = new ConnectionTest(); + XmlTestResultTest results = new XmlTestResultTest(); + NetworkTest net = new NetworkTest(); + LinuxTest linux = new LinuxTest(); + XenTest xen = new XenTest(); + CloudStackPluginTest csp = new CloudStackPluginTest(); + Ovm3HypervisorResource hypervisor = new Ovm3HypervisorResource(); + Ovm3VirtualRoutingResource virtualrouting = new Ovm3VirtualRoutingResource(); + Ovm3ConfigurationTest configTest = new Ovm3ConfigurationTest(); + + public ConnectionTest prepConnectionResults() { + ConnectionTest con = new ConnectionTest(); + con.setIp(con.getHostName()); + return configureResult(con); + } + + public Ovm3HypervisorResource prepare(Map params) throws ConfigurationException { + Ovm3Configuration config = new Ovm3Configuration(params); + con = prepConnectionResults(); + hypervisor.setConnection(con); + results.basicBooleanTest(hypervisor.configure(config.getAgentName(), + configTest.getParams())); + return hypervisor; + } + public ConnectionTest getConnection() { + return con; + } + + public ConnectionTest configureResult(ConnectionTest con) { + con.setMethodResponse("check_dom0_ip", + results.simpleResponseWrap("boolean", "1")); + con.setMethodResponse("ovs_ip_config", + results.simpleResponseWrap("boolean", "1")); + con.setMethodResponse("ovs_local_config", + results.simpleResponseWrap("string", "start")); + con.setMethodResponse("ovs_control_interface", + results.simpleResponseWrap("boolean", "1")); + con.setMethodResponse("update_server_roles", + results.simpleResponseWrap("boolean", "1")); + con.setMethodResponse("discover_network", + results.simpleResponseWrapWrapper(net.getDiscoverNetwork())); + con.setMethodResponse("discover_hardware", + results.simpleResponseWrapWrapper(linux.getDiscoverHw())); + con.setMethodResponse("discover_server", + results.simpleResponseWrapWrapper(linux.getDiscoverserver())); + con.setMethodResponse("discover_mounted_file_systems", + results.simpleResponseWrapWrapper(linux.getDiscoverFs())); + con.setMethodResponse("get_vncport", results.simpleResponseWrapWrapper("5900")); + con.setMethodResponse("echo", results.simpleResponseWrapWrapper("put")); + con.setMethodResponse("list_vms", xen.getMultipleVmsListXML()); + con.setMethodResponse("list_vm", xen.getSingleVmListXML()); + con.setMethodResponse("get_vm_config", xen.getSingleVmConfigXML()); + con.setMethodResponse("create_vm", results.getNil()); + con.setMethodResponse("start_vm", results.getNil()); + con.setMethodResponse("reboot_vm", results.getNil()); + con.setMethodResponse("stop_vm", results.getNil()); + con.setMethodResponse("configure_vm", results.getNil()); + con.setMethodResponse("migrate_vm", results.getNil()); + con.setMethodResponse("copy_file", results.getNil()); + con.setMethodResponse("storage_plugin_destroy", results.getNil()); + con.setMethodResponse("ping", + results.simpleResponseWrap("boolean", "1")); + con.setMethodResponse("check_domr_ssh", + results.simpleResponseWrap("boolean", "1")); + con.setMethodResponse("check_domr_port", + results.simpleResponseWrap("boolean", "1")); + con.setMethodResponse("exec_domr", csp.getDomrExecXml()); + con.setMethodResponse("ovs_domr_upload_file", + results.simpleResponseWrap("boolean", "1")); + con.setMethodResponse("ovs_domU_stats", (csp.getDomuStatsXml())); + con.setMethodResponse("check_dom0_status", (csp.getDom0StorageCheckXml())); + con.setMethodResponse("check_dom0_storage_health", results.simpleResponseWrap("boolean", "1")); + con.setMethodResponse("check_dom0_port", results.simpleResponseWrap("boolean", "1")); + con.setMethodResponse("check_dom0_storage_health_check", (csp.getDom0StorageCheckXml())); + return con; + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c27c6943/plugins/hypervisors/ovm3/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/ovm3/src/test/resources/log4j.properties b/plugins/hypervisors/ovm3/src/test/resources/log4j.properties new file mode 100644 index 0000000..4579c25 --- /dev/null +++ b/plugins/hypervisors/ovm3/src/test/resources/log4j.properties @@ -0,0 +1,8 @@ +# Root logger option +log4j.rootLogger=DEBUG, stdout + +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c27c6943/plugins/hypervisors/ovm3/src/test/resources/scripts/clean_master.sh ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/ovm3/src/test/resources/scripts/clean_master.sh b/plugins/hypervisors/ovm3/src/test/resources/scripts/clean_master.sh new file mode 100755 index 0000000..bbf1cd0 --- /dev/null +++ b/plugins/hypervisors/ovm3/src/test/resources/scripts/clean_master.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# +# 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. +# +for i in `xm list | awk '{ print $1 }' | egrep -v "Name|Domain-0"` +do + xm destroy $i +done +rm /etc/ovs-agent/db/server +rm /etc/ovs-agent/db/repository +rm /etc/ocfs2/cluster.conf +rm /nfsmnt/*/*.img +rm /nfsmnt/*/.ovspoolfs +rm /nfsmnt/*/.generic_fs_stamp +rm /OVS/Repositories/*/.generic_fs_stamp +rm /OVS/Repositories/*/.ovsrepo +/etc/init.d/ovs-agent restart +/etc/init.d/ocfs2 restart +for i in `mount | grep cs-mgmt | awk '{ print $1 }'` +do + umount $i +done +rm -rf /OVS/Repositories/* +rm -rf /nfsmnt/* +ip addr del 192.168.1.230 dev c0a80100 +ip addr del 192.168.1.161 dev c0a80100 +rm /etc/sysconfig/network-scripts/ifcfg-control0 +reboot http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c27c6943/plugins/hypervisors/ovm3/src/test/resources/scripts/clean_slave.sh ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/ovm3/src/test/resources/scripts/clean_slave.sh b/plugins/hypervisors/ovm3/src/test/resources/scripts/clean_slave.sh new file mode 100755 index 0000000..4275ee8 --- /dev/null +++ b/plugins/hypervisors/ovm3/src/test/resources/scripts/clean_slave.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# +# 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. +# +for i in `xm list | awk '{ print $1 }' | egrep -v "Name|Domain-0"` +do + xm destroy $i +done +rm /etc/ovs-agent/db/server +rm /etc/ovs-agent/db/repository +rm /etc/ocfs2/cluster.conf +/etc/init.d/ovs-agent restart +/etc/init.d/ocfs2 restart +for i in `mount | grep cs-mgmt | awk '{ print $1 }'` +do + umount $i +done