Beispiel #1
0
        private void copyDeploymentFilesToBlade(lockableBladeSpec nodeSpec, string biosConfigFile, cancellableDateTime deadline)
        {
            using (hypervisor hyp = _hostManager.makeHypervisorForBlade_LTSP(nodeSpec))
            {
                Dictionary <string, string> toCopy = new Dictionary <string, string>
                {
                    { "applyBIOS.sh", Resources.applyBIOS.Replace("\r\n", "\n") },
                    { "getBIOS.sh", Resources.getBIOS.Replace("\r\n", "\n") },
                    { "conrep.xml", Resources.conrep_xml.Replace("\r\n", "\n") }
                };
                if (biosConfigFile != null)
                {
                    toCopy.Add("newbios.xml", biosConfigFile.Replace("\r\n", "\n"));
                }

                foreach (KeyValuePair <string, string> kvp in toCopy)
                {
                    hypervisor.doWithRetryOnSomeExceptions(() => { hyp.copyToGuestFromBuffer(kvp.Key, kvp.Value); },
                                                           deadline, TimeSpan.FromSeconds(10));
                }
                // And copy this file specifically as binary.
                hypervisor.doWithRetryOnSomeExceptions(() =>
                {
                    hyp.copyToGuestFromBuffer("conrep", Resources.conrep);
                }, deadline, TimeSpan.FromSeconds(10));
            }
        }
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 executionResult callMockedExecutionHandler(hypervisor sender, string command, string args, string workingdir, cancellableDateTime deadline)
        {
            string commandLine = command + " " + args;

            if (executedCommands.Contains(commandLine))
            {
                return(base.callMockedExecutionHandler(sender, commandLine, args, workingdir, deadline));
            }

            throw new hypervisorExecutionException("Injected fault");
        }
Beispiel #4
0
        private bool ensureISCSIInterfaceIsSetUp(hypervisor hyp, string srcAddress, cancellableDateTime deadline)
        {
            executionResult res;

            // First, add our portgroup
            res = hypervisor.doWithRetryOnSomeExceptions(() => hyp.startExecutable("esxcli", "network vswitch standard portgroup add -p vlan11_iscsi -v vSwitch1"));
            if (res.resultCode != 0)
            {
                return(false);
            }
            // And then give the portgroup an address.
            res = hypervisor.doWithRetryOnSomeExceptions(() => hyp.startExecutable(
                                                             "esxcfg-vmknic", "--add --ip " + srcAddress + " --netmask 255.255.0.0 vlan11_iscsi", deadline: deadline));
            if (res.resultCode != 0)
            {
                return(false);
            }

            // Finally, tag it for management traffic. For this, we'll need to get the adaptor name for this portgroup.
            res = hypervisor.doWithRetryOnSomeExceptions(() => hyp.startExecutable("esxcfg-vmknic", "--list", deadline: deadline));
            if (res.resultCode != 0)
            {
                return(false);
            }
            string[] lines       = res.stdout.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            string   adaptorName = null;

            foreach (var line in lines)
            {
                string[] fields = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (fields[1] == "vlan11_iscsi")
                {
                    adaptorName = fields[0];
                    break;
                }
            }
            if (adaptorName == null)
            {
                return(false);
            }

            res = hypervisor.doWithRetryOnSomeExceptions(() => hyp.startExecutable(
                                                             "esxcli", "network ip interface tag add -i " + adaptorName + " -t Management", deadline: deadline));
            if (res.resultCode != 0)
            {
                return(false);
            }

            return(true);
        }
