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
|
"""clientutils module contains functions required for performing
certain operations on client
Supported Wrappers :-
-----------
*) umount
*) umountall
*) mount
*) mountall
"""
import atfutils
import hostutils
from atfutils import commands
from atfglobals import GlobalObj
def umount(mountkey):
"""unmounts a mountpoint
Parameters:
mountkey : name given to a mount as specified in testenv.cfg file.
Ex:-"mount1"
Returns:
Success : 0
Failure : 1`
"""
logger = GlobalObj.getLoggerObj()
output = atfutils.get_new_output_obj()
env = GlobalObj.getTestenvObj()
mount_obj = env.getMount(mountkey)
if not mount_obj:
logger.error("InValid Mount. '%s' not defined in TestEnvironment"
% mountkey)
output["exitstatus"] = 1
return output
clientkey = mount_obj.client
command = ' '.join([commands['umount'], mount_obj.dir])
output = hostutils.execute_command(clientkey, command)
assert_success_status = atfutils.assert_success(output['exitstatus'])
if assert_success_status is not 0:
stdoutdata = str(output["stdoutdata"])
if ((stdoutdata.rfind("not found")) or (stdoutdata.rfind("not mount"))):
output["exitstatus"] = 0
else:
logger.error("Unable to umount %s" % mountkey)
return output
def umountall():
"""unmounts all mount specified in testenv.cfg file.
Ex:- mount1, mount2 etc
Parameters:
None
Returns:
Success : 0
Failure : 1`
"""
umountall_output = atfutils.get_new_output_obj()
env = GlobalObj.getTestenvObj()
mounts_keys = env.getMountsKeys()
for mountkey in mounts_keys:
output = umount(mountkey)
assert_success_status = atfutils.assert_success(output['exitstatus'])
if assert_success_status is not 0:
return output
umountall_output["exitstatus"] = 0
umountall_output["stdoutdata"] = "Successful in unmounting all mounts"
return umountall_output
def mount(mountkey):
"""mounts a filesystem
Parameters:
mountkey : name given to a mount as specified in testenv.cfg file.
Ex:-"mount1"
Returns:
Success : 0
Failure : 1`
"""
logger = GlobalObj.getLoggerObj()
output = atfutils.get_new_output_obj()
env = GlobalObj.getTestenvObj()
mount_obj = env.getMount(mountkey)
if not mount_obj:
logger.error("InValid Mount. %s not defined in TestEnvironment"
% mountkey)
output["exitstatus"] = 1
return output
#mount command
command = [commands['mount']]
#mount type
command.extend(["-t", mount_obj.type])
#mount options if specified
if mount_obj.options:
command.extend(["-o", mount_obj.options])
#mount device
mountdevice_obj = mount_obj.device
device = mountdevice_obj.hostname + ":/" + mountdevice_obj.volumename
command.extend([device, mount_obj.dir])
command = ' '.join(command)
clientkey = mount_obj.client
#create mount directory
output = hostutils.mkdir(clientkey, mount_obj.dir)
assert_success_status = atfutils.assert_success(output["exitstatus"])
if assert_success_status is not 0:
return output
#execute mount command
output = hostutils.execute_command(clientkey, command)
return output
def mountall():
"""mounts a filesystem for all mounts specified in testenv.cfg file.
Parameters:
None
Returns:
Success : 0
Failure : 1`
"""
mountall_output = atfutils.get_new_output_obj()
env = GlobalObj.getTestenvObj()
mounts_keys = env.getMountsKeys()
for mountkey in mounts_keys:
output = mount(mountkey)
assert_success_status = atfutils.assert_success(output['exitstatus'])
if assert_success_status is not 0:
return output
mountall_output["exitstatus"] = 0
mountall_output["stdoutdata"] = "Successful in mounting all mounts"
return mountall_output
def md5sum_of_mount(mountkey):
"""
Parameter: mount (tye: string)
Returns: output of arequal-checksum command execution(type:dict)
Key : Value of the Output
exitstatus: exit status of the arequal-checksum command on mount
stdoutdata: stdout data of arequal-checksum command execution
stderrdata: stderr data of arequal-checksum command execution
"""
logger = GlobalObj.getLoggerObj()
output = atfutils.get_new_output_obj()
env = GlobalObj.getTestenvObj()
mount_obj = env.getMount(mountkey)
if not mount_obj:
logger.error("InValid Mount. %s not defined in TestEnvironment"
% mountkey)
output["exitstatus"] = 1
return output
clientkey = mount_obj.client
path = mount_obj.dir
output = hostutils.md5sum(clientkey, path)
return output
def md5sum_of_mounts(mounts):
"""
Description:
Calculate md5sum of mounts using arequal-checksum
Parameters: mounts (type: List)
Returns: md5sums of all the mounts (type: dict)
Keys: mounts
Value: ouput (type:dict)
exitstatus: exit status of the arequal-checksum command on mount
stdoutdata: stdout data of arequal-checksum command execution
stderrdata: stderr data of arequal-checksum command execution
"""
md5sums = {}
for mountkey in mounts:
output = md5sum_of_mount(mountkey)
md5sums[mountkey] = output
return md5sums
def execute_on_mount(mountkey, command, commandInput=None):
"""
"""
logger = GlobalObj.getLoggerObj()
output = atfutils.get_new_output_obj()
env = GlobalObj.getTestenvObj()
mount_obj = env.getMount(mountkey)
if not mount_obj:
logger.error("InValid Mount. %s not defined in TestEnvironment"
% mountkey)
output["exitstatus"] = 1
return output
clientkey = mount_obj.client
mountdir = mount_obj.dir
command = "cd %s ; %s" % (mountdir , command)
output = hostutils.execute_command(clientkey, command, commandInput)
return output
def execute_on_mounts(mounts, command, commandInput=None):
"""
"""
all_outputs = {}
for mountkey in mounts:
output = execute_on_mount(mountkey, command, commandInput)
all_outputs[mountkey] = output
return all_outputs
|