public void canAllocateAllVMsMocked() { 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" })) { svc.svcDebug._setExecutionResultsIfMocked(mockedExecutionResponses.successful); vmHWAndSWSpec toAlloc = new vmHWAndSWSpec( new VMHardwareSpec() { memoryMB = 4, cpuCount = 1 }, new VMSoftwareSpec()); resultAndBladeName[] res = svc.svcDebug._requestAsManyVMAsPossible(hostIP, toAlloc.hw, toAlloc.sw); foreach (resultAndBladeName resultAndBladeName in res) { testUtils.waitForSuccess(svc, resultAndBladeName, TimeSpan.FromMinutes(1)); } // Now see what we got. Assert.AreEqual(3 * 12, res.Length); } }
public void canAllocateANumberOfVMMocked() { 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" })) { vmHWAndSWSpec[] toAlloc = new vmHWAndSWSpec[8]; for (int i = 0; i < toAlloc.Length; i++) { toAlloc[i] = new vmHWAndSWSpec( new VMHardwareSpec() { memoryMB = 4096, cpuCount = 1 }, new VMSoftwareSpec()); } resultAndBladeName[] allocRes = doVMAllocationsForTest(svc, hostIP, toAlloc); Assert.AreEqual(toAlloc.Length, allocRes.Length); // Group blades by their parent blade's IP IGrouping <string, resultAndBladeName>[] bladesByParent = allocRes.GroupBy(x => svc.svc.getVMByIP_withoutLocking(x.bladeName).parentBladeIP).ToArray(); // We should have two VM servers in use. Assert.AreEqual(2, bladesByParent.Length); // 7 should be on the first blade, and 1 on the second. Assert.AreEqual(7, bladesByParent[0].Count()); Assert.AreEqual("172.17.129.130", bladesByParent[0].Key); Assert.AreEqual(1, bladesByParent[1].Count()); Assert.AreEqual("172.17.129.131", bladesByParent[1].Key); // And release them, checking hardware status after each blade is empty. foreach (IGrouping <string, resultAndBladeName> bladeAndParent in bladesByParent) { //string parentBladeName = uut.db.getConfigurationOfBladeByID((int)bladeAndParent.Key, bladeLockType.lockNone).spec.bladeIP; foreach (resultAndBladeName res in bladeAndParent) { // The VM server should still be allocated before release.. Assert.AreEqual(svc.svcDebug._GetBladeStatus(hostIP, bladeAndParent.Key), GetBladeStatusResult.notYours); resultAndWaitToken releaseWait = svc.svcDebug._ReleaseBladeOrVM(hostIP, res.bladeName, false); testUtils.waitForSuccess(svc, releaseWait, TimeSpan.FromSeconds(30)); } // This VM server should now be unused. Assert.AreEqual(svc.svcDebug._GetBladeStatus(hostIP, bladeAndParent.Key), GetBladeStatusResult.unused); } } }
public void willEnforceSharingWithVMs() { using (bladeDirectorDebugServices uut = new bladeDirectorDebugServices(WCFPath, new[] { "1.1.1.1", "1.1.1.2" })) { string hostipA = "192.168.1.1"; string hostipB = "192.168.1.2"; // Host A requests all the VMs vmHWAndSWSpec toAlloc = new vmHWAndSWSpec( new VMHardwareSpec() { memoryMB = 4, cpuCount = 1 }, new VMSoftwareSpec()); resultAndBladeName[] intialReqs = uut.svcDebug._requestAsManyVMAsPossible(hostipA, toAlloc.hw, toAlloc.sw); for (int index = 0; index < intialReqs.Length; index++) { intialReqs[index] = (resultAndBladeName)testUtils.waitForSuccess(uut, intialReqs[index], TimeSpan.FromMinutes(1)); } // Now B requests a VM resultAndBladeName reqFromB = uut.svcDebug._requestAnySingleVM(hostipB, toAlloc.hw, toAlloc.sw); Assert.AreEqual(resultCode.pending, reqFromB.result.code); // A should be asked to release a single VM, and does as it is told int releaseRequestCount = 0; foreach (resultAndBladeName req in intialReqs) { Debug.WriteLine(uut.svcDebug._GetVMStatus(hostipA, req.bladeName)); if (uut.svcDebug._GetVMStatus(hostipA, req.bladeName) == GetBladeStatusResult.releasePending) { resultAndWaitToken relWait = uut.svcDebug._ReleaseBladeOrVM(hostipA, req.bladeName, false); testUtils.waitForSuccess(uut, relWait, TimeSpan.FromSeconds(30)); releaseRequestCount++; } } Assert.AreEqual(1, releaseRequestCount); // Now, host B should have one VM. resultAndWaitToken newVM = testUtils.waitForSuccess(uut, reqFromB, TimeSpan.FromSeconds(30)); Assert.AreEqual(resultCode.success, newVM.result.code); } }