Beispiel #1
0
        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();
            }
        }
Beispiel #2
0
        private void _SetBIOS(biosThreadState state)
        {
            // SCP some needed files to it.
            copyDeploymentFilesToBlade(state.blade, state.biosxml, state.connectDeadline);

            // And execute the command to deploy the BIOS via SSH.
            using (hypervisor hyp = _hostManager.makeHypervisorForBlade_LTSP(state.blade))
            {
                executionResult res = hyp.startExecutable("bash", "~/applyBIOS.sh");
                if (res.resultCode != 0)
                {
                    string msg = string.Format("Executing applyBIOS.sh on {0} resulted in error code {1}", state.nodeIP, res.resultCode);
                    msg += "stdout: " + res.stdout;
                    msg += "stderr: " + res.stderr;
                    _hostManager.addLogEvent(msg);
                    state.result = new result(resultCode.genericFail, msg);
                }
                else
                {
                    _hostManager.addLogEvent(string.Format("Deployed BIOS successfully to {0}", state.nodeIP));

                    using (var tmp = new tempLockElevation(state.blade, bladeLockType.lockNone, bladeLockType.lockBIOS))
                    {
                        _hostManager.markLastKnownBIOS(state.blade, state.biosxml);
                    }

                    state.result = new result(resultCode.success);
                }

                // All done, now we can power off and return.
                hyp.powerOff(state.connectDeadline);
            }

            state.isFinished = true;
        }
Beispiel #3
0
        public override IAsyncExecutionResult startExecutableAsync(string toExecute, string args, string workingDir = null)
        {
            events.Add(new mockedCall("startExecutableAsync", "toExecute: '" + toExecute + "' args: '" + args + "'" + " working dir: '" + (workingDir ?? "<null>") + "'"));

            executionResult res = _onMockedExecution.Invoke(this, toExecute, args, workingDir);

            return(new asycExcecutionResult_mocked(res));
        }
 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);
     }
 }
        protected override void waitForESXiBootToComplete(hypervisor hyp, cancellableDateTime deadline)
        {
            while (true)
            {
                executionResult res = hypervisor.doWithRetryOnSomeExceptions(
                    () => hyp.startExecutable("/etc/init.d/vpxa", "status"), deadline, TimeSpan.FromSeconds(1));

                if (res.resultCode != 0)
                {
                    deadline.doCancellableSleep(TimeSpan.FromSeconds(4));
                    continue;
                }

                if (res.stdout.Contains("vpxa is running"))
                {
                    return;
                }
            }
        }
Beispiel #7
0
        public void canExportAFile()
        {
            string testPrefix = Guid.NewGuid().ToString();

            FreeNASWithCaching foo = new FreeNASWithCaching(nashostname, nasusername, naspassword);

            // Make a test file to export
            using (SSHExecutor exec = new SSHExecutor(nashostname, nasusername, naspassword))
            {
                exec.startExecutable("touch", nastempspace + "/testfile");
            }
            // Add some targets, extents, target-to-extents, and watch the time taken.
            iscsiTarget tgt = foo.addISCSITarget(new iscsiTarget()
            {
                targetName = testPrefix, targetAlias = testPrefix
            });

            foo.createTargetGroup(foo.getPortals()[0], tgt);
            iscsiExtent ext = foo.addISCSIExtent(new iscsiExtent()
            {
                iscsi_target_extent_name = testPrefix,
                iscsi_target_extent_type = "File",
                iscsi_target_extent_path = nastempspace + "/testfile"
            });

            foo.addISCSITargetToExtent(tgt.id, ext);
            foo.waitUntilISCSIConfigFlushed();

            // Check that ctld has exported the file as we asked
            using (SSHExecutor exec = new SSHExecutor(nashostname, nasusername, naspassword))
            {
                executionResult res = exec.startExecutable("ctladm", "portlist");
                Assert.AreEqual(0, res.resultCode);

                string[] lines = res.stdout.Split('\n');
                Assert.AreEqual(1, lines.Count(x => x.Contains(testPrefix + ",")));
            }
        }
        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);
            }
        }
