Пример #1
0
        public void DeleteShare()
        {
            ws.AddSharePermission("Everyone");

            Assert.IsTrue(ws.Exists());
            Assert.IsTrue(WindowsShare.GetShares().Any(s => s == ws.ShareName));

            ws.DeleteShare();

            Assert.IsFalse(ws.Exists());
            Assert.IsFalse(WindowsShare.GetShares().Any(s => s == ws.ShareName));

            ws = null;
            string contentsRead = File.ReadAllText(@"\\localhost\" + shareName + @"\test.txt");
        }
Пример #2
0
        public void Setup()
        {
            tempPath = Path.GetTempPath();
            shareName = DateTime.Now.Ticks.ToString();
            shareForderPath = Directory.CreateDirectory(Path.Combine(tempPath, shareName)).FullName;
            testFileContent = "this is a test";
            File.WriteAllText(Path.Combine(shareForderPath, "test.txt"), testFileContent);

            ws = WindowsShare.CreateShare(shareName, shareForderPath);

            username = Uhuru.Utilities.Credentials.GenerateCredential();
            password = "******";

            decoratedUsername = Uhuru.Utilities.WindowsVCAPUsers.CreateDecoratedUser(username, password);
        }
Пример #3
0
        private void InstanceSystemSetup(ProvisionedService provisionedService)
        {
            string name = provisionedService.Name;
            string user = provisionedService.User;
            string password = provisionedService.Password;
            string directory = this.GetInstanceDirectory(name);
            int port = provisionedService.Port.Value;

            try
            {
                DateTime start = DateTime.Now;
                Logger.Debug(Strings.SqlNodeCreateDatabaseDebugMessage, provisionedService.SerializeToJson());

                // The group and users have to be recreated if the box was recreated by bosh.
                // In that case only the file system resrouces remain. Every system
                // resource of configuration has to be provisioned again.
                //
                // Create the group and user if necessary
                if (!WindowsUsersAndGroups.ExistsGroup(name))
                {
                    Logger.Info("Creating window group: {0}, for instance {1}", name, name);
                    CreateInstanceGroup(name);

                    // Add group permissions to directory
                    // TODO: stefi: consider cleaning up orphan users and groups
                    Logger.Info("Adding group permissions for directory: {0}", directory);
                    AddDirectoryPermissions(directory, name);

                    if (!WindowsUsersAndGroups.ExistsUser(user))
                    {
                        Logger.Info("Creating user: {0}, for instance {1}", user, name);
                        CreateInstanceUser(name, user, password);
                        AddInstanceUserToGroup(name, user);
                    }
                }

                // create the vhd if necessary
                if (this.useVhd)
                {
                    string vhdDirectory = Path.Combine(this.baseDir, name);
                    string vhd = Path.Combine(this.baseDir, name + ".vhd");

                    if (!VHDUtilities.IsMountPointPresent(vhdDirectory))
                    {
                        Logger.Info("Mounting VHD: {0}, at: {1}, for instance {2}", vhd, vhdDirectory, name);
                        VHDUtilities.MountVHD(vhd, vhdDirectory);
                    }
                }

                if (this.useFsrm)
                {
                    Logger.Info("Setting up windows FSRM for instance: {0}, with quota size: {1} MB", name, this.maxStorageSizeMB);
                    this.dirAccounting.SetDirectoryQuota(directory, this.maxStorageSizeMB * 1024 * 1024);
                }

                // create ftp service if necessary
                if (!FtpUtilities.Exists(name))
                {
                    Logger.Info("Creating ftp site for instance: {0}, at: {1}, with port: {2}", name, directory, port);
                    FtpUtilities.CreateFtpSite(name, directory, port);
                }

                if (!FtpUtilities.HasGroupAccess(name, name))
                {
                    // Add group permissions to ftp share
                    Logger.Info("Adding group permission for ftp site for instance: {0}", name);
                    FtpUtilities.AddGroupAccess(name, name);
                }

                // create the windows share with necessary permission
                var ws = new WindowsShare(name);
                if (!ws.Exists())
                {
                    Logger.Info("Creating windows share for instance: {0}, at: {1}", name, directory);
                    ws = WindowsShare.CreateShare(name, directory);
                }

                if (!ws.HasPermission(name))
                {
                    // Add group permissions to windows share
                    Logger.Info("Adding group permission for windows share for instance: {0}", name);
                    ws.AddSharePermission(name);
                }

                Logger.Debug("Done setting up instance {0}. Took {1}s.", provisionedService.SerializeToJson(), (start - DateTime.Now).TotalSeconds);
            }
            catch (Exception ex)
            {
                Logger.Error("Cloud not setup instance {0}. Exception {1}.", provisionedService.SerializeToJson(), ex.ToString());
            }
        }
Пример #4
0
 public void Teardown()
 {
     if (ws != null)
     {
         ws.DeleteShare();
         ws = null;
     }
     if (username != null)
     {
         Uhuru.Utilities.WindowsVCAPUsers.DeleteDecoratedBasedUser(username);
     }
 }
Пример #5
0
        private bool InstanceCleanup(ProvisionedService provisionedService)
        {
            bool success = true;

            string name = provisionedService.Name;

            try
            {
                Logger.Info(Strings.SqlNodeDeletingDatabaseInfoMessage, name);

                // Try delete ftp site.
                try
                {
                    FtpUtilities.DeleteFtpSite(name);
                }
                catch (Exception ex)
                {
                    success = false;
                    Logger.Error("Unable to delete FTP site for instance {0}. Exception: {1}", name, ex.ToString());
                }

                // Try delete windows share.
                try
                {
                    WindowsShare ws = new WindowsShare(name);
                    ws.DeleteShare();
                }
                catch (Exception ex)
                {
                    success = false;
                    Logger.Error("Unable to delete Windows Share for instance {0}. Exception: {1}", name, ex.ToString());
                }

                // Try delete directory quota.
                try
                {
                    string directory = this.GetInstanceDirectory(name);
                    if (this.useFsrm)
                    {
                        this.dirAccounting.RemoveDirectoryQuota(directory);
                    }
                }
                catch (Exception ex)
                {
                    success = false;
                    Logger.Error("Unable to delete directory quota rule for instance {0}. Exception: {1}", name, ex.ToString());
                }

                if (!this.useVhd)
                {
                    // Try delete instance directory
                    try
                    {
                        string directory = this.GetInstanceDirectory(name);
                        Directory.Delete(directory, true);
                    }
                    catch (Exception ex)
                    {
                        success = false;
                        Logger.Error("Unable to delete instance directory for instance {0}. Exception: {1}", name, ex.ToString());
                    }
                }

                if (this.useVhd)
                {
                    string vhdDirectory = Path.Combine(this.baseDir, name);
                    string vhd = Path.Combine(this.baseDir, name + ".vhd");

                    // Try unmount VHD
                    try
                    {
                        VHDUtilities.UnmountVHD(vhd);
                    }
                    catch (Exception ex)
                    {
                        success = false;
                        Logger.Error("Unable to un-mount VHD {0} for instance {1}. Exception: {2}", vhd, name, ex.ToString());
                    }

                    // Try delete VHD
                    try
                    {
                        File.Delete(vhd);
                    }
                    catch (Exception ex)
                    {
                        success = false;
                        Logger.Error("Unable to delete VHD file {0} for instance {1}. Exception: {2}", vhd, name, ex.ToString());
                    }

                    // Try delete mount dir
                    try
                    {
                        // Do not use recursive. The directory should be empty.
                        // If the dir contains data, some users data may be lost
                        Directory.Delete(vhdDirectory, false);
                    }
                    catch (Exception ex)
                    {
                        success = false;
                        Logger.Error("Unable to delete VHD file {0} for instance {1}. Exception: {2}", vhd, name, ex.ToString());
                    }
                }

                // Try delete the user
                try
                {
                    DeleteInstanceUser(provisionedService.User);
                }
                catch (Exception ex)
                {
                    success = false;
                    Logger.Error("Unable to delete user {0} for instance {1}. Exception: {2}", provisionedService.User, name, ex.ToString());
                }

                // Try delete the group
                try
                {
                    DeleteInstanceGroup(name);
                }
                catch (Exception ex)
                {
                    success = false;
                    Logger.Error("Unable to delete group {0} for instance {1}. Exception: {2}", name, name, ex.ToString());
                }
            }
            catch (Exception ex)
            {
                success = false;
                Logger.Fatal(Strings.SqlNodeCannotDeleteDBFatalMessage, ex.ToString());
            }

            return success;
        }