Exemple #1
0
        private void clearAll()
        {
            // We assume no-one else is using this FreeNAS server right now. We delete everything on it. >:D
            // We do, however, avoid deleting anything beginning with 'blade', so its sort-of safe to run this on
            // the production FreeNAS install, if no-one else is using it, and the only iscsi info you want to keep
            // begins with this string.

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

            foreach (iscsiTarget tgt in foo.getISCSITargets().Where(x => !x.targetName.StartsWith("blade")))
            {
                foo.deleteISCSITarget(tgt);
            }

            foreach (iscsiExtent ext in foo.getExtents().Where(x => !x.iscsi_target_extent_name.StartsWith("blade")))
            {
                foo.deleteISCSIExtent(ext);
            }

            foreach (iscsiTargetToExtentMapping tte in foo.getTargetToExtents())
            {
                var tgt = foo.getISCSITargets().SingleOrDefault(x => x.id == tte.iscsi_target);
                var ext = foo.getExtents().SingleOrDefault(x => x.id == tte.iscsi_extent);
                if (tgt == null || ext == null)
                {
                    foo.deleteISCSITargetToExtent(tte);
                }
            }

            foo.waitUntilISCSIConfigFlushed();
        }
Exemple #2
0
        public void canInvalidateThings()
        {
            // Here, we use a second FreeNAS instance to modify data on the server. We then invalidate the first, and ensure that
            // the differences are seen.
            string testPrefix = Guid.NewGuid().ToString();

            FreeNASWithCaching uut       = new FreeNASWithCaching(nashostname, nasusername, naspassword);
            FreeNAS            directNAS = new FreeNAS(nashostname, nasusername, naspassword);

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

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

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

            // The uut should now be out-of-date
            Assert.AreNotEqual(uut.getExtents().Count, directNAS.getExtents().Count);
            Assert.AreNotEqual(uut.getISCSITargets().Count, directNAS.getISCSITargets().Count);
            Assert.AreNotEqual(uut.getTargetToExtents().Count, directNAS.getTargetToExtents().Count);

            // Invalidate the uut and check that it is then up-to-date.
            uut.invalidateExtents();
            Assert.AreEqual(uut.getExtents().Count, directNAS.getExtents().Count);
            uut.invalidateTargets();
            Assert.AreEqual(uut.getISCSITargets().Count, directNAS.getISCSITargets().Count);
            uut.invalidateTargetToExtents();
            Assert.AreEqual(uut.getTargetToExtents().Count, directNAS.getTargetToExtents().Count);
        }
Exemple #3
0
        public void extentDeletionImpliesTTEDeletion()
        {
            string testPrefix = Guid.NewGuid().ToString();

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

            int origExtentCount = foo.getExtents().Count;
            int origTargetCount = foo.getISCSITargets().Count;
            int origTTECount    = foo.getTargetToExtents().Count;

            // Make a test file to export
            string filePath = nastempspace + "/" + testPrefix;

            using (SSHExecutor exec = new SSHExecutor(nashostname, nasusername, naspassword))
            {
                exec.startExecutable("touch", filePath);
            }

            iscsiTarget tgt1 = foo.addISCSITarget(new iscsiTarget()
            {
                targetName = testPrefix
            });
            iscsiExtent ext1 = foo.addISCSIExtent(new iscsiExtent()
            {
                iscsi_target_extent_name = testPrefix,
                iscsi_target_extent_type = "File",
                iscsi_target_extent_path = filePath
            });

            iscsiTargetToExtentMapping tte1 = foo.addISCSITargetToExtent(tgt1.id, ext1);

            foo.waitUntilISCSIConfigFlushed();

            foo.deleteISCSIExtent(ext1);

            Assert.AreEqual(origTTECount, foo.getTargetToExtents().Count());
            Assert.AreEqual(origTargetCount + 1, foo.getISCSITargets().Count());
            Assert.AreEqual(origExtentCount, foo.getExtents().Count());
        }