Beispiel #9
0
        private void _GetBIOS(biosThreadState state)
        {
            copyDeploymentFilesToBlade(state.blade, null, state.connectDeadline);

            using (hypervisor hyp = _hostManager.makeHypervisorForBlade_LTSP(state.blade))
            {
                executionResult res = hyp.startExecutable("bash", "~/getBIOS.sh");
                if (res.resultCode != 0)
                {
                    string msg = string.Format("Executing getBIOS.sh on {0} resulted in error code {1}", state.nodeIP, res.resultCode);
                    msg += "stdout: " + res.stdout;
                    msg += "stderr: " + res.stderr;
                    _hostManager.addLogEvent(msg);
                    state.result = new result(resultCode.genericFail, msg);
                }
                else
                {
                    string msg = string.Format("Deployed BIOS successfully to {0}", state.nodeIP);
                    _hostManager.addLogEvent(msg);
                    state.result = new result(resultCode.success, msg);
                }

                // Retrieve the output
                state.biosxml = hyp.getFileFromGuest("currentbios.xml", state.connectDeadline);

                // All done, now we can power off and return.
                hyp.powerOff(state.connectDeadline);
            }

            using (var tmp = new tempLockElevation(state.blade, bladeLockType.lockNone, bladeLockType.lockBIOS))
            {
                _hostManager.markLastKnownBIOS(state.blade, state.biosxml);
            }

            state.isFinished = true;
        }
Beispiel #10
0
        public void willAllowManyExportsAtOnce()
        {
            clearAll();
            FreeNASWithCaching foo = new FreeNASWithCaching(nashostname, nasusername, naspassword);

            //
            // Here we export many files (targets/extents/ttes) from ctld. Eventually, the kernel will hit CTL_MAX_PORTS and things
            // will fail. We ensure that this number is high enough that we are unlikely to have any problems.
            //

            // Make some test files to export
            string        testPrefix       = Guid.NewGuid().ToString();
            int           maxfiles         = 10000;
            int           maxFilesPossible = 0;
            List <string> uncheckedExports = new List <string>(10);

            using (SSHExecutor exec = new SSHExecutor(nashostname, nasusername, naspassword))
            {
                exec.startExecutable("/bin/sh", string.Format("-c " +
                                                              "'for a in `seq 0 {0}`; do touch {1}/testfile_${{a}}; done'", maxfiles, nastempspace));

                // Add some targets, extents, target-to-extents, and see how many we add before they stop working.
                // This is likely to be 256 for a 'factory' image, or 2048 for an XDL-customised image. Note, though,
                // that if you're using a small root partition on the FreeNAS box (which you should be, imo, because
                // a large amount of space encourages issues like this one to go unnoticed until they subtly degrade
                // performance later - and wear out the media, if root is on sdcard, which it is on store.xd.lan),
                // you may run out of space if collectd is not stopped. You can confirm this by observing that
                // collectd's dir in /var/db/collectd/rrd is huge.

                int preExisting = foo.getTargetToExtents().Count;
                for (int i = preExisting; i < maxfiles; i++)
                {
                    iscsiTarget tgt = foo.addISCSITarget(new iscsiTarget()
                    {
                        targetName = testPrefix + "-" + i
                    });
                    foo.createTargetGroup(foo.getPortals()[0], tgt);
                    iscsiExtent ext = foo.addISCSIExtent(new iscsiExtent()
                    {
                        iscsi_target_extent_name = testPrefix + "_" + i,
                        iscsi_target_extent_type = "File",
                        iscsi_target_extent_path = nastempspace + "/testfile_" + i
                    });

                    foo.addISCSITargetToExtent(tgt.id, ext);

                    uncheckedExports.Add(tgt.targetName);

                    if (i % 100 == 0)
                    {
                        // Every hundred, we reload and see if each has been exported correctly.
                        Stopwatch watch = new Stopwatch();
                        watch.Start();
                        bool limitReached = false;
                        try
                        {
                            foo.waitUntilISCSIConfigFlushed();
                        }
                        catch (nasServerFullException)
                        {
                            // ok cool, we've reached our limit.
                            limitReached = true;
                        }
                        //Thread.Sleep(1000 + (i * 10));
                        watch.Stop();
                        Debug.WriteLine("Flush after adding " + i + " exports: took " + watch.ElapsedMilliseconds + " ms");

                        executionResult res = exec.startExecutable("ctladm", "portlist -f iscsi");
                        Assert.AreEqual(0, res.resultCode);

                        // Each of our unchecked testfiles should appear exactly once in this list.
                        // If not, we know we've reached the limit of what the kernel can support.
                        string[] lines = res.stdout.Split('\n');
                        for (int uncheckedIndex = 0; uncheckedIndex < uncheckedExports.Count; uncheckedIndex++)
                        {
                            var exportToCheck = uncheckedExports[uncheckedIndex];

                            if (lines.Count(x => x.Contains(exportToCheck + ",")) != 1)
                            {
                                // Oh, we've failed to export something!
                                maxFilesPossible  = i - uncheckedIndex;
                                maxFilesPossible -= 2;
                                i = maxfiles;
                                break;
                            }
                        }
                        if (limitReached)
                        {
                            maxFilesPossible = i;
                            break;
                        }
                        uncheckedExports.Clear();
                    }
                }
            }
            // Our XDL build has CTL_MAX_PORTS set to 2048, so this should be very high.
            Assert.IsTrue(maxFilesPossible >= 2048, "maxFilesPossible is " + maxFilesPossible + " which is less than 2048");
        }
