diff options
Diffstat (limited to 'Libraries/TestEnv/ATFTestEnv.py')
-rwxr-xr-x | Libraries/TestEnv/ATFTestEnv.py | 460 |
1 files changed, 460 insertions, 0 deletions
diff --git a/Libraries/TestEnv/ATFTestEnv.py b/Libraries/TestEnv/ATFTestEnv.py new file mode 100755 index 0000000..09c5b79 --- /dev/null +++ b/Libraries/TestEnv/ATFTestEnv.py @@ -0,0 +1,460 @@ +#!/usr/bin/env python + +######################################################################## +## TestEnv Class contains variables and methods for storing and retrieving +## information about the Test Environment. +## +## Variables: +## Hosts: List of Dictionaries. +## Each Dictionary contains {'name':name, 'host':host} +## information +## +## Users: List of Dictionaries +## Each Dictionary contains {'name':name, 'user':user} +## information +## +## Servers: List of Dictionaries. +## Each Dictionary contains {'name': name, 'host': host, +## 'user': user} information +## +## Clients: List of Dictionaries. +## Each Dictionary contains {'name': name, 'host': host, +## 'user': user} information +## +## ExportDirs: List of Dictionaries. +## Each Dictionary contains {'exportname': exportname, +## 'exportdir': exportdir} information +## +## ServersHostList: Unique List of Hosts derieved from Servers List +## +## ClientsHostList: Unique List of Hosts derieved from Clients List +## +## +######################################################################## + +class TestEnv(): + + + def __init__(self): + self.Hosts = [] + self.Users = [] + self.Servers = [] + self.Clients = [] + self.ExportDirs = [] + self.ServersHostList = [] + self.ClientsHostList = [] + self.MountPoints = [] + self.Volumes = [] + self.GlobalParamFile = '' + + def set_globalparamfile(self, filename): + """ + Description: + Sets GlobalParameter file name + + Parameter: + filename: Name of the GlobalParam File + + Returns: + """ + + self.GlobalParamFile = filename + return + + def get_globalparamfile(self): + """ + Description: + Return GlobalParamFileName + + Parameter: + None + + Returns: + GlobalParamFIleName + """ + + return self.GlobalParamFile + + def add_host(self, name, host): + """ + Description: + Add a host to Hosts List + + Parameters: + name: Name of the host Ex: host1, host2 + host: Address of the host Ex: 192.168.1.5 + + Return: + """ + + self.Hosts.append({'name': name, 'host': host}) + return + + def get_host(self, name): + """ + Description: + Return host with name 'name' + + Parameters: + name: Name of the host to return + + Returns: + Success: host + Failure: '' + """ + + output = '' + + for host in self.Hosts: + if host['name'] == name: + output = host['host'] + break + + return output + + def get_hostslist(self): + """ + Description: + Returns self.Servers List + Returns: + self.Servers + """ + + return self.Hosts + + def add_user(self, name, user): + """ + Description: + Add a user to Users List + + Parameters: + name: key to recognize a user Ex: user1/user2 + user: Username + + Return: + """ + + self.Users.append({'name': name, 'user': user}) + return + + def get_user(self, name): + """ + Description: + Return user with key 'name' + + Parameters: + name: key used to recognize the user + + Returns: + Success: user + Failure: '' + """ + + output = '' + + for user in self.Users: + if user['name'] == name: + output = user['user'] + break + + return output + + def add_server(self, name, hostkey, userkey): + """ + Description: + Add a server to Servers List + + Parameters: + name: Name of the server (Example: Server1/Server2) + host: IP Address of the server + user: Username of User on 'host' + + Returns: + Success: 0 + Failure: 1 + """ + + host = self.get_host(hostkey) + user = self.get_user(userkey) + + if host == '' or user == '': + ATFUtils.Logger.error("%s or %s Not Defined " % (hostkey, userkey)) + return 1 + + self.Servers.append({'name': name, 'host': host, 'user': user}) + return 0 + + def get_server(self, name): + """ + Description: + Returns [host, user] tuple for Server Name 'name' + + Parameters: + name: Name of the Server + + Returns: + Success: Returns [host, user] tuple + Failure: ['', ''] tuple + """ + + output = ['', ''] + + for server in self.Servers: + if server['name'] == name: + output = [server['host'], server['user']] + break + + return output + + def get_serverslist(self): + """ + Description: + Returns self.Servers List + + Parameters: + None + + Returns: + self.Servers + """ + + return self.Servers + + def add_client(self, name, hostkey, userkey): + """ + Description: + Add a client to Clients List + + Parameters: + name: Name of the client (Example: Client1/Client2) + host: IP Address of the client + user: Username of User on 'host' + + Returns: + Success: 0 + Failure: 1 + """ + + host = self.get_host(hostkey) + user = self.get_user(userkey) + + if host == '' or user == '': + ATFUtils.Logger.error("%s or %s Not Defined " % (hostkey, userkey)) + return 1 + + self.Clients.append({'name': name, 'host': host, 'user': user}) + return 0 + + def get_client(self, name): + """ + Description: + Returns [host, user] tuple for Client Name 'name' + + Parameters: + name: Name of the Client + + Returns: + Success: Returns [host, user] tuple + Failure: ['', ''] tuple + """ + + output = ['', ''] + + for client in self.Clients: + if client['name'] == name: + output = [client['host'], client['user']] + break + + return output + + def get_clientslist(self): + """ + Description: + Returns self.Clients List + + Parameters: + None + + Returns: + self.Clients + """ + + return self.Clients + + def add_exportdir(self, exportname, dirname): + """ + Description: + Add a Export Directory to the Export Directory List + + Parameters: + exportname: Name of a Export Directory(Example: export1/export2) + dirname: Absolute Path of the Export DIrecotry + + Returns: + """ + + self.ExportDirs.append({'exportname': exportname, 'dirname': dirname}) + return + + def get_exportdir(self, exportname): + """ + Description: + Return Dir Name of the Export Directory Name 'exportname' + + Parameters: + exportname: Name of a Export Directory + + Returns: + Success: Absolute Path of Export DIrectory + Failure: '' + """ + + output = '' + + for exportdir in self.ExportDirs: + if exportdir['exportname'] == exportname: + output = exportdir['dirname'] + break + + return output + + def add_mountpoint(self, mountname, dirname): + """ + Description: + Add a Mount Point to the MountPoint List + + Parameters: + mountname: Name of a MountPoint(Example: mount1/mount2) + dirname: Absolute Path of the Mount Point + + Returns: + """ + + self.MountPoints.append({'mountname': mountname, 'dirname': dirname}) + return + + def get_mountpoint(self, mountname): + """ + Description: + Return MountPoint with Name 'mountname' + + Parameters: + mountname: Name of a MountPoint + + Returns: + Success: Absolute Path of MountPoint + Failure: '' + """ + + output = '' + + for mountpoint in self.MountPoints: + if mountpoint['mountname'] == mountname: + output = mountpoint['dirname'] + break + + return output + + def add_volume(self, volumekey, volumename): + """ + Description: + Add a Volume to Volumes List + + Parameters: + volumekey: key used to recognize the volumename Ex: volume1 + volumename: Volume Name Ex: Replicate_Volume + + Returns: + """ + + self.Volumes.append({'volumekey': volumekey, 'volumename': volumename}) + return + + def get_volume(self, volumekey): + """ + Description: + Returns Volumename with Volumekey 'volumekey' + + Parameters: + volumekey: VolumeKey + + Returns: + Success: Volumename + Failure: '' + """ + + output = '' + + for volume in self.Volumes: + if volume['volumekey'] == volumekey: + output = volume['volumename'] + break + + return output + + def create_servershostlist(self): + """ + Description: + Creats a Unique List of Hosts from the Servers List + + Parameters: + None + + Returns: + """ + + for server in self.Servers: + host = server['host'] + + if host not in self.ServersHostList: + self.ServersHostList.append(host) + + return + + def create_clientshostlist(self): + """ + Description: + Creats a Unique List of Hosts from the Clients List + + Parameters: + None + + Returns: + """ + + for client in self.Clients: + host = client['host'] + + if host not in self.ClientsHostList: + self.ClientsHostList.append(host) + + return + + def get_servershostlist(self): + """ + Description: + Returns ServersHostList + + Parameters: + None + + Returns: + Return ServersHostList + """ + + return self.ServersHostList + + def get_clientshostlist(self): + """ + Description: + Returns ClientsHostList + + Parameters: + None + + Returns: + Return ClientsHostList + """ + + return self.ClientsHostList + |