Exemplo n.º 1
0
        public void testDBObjectCanDoDelayedDisposalWhileUpgraded()
        {
            using (hostDB db = new hostDB())
            {
                bladeDirectorWCF.vmSpec toDB = new bladeDirectorWCF.vmSpec(db.conn, "1.1.1.3", bladeLockType.lockAll, bladeLockType.lockAll);
                db.addNode(toDB);

                using (lockableVMSpec refA = db.getVMByIP("1.1.1.3", bladeLockType.lockNone, bladeLockType.lockNone))
                {
                    using (new tempLockElevation(refA,
                                                 bladeLockType.lockVirtualHW,
                                                 bladeLockType.lockOwnership))
                    {
                        Assert.AreEqual(bladeLockType.lockIPAddresses | bladeLockType.lockVirtualHW | bladeLockType.lockOwnership, refA.spec.permittedAccessRead);
                        Assert.AreEqual(bladeLockType.lockOwnership, refA.spec.permittedAccessWrite);
                        refA.Dispose();
                        refA.inhibitNextDisposal();
                    }
                }

                // As a final check, make sure we can re-acquire the locks. This will make sure we didn't 'leak' any.
                using (lockableVMSpec refA = db.getVMByIP("1.1.1.3", bladeLockType.lockAll, bladeLockType.lockAll))
                {
                    // ..
                }
            }
        }
Exemplo n.º 2
0
        public void testDBObjectIsUpdatedFromDBOnPermissionUpgrade()
        {
            using (hostDB db = new hostDB())
            {
                bladeDirectorWCF.vmSpec toDB = new bladeDirectorWCF.vmSpec(db.conn, "1.1.1.2", bladeLockType.lockAll, bladeLockType.lockAll);
                db.addNode(toDB);

                using (lockableVMSpec refB = db.getVMByIP("1.1.1.2", bladeLockType.lockNone, bladeLockType.lockNone))
                {
                    Thread innerThread = new Thread(() =>
                    {
                        using (lockableVMSpec refA = db.getVMByIP("1.1.1.2", bladeLockType.lockNone,
                                                                  bladeLockType.lockVirtualHW | bladeLockType.lockOwnership))
                        {
                            refA.spec.friendlyName = "test data";
                            refA.spec.currentOwner = "Dave_Lister";
                        }
                    });
                    innerThread.Start();
                    innerThread.Join();

                    refB.upgradeLocks(bladeLockType.lockVirtualHW | bladeLockType.lockOwnership, bladeLockType.lockNone);
                    Assert.AreEqual("test data", refB.spec.friendlyName);
                    Assert.AreEqual("Dave_Lister", refB.spec.currentOwner);
                }
            }
        }
Exemplo n.º 3
0
        public void testDBObjectThrowsAfterDowngradeToReadOnlyAccess()
        {
            using (hostDB db = new hostDB())
            {
                bladeDirectorWCF.vmSpec toDB = new bladeDirectorWCF.vmSpec(db.conn, "1.1.1.4", bladeLockType.lockAll, bladeLockType.lockAll);
                db.addNode(toDB);

                // Lock with write access to a field, and then downgrade to read-only access. Then, try to write to the field we
                // originally locked, and expect an exception to be thrown.
                using (lockableVMSpec refA = db.getVMByIP("1.1.1.4", bladeLockType.lockNone,
                                                          bladeLockType.lockVirtualHW | bladeLockType.lockOwnership))
                {
                    refA.downgradeLocks(
                        bladeLockType.lockNone | bladeLockType.lockNone,
                        bladeLockType.lockVirtualHW | bladeLockType.lockOwnership);

                    // We have released the write lock, so we should be holding the read lock only.
                    Assert.AreEqual(bladeLockType.lockIPAddresses | bladeLockType.lockOwnership | bladeLockType.lockVirtualHW, refA.spec.permittedAccessRead);
                    Assert.AreEqual(bladeLockType.lockNone, refA.spec.permittedAccessWrite);

                    // We should not be permitted to write fields
                    failIfNoThrow(() => { refA.spec.friendlyName = "test data"; });
                    failIfNoThrow(() => { refA.spec.currentOwner = "Dave_Lister"; });
                    // but should be permitted to read them.
                    failIfThrow(() => { Debug.WriteLine(refA.spec.currentOwner); });
                    failIfThrow(() => { Debug.WriteLine(refA.spec.friendlyName); });
                }
            }
        }
