public static void prepVM(hypervisor_vmware hypervisor) { hypervisor.connect(); hypervisor.powerOff(); hypervisor.restoreSnapshot(); hypervisor.powerOn(); }
public void init() { var s = Properties.Settings.Default; using (hypervisor_vmware hyp = new hypervisor_vmware(new hypSpec_vmware( s.NASVMName, s.NASVMServerHostname, s.NASVMServerUsername, s.NASVMServerPassword, nasusername, naspassword, "clean", null, 0, null, nashostname), clientExecutionMethod.SSHToBASH)) { // Restore the FreeNAS VM to a known-good state, power it on, and wait for it to boot. hyp.powerOff(); hyp.restoreSnapshot(); hyp.powerOn(); // Wait until boot has finished (this isn't a great way of checking, but oh well) while (true) { executionResult cronStatus = hyp.startExecutable("service", "cron status"); if (cronStatus.resultCode == 0) { break; } Thread.Sleep(TimeSpan.FromSeconds(2)); } var aa = hyp.startExecutable("service", "collectd stop"); var bb = hyp.startExecutable("service", "syslog-ng stop"); hyp.patchFreeNASInstallation(); } }
public static void doWorkingDirTest(clientExecutionMethod exec, string newWorkingDir) { using (hypervisor_vmware hyp = machinePools.vmware.createHypervisorForNextFreeVMOrWait(execType: exec)) { prepVM(hyp); executionResult res = hyp.startExecutable("cmd /c", "cd", newWorkingDir); Assert.AreEqual(newWorkingDir + "\r\n", res.stdout); } }
public static void doExecTest(clientExecutionMethod exec) { using (hypervisor_vmware hyp = machinePools.vmware.createHypervisorForNextFreeVMOrWait(execType: exec)) { prepVM(hyp); executionResult res = hyp.startExecutable("cmd.exe", "/c echo This is a test&&echo and stderr 1>&2 && exit /b 1234"); Assert.AreEqual("This is a test\r\n", res.stdout); Assert.AreEqual("and stderr \r\n", res.stderr); Assert.AreEqual(1234, res.resultCode); } }
private void onDestruction(hypSpec_vmware beingDestroyed) { lock (hypervisorSpecLock) { // Make a new hypervisor object, just so we can make sure the old blade is powered off. hypervisorWithSpec <hypSpec_vmware> VMBeingDestroyed = new hypervisor_vmware(beingDestroyed); { VMBeingDestroyed.powerOff(); } hypervisorSpecs[beingDestroyed] = false; } }
public hypervisor_vmware createHypervisorForNextFreeVMOrWait(string snapshotName = "clean", clientExecutionMethod execType = clientExecutionMethod.smbWithWMI, string bladeID = null, VMSource src = VMSource.configuredServer) { while (true) { hypervisor_vmware toRet = createHypervisorForNextFreeVMOrNull(snapshotName, execType, bladeID: bladeID, src: src); if (toRet != null) { return(toRet); } Thread.Sleep(TimeSpan.FromSeconds(5)); } }
public hypervisorCollection <hypSpec_vmware> createVMs(int VMsToAlloc, string snapshotName = "clean", clientExecutionMethod execType = clientExecutionMethod.smbWithWMI, VMSource src = VMSource.configuredServer, string bladeID = null) { hypervisorCollection <hypSpec_vmware> hyps = new hypervisorCollection <hypSpec_vmware>(); for (int i = 0; i < VMsToAlloc; i++) { hypervisor_vmware thisHyp = machinePools.vmware.createHypervisorForNextFreeVMOrNull(snapshotName, execType, src, bladeID); if (thisHyp == null) { break; } hyps.TryAdd(thisHyp.getConnectionSpec().kernelDebugIPOrHostname, thisHyp); } return(hyps); }
public hypervisor_vmware createHypervisorForNextFreeVMOrNull(string snapshotName = "clean", clientExecutionMethod execType = clientExecutionMethod.smbWithWMI, VMSource src = VMSource.configuredServer, string bladeID = null) { lock (hypervisorSpecLock) { populateSpecsIfNeeded(snapshotName, src); // Atomically find an unused VM, and mark it as in-use KeyValuePair <hypSpec_vmware, bool> hypKVP; lock (hypervisorSpecLock) { KeyValuePair <hypSpec_vmware, bool>[] selectedHyp = hypervisorSpecs.Where(x => x.Value == false).ToArray(); if (selectedHyp.Length == 0) { // Allocation failed return(null); } if (bladeID != null) { // We actually throw if a user filter returned nothing, for now. selectedHyp = selectedHyp.Where(x => x.Key.kernelVMServer.ToLower().Contains(bladeID.ToLower())).ToArray(); if (selectedHyp.Length == 0) { throw new Exception("XDL blade not found"); } } hypKVP = selectedHyp.First(); hypervisorSpecs[hypKVP.Key] = true; } try { hypervisor_vmware toRet = new hypervisor_vmware(hypKVP.Key, execType); toRet.setDisposalCallback(onDestruction); return(toRet); } catch (Exception) { lock (hypervisorSpecLock) { hypervisorSpecs[hypKVP.Key] = false; throw; } } } }
public static void doExecTestAsync(clientExecutionMethod exec) { using (hypervisor_vmware hyp = machinePools.vmware.createHypervisorForNextFreeVMOrWait(execType: exec)) { prepVM(hyp); IAsyncExecutionResult asyncRes = null; while (asyncRes == null) { asyncRes = hyp.startExecutableAsync("cmd.exe", "/c choice /t 5 /d y >nul & echo This is a test&echo and stderr 1>&2 & exit /b 1234"); } executionResult res = null; while (res == null) { res = asyncRes.getResultIfComplete(); Thread.Sleep(TimeSpan.FromSeconds(1)); } Assert.AreEqual("This is a test\r\n", res.stdout); Assert.AreEqual("and stderr \r\n", res.stderr); Assert.AreEqual(1234, res.resultCode); } }