Пример #1
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);
        }