Beispiel #11
0
        public TimeSpan canExportNewFilesQuickly(string testPrefix, int newExportsCount)
        {
            // FIXME: use testprefix for filenames

            Stopwatch timer = new Stopwatch();

            timer.Start();
            FreeNASWithCaching foo = new FreeNASWithCaching(nashostname, nasusername, naspassword);

            timer.Stop();
            Debug.WriteLine("Instantiation took " + timer.ElapsedMilliseconds + " ms");

            // Make some test files to export
            using (SSHExecutor exec = new SSHExecutor(nashostname, nasusername, naspassword))
            {
                for (int i = 0; i < newExportsCount; i++)
                {
                    exec.startExecutable("touch", nastempspace + "/testfile_" + i);
                }
            }
            // Add some targets, extents, target-to-extents, and watch the time taken.
            timer.Restart();
            int flushesBefore = foo.flushCount;

            for (int i = 0; i < newExportsCount; i++)
            {
                iscsiTarget tgt = foo.addISCSITarget(new iscsiTarget()
                {
                    targetName = testPrefix + "-" + i
                });
                foo.createTargetGroup(foo.getPortals()[0], tgt);
                iscsiExtent ext = foo.addISCSIExtent(new iscsiExtent()
                {
                    iscsi_target_extent_name = testPrefix + "_" + i,
                    iscsi_target_extent_type = "File",
                    iscsi_target_extent_path = nastempspace + "/testfile_" + i
                });

                foo.addISCSITargetToExtent(tgt.id, ext);
            }
            timer.Stop();
            int flushesAfter = foo.flushCount;

            Debug.WriteLine("Adding " + newExportsCount + " target, extents, and target-to-extent records took " + timer.ElapsedMilliseconds + " ms and required " +
                            (flushesAfter - flushesBefore) + " flushes");
            Assert.IsTrue(timer.Elapsed < TimeSpan.FromSeconds(15));

            timer.Restart();
            foo.waitUntilISCSIConfigFlushed();
            timer.Stop();

            // Check that ctld has exported the files as we asked
            using (SSHExecutor exec = new SSHExecutor(nashostname, nasusername, naspassword))
            {
                executionResult res = exec.startExecutable("ctladm", "portlist");
                Assert.AreEqual(0, res.resultCode);
                // Each of our testfiles should appear exactly once in this list.
                string[] lines = res.stdout.Split('\n');
                for (int i = 0; i < newExportsCount; i++)
                {
                    try
                    {
                        Assert.AreEqual(1, lines.Count(x => x.Contains(testPrefix + "-" + i + ",")));
                    }
                    catch (AssertFailedException)
                    {
                        Debug.Write(res.stdout);
                        Debug.Write(res.stderr);
                        throw;
                    }
                }
            }

            return(timer.Elapsed);
        }
