public void willDeallocateOldVMsOnLogon()
        {
            using (bladeDirectorDebugServices svc = new bladeDirectorDebugServices(basicBladeTests.WCFPath, "172.17.129.131", true))
            {
                string hostIP = "1.1.1.1";
                testUtils.doLogin(svc, hostIP);

                // Allocate all the blades, then login again. The allocated blades should no longer be allocated.
                string ourVM = testUtils.doVMAllocationForTest(svc, hostIP);

                // Find the parent blade of the VM we got, and make sure it is now in use (by the blade director)
                vmSpec    VMSpec    = svc.svc.getVMByIP_withoutLocking(ourVM);
                bladeSpec bladeSpec = svc.svc.getBladeByIP_withoutLocking(VMSpec.parentBladeIP);

                GetBladeStatusResult bladeState = svc.svcDebug._GetBladeStatus(hostIP, bladeSpec.bladeIP);
                string bladeIP = bladeSpec.bladeIP;
                Assert.AreEqual(bladeState, GetBladeStatusResult.notYours);

                // Do a new login, which should cause our blades to be deallocated.
                testUtils.doLogin(svc, hostIP);

                // The VM should now not exist.
                Assert.AreEqual(null, svc.svc.getVMByIP_withoutLocking(ourVM));

                // Find the parent blade of the VM we got, and make sure it is now unused.
                GetBladeStatusResult bladeState2 = svc.svcDebug._GetBladeStatus(hostIP, bladeIP);
                Assert.AreEqual(bladeState2, GetBladeStatusResult.unused);
            }
        }
예제 #2
0
        public void reportsVMCreationFailureNeatly()
        {
            string hostIP = "1.1.1.1";

            using (bladeDirectorDebugServices uut = new bladeDirectorDebugServices(basicBladeTests.WCFPath, new[] { "1.1.1.1", "2.2.2.2", "3.3.3.3" }))
            {
                VMHardwareSpec hwSpec = new VMHardwareSpec()
                {
                    memoryMB = 2344, cpuCount = 2
                };
                VMSoftwareSpec swSpec = new VMSoftwareSpec();

                uut.svcDebug.initWithBladesFromIPList(new[] { "172.17.129.131", "172.17.129.130" }, true, NASFaultInjectionPolicy.failSnapshotDeletionOnFirstSnapshot);
                uut.svcDebug._setExecutionResultsIfMocked(mockedExecutionResponses.successful);

                resultAndBladeName allocRes;

                allocRes = uut.svcDebug._requestAnySingleVM(hostIP, hwSpec, swSpec);
                Assert.AreEqual(resultCode.pending, allocRes.result.code);

                waitToken waitTok = allocRes.waitToken;
                while (true)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(1));

                    resultAndBladeName progress = (resultAndBladeName)uut.svc.getProgress(waitTok);
                    waitTok = progress.waitToken;

                    if (progress.result.code == resultCode.pending)
                    {
                        continue;
                    }
                    Assert.AreEqual(resultCode.genericFail, progress.result.code);
                    Assert.AreEqual("172.17.158.1", progress.bladeName);
                    break;
                }
                // OK, our allocation failed. Try allocating a second VM - this one should succeed.

                allocRes = uut.svcDebug._requestAnySingleVM(hostIP, hwSpec, swSpec);
                Assert.AreEqual(resultCode.pending, allocRes.result.code);
                allocRes = (resultAndBladeName)testUtils.waitForSuccess(uut, allocRes, TimeSpan.FromMinutes(11));

                Assert.AreNotEqual("172.17.158.1", allocRes.bladeName);
                Assert.AreNotEqual("172.17.158.1", allocRes.bladeName);
                vmSpec VMConfig = uut.svc.getVMByIP_withoutLocking(allocRes.bladeName);
                Assert.AreNotEqual("00:50:56:00:30:01", VMConfig.eth0MAC);
                Assert.AreNotEqual("00:50:56:01:30:01", VMConfig.eth1MAC);
            }
        }