Exemplo n.º 4
0
        public void testDBObjectFlushesToDBOnLockDowngrade()
        {
            using (hostDB db = new hostDB())
            {
                bladeDirectorWCF.vmSpec toDB = new bladeDirectorWCF.vmSpec(db.conn, "1.1.1.7", bladeLockType.lockAll, bladeLockType.lockAll);
                db.addNode(toDB);

                ManualResetEvent canCheckRefB = new ManualResetEvent(false);
                ManualResetEvent testEnded    = new ManualResetEvent(false);

                Thread innerThread = new Thread(() =>
                {
                    using (lockableVMSpec refA = db.getVMByIP("1.1.1.7", bladeLockType.lockNone,
                                                              bladeLockType.lockVirtualHW | bladeLockType.lockOwnership))
                    {
                        // Set some data, and then downgrade to a read-only lock.
                        // The data should be flushed to the DB at that point, so we set a ManualResetEvent and the main thread
                        // will check that the data has indeed been flushed, by reading from the DB.

                        refA.spec.friendlyName = "test data";
                        refA.spec.currentOwner = "Dave_Lister";

                        refA.downgradeLocks(
                            bladeLockType.lockNone | bladeLockType.lockNone,
                            bladeLockType.lockVirtualHW | bladeLockType.lockOwnership);

                        Assert.AreEqual(bladeLockType.lockIPAddresses | bladeLockType.lockOwnership | bladeLockType.lockVirtualHW, refA.spec.permittedAccessRead);
                        Assert.AreEqual(bladeLockType.lockNone, refA.spec.permittedAccessWrite);

                        canCheckRefB.Set();
                        testEnded.WaitOne();
                    }
                });
                innerThread.Start();
                canCheckRefB.WaitOne();
                try
                {
                    using (lockableVMSpec refB = db.getVMByIP("1.1.1.7",
                                                              bladeLockType.lockVirtualHW | bladeLockType.lockOwnership,
                                                              bladeLockType.lockNone))
                    {
                        Assert.AreEqual("Dave_Lister", refB.spec.currentOwner);
                        Assert.AreEqual("test data", refB.spec.friendlyName);
                    }
                }
                finally
                {
                    testEnded.Set();
                    innerThread.Join();
                }
            }
        }
Exemplo n.º 5
0
        public static hypervisor_vmware_FreeNAS createHypForVM(vmSpec vmSpec, bladeSpec vmServerSpec, snapshotDetails snapshotInfo, NASParams nas, clientExecutionMethod exec = clientExecutionMethod.smbWithWMI)
        {
            userDesc usernameToUse = vmSpec.credentials.First();

            return(new hypervisor_vmware_FreeNAS(
                       new hypSpec_vmware(
                           vmSpec.friendlyName, vmServerSpec.bladeIP, vmServerSpec.ESXiUsername, vmServerSpec.ESXiPassword,
                           usernameToUse.username, usernameToUse.password, snapshotInfo.friendlyName, snapshotInfo.path,
                           vmSpec.kernelDebugPort, vmSpec.kernelDebugKey, vmSpec.VMIP
                           ),
                       nas.IP, nas.username, nas.password,
                       exec));
        }
Exemplo n.º 6
0
        public lockableVMSpec createChildVM(SQLiteConnection conn, hostDB db, VMHardwareSpec reqhw, VMSoftwareSpec reqsw, string newOwner)
        {
            if ((permittedAccessRead & bladeLockType.lockVMCreation) == bladeLockType.lockNone)
            {
                throw new Exception("lockVMCreation is needed when calling .createChildVM");
            }

            vmserverTotals totals        = db.getVMServerTotals(this);
            int            indexOnServer = totals.VMs + 1;
            string         newBladeName  = xdlClusterNaming.makeVMName(bladeIP, indexOnServer);

            // If we set the debugger port automatically, make sure we reset it to zero before we return.
            bool needToResetReqSWDebugPort = false;

            if (reqsw.debuggerPort == 0)
            {
                reqsw.debuggerPort        = xdlClusterNaming.makeVMKernelDebugPort(bladeIP, indexOnServer);
                needToResetReqSWDebugPort = true;
            }

            vmSpec newVM = new vmSpec(conn, newBladeName, reqsw, bladeLockType.lockAll, bladeLockType.lockAll);

            newVM.parentBladeIP = bladeIP;
            newVM.state         = bladeStatus.inUseByDirector;
            newVM.currentOwner  = "vmserver"; // We own the blade until we are done setting it up
            newVM.nextOwner     = newOwner;
            newVM.parentBladeID = bladeID.Value;
            newVM.memoryMB      = reqhw.memoryMB;
            newVM.cpuCount      = reqhw.cpuCount;
            newVM.indexOnServer = indexOnServer;

            newVM.VMIP    = xdlClusterNaming.makeVMIP(bladeIP, newVM);
            newVM.iscsiIP = xdlClusterNaming.makeiSCSIIP(bladeIP, newVM);
            newVM.eth0MAC = xdlClusterNaming.makeEth0MAC(bladeIP, newVM);
            newVM.eth1MAC = xdlClusterNaming.makeEth1MAC(bladeIP, newVM);

            // VMs always have this implicit snapshot.
            newVM.currentSnapshot = "vm";

            if (needToResetReqSWDebugPort)
            {
                reqsw.debuggerPort = 0;
            }

            lockableVMSpec toRet = new lockableVMSpec(newVM.VMIP, bladeLockType.lockAll, bladeLockType.lockAll);

            toRet.setSpec(newVM);
            return(toRet);
        }