Beispiel #5
0
        public override executionResult callMockedExecutionHandler(hypervisor sender, string command, string args, string workingdir, cancellableDateTime deadline)
        {
            string commandLine = command + " " + args;

            switch (commandLine)
            {
            case "bash ~/applyBIOS.sh":
                return(new executionResult("bios stuff", "", 0));

            case "esxcfg-nas -l":
                return(new executionResult("esxivms is /mnt/SSDs/esxivms from 10.0.255.254 mounted available", null, 0));

            case @"C:\windows\system32\cmd /c shutdown -s -f -t 01":
                sender.powerOff();
                return(new executionResult("", "", 0));
            }

            if (commandLine.StartsWith("vim-cmd vmsvc/power.off `vim-cmd vmsvc/getallvms | grep"))
            {
                return(new executionResult("", null, 0));
            }
            if (commandLine.StartsWith("vim-cmd vmsvc/unregister `vim-cmd vmsvc/getallvms"))
            {
                return(new executionResult("", null, 0));
            }
            if (commandLine.StartsWith("rm  -rf /vmfs/volumes/esxivms/"))
            {
                return(new executionResult("", null, 0));
            }
            if (commandLine.StartsWith("cp  -R /vmfs/volumes/esxivms/PXETemplate /vmfs/volumes/esxivms/"))
            {
                return(new executionResult("", null, 0));
            }
            if (commandLine.StartsWith("sed  -e "))
            {
                return(new executionResult("", null, 0));
            }
            if (commandLine.StartsWith("vim-cmd  solo/registervm /vmfs/volumes/esxivms/"))
            {
                return(new executionResult("", null, 0));
            }
            if (commandLine.StartsWith("cmd.exe /c c:\\deployed.bat "))
            {
                return(new executionResult("", null, 0));
            }

            throw new Exception("executed unexpected command " + commandLine);
        }
        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 override void mountDataStore(hypervisor hyp, string srcAddress, string dataStoreName, string serverName, string mountPath, cancellableDateTime deadline)
        {
            while (ensureISCSIInterfaceIsSetUp(hyp, srcAddress, deadline) == false)
            {
                deadline.doCancellableSleep(TimeSpan.FromSeconds(5));
            }

            string expectedLine = String.Format("{0} is {1} from {2} mounted available", dataStoreName, mountPath, serverName);

            string[] nfsMounts  = hypervisor.doWithRetryOnSomeExceptions(() => hyp.startExecutable("esxcfg-nas", "-l")).stdout.Split(new[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);
            string   foundMount = nfsMounts.SingleOrDefault(x => x.Contains(expectedLine));

            while (foundMount == null)
            {
                hypervisor.doWithRetryOnSomeExceptions(() => hyp.startExecutable("esxcfg-nas", "-d " + dataStoreName, deadline: deadline));
                hypervisor.doWithRetryOnSomeExceptions(() => hyp.startExecutable("esxcfg-nas", "-a --host " + serverName + " --share " + mountPath + " " + dataStoreName, deadline: deadline));
                hypervisor.doWithRetryOnSomeExceptions(() => hyp.startExecutable("esxcfg-rescan", "--all", deadline: deadline));

                nfsMounts  = hypervisor.doWithRetryOnSomeExceptions(() => hyp.startExecutable("esxcfg-nas", "-l", deadline: deadline)).stdout.Split(new[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);
                foundMount = nfsMounts.SingleOrDefault(x => x.Contains(expectedLine));

                deadline.throwIfTimedOutOrCancelled("While trying to mount NFS");
            }
        }
Beispiel #8
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 #9
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);
                    }
                }
            }
        }
 public abstract void mountDataStore(hypervisor hyp, string srcAddress, string dataStoreName, string serverName, string mountPath, cancellableDateTime deadline);
Beispiel #11
0
 private executionResult callMockedExecutionHandler(hypervisor sender, string command, string args, string workingdir, cancellableDateTime deadline)
 {
     return(handler.callMockedExecutionHandler(sender, command, args, workingdir, deadline));
 }
Beispiel #12
0
 protected override void waitForESXiBootToComplete(hypervisor hyp, cancellableDateTime deadline)
 {
 }
Beispiel #13
0
 public abstract executionResult callMockedExecutionHandler(hypervisor sender, string command, string args, string workingdir, cancellableDateTime deadline);
Beispiel #14
0
 public override executionResult callMockedExecutionHandler(hypervisor sender, string command, string args, string workingdir, cancellableDateTime deadline)
 {
     Thread.Sleep(TimeSpan.FromSeconds(10));
     return(base.callMockedExecutionHandler(sender, command, args, workingdir, deadline));
 }
Beispiel #15
0
 public override void mountDataStore(hypervisor hyp, string vmServerBladeIpAddressISCSI, string dataStoreName, string serverName, string mountPath, cancellableDateTime deadline)
 {
     // TODO: store somewhere
 }