diff options
Diffstat (limited to 'Libraries/ClientUtils/ATFClientUtils.py')
-rwxr-xr-x | Libraries/ClientUtils/ATFClientUtils.py | 213 |
1 files changed, 213 insertions, 0 deletions
diff --git a/Libraries/ClientUtils/ATFClientUtils.py b/Libraries/ClientUtils/ATFClientUtils.py new file mode 100755 index 0000000..e3a1bfe --- /dev/null +++ b/Libraries/ClientUtils/ATFClientUtils.py @@ -0,0 +1,213 @@ +#!/usr/bin/env python + +import re +import ATFUtils + +def create_mountpoint(mountname, **arguments): + """ + Description: + Create a Mount Point On the Client + + Parameter: + mountname: Name of the MountPoint + **arguments: key=value pair for specifying server, host, user + + Example: + mountname=mount1 + server=server1 + host=host1 + user=user1 + + Returns: + Success: 0 + Failure: 1 + """ + + command = "mkdir -p" + mountpoint = ATFUtils.TestEnvObj.get_mountpoint(mountname) + + if mountpoint == '': + ATFUtils.Logger.error("MountPoint: %s Not defined in GlobalParam File" + % mountname) + return 1 + else: + command = command + " " + mountpoint + + arguments['user'] = 'root' + status, stdin, stdout, stderr = ATFUtils.execute_command(command, + **arguments) + + if status == 1: + return 1 + else: + output = ATFUtils.parse_output(stdout, stderr) + return ATFUtils.set_environ(ATF_MOUNTPOINT = mountname) + +def umount(mountname, **arguments): + """ + Description: + Unmount a mount point + + Parameters: + mountname: Name of the mountpoint to unmount + **arguments: key=value pair for specifying server, host, user + + Example: + mountname=mount1 + server=server1 + host=host1 + user=user1 + + Returns: + Success: 0 + Failure: 1 + """ + + command = "umount" + + mountpoint = ATFUtils.TestEnvObj.get_mountpoint(mountname) + + if mountpoint == '': + ATFUtils.Logger.error("MountPoint: %s Not defined in GlobalParam File" + % mountname) + return 1 + else: + command = command + " " + mountpoint + + arguments['user'] = 'root' + status, stdin, stdout, stderr = ATFUtils.execute_command(command, + **arguments) + + if status == 1: + return 1 + else: + return ATFUtils.parse_output(stdout, stderr) + + +def mount(mountname, fstype, hostvolume, **arguments): + """ + Description: + Mount a filesystem + + Parameter: + mountname: Absolute Path of the mount point + fstype: FileSystem type + hostvolume: HostVolumeName to mount on mountpoint + **arguments: key=value pair for specifying host, user + + Returns: + Success: 0 + Failure: 1 + """ + + command = "mount" + mounttype = " -t " + fstype + command = command + mounttype + hostkey, volumekey = re.split(":", hostvolume) + + host = ATFUtils.TestEnvObj.get_host(hostkey) + if host == '': + ATFUtils.Logger.error("Host %s Not defined in GlobalParam File" % + hostkey) + return 1 + + volumename = ATFUtils.TestEnvObj.get_volume(volumekey) + if volumename == '': + ATFUtils.Logger.error("Volume %s Not defined in GlobalParam File" % + volumekey) + return 1 + + mountpoint = ATFUtils.TestEnvObj.get_mountpoint(mountname) + if mountpoint == '': + ATFUtils.Logger.error("MountPoint: %s Not defined in GlobalParam File" + % mountname) + return 1 + + hostvolume = host + ":" + volumename + command = command + " " + hostvolume + " " + mountpoint + arguments['user'] = 'root' + status, stdin, stdout, stderr = ATFUtils.execute_command(command, + **arguments) + + if status == 1: + return 1 + else: + return ATFUtils.parse_output(stdout, stderr) + + +def touch(filename, mountname='', **arguments): + """ + Description: + Creates a File. + + Parameters: + filename: Name of a file + mountname : Name of the MountPoint + **arguments: key=value pair for specifying host, user + + Returns: + Success: 0 + Failure: 1 + """ + + command = "touch" + + if mountname == '': + mountname = ATFUtils.get_environ('ATF_MOUNTPOINT') + if mountname == 1: + return 1 + + mountpoint = ATFUtils.TestEnvObj.get_mountpoint(mountname) + if mountpoint == '': + ATFUtils.Logger.error("MountPoint: %s Not defined in GlobalParam File" + % mountname) + return 1 + + abspath = mountpoint + "/" + filename + command = command + " " + abspath + status, stdin, stdout, stderr = ATFUtils.execute_command(command, + **arguments) + + if status == 1: + return 1 + else: + return ATFUtils.parse_output(stdout, stderr) + +def mkdir(dirname, mountname='', **arguments): + """ + Description: + Create a Directory under the mountpoint + + Parameters: + dirname: directory path (Relative path from the mount point) + mountname: Name of the Mount Point + **arguments: key=value pair for specifying host, user + + Returns: + Success: 0 + Failure: 1 + """ + + command = "mkdir" + + if mountname == '': + mountname = ATFUtils.get_environ('ATF_MOUNTPOINT') + if mountname == 1: + return 1 + + mountpoint = ATFUtils.TestEnvObj.get_mountpoint(mountname) + if mountpoint == '': + ATFUtils.Logger.error("MountPoint: %s Not defined in GlobalParam File" + % mountname) + return 1 + + abspath = mountpoint + "/" + dirname + command = command + " " + abspath + status, stdin, stdout, stderr = ATFUtils.execute_command(command, + **arguments) + + if status == 1: + return 1 + else: + return ATFUtils.parse_output(stdout, stderr) + |