Exemplo n.º 7
0
        public void testDBObjectThrowsAfterUpgradeToWriteAccess()
        {
            using (hostDB db = new hostDB())
            {
                bladeDirectorWCF.vmSpec toDB = new bladeDirectorWCF.vmSpec(db.conn, "1.1.1.6", bladeLockType.lockAll, bladeLockType.lockAll);
                db.addNode(toDB);

                using (lockableVMSpec refA = db.getVMByIP("1.1.1.6", bladeLockType.lockNone, bladeLockType.lockNone))
                {
                    refA.upgradeLocks(
                        bladeLockType.lockVirtualHW | bladeLockType.lockOwnership,
                        bladeLockType.lockVirtualHW | bladeLockType.lockOwnership);

                    Assert.AreEqual(bladeLockType.lockIPAddresses | bladeLockType.lockOwnership | bladeLockType.lockVirtualHW, refA.spec.permittedAccessRead);
                    Assert.AreEqual(bladeLockType.lockOwnership | bladeLockType.lockVirtualHW, refA.spec.permittedAccessWrite);

                    failIfThrow(() => { refA.spec.friendlyName = "test data"; });
                    failIfThrow(() => { refA.spec.currentOwner = "Dave_Lister"; });
                    failIfThrow(() => { Debug.WriteLine(refA.spec.friendlyName); });
                    failIfThrow(() => { Debug.WriteLine(refA.spec.currentOwner); });
                }
            }
        }
Exemplo n.º 8
0
        public void testDBObjectThrowsAfterDowngradeToNoAccess()
        {
            using (hostDB db = new hostDB())
            {
                bladeDirectorWCF.vmSpec toDB = new bladeDirectorWCF.vmSpec(db.conn, "1.1.1.3", bladeLockType.lockAll, bladeLockType.lockAll);
                db.addNode(toDB);

                // Lock with write access to a field, and then downgrade to no access. Then, access the field we originally
                // locked, and expect an exception to be thrown.
                using (lockableVMSpec refA = db.getVMByIP("1.1.1.3", bladeLockType.lockNone,
                                                          bladeLockType.lockVirtualHW | bladeLockType.lockOwnership))
                {
                    refA.downgradeLocks(
                        bladeLockType.lockVirtualHW | bladeLockType.lockOwnership,
                        bladeLockType.lockVirtualHW | bladeLockType.lockOwnership);

                    Assert.AreEqual(bladeLockType.lockIPAddresses, refA.spec.permittedAccessRead);
                    Assert.AreEqual(bladeLockType.lockNone, refA.spec.permittedAccessWrite);

                    failIfNoThrow(() => { refA.spec.friendlyName = "test data"; });
                    failIfNoThrow(() => { refA.spec.currentOwner = "Dave_Lister"; });
                }
            }
        }
Exemplo n.º 9
0
 public hypervisor_mocked_vmware(vmSpec spec, bladeSpec parentSpec, hostStateManagerMocked.mockedExecutionDelegate onMockedExecution)
     : base(null, onMockedExecution)
 {
     _spec = new hypSpec_vmware(spec.friendlyName, parentSpec.bladeIP, Settings.Default.esxiUsername, Settings.Default.esxiPassword, Settings.Default.vmUsername, Settings.Default.vmPassword, spec.currentSnapshot, null, spec.kernelDebugPort, spec.kernelDebugKey, spec.VMIP);
 }
Exemplo n.º 10
0
 public static string makeVMIP(string bladeIP, vmSpec newVM)
 {
     byte[] VMServerIPBytes = IPAddress.Parse(bladeIP).GetAddressBytes();
     return("172.17." + (28 + VMServerIPBytes[3]) + "." + newVM.indexOnServer);
 }
Exemplo n.º 11
0
 public static string makeEth1MAC(string bladeIP, vmSpec newVM)
 {
     byte[] VMServerIPBytes = IPAddress.Parse(bladeIP).GetAddressBytes();
     return("00:50:56:01:" + (VMServerIPBytes[3] - 100).ToString("D2") + ":" + newVM.indexOnServer.ToString("D2"));
 }