From 1811ec9c6177feebff19e5e02a1b26a942d3dcf8 Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 10 Aug 2011 13:16:43 +0530 Subject: Bug 3374 - [CIFS] updating volume with a non-existent user succeeds. Added checks to find non-existing user/s Moved CIFS_VOLUME_FILE, CIFS_USER_FILE, DEFAULT_UID to Globals.py Added getCifsUserUid function into Utils.py Fixed typo in grun.py --- .../WebContent/scripts/create_volume_cifs_all.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/com.gluster.storage.management.gateway/WebContent/scripts/create_volume_cifs_all.py') diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/create_volume_cifs_all.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/create_volume_cifs_all.py index 70b84e6b..59e74bed 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/create_volume_cifs_all.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/create_volume_cifs_all.py @@ -11,30 +11,28 @@ if not p1 in sys.path: sys.path.append(p1) if not p2 in sys.path: sys.path.append(p2) +import Globals import Utils -cifsVolumeFile = "/opt/glustermg/etc/volumes.cifs" - - def addVolumeCifsConf(volumeName, userList): try: - fp = open(cifsVolumeFile) + fp = open(Globals.CIFS_VOLUME_FILE) content = fp.read() fp.close() except IOError, e: - Utils.log("failed to read file %s: %s" % (cifsVolumeFile, str(e))) + Utils.log("failed to read file %s: %s" % (Globals.CIFS_VOLUME_FILE, str(e))) content = "" try: - fp = open(cifsVolumeFile, "w") + fp = open(Globals.CIFS_VOLUME_FILE, "w") for line in content.split(): if line.split(":")[0] != volumeName: fp.write("%s\n" % line) fp.write("%s:%s\n" % (volumeName, ":".join(userList))) fp.close() except IOError, e: - Utils.log("failed to write file %s: %s" % (cifsVolumeFile, str(e))) + Utils.log("failed to write file %s: %s" % (Globals.CIFS_VOLUME_FILE, str(e))) return False return True @@ -48,6 +46,15 @@ def main(): volumeName = sys.argv[2] userList = sys.argv[3:] + missingUserList = [] + for userName in userList: + if not Utils.getCifsUserUid(userName): + missingUserList.append(userName) + + if missingUserList: + sys.stderr.write("User %s does not exists\n" % missingUserList) + sys.exit(1) + rv = Utils.runCommand(["grun.py", serverFile, "create_volume_cifs.py", volumeName] + userList) if rv == 0: if not addVolumeCifsConf(volumeName, userList): -- cgit