예제 #3
0
        public void canAllocateVMMocked()
        {
            string hostIP = "1.1.1.1";

            using (bladeDirectorDebugServices svc = new bladeDirectorDebugServices(basicBladeTests.WCFPath, new[] { "1.1.1.1", "2.2.2.2", "3.3.3.3" }))
            {
                VMHardwareSpec hwSpec = new VMHardwareSpec()
                {
                    memoryMB = 2344, cpuCount = 2
                };
                VMSoftwareSpec swSpec = new VMSoftwareSpec();

                resultAndBladeName[] allocRes = doVMAllocationsForTest(svc, hostIP, new[] { new vmHWAndSWSpec(hwSpec, swSpec) });
                Assert.AreEqual(1, allocRes.Length);
                resultAndBladeName allocatedBlade = allocRes[0];

                // TODO: check nas events
                mockedCall[] nasEvents = svc.svcDebug._getNASEventsIfMocked();
                foreach (mockedCall call in nasEvents)
                {
                    Debug.WriteLine(call.functionName + " " + call.message);
                }
                // TODO: check executions all happened okay

                // This blade should become a VM server
                GetBladeStatusResult allocated1 = svc.svcDebug._GetBladeStatus(hostIP, "172.17.129.130");
                Assert.AreEqual(allocated1, GetBladeStatusResult.notYours);

                // And there should now be one VM allocated to us at present.
                vmSpec VMConfig = svc.svc.getVMByIP_withoutLocking(allocatedBlade.bladeName);
                Assert.AreEqual("172.17.158.1", allocatedBlade.bladeName);
                Assert.AreEqual("VM_30_01", VMConfig.friendlyName);
                Assert.AreEqual("172.17.158.1", VMConfig.VMIP);
                Assert.AreEqual("10.0.158.1", VMConfig.iscsiIP);
                Assert.AreEqual("00:50:56:00:30:01", VMConfig.eth0MAC);
                Assert.AreEqual("00:50:56:01:30:01", VMConfig.eth1MAC);
                Assert.AreEqual(2344, VMConfig.memoryMB);
                Assert.AreEqual(2, VMConfig.cpuCount);
                Assert.AreEqual(hostIP, VMConfig.currentOwner);
            }
        }