Beispiel #12
0
        public void willProvisionBlade()
        {
            using (bladeDirectorDebugServices svc = new bladeDirectorDebugServices(basicBladeTests.WCFPath, basicBladeTests.WebURI))
            {
                machinePools.bladeDirectorURL = svc.servicesURL;

                string hostip = "1.2.3.4";
                //string debuggerHost = testUtils.getBestRouteTo(IPAddress.Parse("172.17.129.131")).ToString();

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

                resultAndBladeName res = svc.svcDebug._RequestAnySingleNode(hostip);
                testUtils.waitForSuccess(svc, res, TimeSpan.FromMinutes(15));

                string             bladeName = res.bladeName;
                resultAndWaitToken res2      = svc.svcDebug._selectSnapshotForBladeOrVM(hostip, bladeName, "discord");
                testUtils.waitForSuccess(svc, res2, TimeSpan.FromMinutes(30));

                // Okay, we have our blade allocated now.
                bladeSpec       createdBlade = svc.svc.getBladeByIP_withoutLocking(bladeName);
                snapshotDetails snap         = svc.svc.getCurrentSnapshotDetails(bladeName);
                NASParams       nas          = svc.svc.getNASParams();
                using (hypervisor foo = utils.createHypForBlade(createdBlade, snap, nas))
                {
                    foo.powerOn(new cancellableDateTime(TimeSpan.FromMinutes(5)));

                    // Check that debugging has been provisioned correctly
                    executionResult bcdEditRes = foo.startExecutable("bcdedit", "/dbgsettings");
                    try
                    {
                        Assert.AreEqual(0, bcdEditRes.resultCode);
                        Assert.IsTrue(Regex.IsMatch(bcdEditRes.stdout, "key\\s*xdl.hacks.the.planet"), "bcdedit did not match regex for debug key");
                        Assert.IsTrue(Regex.IsMatch(bcdEditRes.stdout, "debugtype\\s*NET"), "bcdedit did not match regex for debug type");
                        Assert.IsTrue(Regex.IsMatch(bcdEditRes.stdout, "hostip\\s*1.2.3.4"), "bcdedit did not match regex for debug host");
                        Assert.IsTrue(Regex.IsMatch(bcdEditRes.stdout, "port\\s*53101"), "bcdedit did not match regex for debug port");
                    }
                    catch (AssertFailedException)
                    {
                        Debug.WriteLine("return code " + bcdEditRes.resultCode);
                        Debug.WriteLine("stdout " + bcdEditRes.stdout);
                        Debug.WriteLine("stderr " + bcdEditRes.stderr);
                    }

                    executionResult getNameRes = foo.startExecutable("echo %COMPUTERNAME%", "");
                    try
                    {
                        Assert.AreEqual(0, getNameRes.resultCode);
                        Assert.AreSame(getNameRes.stdout.ToLower(), "newBlade".Trim().ToLower(), "machine name was incorrect");
                    }
                    catch (AssertFailedException)
                    {
                        Debug.WriteLine("return code " + bcdEditRes.resultCode);
                        Debug.WriteLine("stdout " + bcdEditRes.stdout);
                        Debug.WriteLine("stderr " + bcdEditRes.stderr);
                    }
                }
            }
        }
