1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
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
|