예제 #4
0
        public void willProvisionVM()
        {
            using (bladeDirectorDebugServices svc = new bladeDirectorDebugServices(basicBladeTests.WCFPath, basicBladeTests.WebURI))
            {
                machinePools.bladeDirectorURL = svc.servicesURL;

                string hostip = "1.2.3.4";

                // We will be using this blade for our tests.
                bladeSpec spec = svc.svcDebug.createBladeSpecForXDLNode(31, "xdl.hacks.the.planet", bladeLockType.lockAll, bladeLockType.lockAll);
                svc.svcDebug.initWithBladesFromBladeSpec(new[] { spec }, false, NASFaultInjectionPolicy.retunSuccessful);

                string         debuggerHost = ipUtils.getBestRouteTo(IPAddress.Parse(spec.bladeIP)).ToString();
                VMSoftwareSpec sw           = new VMSoftwareSpec()
                {
                    debuggerHost = debuggerHost,
                    debuggerKey  = "a.b.c.d",
                    debuggerPort = 60234
                };
                VMHardwareSpec hw = new VMHardwareSpec()
                {
                    cpuCount = 1, memoryMB = 4096
                };
                resultAndBladeName res = svc.svcDebug._requestAnySingleVM(hostip, hw, sw);
                testUtils.waitForSuccess(svc, res, TimeSpan.FromMinutes(15));

                string VMName = res.bladeName;

                // Okay, we have our new VM allocated now.
                vmSpec          createdBlade = svc.svc.getVMByIP_withoutLocking(VMName);
                bladeSpec       parentBlade  = svc.svc.getBladeByIP_withoutLocking(createdBlade.parentBladeIP);
                snapshotDetails snap         = svc.svc.getCurrentSnapshotDetails(VMName);
                NASParams       nas          = svc.svc.getNASParams();
                using (hypervisor_vmware_FreeNAS hyp = utils.createHypForVM(createdBlade, parentBlade, snap, nas))
                {
                    hyp.powerOn(new cancellableDateTime(TimeSpan.FromMinutes(2)));

                    // Check that debugging has been provisioned correctly
                    executionResult bcdEditRes = hyp.startExecutable("bcdedit", "/dbgsettings");
                    try
                    {
                        Assert.AreEqual(0, bcdEditRes.resultCode);
                        Assert.IsTrue(Regex.IsMatch(bcdEditRes.stdout, "key\\s*a.b.c.d"));
                        Assert.IsTrue(Regex.IsMatch(bcdEditRes.stdout, "debugtype\\s*NET"));
                        Assert.IsTrue(Regex.IsMatch(bcdEditRes.stdout, "hostip\\s*" + hostip));
                        Assert.IsTrue(Regex.IsMatch(bcdEditRes.stdout, "port\\s*60234"));
                    }
                    catch (AssertFailedException)
                    {
                        Debug.WriteLine("bcdedit stdout " + bcdEditRes.stdout);
                        Debug.WriteLine("bcdedit stderr " + bcdEditRes.stderr);

                        throw;
                    }

                    executionResult wmicRes = hyp.startExecutable("wmic", "computersystem get totalPhysicalMemory,name,numberOfLogicalProcessors /format:value");
                    try
                    {
                        // We expect an response similar to:
                        //
                        // Name=ALIZANALYSIS
                        // NumberOfLogicalProcessors=8
                        // TotalPhysicalMemory=17119825920
                        //

                        Assert.AreEqual(0, wmicRes.resultCode);
                        string[] lines = wmicRes.stdout.Split(new[] { '\n', 'r' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string line in lines)
                        {
                            if (line.Trim().Length == 0)
                            {
                                continue;
                            }

                            string[] parts = line.Split('=');

                            string name  = parts[0].ToLower().Trim();
                            string value = parts[1].ToLower().Trim();

                            switch (name)
                            {
                            case "name":
                                Assert.AreEqual("VM_31_01", value, "Name is incorrect");
                                break;

                            case "NumberOfLogicalProcessors":
                                Assert.AreEqual("1", value, "CPU count is incorrect");
                                break;

                            case "TotalPhysicalMemory":
                                Assert.AreEqual((4096L * 1024L * 1024L).ToString(), value, "RAM size is incorrect");
                                break;

                            default:
                                break;
                            }
                        }
                    }
                    catch (AssertFailedException)
                    {
                        Debug.WriteLine("WMIC reported stdout '" + wmicRes.stdout + "'");
                        Debug.WriteLine("WMIC reported stderr '" + wmicRes.stderr + "'");
                    }
                }
            }
        }
        public hypervisorCollection <hypSpec_vmware> requestVMs(VMSpec[] specs, bool allowPartialAllocation = false)
        {
            initialiseIfNeeded();

            Stopwatch allocWatch = new Stopwatch();

            using (BladeDirectorServices director = new BladeDirectorServices(machinePools.bladeDirectorURL))
            {
                DateTime             deadline = DateTime.Now + TimeSpan.FromMinutes(30);
                resultAndBladeName[] results  = new resultAndBladeName[specs.Length];
                for (int n = 0; n < specs.Length; n++)
                {
                    results[n] = director.svc.RequestAnySingleVM(specs[n].hw, specs[n].sw);

                    if (results[n].result.code == resultCode.bladeQueueFull)
                    {
                        if (allowPartialAllocation)
                        {
                            results[n] = null;
                            break;
                        }
                    }

                    if (results[n].result.code != resultCode.success &&
                        results[n].result.code != resultCode.pending)
                    {
                        throw new bladeAllocationException(results[n].result.code);
                    }
                }

                hypervisorCollection <hypSpec_vmware> toRet = new hypervisorCollection <hypSpec_vmware>();
                try
                {
                    foreach (resultAndBladeName res in results)
                    {
                        if (res == null)
                        {
                            continue;
                        }

                        resultAndBladeName progress = director.waitForSuccessWithoutThrowing(res, deadline - DateTime.Now);
                        if (progress == null)
                        {
                            throw new TimeoutException();
                        }
                        if (progress.result.code == resultCode.bladeQueueFull)
                        {
                            if (allowPartialAllocation)
                            {
                                continue;
                            }
                            throw new Exception("Not enough blades available to accomodate new VMs");
                        }
                        if (progress.result.code != resultCode.success)
                        {
                            if (allowPartialAllocation)
                            {
                                continue;
                            }
                            throw new Exception("Unexpected status while allocing: " + progress.result.code);
                        }

                        vmSpec          vmSpec       = director.svc.getVMByIP_withoutLocking(progress.bladeName);
                        bladeSpec       vmServerSpec = director.svc.getBladeByIP_withoutLocking(vmSpec.parentBladeIP);
                        snapshotDetails snapshotInfo = director.svc.getCurrentSnapshotDetails(vmSpec.VMIP);
                        NASParams       nasParams    = director.svc.getNASParams();

                        hypervisor_vmware_FreeNAS newVM = utils.createHypForVM(vmSpec, vmServerSpec, snapshotInfo, nasParams);

                        ipUtils.ensurePortIsFree(vmSpec.kernelDebugPort);

                        newVM.setDisposalCallback(onDestruction);

                        if (!toRet.TryAdd(vmSpec.VMIP, newVM))
                        {
                            throw new Exception();
                        }
                    }
                }
                catch (Exception)
                {
                    foreach (KeyValuePair <string, hypervisorWithSpec <hypSpec_vmware> > allocedBlades in toRet)
                    {
                        if (allocedBlades.Key != null)
                        {
                            try
                            {
                                director.svc.ReleaseBladeOrVM(allocedBlades.Key);
                            }
                            catch (Exception)
                            {
                                // ...
                            }
                        }
                    }
                    throw;
                }
                allocWatch.Stop();
                Debug.WriteLine("Allocated all VMs, took " + allocWatch.Elapsed.ToString());
                return(toRet);
            }
        }