Beispiel #13
0
        public void willProvisionManyVM()
        {
            using (bladeDirectorDebugServices svc = new bladeDirectorDebugServices(basicBladeTests.WCFPath, basicBladeTests.WebURI))
            {
                machinePools.bladeDirectorURL = svc.servicesURL;

                // Create four blades, and request a load of VMs from them.
                List <bladeSpec> specs = new List <bladeSpec>();
                for (int bladeID = 28; bladeID < 32; bladeID++)
                {
                    specs.Add(svc.svcDebug.createBladeSpecForXDLNode(bladeID, "xdl.hacks.the.planet", bladeLockType.lockAll, bladeLockType.lockAll));
                }
                svc.svcDebug.initWithBladesFromBladeSpec(specs.ToArray(), false, NASFaultInjectionPolicy.retunSuccessful);

                // Ask for lots of VMs. We will get back only those that 'fit' on the cluster.
                List <VMSpec> requestedVMSpecs = new List <VMSpec>();
                foreach (bladeSpec thisBlade in specs)
                {
                    string debuggerHost = ipUtils.getBestRouteTo(IPAddress.Parse(thisBlade.bladeIP)).ToString();

                    // Add fifty VMs for each blade. Don't forget, we will only get those that
                    // 'fit' on the cluster.
                    for (int vmCount = 0; vmCount < 50; vmCount++)
                    {
                        requestedVMSpecs.Add(new VMSpec()
                        {
                            hw = new VMHardwareSpec()
                            {
                                cpuCount = 1, memoryMB = 2048
                            },
                            sw = new VMSoftwareSpec()
                            {
                                debuggerHost = debuggerHost,
                                debuggerKey  = "a.b.c.d",
                                debuggerPort = 0    // auto
                            }
                        });
                    }
                }

                using (hypervisorCollection <hypSpec_vmware> vms = machinePools.ilo.requestVMs(requestedVMSpecs.ToArray(), true))
                {
                    // Okay, we have our new VMs allocated now. Lets verify them all.
                    // Make a list of the created computer names and debug ports, since they are different for each request, and
                    // make sure that they are all different and in the expected range.
                    List <int>    debugPorts   = new List <int>();
                    List <string> displayNames = new List <string>();
                    // We test each VM in parallel, otherwise things are reaaaally slow.
                    List <Thread> VMTestThreads = new List <Thread>();
                    foreach (hypervisorWithSpec <hypSpec_vmware> hyp in vms.Values)
                    {
                        Thread vmTest = new Thread(() =>
                        {
                            hyp.powerOn(new cancellableDateTime(TimeSpan.FromMinutes(10)));

                            // 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*127.0.0.1"));
                                // verify port assignment and extract the port
                                Match m = Regex.Match(bcdEditRes.stdout, "port\\s*([0-9]+)", RegexOptions.IgnoreCase);
                                Assert.IsTrue(m.Success);
                                int port = Int32.Parse(m.Groups[1].Value);
                                debugPorts.Add(port);
                            }
                            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":
                                        displayNames.Add(value);
                                        break;

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

                                    case "totalphysicalmemory":
                                        Assert.AreEqual("2144903168", value, "RAM size is incorrect");
                                        break;

                                    default:
                                        break;
                                    }
                                }
                            }
                            catch (AssertFailedException)
                            {
                                Debug.WriteLine("WMIC reported stdout '" + wmicRes.stdout + "'");
                                Debug.WriteLine("WMIC reported stderr '" + wmicRes.stderr + "'");
                            }
                        });
                        VMTestThreads.Add(vmTest);
                        vmTest.Start();
                    }

                    // Wait for them all to run
                    foreach (Thread vmtask in VMTestThreads)
                    {
                        vmtask.Join();
                    }

                    // Now we can verify the contents of the name/port arrays we made.

                    try
                    {
                        // All computers should have unique names
                        Assert.AreEqual(displayNames.Count, displayNames.Distinct().Count());
                        // And should follow this pattern
                        Assert.IsTrue(displayNames.All(x => x.StartsWith("vm_")));
                    }
                    catch (AssertFailedException)
                    {
                        foreach (string displayName in displayNames)
                        {
                            Debug.WriteLine("Machine name: '" + displayName + "'");
                        }
                        throw;
                    }

                    try
                    {
                        // All computers should have unique debug ports
                        Assert.AreEqual(debugPorts.Count, debugPorts.Distinct().Count());
                        // And should follow this pattern
                        Assert.IsTrue(debugPorts.All(x => x > 52800));
                        Assert.IsTrue(debugPorts.All(x => x < 63200));
                    }
                    catch (AssertFailedException)
                    {
                        Debug.WriteLine("Machine debug ports:");
                        foreach (string debugPort in displayNames)
                        {
                            Debug.WriteLine(debugPort);
                        }
                        throw;
                    }
                }
            }
        }
Beispiel #14
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 + "'");
                    }
                }
            }
        }
Beispiel #15
0
 public asycExcecutionResult_mocked(executionResult res)
 {
     _res = res;
 }